Project

General

Profile

Revision aa997cff

IDaa997cff75987a02661c2f5a8a362aad10a0dc9c
Parent c7ac6fa6
Child c01d683c

Added by Cherian Mathew almost 6 years ago

pom.xml : comment for the file permissions problem
eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF : removed version numbers and added plugin for repository metadata
ApplicationWorkbenchWindowAdvisor : added saving of repositories to post window close
P2Util, PreferencesUtil, PreferencesUtil : added loading / saving of repositories from / to preference store
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF : added plugin for repository metadata

View differences:

eu.etaxonomy.taxeditor.application/META-INF/MANIFEST.MF
11 11
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
12 12
Import-Package: org.apache.log4j,
13 13
 org.eclipse.equinox.app,
14
 org.eclipse.equinox.p2.repository.metadata,
14 15
 org.osgi.framework,
15 16
 org.osgi.service.packageadmin
16 17
Require-Bundle: org.eclipse.ui,
......
29 30
 org.eclipse.equinox.p2.updatechecker,
30 31
 org.eclipse.equinox.p2.operations,
31 32
 org.eclipse.help.ui,
32
 org.eclipse.equinox.p2.metadata;bundle-version="2.1.0",
33
 org.eclipse.equinox.p2.engine;bundle-version="2.1.1"
33
 org.eclipse.equinox.p2.metadata,
34
 org.eclipse.equinox.p2.engine,
35
 org.eclipse.equinox.p2.metadata.repository,
36
 org.eclipse.equinox.p2.repository
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
61 61
            CdmStore.connect();
62 62
        }
63 63

  
64
		P2Util.setDefaultUpdateRepositories();
64
		P2Util.setP2UpdateRepositories();
65 65

  
66 66
	}
67 67

  
68
	/* (non-Javadoc)
69
	 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
70
	 */
71
	@Override
72
    public void postWindowClose() {
73
        P2Util.saveP2RepositoryPreferences();
74
    }
