]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/management/install/InstallerUtil.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / install / InstallerUtil.java
index 029a0dc249e19440b9a4c4896dfb347e1c858e7b..a3ac072d51f4ccb1a6834ca04b5d2caa7735073c 100644 (file)
-package org.simantics.project.management.install;\r
-\r
-import java.io.IOException;\r
-\r
-import org.eclipse.core.runtime.IPath;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.core.runtime.IStatus;\r
-import org.eclipse.core.runtime.SubMonitor;\r
-import org.eclipse.equinox.internal.provisional.p2.installer.InstallAdvisor;\r
-import org.eclipse.equinox.internal.provisional.p2.installer.InstallDescription;\r
-import org.eclipse.equinox.p2.core.IProvisioningAgent;\r
-import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;\r
-import org.eclipse.equinox.p2.core.ProvisionException;\r
-import org.eclipse.equinox.p2.core.UIServices;\r
-import org.osgi.framework.BundleContext;\r
-import org.osgi.framework.ServiceReference;\r
-import org.simantics.project.management.P2Util;\r
-import org.simantics.project.management.TrustAllCertificates;\r
-\r
-/**\r
- * P2 installer util.\r
- * \r
- * Heavily inspired by org.eclipse.equinox.p2.installer project.\r
- * \r
- * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
- */\r
-public class InstallerUtil {\r
-\r
-       private static final String SYS_PROP_INSTALL_DESCRIPTION = "org.eclipse.equinox.p2.installDescription";\r
-       \r
-       public static IStatus install(InstallAdvisor advisor, InstallDescription description, IProgressMonitor monitor) throws Exception {\r
-               if (advisor == null)\r
-                       advisor = getDefaultAdvisor();\r
-               if (description == null)\r
-                       description = getDefaultDescription(SubMonitor.convert(monitor));\r
-\r
-               advisor.prepareInstallDescription(description);\r
-               IProvisioningAgent agent = startAgent(description);             \r
-               \r
-               InstallUpdateProductOperation operation = new InstallUpdateProductOperation(agent, description);\r
-               \r
-               IStatus status = advisor.performInstall(operation);\r
-               if (!status.isOK()) {\r
-//                     ShowMessage.showStatus(status);\r
-               }\r
-               advisor.setResult(status);\r
-               advisor.stop();\r
-               agent.stop();\r
-               return status;\r
-       }\r
-       \r
-       public static InstallDescription getDefaultDescription(SubMonitor monitor) throws Exception {\r
-               String site = System.getProperty(SYS_PROP_INSTALL_DESCRIPTION);\r
-               return InstallDescriptionParser.createDescription(site, monitor);\r
-               \r
-       }\r
-       \r
-       public static InstallAdvisor getDefaultAdvisor() {\r
-               InstallAdvisor advisor = new DefaultInstallAdvisor();\r
-               advisor.start();\r
-               return advisor;\r
-       }\r
-       \r
-       public static IProvisioningAgent startAgent(InstallDescription description) throws Exception {\r
-               IPath installLocation = description.getInstallLocation();\r
-               if (installLocation == null)\r
-                       throw new Exception("No install location");\r
-               \r
-               try {\r
-                       // Create recruiter\r
-                       IProvisioningAgentProvider provider = P2Util.getProvisioningAgentProvider();\r
-                       \r
-                       // Set agent location if specified. Contains P2 install data\r
-                       IPath agentLocation = description.getAgentLocation();\r
-                       \r
-                       // Recruit Agent - Permission to provision\r
-                       IProvisioningAgent agent = provider.createAgent(agentLocation == null ? null : agentLocation.toFile().toURI());\r
-                       \r
-                       // Omit "This bundle is not certified" dialog.                  \r
-                       UIServices serviceUI = new TrustAllCertificates();\r
-                       agent.registerService("org.eclipse.equinox.p2.core.UIServices", serviceUI);\r
-                       \r
-                       \r
-                       return agent;\r
-               } catch (ProvisionException e) {\r
-                       throw new Exception("Cannot create agent", e);\r
-               }\r
-       }\r
-\r
-       \r
-       /**\r
-        * Copied from ServiceHelper because we need to obtain services\r
-        * before p2 has been started.\r
-        */\r
-       public static Object getService(BundleContext context, String name) {\r
-               if (context == null)\r
-                       return null;\r
-               ServiceReference reference = context.getServiceReference(name);\r
-               if (reference == null)\r
-                       return null;\r
-               Object result = context.getService(reference);\r
-               context.ungetService(reference);\r
-               return result;\r
-       }\r
-       \r
-       \r
-       public static void launchProduct(InstallDescription description) throws Exception {\r
-               IPath installLocation = description.getInstallLocation();\r
-               IPath toRun = installLocation.append(description.getLauncherName());\r
-               try {\r
-                       Runtime.getRuntime().exec(toRun.toString(), null, installLocation.toFile());\r
-               } catch (IOException e) {\r
-                       throw new Exception("Lanuching an app failed", e);\r
-               }\r
-\r
-       }\r
-}\r
+package org.simantics.project.management.install;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.equinox.internal.provisional.p2.installer.InstallAdvisor;
+import org.eclipse.equinox.internal.provisional.p2.installer.InstallDescription;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.core.UIServices;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.simantics.project.management.P2Util;
+import org.simantics.project.management.TrustAllCertificates;
+
+/**
+ * P2 installer util.
+ * 
+ * Heavily inspired by org.eclipse.equinox.p2.installer project.
+ * 
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
+ */
+public class InstallerUtil {
+
+       private static final String SYS_PROP_INSTALL_DESCRIPTION = "org.eclipse.equinox.p2.installDescription";
+       
+       public static IStatus install(InstallAdvisor advisor, InstallDescription description, IProgressMonitor monitor) throws Exception {
+               if (advisor == null)
+                       advisor = getDefaultAdvisor();
+               if (description == null)
+                       description = getDefaultDescription(SubMonitor.convert(monitor));
+
+               advisor.prepareInstallDescription(description);
+               IProvisioningAgent agent = startAgent(description);             
+               
+               InstallUpdateProductOperation operation = new InstallUpdateProductOperation(agent, description);
+               
+               IStatus status = advisor.performInstall(operation);
+               if (!status.isOK()) {
+//                     ShowMessage.showStatus(status);
+               }
+               advisor.setResult(status);
+               advisor.stop();
+               agent.stop();
+               return status;
+       }
+       
+       public static InstallDescription getDefaultDescription(SubMonitor monitor) throws Exception {
+               String site = System.getProperty(SYS_PROP_INSTALL_DESCRIPTION);
+               return InstallDescriptionParser.createDescription(site, monitor);
+               
+       }
+       
+       public static InstallAdvisor getDefaultAdvisor() {
+               InstallAdvisor advisor = new DefaultInstallAdvisor();
+               advisor.start();
+               return advisor;
+       }
+       
+       public static IProvisioningAgent startAgent(InstallDescription description) throws Exception {
+               IPath installLocation = description.getInstallLocation();
+               if (installLocation == null)
+                       throw new Exception("No install location");
+               
+               try {
+                       // Create recruiter
+                       IProvisioningAgentProvider provider = P2Util.getProvisioningAgentProvider();
+                       
+                       // Set agent location if specified. Contains P2 install data
+                       IPath agentLocation = description.getAgentLocation();
+                       
+                       // Recruit Agent - Permission to provision
+                       IProvisioningAgent agent = provider.createAgent(agentLocation == null ? null : agentLocation.toFile().toURI());
+                       
+                       // Omit "This bundle is not certified" dialog.                  
+                       UIServices serviceUI = new TrustAllCertificates();
+                       agent.registerService("org.eclipse.equinox.p2.core.UIServices", serviceUI);
+                       
+                       
+                       return agent;
+               } catch (ProvisionException e) {
+                       throw new Exception("Cannot create agent", e);
+               }
+       }
+
+       
+       /**
+        * Copied from ServiceHelper because we need to obtain services
+        * before p2 has been started.
+        */
+       public static Object getService(BundleContext context, String name) {
+               if (context == null)
+                       return null;
+               ServiceReference reference = context.getServiceReference(name);
+               if (reference == null)
+                       return null;
+               Object result = context.getService(reference);
+               context.ungetService(reference);
+               return result;
+       }
+       
+       
+       public static void launchProduct(InstallDescription description) throws Exception {
+               IPath installLocation = description.getInstallLocation();
+               IPath toRun = installLocation.append(description.getLauncherName());
+               try {
+                       Runtime.getRuntime().exec(toRun.toString(), null, installLocation.toFile());
+               } catch (IOException e) {
+                       throw new Exception("Lanuching an app failed", e);
+               }
+
+       }
+}