Project

General

Profile

Revision 598845be

ID598845be674417e5a4d79cc533f3ff3b1a0b4cdb
Parent 14c03fc1
Child c72cace9

Added by Patrick Plitzner over 1 year ago

ref #7268, #6913 Remove p2 related code

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
15 15
import org.eclipse.ui.internal.WorkbenchWindow;
16 16

  
17 17
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
18
import eu.etaxonomy.taxeditor.handler.update.P2Util;
19 18
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 19
import eu.etaxonomy.taxeditor.store.CdmStore;
21 20
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
......
73 72
            CdmStore.connect();
74 73
        }
75 74

  
76
		P2Util.setP2UpdateRepositories();
77

  
78 75
	}
79 76

  
80
	@Override
81
    public void postWindowClose() {
82
        P2Util.saveP2RepositoryPreferences();
83
    }
84 77
}
85 78

  
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/TaxonomicEditorPlugin.java
1 1
package eu.etaxonomy.taxeditor;
2 2

  
3 3
import org.apache.log4j.Logger;
4
import org.eclipse.equinox.p2.core.IProvisioningAgent;
5
import org.eclipse.equinox.p2.engine.IProfileRegistry;
6
import org.eclipse.equinox.p2.operations.ProvisioningSession;
7
import org.eclipse.equinox.p2.ui.Policy;
8
import org.eclipse.equinox.p2.ui.ProvisioningUI;
9 4
import org.eclipse.ui.plugin.AbstractUIPlugin;
10 5
import org.osgi.framework.Bundle;
11 6
import org.osgi.framework.BundleContext;
12 7
import org.osgi.framework.ServiceReference;
13
import org.osgi.framework.ServiceRegistration;
14 8
import org.osgi.service.packageadmin.PackageAdmin;
15 9

  
16 10
import eu.etaxonomy.taxeditor.model.MessagingUtils;
......
26 20
			.getLogger(TaxonomicEditorPlugin.class);
27 21

  
28 22
	// The plug-in ID
29
	/** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.application"</code> */
30 23
	public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.application";
31 24

  
32 25
	// The shared instance
......
36 29

  
37 30
	private ServiceReference packageAdminRef;
38 31

  
39
	/** Constant <code>bundleContext</code> */
40 32
	protected static BundleContext bundleContext;
41 33

  
42 34

  
43
	private ServiceRegistration policyRegistration;
44

  
45
	private ProvisioningSession session;
46
	private ProvisioningUI ui;
47

  
48
//	private CloudPolicy policy;
49

  
50
	/**
51
	 * The constructor
52
	 */
53 35
	public TaxonomicEditorPlugin() {
54 36
	}
55 37

  
56
	/*
57
	 * (non-Javadoc)
58
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
59
	 */
60
	/** {@inheritDoc} */
61 38
	@Override
62 39
    public void start(BundleContext context) throws Exception {
63 40
		super.start(context);
......
88 65
		return null;
89 66
	}
90 67

  
91
	/*
92
	 * (non-Javadoc)
93
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
94
	 */
95 68
	/** {@inheritDoc} */
96 69
	@Override
97 70
	public void stop(BundleContext context) throws Exception {
......
113 86
	    return bundleContext;
114 87
	}
115 88

  
116
	public ProvisioningUI getProvisioningUI() {
117

  
118
	    if (ui == null) {
119
	        ServiceReference reference = bundleContext.getServiceReference(IProvisioningAgent.SERVICE_NAME);
120
	        IProvisioningAgent agent = (IProvisioningAgent) bundleContext.getService(reference);
121
	        session = new ProvisioningSession(agent);
122
	        Policy policy = null;// = (Policy) ServiceHelper.getService(ProvUIActivator.getContext(), Policy.class.getName());
123
	        if (policy == null) {
124
	            policy = new Policy();
125
	        }
126
	        ui = new ProvisioningUI(session, IProfileRegistry.SELF, policy);
127
	    }
128
	    return ui;
129
	}
130

  
131

  
132 89
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/P2Util.java
2 2

  
3 3
import java.net.URI;
4 4
import java.net.URISyntaxException;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
import org.eclipse.equinox.internal.p2.ui.ProvUI;
9
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
10
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
11
import org.eclipse.equinox.p2.repository.IRepository;
12
import org.eclipse.equinox.p2.repository.IRepositoryManager;
13
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
14
import org.eclipse.equinox.p2.ui.ProvisioningUI;
15 5

  
16 6
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18 7
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
19 8

  
20 9
/**
......
40 29
    private static String EDIT_STABLE_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
41 30
    private static String EDIT_STABLE_UPDATE_SITE_NAME = "Taxonomic Editor Stable";
42 31

  
43
    /**
44
     * Retrieve and load the saved list of repositories from the preference store,
45
     * making sure that at least the default repository is always loaded.
46
     */
47
    @SuppressWarnings("restriction")
