/*******************************************************************************
* Copyright (c) 2008 Pierre-Antoine Grégoire.
* 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:
* Pierre-Antoine Grégoire - initial API and implementation
*******************************************************************************/
package org.org.eclipse.dws.core.internal.bridges;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
import org.apache.log4j.Logger;
import org.eclipse.core.runtime.IPath;
import org.org.eclipse.core.ui.dialogs.ErrorDialog;
import org.org.eclipse.core.utils.platform.binding.BindingException;
import org.org.eclipse.core.utils.platform.preferences.PreferencesFacade;
import org.org.eclipse.core.utils.platform.tools.IOToolBox;
import org.org.eclipse.core.utils.platform.tools.PluginToolBox;
import org.org.eclipse.dws.core.DWSCorePlugin;
import org.org.eclipse.dws.core.internal.configuration.ConfigurationConstants;
import org.org.eclipse.dws.core.internal.configuration.preferences.PatternSetPreferencesHelper;
import org.org.eclipse.dws.core.internal.configuration.preferences.PreferencesNames;
import org.org.eclipse.dws.core.internal.model.ModelConstants;
import org.org.eclipse.dws.core.internal.xml.IXmlRepositoriesBinder;
import org.org.eclipse.dws.core.internal.xml.StaxRepositoriesBinder;
import org.org.model.IModelItemListener;
import org.org.model.RootModelItem;
import org.org.repository.crawler.IExternalInterruptionFlagSetter;
import org.org.repository.crawler.items.IFileSystemCrawledRepositorySetup;
import org.org.repository.crawler.items.IHttpCrawledRepositorySetup;
import org.org.repository.crawler.items.IPatternSet;
import org.org.repository.crawler.items.mutable.HttpCrawledRepositorySetup;
import org.org.repository.crawler.maven2.RepositoryCrawlerService;
import org.org.repository.crawler.maven2.model.Artifact;
import org.org.repository.crawler.maven2.model.Group;
import org.org.repository.crawler.maven2.model.CrawledRepository;
import org.org.repository.crawler.maven2.model.protocolplugins.FileSystemRepositoryBrowserPlugin;
import org.org.repository.crawler.maven2.model.protocolplugins.HttpRepositoryBrowserPlugin;
/**
* The Class RepositoryModelPersistence.
*
* @author pagregoire
*/
public class RepositoryModelPersistence {
/** The logger. */
private static Logger logger = Logger.getLogger(RepositoryModelPersistence.class);
/** The Constant OUT_OF_SYNC. */
public final static Integer OUT_OF_SYNC = Integer.valueOf(0);
/** The Constant SYNC. */
public final static Integer SYNC = Integer.valueOf(1);
/** The workspace persistence status. */
private static Integer workspacePersistenceStatus = OUT_OF_SYNC;
/**
* Adds the entry pattern autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addEntryPatternAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ENTRY_PATTERN_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ENTRY_PATTERN_AUTOCOMPLETE, proposals);
}
/**
* Adds the fs repository autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addFSRepositoryAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_FS_REPOSITORIES_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_FS_REPOSITORIES_AUTOCOMPLETE, proposals);
}
/**
* ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
* autocomplete setting method
* *******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************.
*
* @param proposal
* the proposal
*/
public static void addHttpBrowsedRepositoryAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_HTTP_REPOSITORIES_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_HTTP_REPOSITORIES_AUTOCOMPLETE, proposals);
}
/**
* Adds the parent pattern autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addParentPatternAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PARENT_PATTERN_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PARENT_PATTERN_AUTOCOMPLETE, proposals);
}
/**
* Adds the proxy host autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addProxyHostAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_HOST_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_HOST_AUTOCOMPLETE, proposals);
}
/**
* Adds the proxy port autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addProxyPortAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_PORT_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_PORT_AUTOCOMPLETE, proposals);
}
/**
* Adds the repository name autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addRepositoryNameAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_REPOSITORY_NAME_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_REPOSITORY_NAME_AUTOCOMPLETE, proposals);
}
/**
* Adds the group id autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addGroupIdAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_GROUPID_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_GROUPID_AUTOCOMPLETE, proposals);
}
/**
* Adds the artifact id autocomplete proposal.
*
* @param proposal
* the proposal
*/
public static void addArtifactIdAutocompleteProposal(String proposal) {
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ARTIFACTID_AUTOCOMPLETE, String.class);
String frontSeparator = proposals.trim().endsWith(ConfigurationConstants.PIPE_SEPARATOR) ? "" : ConfigurationConstants.PIPE_SEPARATOR;
proposals += frontSeparator + proposal + ConfigurationConstants.PIPE_SEPARATOR;
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ARTIFACTID_AUTOCOMPLETE, proposals);
}
/**
* Check status.
*/
public static void checkStatus() {
if (getWorkspacePersistencesStatus().equals(OUT_OF_SYNC)) {
saveRepositoryInfo();
}
}
/**
* Gets the entry pattern autocomplete proposals.
*
* @return the entry pattern autocomplete proposals
*/
public static Set<String> getEntryPatternAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ENTRY_PATTERN_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the fS browsed repository autocomplete proposals.
*
* @return the fS browsed repository autocomplete proposals
*/
public static Set<String> getFSBrowsedRepositoryAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_FS_REPOSITORIES_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* ********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************
* autocomplete retrieval method
* *******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************.
*
* @return the http browsed repository autocomplete proposals
*/
public static Set<String> getHttpBrowsedRepositoryAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_HTTP_REPOSITORIES_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the parent pattern autocomplete proposals.
*
* @return the parent pattern autocomplete proposals
*/
public static Set<String> getParentPatternAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PARENT_PATTERN_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
public static IPatternSet getPatternSets() {
return PatternSetPreferencesHelper.deserialize((String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PATTERNSET_DEFAULT, String.class));
}
/**
* Gets the proxy host autocomplete proposals.
*
* @return the proxy host autocomplete proposals
*/
public static Set<String> getProxyHostAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_HOST_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the proxy port autocomplete proposals.
*
* @return the proxy port autocomplete proposals
*/
public static Set<String> getProxyPortAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_PROXY_PORT_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the repository name autocomplete proposals.
*
* @return the repository name autocomplete proposals
*/
public static Set<String> getRepositoryNameAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_REPOSITORY_NAME_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the group id autocomplete proposals.
*
* @return the group id autocomplete proposals
*/
public static Set<String> getGroupIdAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_GROUPID_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the artifact id autocomplete proposals.
*
* @return the artifact id autocomplete proposals
*/
public static Set<String> getArtifactIdAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_ARTIFACTID_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the directory entry pattern autocomplete proposals.
*
* @return the directory entry pattern autocomplete proposals
*/
public static Set<String> getDirectoryEntryPatternAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_DIRECTORY_ENTRY_PATTERN_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the file entry pattern autocomplete proposals.
*
* @return the file entry pattern autocomplete proposals
*/
public static Set<String> getFileEntryPatternAutocompleteProposals() {
Set<String> result = new TreeSet<String>();
String proposals = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_FILE_ENTRY_PATTERN_AUTOCOMPLETE, String.class);
StringTokenizer tkz = new StringTokenizer(proposals, ConfigurationConstants.PIPE_SEPARATOR, false);
while (tkz.hasMoreTokens()) {
result.add(tkz.nextToken());
}
return result;
}
/**
* Gets the workspace persistences status.
*
* @return the workspace persistences status
*/
public static Integer getWorkspacePersistencesStatus() {
return workspacePersistenceStatus;
}
/**
* Load repository info.
*/
public static void loadRepositoryInfo() {
// Try first to retrieve former repositories from Preferences.
logger.info("Trying to load from legacy preferences storage.");
boolean loadedFromLegacyStorage = false;
String contentsStr = (String) PreferencesFacade.getPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_REPOSITORIES_INFOS, String.class);
InputStream contents = null;
if (contentsStr != null && !contentsStr.trim().equals("")) {
try {
contents = new ByteArrayInputStream(contentsStr.getBytes());
loadRepositoryInfo(contents);
loadedFromLegacyStorage = true;
logger.info("loaded repositories from preferences.");
} catch (Exception e) {
logger.error("unable to load repositories from preferences.");
} finally {
try {
contents.close();
} catch (Throwable e) {
}
}
}
// Then try to load from proper storage.
if (!loadedFromLegacyStorage) {
logger.info("Now loading from proper file storage.");
IPath persistedRepositories = getPersistedRepositoriesPath();
try {
contents = new FileInputStream(persistedRepositories.toFile());
loadRepositoryInfo(contents);
logger.info("loaded repositories from file " + persistedRepositories.toFile().toString() + ".");
} catch (Exception e) {
logger.error("unable to load repositories from file " + persistedRepositories.toFile().toString() + ".");
} finally {
try {
contents.close();
} catch (Exception e) {
}
}
}
// finally remove legacy storage.
PreferencesFacade.setPreference(DWSCorePlugin.getDefault(), PreferencesNames.P_MAVEN_REPOSITORIES_INFOS, "");
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
private static IPath getPersistedRepositoriesPath() {
IPath persistedRepositories = PluginToolBox.getCurrentWorkspace().getRoot().getRawLocation();
persistedRepositories = persistedRepositories.append("/.org.org.eclipse.dws-repositories.xml");
return persistedRepositories;
}
/**
* Load repository info.
*
* @param contents
* the contents
* @throws BindingException
* @param contents
* the contents
*/
private static void loadRepositoryInfo(InputStream contents) throws BindingException {
IXmlRepositoriesBinder xmlRepositoriesBinder = new StaxRepositoriesBinder();
List<CrawledRepository> repositoryModelItems = xmlRepositoriesBinder.parseXmlRepositories(contents);
RootModelItem<CrawledRepository> root = RootModelItem.<CrawledRepository> getInstance(ModelConstants.REPOSITORIES_ROOT);
root.toggleListenersOn();
for (CrawledRepository crawledRepository : repositoryModelItems) {
root.addChild(crawledRepository);
}
}
/**
* Refresh artifact.
*
* @param artifact
* the artifact
* @param modelItemListener
* the model item listener
*/
public static void refreshArtifact(Artifact artifact, IModelItemListener modelItemListener) {
Group parentGroup = artifact.getParent();
CrawledRepository parentRepo = (CrawledRepository) parentGroup.getParent();
if (parentRepo.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
artifact = mavenRepositoryService.refreshArtifact(artifact, (IHttpCrawledRepositorySetup) parentRepo.getRepositorySetup(), parentGroup.getName(), artifact.getId(), modelItemListener);
} else if (parentRepo.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
artifact = mavenRepositoryService.refreshArtifact(artifact, (IFileSystemCrawledRepositorySetup) parentRepo.getRepositorySetup(), parentGroup.getName(), artifact.getId(), modelItemListener);
}
parentGroup.addChild(artifact);
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
/**
* Refresh group.
*
* @param group
* the group
* @param modelItemListener
* the model item listener
* @param externalInterruptionFlagSetter
* the external interruption flag setter
*/
public static void refreshGroup(Group group, IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener) {
CrawledRepository parentRepo = (CrawledRepository) group.getParent();
if (parentRepo.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshGroup(group, (IHttpCrawledRepositorySetup) parentRepo.getRepositorySetup(), group.getName(), modelItemListener);
} else if (parentRepo.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshGroup(group, (IFileSystemCrawledRepositorySetup) parentRepo.getRepositorySetup(), group.getName(), modelItemListener);
}
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
/**
* Adds the precise group to repository.
*
* @param modelItemListener
* the model item listener
* @param parentRepo
* the parent repo
* @param groupId
* the group id
* @param externalInterruptionFlagSetter
* the external interruption flag setter
*/
public static void addPreciseGroupToRepository(CrawledRepository parentRepo, String groupId, IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener) {
parentRepo.addGroupFilter(groupId);
Group group = new Group(groupId);
if (parentRepo.hasChild(group.getUID())) {
group = parentRepo.getChild(group.getUID());
} else {
parentRepo.addChild(group);
}
if (parentRepo.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
group = mavenRepositoryService.refreshGroup(group, (IHttpCrawledRepositorySetup) parentRepo.getRepositorySetup(), groupId, modelItemListener);
} else if (parentRepo.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
group = mavenRepositoryService.refreshGroup(group, (IFileSystemCrawledRepositorySetup) parentRepo.getRepositorySetup(), groupId, modelItemListener);
}
if (group != null) {
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
}
/**
* Adds the precise artifact to repository.
*
* @param parentRepo
* the parent repo
* @param groupId
* the group id
* @param artifactId
* the artifact id
* @param externalInterruptionFlagSetter
* the external interruption flag setter
* @param modelItemListener
* the model item listener
* @param declareOutOfSync
* the declare out of sync
*/
public static void addPreciseArtifactToRepository(CrawledRepository parentRepo, String groupId, String artifactId, IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener, boolean declareOutOfSync) {
parentRepo.addGroupFilter(groupId);
Group group = new Group(groupId);
Artifact artifact = new Artifact(artifactId);
if (parentRepo.hasChild(group.getUID())) {
group = parentRepo.getChild(group.getUID());
} else {
parentRepo.addChild(group);
}
if (group.hasChild(artifact.getUID())) {
artifact = group.getChild(artifact.getUID());
} else {
group.addChild(artifact);
}
if (parentRepo.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
IHttpCrawledRepositorySetup repositorySetup = (IHttpCrawledRepositorySetup) parentRepo.getRepositorySetup();
HttpCrawledRepositorySetup mutableRepositorySetup = (HttpCrawledRepositorySetup) repositorySetup.getMutable();
Proxy proxy;
try {
proxy = IOToolBox.determineProxy(new URL(mutableRepositorySetup.getBaseUrl()));
InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
mutableRepositorySetup.setProxyHost(proxyAddress.getHostName());
mutableRepositorySetup.setProxyPort(proxyAddress.getPort());
} catch (Exception e) {
e.printStackTrace();
}
artifact = mavenRepositoryService.refreshArtifact(artifact, (IHttpCrawledRepositorySetup) mutableRepositorySetup.getImmutable(), groupId, artifactId, modelItemListener);
} else if (parentRepo.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
artifact = mavenRepositoryService.refreshArtifact(artifact, (IFileSystemCrawledRepositorySetup) parentRepo.getRepositorySetup(), groupId, artifactId, modelItemListener);
}
if (artifact != null && declareOutOfSync) {
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
}
/**
* Adds the group filter to repository.
*
* @param modelItemListener
* the model item listener
* @param parentRepo
* the parent repo
* @param groupId
* the group id
* @param externalInterruptionFlagSetter
* the external interruption flag setter
*/
public static void addGroupFilterToRepository(CrawledRepository parentRepo, String groupId, IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener) {
parentRepo.addGroupFilter(groupId);
if (parentRepo.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshRepository(parentRepo, groupId, modelItemListener);
} else if (parentRepo.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshRepository(parentRepo, groupId, modelItemListener);
}
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
/**
* Refresh model.
*
* @param externalInterruptionFlagSetter
* the external interruption flag setter
* @param modelItemListener
* the model item listener
*/
public static void refreshModel(IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener) {
for (CrawledRepository crawledRepository : RootModelItem.<CrawledRepository> getInstance(ModelConstants.REPOSITORIES_ROOT).getChildren()) {
if (crawledRepository.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
crawledRepository = mavenRepositoryService.refreshRepository(crawledRepository, crawledRepository.getLabel(), modelItemListener);
} else if (crawledRepository.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
crawledRepository = mavenRepositoryService.refreshRepository(crawledRepository, crawledRepository.getLabel(), modelItemListener);
}
RootModelItem.<CrawledRepository> getInstance(ModelConstants.REPOSITORIES_ROOT).addChild(crawledRepository);
}
}
/**
* Refresh repository.
*
* @param crawledRepository
* the repository
* @param externalInterruptionFlagSetter
* the external interruption flag setter
* @param modelItemListener
* the model item listener
*/
public static void refreshRepository(CrawledRepository crawledRepository, IExternalInterruptionFlagSetter externalInterruptionFlagSetter, IModelItemListener modelItemListener) {
if (crawledRepository.getRepositorySetup() instanceof IHttpCrawledRepositorySetup) {
RepositoryCrawlerService<IHttpCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IHttpCrawledRepositorySetup>(new HttpRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshRepository(crawledRepository, crawledRepository.getLabel(), modelItemListener);
} else if (crawledRepository.getRepositorySetup() instanceof IFileSystemCrawledRepositorySetup) {
RepositoryCrawlerService<IFileSystemCrawledRepositorySetup> mavenRepositoryService = new RepositoryCrawlerService<IFileSystemCrawledRepositorySetup>(new FileSystemRepositoryBrowserPlugin());
mavenRepositoryService.addExternalInterruptionFlagSetter(0, externalInterruptionFlagSetter);
mavenRepositoryService.refreshRepository(crawledRepository, crawledRepository.getLabel(), modelItemListener);
}
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
/**
* Save repository info.
*/
public static void saveRepositoryInfo() {
IPath persistedRepositories = getPersistedRepositoriesPath();
IXmlRepositoriesBinder xmlRepositoriesBinder = new StaxRepositoriesBinder();
try {
xmlRepositoriesBinder.toXmlRepositories(new LinkedList<CrawledRepository>(RootModelItem.<CrawledRepository> getInstance(ModelConstants.REPOSITORIES_ROOT).getChildren()), new FileOutputStream(persistedRepositories.toFile()));
logger.info("saved repositories to file " + persistedRepositories.toFile().toString() + ".");
setWorkspacePersistenceStatus(SYNC);
} catch (BindingException e) {
logger.error("impossible to save repositories to file " + persistedRepositories.toFile().toString() + ".", e);
ErrorDialog errorDialog = new ErrorDialog("Binding Error", "An error occured while saving repository information to file " + persistedRepositories.toFile().toString() + ".", e);
errorDialog.open();
} catch (FileNotFoundException e) {
logger.error("impossible to save repositories to file " + persistedRepositories.toFile().toString() + ".", e);
ErrorDialog errorDialog = new ErrorDialog("Binding Error", "An error occured while saving repository information to file " + persistedRepositories.toFile().toString() + ".", e);
errorDialog.open();
}
}
/**
* Sets the workspace persistence status.
*
* @param status
* the new workspace persistence status
*/
public static void setWorkspacePersistenceStatus(Integer status) {
workspacePersistenceStatus = status;
}
/**
* Export repository info.
*
* @param crawledRepositories
* the repositories
* @param file
* the file
*
* @throws FileNotFoundException
* the file not found exception
*/
public static void exportRepositoryInfo(Set<CrawledRepository> crawledRepositories, File file) throws FileNotFoundException {
FileOutputStream baos = new FileOutputStream(file);
IXmlRepositoriesBinder xmlRepositoriesBinder = new StaxRepositoriesBinder();
try {
xmlRepositoriesBinder.toXmlRepositories(new LinkedList<CrawledRepository>(crawledRepositories), baos);
logger.info("exported repository model to file:" + file.toString());
setWorkspacePersistenceStatus(SYNC);
} catch (BindingException e) {
ErrorDialog errorDialog = new ErrorDialog("Binding Error", "An error occured while exporting repository information.", e);
errorDialog.open();
}
}
/**
* Import repository info.
*
* @param tmpFile
* the tmp file
*
* @throws FileNotFoundException
* the file not found exception
*/
public static void importRepositoryInfo(File tmpFile) throws FileNotFoundException {
InputStream contents = new FileInputStream(tmpFile);
if (tmpFile.exists() && !(tmpFile.length() == 0L)) {
try {
loadRepositoryInfo(contents);
} catch (Exception e) {
logger.error("unable to load repositories from an external file.");
} finally {
try {
contents.close();
} catch (IOException e) {
}
logger.info("loaded repositories from an external file.");
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
}
}
/**
* Import repository info.
*
* @param inputStream
* the input stream
*/
public static void importRepositoryInfo(InputStream inputStream) {
try {
loadRepositoryInfo(inputStream);
} catch (Exception e) {
logger.error("unable to load repositories from a stream.");
} finally {
try {
inputStream.close();
} catch (IOException e) {
}
logger.info("loaded repositories from a stream.");
setWorkspacePersistenceStatus(OUT_OF_SYNC);
}
}
}