1 package eu
.etaxonomy
.taxeditor
.update
;
4 import java
.net
.URISyntaxException
;
5 import java
.util
.ArrayList
;
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
;
16 import eu
.etaxonomy
.taxeditor
.TaxonomicEditorPlugin
;
17 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
18 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
19 import eu
.etaxonomy
.taxeditor
.util
.ApplicationUtil
;
22 * This class is a utility class for updating the editor from a p2 update site,
23 * greatly inspired by the links given below.
27 * - Allow configurable update sites
32 * @see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application
33 * @see http://bugs.eclipse.org/281226
34 * @see http://www.vogella.com/tutorials/EclipseP2Update/article.html
38 //private static String LOCAL_UPDATE_SITE = "file:///path/.../to/Development/EDIT/taxeditor/eu.etaxonomy.taxeditor/target/repository/";
40 private static String EDIT_NIGHTLY_UPDATE_SITE
= "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
41 private static String EDIT_NIGHTLY_UPDATE_SITE_NAME
= "Taxonomic Editor Nightly";
43 private static String EDIT_SNAPSHOT_UPDATE_SITE
= "http://cybertaxonomy.eu/download/taxeditor/update/snapshot/";
44 private static String EDIT_SNAPSHOT_UPDATE_SITE_NAME
= "Taxonomic Editor Snapshot";
46 private static String EDIT_STABLE_UPDATE_SITE
= "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
47 private static String EDIT_STABLE_UPDATE_SITE_NAME
= "Taxonomic Editor Stable";
50 * Retrieve and load the saved list of repositories from the preference store,
51 * making sure that at least the default repository is always loaded.
53 @SuppressWarnings("restriction")
54 public static void setP2UpdateRepositories() {
55 String updateSite
= EDIT_NIGHTLY_UPDATE_SITE
;
56 String updateSiteName
= EDIT_NIGHTLY_UPDATE_SITE_NAME
;
58 if(ApplicationUtil
.isStable()) {
59 updateSite
= EDIT_STABLE_UPDATE_SITE
;
60 updateSiteName
= EDIT_STABLE_UPDATE_SITE_NAME
;
62 List
<MetadataRepositoryElement
> repoElements
= new ArrayList
<MetadataRepositoryElement
>();
63 List
<MetadataRepositoryElement
> savedRepoElements
= PreferencesUtil
.getP2Repositories();
64 if(savedRepoElements
.isEmpty()) {
65 // we always need an update site, so we add the default one
67 MetadataRepositoryElement element
= new MetadataRepositoryElement(null, new URI(updateSite
), true);
68 element
.setNickname(updateSiteName
);
69 repoElements
.add(element
);
70 } catch (URISyntaxException e
) {
71 MessagingUtils
.errorDialog("Invalid update site URI",
73 "The update site URI has an invalid syntax",
74 TaxonomicEditorPlugin
.PLUGIN_ID
,
79 repoElements
.addAll(savedRepoElements
);
81 ElementUtils
.updateRepositoryUsingElements(ProvisioningUI
.getDefaultUI(),repoElements
82 .toArray(new MetadataRepositoryElement
[]{} ));
87 * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
88 * in preferences does not create a preference store and hence the changes are not saved. This means
89 * that we need to save it ourselves.
91 * This method saves the list of current repositories in the preference store as a string with
92 * specific delimiters.
95 public static void saveP2RepositoryPreferences() {
97 IMetadataRepositoryManager metaManager
= ProvUI
.getMetadataRepositoryManager(ProvisioningUI
.getDefaultUI().getSession());
99 URI
[] currentlyEnabled
= metaManager
.getKnownRepositories(IRepositoryManager
.REPOSITORIES_ALL
);
100 URI
[] currentlyDisabled
= metaManager
.getKnownRepositories(IRepositoryManager
.REPOSITORIES_DISABLED
);
102 List
<MetadataRepositoryElement
> repoElements
= new ArrayList
<MetadataRepositoryElement
>();
104 for(URI repo
: currentlyEnabled
) {
105 boolean enabled
= true;
106 String nickname
= metaManager
.getRepositoryProperty(repo
, IRepository
.PROP_NICKNAME
);
107 MetadataRepositoryElement element
= new MetadataRepositoryElement(null, repo
, true);
108 element
.setNickname(nickname
);
109 element
.setEnabled(enabled
);
110 repoElements
.add(element
);
113 for(URI repo
: currentlyDisabled
) {
114 boolean enabled
= false;
115 String nickname
= metaManager
.getRepositoryProperty(repo
, IRepository
.PROP_NICKNAME
);
116 MetadataRepositoryElement element
= new MetadataRepositoryElement(null, repo
, true);
117 element
.setNickname(nickname
);
118 element
.setEnabled(enabled
);
119 repoElements
.add(element
);
121 PreferencesUtil
.setP2Repositories(repoElements
);