ref #7268, #6913 Remove p2 related code
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 May 2018 12:08:37 +0000 (14:08 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 15 May 2018 14:25:06 +0000 (16:25 +0200)
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/TaxonomicEditorPlugin.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/P2Util.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/InstallNewSoftwareHandler.java [deleted file]
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/PreloadingRepositoryHandler.java [deleted file]

index 79b4a8fde90b26d08b4844a924b75ee74788a988..04ca7b60995411e5e20c3ab5a96642bd59be4a44 100644 (file)
@@ -15,7 +15,6 @@ import org.eclipse.ui.application.WorkbenchWindowAdvisor;
 import org.eclipse.ui.internal.WorkbenchWindow;
 
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
-import eu.etaxonomy.taxeditor.handler.update.P2Util;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 import eu.etaxonomy.taxeditor.util.ApplicationUtil;
@@ -73,13 +72,7 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
             CdmStore.connect();
         }
 
-               P2Util.setP2UpdateRepositories();
-
        }
 
-       @Override
-    public void postWindowClose() {
-        P2Util.saveP2RepositoryPreferences();
-    }
 }
 
index 3d2a3330d82d3d416643d716e1bde9c1dbd5ff97..5aab8ba505f864ffb7144935d69e0ecf99618c98 100644 (file)
@@ -1,16 +1,10 @@
 package eu.etaxonomy.taxeditor;
 
 import org.apache.log4j.Logger;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.engine.IProfileRegistry;
-import org.eclipse.equinox.p2.operations.ProvisioningSession;
-import org.eclipse.equinox.p2.ui.Policy;
-import org.eclipse.equinox.p2.ui.ProvisioningUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.packageadmin.PackageAdmin;
 
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
@@ -26,7 +20,6 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
                        .getLogger(TaxonomicEditorPlugin.class);
 
        // The plug-in ID
-       /** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
        public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
 
        // The shared instance
@@ -36,28 +29,12 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
 
        private ServiceReference packageAdminRef;
 
-       /** Constant <code>bundleContext</code> */
        protected static BundleContext bundleContext;
 
 
-       private ServiceRegistration policyRegistration;
-
-       private ProvisioningSession session;
-       private ProvisioningUI ui;
-
-//     private CloudPolicy policy;
-
-       /**
-        * The constructor
-        */
        public TaxonomicEditorPlugin() {
        }
 
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
-        */
-       /** {@inheritDoc} */
        @Override
     public void start(BundleContext context) throws Exception {
                super.start(context);
@@ -88,10 +65,6 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
                return null;
        }
 
-       /*
-        * (non-Javadoc)
-        * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
-        */
        /** {@inheritDoc} */
        @Override
        public void stop(BundleContext context) throws Exception {
@@ -113,20 +86,4 @@ public class TaxonomicEditorPlugin extends AbstractUIPlugin {
            return bundleContext;
        }
 
-       public ProvisioningUI getProvisioningUI() {
-
-           if (ui == null) {
-               ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
-               IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
-               session = new ProvisioningSession(agent);
-               Policy policy = null;// = (Policy) ServiceHelper.getService(ProvUIActivator.getContext(), Policy.class.getName());
-               if (policy == null) {
-                   policy = new Policy();
-               }
-               ui = new ProvisioningUI(session, IProfileRegistry.SELF, policy);
-           }
-           return ui;
-       }
-
-
 }
