eu.etaxonomy.taxeditor.product, eu.etaxonomy.taxeditor.feature/feature.xml, eu.etaxon...
[taxeditor.git] / eu.etaxonomy.taxeditor.application / src / main / java / eu / etaxonomy / taxeditor / update / P2Util.java
index f73213854e72a1acd50b58567735a5a93e2038e2..e666929acc0b96365cf295874c7fdef93a2c2738 100644 (file)
@@ -10,11 +10,14 @@ import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.IJobChangeEvent;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
+import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
 import org.eclipse.equinox.p2.core.IProvisioningAgent;
 import org.eclipse.equinox.p2.operations.ProvisioningJob;
 import org.eclipse.equinox.p2.operations.ProvisioningSession;
 import org.eclipse.equinox.p2.operations.Update;
 import org.eclipse.equinox.p2.operations.UpdateOperation;
+import org.eclipse.equinox.p2.ui.ProvisioningUI;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.PlatformUI;
 import org.osgi.framework.BundleContext;
@@ -46,17 +49,37 @@ public class P2Util {
 
     //private static String LOCAL_UPDATE_SITE = "file:///path/.../to/Development/EDIT/taxeditor/eu.etaxonomy.taxeditor/target/repository/";
     private static String EDIT_NIGHTLY_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
+    private static String EDIT_NIGHTLY_UPDATE_SITE_NAME = "Taxonomic Editor Nightly";
+
     private static String EDIT_SNAPSHOT_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/snapshot/";
+    private static String EDIT_SNAPSHOT_UPDATE_SITE_NAME = "Taxonomic Editor Snapshot";
+
     private static String EDIT_STABLE_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
+    private static String EDIT_STABLE_UPDATE_SITE_NAME = "Taxonomic Editor Stable";
 
-    public static void setUpdateRepositories(UpdateOperation operation) throws URISyntaxException {
+    @SuppressWarnings("restriction")
+    public static void setDefaultUpdateRepositories() {
         String updateSite = EDIT_NIGHTLY_UPDATE_SITE;
+        String updateSiteName = EDIT_NIGHTLY_UPDATE_SITE_NAME;
+
         if(ApplicationUtil.isStable()) {
             updateSite = EDIT_STABLE_UPDATE_SITE;
+            updateSiteName = EDIT_STABLE_UPDATE_SITE_NAME;
         }
-        operation.getProvisioningContext().setMetadataRepositories(new URI[]{new URI(updateSite)});
-        operation.getProvisioningContext().setArtifactRepositories(new URI[]{new URI(updateSite)});
-    }
+        try {
+          final MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
+          element.setNickname(updateSiteName);
+          ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),new MetadataRepositoryElement[] {element}, null);
+        } catch (URISyntaxException e) {
+            MessagingUtils.errorDialog("Invalid update site URI",
+                    P2Util.class,
+                    "The update site URI has an invalid syntax",
+                    TaxonomicEditorPlugin.PLUGIN_ID,
+                    e,
+                    false);
+        }
+      }
+
     /**
      *
      *
@@ -110,17 +133,17 @@ public class P2Util {
         // which installable units are being updated, use the more detailed
         // constructors.
         final UpdateOperation operation = new UpdateOperation(session);
-        try {
-            setUpdateRepositories(operation);
-        } catch (URISyntaxException e) {
-            MessagingUtils.errorDialog("Invalid update site URI",
-                    operation,
-                    "The update site URI has an invalid syntax",
-                    TaxonomicEditorPlugin.PLUGIN_ID,
-                    e,
-                    false);
-            return null;
-        }
+//        try {
+//            setUpdateRepositories(operation);
+//        } catch (URISyntaxException e) {
+//            MessagingUtils.errorDialog("Invalid update site URI",
+//                    operation,
+//                    "The update site URI has an invalid syntax",
+//                    TaxonomicEditorPlugin.PLUGIN_ID,
+//                    e,
+//                    false);
+//            return null;
+//        }
 
         final IStatus status = operation.resolveModal(monitor);