48
    public static void setP2UpdateRepositories() {
49
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
50
        List<MetadataRepositoryElement> savedRepoElements = new ArrayList<>();
51

  
52
        MetadataRepositoryElement mre = new MetadataRepositoryElement(null, getP2UpdateRepository(), true);
53
        mre.setNickname(getP2UpdateRepositoryName());
54
        savedRepoElements.add(mre);
55

  
56
        repoElements.addAll(savedRepoElements);
57

  
58
        ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
59
                .toArray(new MetadataRepositoryElement[]{} ));
60

  
61
    }
62

  
63
    public static String getP2UpdateRepositoryName(){
64
        return ApplicationUtil.isStable()?EDIT_STABLE_UPDATE_SITE_NAME:EDIT_NIGHTLY_UPDATE_SITE_NAME;
65
    }
66 32

  
67 33
    public static URI getP2UpdateRepository(){
68 34
        try {
......
72 38
        }
73 39
        return null;
74 40
    }
75

  
76
    /**
77
     * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
78
     * in preferences does not create a preference store and hence the changes are not saved. This means
79
     * that we need to save it ourselves.
80
     *
81
     * This method saves the list of current repositories in the preference store as a string with
82
     * specific delimiters.
83
     */
84

  
85
    public static void saveP2RepositoryPreferences() {
86

  
87
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
88

  
89
        URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
90
        URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
91

  
92
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
93

  
94
        for(URI repo : currentlyEnabled) {
95
            boolean enabled = true;
96
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
97
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
98
            element.setNickname(nickname);
99
            element.setEnabled(enabled);
100
            repoElements.add(element);
101
        }
102

  
103
        for(URI repo : currentlyDisabled) {
104
            boolean enabled = false;
105
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
106
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
107
            element.setNickname(nickname);
108
            element.setEnabled(enabled);
109
            repoElements.add(element);
110
        }
111
        PreferencesUtil.setP2Repositories(repoElements);
112
    }
113 41
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
173 173

  
174 174
    public static final String IS_SHOW_UP_WIDGET_IS_DISPOSED = "eu.etaxonomy.taxeditor.isShowUpWidgetIsDisposed";
175 175

  
176
    /**
177
     * Key for the saved P2 repositories
178
     */
179
    public static final String P2_REPOSITORY_LIST = "eu.etaxonomy.taxeditor.p2.repositories";
180 176
//    public static final String ALLOW_OVERRIDE_NAMEDETAILS = "eu.etaxonomy.taxeditor.details.allow_override";
181 177
    public static final String ALLOW_OVERRIDE_RL = "eu.etaxonomy.taxeditor.isRL.allow_override";
182 178
    public static final String ALLOW_OVERRIDE_SPECIMEN_PREF = "eu.etaxonomy.taxeditor.specimen.allowOverride";
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/PreferencesUtil.java
13 13
import java.io.FileInputStream;
14 14
import java.io.FileOutputStream;
15 15
import java.io.IOException;
16
import java.net.URI;
17
import java.net.URISyntaxException;
18 16
import java.util.ArrayList;
19 17
import java.util.Arrays;
20 18
import java.util.HashMap;
......
22 20
import java.util.Map;
23 21
import java.util.Properties;
24 22
import java.util.Set;
25
import java.util.StringTokenizer;
26 23
import java.util.UUID;
27 24

  
28 25
import org.apache.commons.lang.StringUtils;
29 26
import org.apache.log4j.Logger;
30
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
31 27
import org.eclipse.jface.preference.IPreferenceStore;
32 28
import org.eclipse.jface.window.Window;
33 29
import org.eclipse.swt.widgets.Composite;
......
79 75
 */
80 76
public class PreferencesUtil implements IPreferenceKeys {
81 77

  
82
	/**
83
	 *
84
	 */
85 78
	public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
86 79

  
87
	public static final String P2_REPOSITORIES_DELIM = ",";
88
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
89

  
90 80
	private final static Logger logger = Logger.getLogger(PreferencesUtil.class);
91 81

  
92 82
	/**
......
877 867
        fos.close();
878 868
    }
879 869

  
880
    /**
881
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
882
     *
883
     * @param p2Repos
884
     */
885
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
886
        StringBuilder sb = new StringBuilder();
887
        for(MetadataRepositoryElement p2Repo : p2Repos) {
888
            sb.append(P2_REPOSITORIES_DELIM);
889
            if(p2Repo.getName() == null || p2Repo.getName().isEmpty()) {
890
                sb.append("-");
891
            } else {
892
                sb.append(p2Repo.getName());
893
            }
894
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
895
            sb.append(p2Repo.getLocation().toString());
896
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
897
            sb.append(String.valueOf(p2Repo.isEnabled()));
898
        }
899
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
900
    }
901

  
902

  
903
    /**
904
     * Retrieves a list of previously saved P2 repositories
905
     *
906
     * @return
907
     */