75

  
68 76
	private int authenticate(){
69 77
		Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
70 78

  
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/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;
5 7

  
6 8
import org.eclipse.core.runtime.IProgressMonitor;
7 9
import org.eclipse.core.runtime.IStatus;
10
import org.eclipse.core.runtime.NullProgressMonitor;
8 11
import org.eclipse.core.runtime.OperationCanceledException;
9 12
import org.eclipse.core.runtime.Status;
10 13
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
11 14
import org.eclipse.core.runtime.jobs.Job;
12 15
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
16
import org.eclipse.equinox.internal.p2.ui.ProvUI;
13 17
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
14 18
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
19
import org.eclipse.equinox.p2.repository.IRepository;
20
import org.eclipse.equinox.p2.repository.IRepositoryManager;
21
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
22
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
15 23
import org.eclipse.equinox.p2.core.IProvisioningAgent;
24
import org.eclipse.equinox.p2.core.ProvisionException;
16 25
import org.eclipse.equinox.p2.operations.ProvisioningJob;
17 26
import org.eclipse.equinox.p2.operations.ProvisioningSession;
27
import org.eclipse.equinox.p2.operations.RepositoryTracker;
18 28
import org.eclipse.equinox.p2.operations.Update;
19 29
import org.eclipse.equinox.p2.operations.UpdateOperation;
20 30
import org.eclipse.equinox.p2.ui.ProvisioningUI;
......
26 36
import eu.etaxonomy.taxeditor.ApplicationUtil;
27 37
import eu.etaxonomy.taxeditor.TaxonomicEditorPlugin;
28 38
import eu.etaxonomy.taxeditor.model.MessagingUtils;
39
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
29 40

  
30 41
/**
31 42
 * This class is a utility class for updating the editor from a p2 update site,
......
36 47
 * - Allow configurable update sites
37 48
 *
38 49
 * Notes :
39
 * - tried to get rid of the popup dialog which warns about unsigned jars using
40
 *   -Declipse.p2.unsignedPolicy=allow but this does not work due to
41
 *   https://bugs.eclipse.org/bugs/show_bug.cgi?id=391399, so the only solution
42
 *   is to sign the jars with an official certificate.
50
 *
43 51
 *
44 52
 * @see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application
45 53
 * @see http://bugs.eclipse.org/281226
......
48 56
public class P2Util {
49 57

  
50 58
    //private static String LOCAL_UPDATE_SITE = "file:///path/.../to/Development/EDIT/taxeditor/eu.etaxonomy.taxeditor/target/repository/";
59

  
51 60
    private static String EDIT_NIGHTLY_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
52 61
    private static String EDIT_NIGHTLY_UPDATE_SITE_NAME = "Taxonomic Editor Nightly";
53 62

  
......
57 66
    private static String EDIT_STABLE_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
58 67
    private static String EDIT_STABLE_UPDATE_SITE_NAME = "Taxonomic Editor Stable";
59 68

  
69
    /**
70
     * Retrieve and load the saved list of repositories from the preference store,
71
     * making sure that at least the default repository is always loaded.
72
     */
60 73
    @SuppressWarnings("restriction")
61
    public static void setDefaultUpdateRepositories() {
74
    public static void setP2UpdateRepositories() {
62 75
        String updateSite = EDIT_NIGHTLY_UPDATE_SITE;
63 76
        String updateSiteName = EDIT_NIGHTLY_UPDATE_SITE_NAME;
64 77

  
......
66 79
            updateSite = EDIT_STABLE_UPDATE_SITE;
67 80
            updateSiteName = EDIT_STABLE_UPDATE_SITE_NAME;
68 81
        }
69
        try {
70
          final MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
71
          element.setNickname(updateSiteName);
72
          ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),new MetadataRepositoryElement[] {element}, null);
73
        } catch (URISyntaxException e) {
74
            MessagingUtils.errorDialog("Invalid update site URI",
75
                    P2Util.class,
76
                    "The update site URI has an invalid syntax",
77
                    TaxonomicEditorPlugin.PLUGIN_ID,
78
                    e,
79
                    false);
82
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
83
        List<MetadataRepositoryElement> savedRepoElements = PreferencesUtil.getP2Repositories();
84
        if(savedRepoElements.isEmpty()) {
85
            // we always need an update site, so we add the default one
86
            try {
87
                MetadataRepositoryElement element = new MetadataRepositoryElement(null, new URI(updateSite), true);
88
                element.setNickname(updateSiteName);
89
                repoElements.add(element);
90
            } catch (URISyntaxException e) {
91
                MessagingUtils.errorDialog("Invalid update site URI",
92
                        P2Util.class,
93
                        "The update site URI has an invalid syntax",
94
                        TaxonomicEditorPlugin.PLUGIN_ID,
95
                        e,
96
                        false);
97
            }
98
        }
99
        repoElements.addAll(savedRepoElements);
100

  
101
        ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
102
                .toArray(new MetadataRepositoryElement[]{} ), null);
103

  
104
    }
105

  
106
    /**
107
     * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
108
     * in preferences does not create a preference store and hence the changes are not saved. This means
109
     * that we need to save it ourselves.
110
     *
111
     * This method saves the list of current repositories in the preference store as a string with
112
     * specific delimiters.
113
     */
114

  
115
    public static void saveP2RepositoryPreferences() {
116

  
117
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
118

  
119
        URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
120
        URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
121

  
122
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
123

  
124
        for(URI repo : currentlyEnabled) {
125
            boolean enabled = true;
126
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
127
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
128
            element.setNickname(nickname);
129
            element.setEnabled(enabled);
130
            repoElements.add(element);
80 131
        }
81
      }
132

  
133
        for(URI repo : currentlyDisabled) {
134
            boolean enabled = false;
135
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
136
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
137
            element.setNickname(nickname);
138
            element.setEnabled(enabled);
139
            repoElements.add(element);
140
        }
141
        PreferencesUtil.setP2Repositories(repoElements);
142
    }
82 143

  
83 144
    /**
84 145
     *
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
64 64
 org.eclipse.core.expressions,
65 65
 org.eclipse.core.runtime,
66 66
 org.eclipse.core.runtime.jobs,
67
 org.eclipse.core.runtime.preferences;
67
 org.eclipse.core.runtime.preferences,
68
 org.eclipse.equinox.internal.p2.ui.model,
68 69
 org.eclipse.jface.action,
69 70
 org.eclipse.jface.dialogs,
70 71
 org.eclipse.jface.preference,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/IPreferenceKeys.java
133 133

  
134 134
    public static final String DEFAULT_LANGUAGE_EDITOR = "eu.etaxonomy.taxeditor.default.language";
135 135

  
136
    /**
137
     * Key for the saved P2 repositories
138
     */
