Project

General

Profile

« Previous | Next » 

Revision 598845be

Added by Patrick Plitzner almost 6 years ago

ref #7268, #6913 Remove p2 related code

View differences:

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
}

Also available in: Unified diff