ref #7268 Hard-code P2 update site and remove from preferences
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 19 Feb 2018 10:34:17 +0000 (11:34 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 19 Feb 2018 10:34:25 +0000 (11:34 +0100)
 - update site is derived from the build version (nightly or stable)

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/P2Util.java

index dcc0a844975d89f94012e46936682899cc187cc3..41a39d2482151237a267a319de008634df75bb18 100644 (file)
@@ -13,7 +13,6 @@ import org.eclipse.equinox.p2.repository.IRepositoryManager;
 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
 import org.eclipse.equinox.p2.ui.ProvisioningUI;
 
-import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.util.ApplicationUtil;
@@ -35,14 +34,9 @@ import eu.etaxonomy.taxeditor.util.ApplicationUtil;
  */
 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";
 
@@ -52,30 +46,13 @@ public class P2Util {
      */
     @SuppressWarnings("restriction")
     public static void setP2UpdateRepositories() {
-        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;
-        }
         List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
-        List<MetadataRepositoryElement> savedRepoElements = PreferencesUtil.getP2Repositories();
-        if(savedRepoElements.isEmpty()) {
-            // we always need an update site, so we add the default one
-            try {
-                MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
-                element.setNickname(updateSiteName);
-                repoElements.add(element);
-            } catch (URISyntaxException e) {
-                MessagingUtils.errorDialog("Invalid update site URI",
-                        P2Util.class,
-                        "The update site URI has an invalid syntax",
-                        TaxonomicEditorPlugin.PLUGIN_ID,
-                        e,
-                        false);
-            }
-        }
+        List<MetadataRepositoryElement> savedRepoElements = new ArrayList<>();
+
+        MetadataRepositoryElement mre = new MetadataRepositoryElement(null, getP2UpdateRepository(), true);
+        mre.setNickname(getP2UpdateRepositoryName());
+        savedRepoElements.add(mre);
+
         repoElements.addAll(savedRepoElements);
 
         ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
@@ -83,6 +60,19 @@ public class P2Util {
 
     }
 
+    public static String getP2UpdateRepositoryName(){
+        return ApplicationUtil.isStable()?EDIT_STABLE_UPDATE_SITE_NAME:EDIT_NIGHTLY_UPDATE_SITE_NAME;
+    }
+
+    public static URI getP2UpdateRepository(){
+        try {
+            return ApplicationUtil.isStable()?new URI(EDIT_STABLE_UPDATE_SITE):new URI(EDIT_NIGHTLY_UPDATE_SITE);
+        } catch (URISyntaxException e) {
+            MessagingUtils.error(P2Util.class, e);
+        }
+        return null;
+    }
+
     /**
      * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
      * in preferences does not create a preference store and hence the changes are not saved. This means