index 5d99d19658317a3d3b8ed261312748c83466a25e..08f1e79f1f6324cbb54ee860a03e1a1b3b3e5245 100644 (file)
@@ -2,19 +2,8 @@ package eu.etaxonomy.taxeditor.handler.update;
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.equinox.internal.p2.ui.ProvUI;
-import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
-import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
-import org.eclipse.equinox.p2.repository.IRepository;
-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.model.MessagingUtils;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.util.ApplicationUtil;
 
 /**
@@ -40,29 +29,6 @@ public class P2Util {
     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";
 
-    /**
-     * Retrieve and load the saved list of repositories from the preference store,
-     * making sure that at least the default repository is always loaded.
-     */
-    @SuppressWarnings("restriction")
-    public static void setP2UpdateRepositories() {
-        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
-        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
-                .toArray(new MetadataRepositoryElement[]{} ));
-
-    }
-
-    public static String getP2UpdateRepositoryName(){
-        return ApplicationUtil.isStable()?EDIT_STABLE_UPDATE_SITE_NAME:EDIT_NIGHTLY_UPDATE_SITE_NAME;
-    }
 
     public static URI getP2UpdateRepository(){
         try {
@@ -72,42 +38,4 @@ public class P2Util {
         }
         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
-     * that we need to save it ourselves.
-     *
-     * This method saves the list of current repositories in the preference store as a string with
-     * specific delimiters.
-     */
-
-    public static void saveP2RepositoryPreferences() {
-
-        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
-
-        URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
-        URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
-
-        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
-
-        for(URI repo : currentlyEnabled) {
-            boolean enabled = true;
-            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
-            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
-            element.setNickname(nickname);
-            element.setEnabled(enabled);
-            repoElements.add(element);
-        }
-
-        for(URI repo : currentlyDisabled) {
-            boolean enabled = false;
-            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
-            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
-            element.setNickname(nickname);
-            element.setEnabled(enabled);
-            repoElements.add(element);
-        }
-        PreferencesUtil.setP2Repositories(repoElements);
-    }
 }
index 82b5ce51f512ec8f2a7a36ae6b8a2b37aef6a930..d83ad54ffee7f4556a834d933c5463624d909a81 100644 (file)
@@ -173,10 +173,6 @@ public interface IPreferenceKeys {
 
     public static final String IS_SHOW_UP_WIDGET_IS_DISPOSED = "eu.etaxonomy.taxeditor.isShowUpWidgetIsDisposed";
 
-    /**
-     * Key for the saved P2 repositories
-     */
-    public static final String P2_REPOSITORY_LIST = "eu.etaxonomy.taxeditor.p2.repositories";
 //    public static final String ALLOW_OVERRIDE_NAMEDETAILS = "eu.etaxonomy.taxeditor.details.allow_override";
     public static final String ALLOW_OVERRIDE_RL = "eu.etaxonomy.taxeditor.isRL.allow_override";
     public static final String ALLOW_OVERRIDE_SPECIMEN_PREF = "eu.etaxonomy.taxeditor.specimen.allowOverride";
index 489b5723aec6ecf93da93e268a1c7dac914fe281..6c2476a21a924d0f06fe4f53254fd3faae9f9932 100644 (file)
@@ -13,8 +13,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -22,12 +20,10 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.UUID;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
-import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.window.Window;
 import org.eclipse.swt.widgets.Composite;
@@ -79,14 +75,8 @@ import eu.etaxonomy.taxeditor.ui.dialog.DefaultLanguageDialog;
  */
 public class PreferencesUtil implements IPreferenceKeys {
 
-       /**
-        *
-        */
        public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
 
-       public static final String P2_REPOSITORIES_DELIM = ",";
-       public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
-
        private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
 
        /**
@@ -877,62 +867,6 @@ public class PreferencesUtil implements IPreferenceKeys {
         fos.close();
     }
 
-    /**
-     * Saves a list of P2 Metadata Repositories as string with specified delimiters
-     *
-     * @param p2Repos
-     */
-    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
-        StringBuilder sb = new StringBuilder();
-        for(MetadataRepositoryElement p2Repo : p2Repos) {
-            sb.append(P2_REPOSITORIES_DELIM);
-            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
-                sb.append("-");
-            } else {
-                sb.append(p2Repo.getName());
-            }
-            sb.append(P2_REPOSITORY_FIELDS_DELIM);
-            sb.append(p2Repo.getLocation().toString());
-            sb.append(P2_REPOSITORY_FIELDS_DELIM);
-            sb.append(String.valueOf(p2Repo.isEnabled()));
-        }
-        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
-    }
-
-
-    /**
-     * Retrieves a list of previously saved P2 repositories
-     *
-     * @return
-     */
-    public static List<MetadataRepositoryElement> getP2Repositories() {
-        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
-        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
-        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
-            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
-
-            while(p2ReposPrefST.hasMoreTokens()) {
-                String p2RepoStr = p2ReposPrefST.nextToken();
-                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
-                if(p2ReposStrST.countTokens()==3) {
-                    String nickname = p2ReposStrST.nextToken();
-                    URI uri = null;
-                    try {
-                        uri = new URI(p2ReposStrST.nextToken());
-                    } catch (URISyntaxException e) {
-                        continue;
-                    }
-                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
-                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
-                    mre.setNickname(nickname);
-                    mre.setEnabled(enabled);
-                    p2Repos.add(mre);
-                }
-            }
-        }
-
-        return p2Repos;
-    }
 
     /**
      * enables/disables nested composite. <br>
diff --git a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/InstallNewSoftwareHandler.java b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/InstallNewSoftwareHandler.java
deleted file mode 100644 (file)
index 9d81fad..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- *  Copyright (c) 2008, 2009 IBM Corporation and others.
- *  All rights reserved. This program and the accompanying materials
- *  are made available under the terms of the Eclipse Public License v1.0
- *  which accompanies this distribution, and is available at
- *  http://www.eclipse.org/legal/epl-v10.html
- *
- *  Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package eu.etaxonomy.taxeditor.workbench.update;
-
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
-
-/**
- * InstallNewSoftwareHandler invokes the install wizard
- *
- * @since 3.5
- */
-public class InstallNewSoftwareHandler extends PreloadingRepositoryHandler {
-
-       /**
-        * The constructor.
-        */
-       public InstallNewSoftwareHandler() {
-               super();
-       }
-
-       @Override
-    protected void doExecute(LoadMetadataRepositoryJob job) {
-               getProvisioningUI().openInstallWizard(null, null, job);
-       }
-
-       @Override
-    protected boolean waitForPreload() {
-               // If the user cannot see repositories, then we may as well wait
-               // for existing repos to load so that content is available.
-               // If the user can manipulate the repositories, then we don't wait,
-               // because we don't know which ones they want to work with.
-               return !getProvisioningUI().getPolicy().getRepositoriesVisible();
-       }
-
-       @Override
-    protected void setLoadJobProperties(Job loadJob) {
-               super.setLoadJobProperties(loadJob);
-               // If we are doing a background load, we do not wish to authenticate, as the
-               // user is unaware that loading was needed
-               if (!waitForPreload()) {
-                       loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true));
-                       loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_REPOSITORY_EVENTS, Boolean.toString(true));
-               }
-       }
-}
diff --git a/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/PreloadingRepositoryHandler.java b/eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/PreloadingRepositoryHandler.java
deleted file mode 100644 (file)
index 895e576..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package eu.etaxonomy.taxeditor.workbench.update;
-
-import org.eclipse.core.runtime.jobs.IJobChangeEvent;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.core.runtime.jobs.JobChangeAdapter;
-import org.eclipse.e4.core.di.annotations.Execute;
-import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
-import org.eclipse.equinox.p2.ui.ProvisioningUI;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * PreloadingRepositoryHandler provides background loading of
- * repositories before executing the provisioning handler.
- *
- * @since 3.5
- */
-abstract class PreloadingRepositoryHandler{
-
-       /**
-        * The constructor.
-        */
-       public PreloadingRepositoryHandler() {
-               // constructor
-       }
-
-       /**
-        * Execute the command.
-        */
-       @Execute
-       public Object execute() {
-               doExecuteAndLoad();
-               return null;
-       }
-
-       private void doExecuteAndLoad() {
-               if (preloadRepositories()) {
-                       //cancel any load that is already running
-                       Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
-                       final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
-                       setLoadJobProperties(loadJob);
-                       if (waitForPreload()) {
-                               loadJob.addJobChangeListener(new JobChangeAdapter() {
-                                       @Override
-                    public void done(IJobChangeEvent event) {
-                                               if (PlatformUI.isWorkbenchRunning()) {
-                            if (event.getResult().isOK()) {
-                                                               PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
-                                                                       @Override
-                                    public void run() {
-                                                                               doExecute(loadJob);
-                                                                       }
-                                                               });
-                                                       }
-                        }
-                                       }
-                               });
-                               loadJob.setUser(true);
-                               loadJob.schedule();
-
-                       } else {
-                               loadJob.setSystem(true);
-                               loadJob.setUser(false);
-                               loadJob.schedule();
-                               doExecute(null);
-                       }
-               } else {
-                       doExecute(null);
-               }
-       }
-
-       protected abstract void doExecute(LoadMetadataRepositoryJob job);
-
-       protected boolean preloadRepositories() {
-               return true;
-       }
-
-       protected boolean waitForPreload() {
-               return true;
-       }
-
-       protected void setLoadJobProperties(Job loadJob) {
-               loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
-       }
-
-       protected ProvisioningUI getProvisioningUI() {
-               return ProvisioningUI.getDefaultUI();
-       }
-
-       /**
-        * Return a shell appropriate for parenting dialogs of this handler.
-        * @return a Shell
-        */
-       protected Shell getShell() {
-               return PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
-       }
-}