139
    public static final String P2_REPOSITORY_LIST = "eu.etaxonomy.taxeditor.p2.repositories";
140

  
136 141
}
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
import java.util.ArrayList;
16 19
import java.util.Arrays;
17 20
import java.util.HashMap;
18 21
import java.util.List;
19 22
import java.util.Map;
20 23
import java.util.Properties;
21 24
import java.util.Set;
25
import java.util.StringTokenizer;
22 26
import java.util.UUID;
23 27

  
24 28
import org.apache.commons.lang.StringUtils;
29
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
25 30
import org.eclipse.jface.preference.IPreferenceStore;
26 31
import org.eclipse.swt.widgets.Shell;
27 32
import org.eclipse.ui.PlatformUI;
......
69 74
	 */
70 75
	public static final String PREFERRED_TERMS_CHANGE = "preferred_terms";
71 76

  
77
	public static final String P2_REPOSITORIES_DELIM = ",";
78
	public static final String P2_REPOSITORY_FIELDS_DELIM = ";";
79

  
72 80
	/**
73 81
	 * <p>
74 82
	 * getPreferenceStore
......
653 661
        fos.close();
654 662
    }
655 663

  
664
    /**
665
     * Saves a list of P2 Metadata Repositories as string with specified delimiters
666
     *
667
     * @param p2Repos
668
     */
669
    public static void setP2Repositories(List<MetadataRepositoryElement> p2Repos) {
670
        StringBuilder sb = new StringBuilder();
671
        for(MetadataRepositoryElement p2Repo : p2Repos) {
672
            sb.append(P2_REPOSITORIES_DELIM);
673
            sb.append(p2Repo.getName());
674
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
675
            sb.append(p2Repo.getLocation().toString());
676
            sb.append(P2_REPOSITORY_FIELDS_DELIM);
677
            sb.append(String.valueOf(p2Repo.isEnabled()));
678
        }
679
        getPreferenceStore().setValue(P2_REPOSITORY_LIST, sb.toString());
680
    }
681

  
682

  
683
    /**
684
     * Retrieves a list of previously saved P2 repositories
685
     *
686
     * @return
687
     */
688
    public static List<MetadataRepositoryElement> getP2Repositories() {
689
        List<MetadataRepositoryElement> p2Repos = new ArrayList<MetadataRepositoryElement>();
690
        String p2ReposPref =  getPreferenceStore().getString(P2_REPOSITORY_LIST);
691
        if(p2ReposPref != null && !p2ReposPref.isEmpty()) {
692
            StringTokenizer p2ReposPrefST = new StringTokenizer(p2ReposPref,P2_REPOSITORIES_DELIM);
693
            while(p2ReposPrefST.hasMoreTokens()) {
694
                String p2RepoStr = p2ReposPrefST.nextToken();
695
                StringTokenizer p2ReposStrST = new StringTokenizer(p2RepoStr,P2_REPOSITORY_FIELDS_DELIM);
696
                String nickname = p2ReposStrST.nextToken();
697
                URI uri = null;
698
                try {
699
                    uri = new URI(p2ReposStrST.nextToken());
700
                } catch (URISyntaxException e) {
701
                    continue;
702
                }
703
                boolean enabled = Boolean.parseBoolean(p2ReposStrST.nextToken());
704
                MetadataRepositoryElement mre = new MetadataRepositoryElement(null, uri, true);
705
                mre.setNickname(nickname);
706
                mre.setEnabled(enabled);
707
                p2Repos.add(mre);
708
            }
709
        }
710

  
711
        return p2Repos;
712
    }
656 713
}
eu.etaxonomy.taxeditor/pom.xml
95 95
    </profile>
96 96
    <profile>
97 97
      <!-- Upload the repo to the server -->
98
      <!-- ATTENTION : This does not work well currently since the file permissions
99
           are set with read permission set to off after upload -->
98 100
      <id>uploadRepo</id>
99 101
      <build>
100 102
        <plugins>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)