908
    public static List<MetadataRepositoryElement> getP2Repositories() {
909
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
910
        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
911
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
912
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
913

  
914
            while(p2ReposPrefST.hasMoreTokens()) {
915
                String p2RepoStr = p2ReposPrefST.nextToken();
916
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
917
                if(p2ReposStrST.countTokens()==3) {
918
                    String nickname = p2ReposStrST.nextToken();
919
                    URI uri = null;
920
                    try {
921
                        uri = new URI(p2ReposStrST.nextToken());
922
                    } catch (URISyntaxException e) {
923
                        continue;
924
                    }
925
                    boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
926
                    MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
927
                    mre.setNickname(nickname);
928
                    mre.setEnabled(enabled);
929
                    p2Repos.add(mre);
930
                }
931
            }
932
        }
933

  
934
        return p2Repos;
935
    }
936 870

  
937 871
    /**
938 872
     * enables/disables nested composite. <br>
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/InstallNewSoftwareHandler.java
1
/*******************************************************************************
2
 *  Copyright (c) 2008, 2009 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package eu.etaxonomy.taxeditor.workbench.update;
12

  
13
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
15

  
16
/**
17
 * InstallNewSoftwareHandler invokes the install wizard
18
 *
19
 * @since 3.5
20
 */
21
public class InstallNewSoftwareHandler extends PreloadingRepositoryHandler {
22

  
23
	/**
24
	 * The constructor.
25
	 */
26
	public InstallNewSoftwareHandler() {
27
		super();
28
	}
29

  
30
	@Override
31
    protected void doExecute(LoadMetadataRepositoryJob job) {
32
		getProvisioningUI().openInstallWizard(null, null, job);
33
	}
34

  
35
	@Override
36
    protected boolean waitForPreload() {
37
		// If the user cannot see repositories, then we may as well wait
38
		// for existing repos to load so that content is available.
39
		// If the user can manipulate the repositories, then we don't wait,
40
		// because we don't know which ones they want to work with.
41
		return !getProvisioningUI().getPolicy().getRepositoriesVisible();
42
	}
43

  
44
	@Override
45
    protected void setLoadJobProperties(Job loadJob) {
46
		super.setLoadJobProperties(loadJob);
47
		// If we are doing a background load, we do not wish to authenticate, as the
48
		// user is unaware that loading was needed
49
		if (!waitForPreload()) {
50
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true));
51
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_REPOSITORY_EVENTS, Boolean.toString(true));
52
		}
53
	}
54
}
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/PreloadingRepositoryHandler.java
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package eu.etaxonomy.taxeditor.workbench.update;
12

  
13
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
14
import org.eclipse.core.runtime.jobs.Job;
15
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
18
import org.eclipse.equinox.p2.ui.ProvisioningUI;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.ui.PlatformUI;
21

  
22
/**
23
 * PreloadingRepositoryHandler provides background loading of
24
 * repositories before executing the provisioning handler.
25
 *
26
 * @since 3.5
27
 */
28
abstract class PreloadingRepositoryHandler{
29

  
30
	/**
31
	 * The constructor.
32
	 */
33
	public PreloadingRepositoryHandler() {
34
		// constructor
35
	}
36

  
37
	/**
38
	 * Execute the command.
39
	 */
40
	@Execute
41
	public Object execute() {
42
		doExecuteAndLoad();
43
		return null;
44
	}
45

  
46
	private void doExecuteAndLoad() {
47
		if (preloadRepositories()) {
48
			//cancel any load that is already running
49
			Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
50
			final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
51
			setLoadJobProperties(loadJob);
52
			if (waitForPreload()) {
53
				loadJob.addJobChangeListener(new JobChangeAdapter() {
54
					@Override
55
                    public void done(IJobChangeEvent event) {
56
						if (PlatformUI.isWorkbenchRunning()) {
57
                            if (event.getResult().isOK()) {
58
								PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
59
									@Override
60
                                    public void run() {
61
										doExecute(loadJob);
62
									}
63
								});
64
							}
65
                        }
66
					}
67
				});
68
				loadJob.setUser(true);
69
				loadJob.schedule();
70

  
71
			} else {
72
				loadJob.setSystem(true);
73
				loadJob.setUser(false);
74
				loadJob.schedule();
75
				doExecute(null);
76
			}
77
		} else {
78
			doExecute(null);
79
		}
80
	}
81

  
82
	protected abstract void doExecute(LoadMetadataRepositoryJob job);
83

  
84
	protected boolean preloadRepositories() {
85
		return true;
86
	}
87

  
88
	protected boolean waitForPreload() {
89
		return true;
90
	}
91

  
92
	protected void setLoadJobProperties(Job loadJob) {
93
		loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
94
	}
95

  
96
	protected ProvisioningUI getProvisioningUI() {
97
		return ProvisioningUI.getDefaultUI();
98
	}
99

  
100
	/**
101
	 * Return a shell appropriate for parenting dialogs of this handler.
102
	 * @return a Shell
103
	 */
104
	protected Shell getShell() {
105
		return PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
106
	}
107
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)