Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Zarna2011-02-14 11:40:24 -0500
committerTomasz Zarna2011-02-14 11:40:24 -0500
commit64ca42e7341fe18089a849124c582db2f7aeb890 (patch)
treeb60c8f8ff08017b29b6d120653f6b5a2a4cb10ce
parentc82d5c49fda1e30a7af2034aa3c08798032dd4e4 (diff)
downloadeclipse.platform.team-64ca42e7341fe18089a849124c582db2f7aeb890.tar.gz
eclipse.platform.team-64ca42e7341fe18089a849124c582db2f7aeb890.tar.xz
eclipse.platform.team-64ca42e7341fe18089a849124c582db2f7aeb890.zip
bug 330490: API and UI to configure SCM URLs for import -- adding abstract BundleImporterDelegate
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/BundleImporterDelegate.java101
-rw-r--r--bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/IBundleImporterDelegate.java3
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CvsBundleImporterDelegate.java94
3 files changed, 117 insertions, 81 deletions
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/BundleImporterDelegate.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/BundleImporterDelegate.java
new file mode 100644
index 000000000..b04e4ac56
--- /dev/null
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/BundleImporterDelegate.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2011 IBM Corporation and others.
+ * 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.core.importing.provisional;
+
+import java.util.*;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.*;
+import org.eclipse.osgi.util.ManifestElement;
+import org.eclipse.team.core.*;
+import org.eclipse.team.internal.core.TeamPlugin;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+
+/**
+ * Abstract implementation of {@link IBundleImporterDelegate} that can be subclassed by
+ * clients.
+ */
+public abstract class BundleImporterDelegate implements IBundleImporterDelegate {
+
+ //private static final String ATTR_TAG = "tag"; //$NON-NLS-1$
+ private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$
+
+ public static final String ECLIPSE_SOURCE_REFERENCES = "Eclipse-SourceReferences"; //$NON-NLS-1$
+
+ protected abstract Set getSupportedValues();
+
+ protected abstract RepositoryProviderType getProviderType();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.core.project.IBundleImporterDelegate#validateImport(java.util.Map[])
+ */
+ public ScmUrlImportDescription[] validateImport(Map[] manifests) {
+ ScmUrlImportDescription[] results = new ScmUrlImportDescription[manifests.length];
+ if (getProviderType() != null) {
+ for (int i = 0; i < manifests.length; i++) {
+ Map manifest = manifests[i];
+ String value = (String) manifest.get(ECLIPSE_SOURCE_REFERENCES);
+ if (value != null && value.length() > 8) {
+ String prefix = value.substring(0, 8);
+ if (getSupportedValues().contains(prefix)) {
+ try {
+ ManifestElement[] elements = ManifestElement.parseHeader(ECLIPSE_SOURCE_REFERENCES, value);
+ for (int j = 0; j < elements.length; j++) {
+ ManifestElement element = elements[j];
+ String url = element.getValue();
+ //String tag = element.getAttribute(ATTR_TAG);
+ String project = element.getAttribute(ATTR_PROJECT);
+ if (project == null) {
+ String bsn = (String) manifests[i].get(Constants.BUNDLE_SYMBOLICNAME);
+ if (bsn != null) {
+ ManifestElement[] bsnElement = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, bsn);
+ project = bsnElement[0].getValue();
+ }
+ }
+ results[i] = new ScmUrlImportDescription(url, project);
+ }
+ } catch (BundleException e) {
+ TeamPlugin.log(IStatus.ERROR, "An exception occured while parsing a manifest header", e);//$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ return results;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.pde.core.importing.IBundleImporterDelegate#performImport(org.eclipse.pde.core.importing.BundleImportDescription[], org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IProject[] performImport(ScmUrlImportDescription[] descriptions, IProgressMonitor monitor) throws CoreException {
+ // TODO: import takes places when finishing contributed pages. this method can be removed
+ List references = new ArrayList();
+ ProjectSetCapability psfCapability = getProviderType().getProjectSetCapability();
+ // collect and validate all header values
+ for (int i = 0; i < descriptions.length; i++) {
+ ScmUrlImportDescription description = (ScmUrlImportDescription) descriptions[i];
+ references.add(psfCapability.asReference(description.getUri(), description.getProject()));
+ }
+ // create projects
+ if (!references.isEmpty()) {
+ SubMonitor subMonitor = SubMonitor.convert(monitor, references.size());
+ if (psfCapability != null) {
+ // TODO: specify shell
+ psfCapability.addToWorkspace((String[]) references.toArray(new String[references.size()]), new ProjectSetSerializationContext(), subMonitor);
+ } else {
+ //TODO: error
+ }
+ subMonitor.done();
+ }
+ return null;
+ }
+}
diff --git a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/IBundleImporterDelegate.java b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/IBundleImporterDelegate.java
index bc6458ac5..b895475db 100644
--- a/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/IBundleImporterDelegate.java
+++ b/bundles/org.eclipse.team.core/src/org/eclipse/team/core/importing/provisional/IBundleImporterDelegate.java
@@ -31,7 +31,8 @@ import org.eclipse.team.core.ScmUrlImportDescription;
* </pre>
* </p>
* <p>
- * Clients contributing bundle importer extensions are intended to implement this interface.
+ * Clients contributing bundle importer extensions are intended to implement this interface.
+ * They can also subclass {@link BundleImporterDelegate}.
* </p>
* <p>
* <strong>EXPERIMENTAL</strong>. This interface has been added as
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CvsBundleImporterDelegate.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CvsBundleImporterDelegate.java
index 8fb3c073a..c58ce2015 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CvsBundleImporterDelegate.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CvsBundleImporterDelegate.java
@@ -10,15 +10,11 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.core;
-import java.util.*;
+import java.util.HashSet;
+import java.util.Set;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.*;
-import org.eclipse.osgi.util.ManifestElement;
-import org.eclipse.team.core.*;
-import org.eclipse.team.core.importing.provisional.IBundleImporterDelegate;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
+import org.eclipse.team.core.RepositoryProviderType;
+import org.eclipse.team.core.importing.provisional.BundleImporterDelegate;
/**
* Handles SCM CVS headers of the following form. Tag and project name can be specified
@@ -28,9 +24,8 @@ import org.osgi.framework.Constants;
* scm:cvs&lt;delimiter&gt;&lt;method&gt;&lt;delimiter&gt;path_to_repository&lt;delimiter&gt;module_name[;tag=version][;project=name]
* scm:psf&lt;delimiter&gt;&lt;method&gt;&lt;delimiter&gt;path_to_repository&lt;delimiter&gt;module_name[;tag=version][;project=name]
* </pre>
- * @since 3.7
*/
-public class CvsBundleImporterDelegate implements IBundleImporterDelegate {
+public class CvsBundleImporterDelegate extends BundleImporterDelegate {
private static Set SUPPORTED_VALUES;
@@ -40,12 +35,7 @@ public class CvsBundleImporterDelegate implements IBundleImporterDelegate {
private static final String COLON = ":"; //$NON-NLS-1$
private static final String PIPE = "|"; //$NON-NLS-1$
- //private static final String ATTR_TAG = "tag"; //$NON-NLS-1$
- private static final String ATTR_PROJECT = "project"; //$NON-NLS-1$
-
- public static final String ECLIPSE_SOURCE_REFERENCES = "Eclipse-SourceReferences"; //$NON-NLS-1$
-
- private static RepositoryProviderType CVS_PROVIDER_TYPE = RepositoryProviderType.getProviderType("org.eclipse.team.cvs.core.cvsnature"); //$NON-NLS-1$
+ private RepositoryProviderType providerType;
static {
SUPPORTED_VALUES = new HashSet();
@@ -54,71 +44,15 @@ public class CvsBundleImporterDelegate implements IBundleImporterDelegate {
// SUPPORTED_VALUES.add(SCM + PSF + COLON);
// SUPPORTED_VALUES.add(SCM + PSF + PIPE);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.core.project.IBundleImporterDelegate#validateImport(java.util.Map[])
- */
- public ScmUrlImportDescription[] validateImport(Map[] manifests) {
- // TODO: this is not CVS specific, the code is the same for all providers
- ScmUrlImportDescription[] results = new ScmUrlImportDescription[manifests.length];
- if (CVS_PROVIDER_TYPE != null) {
- for (int i = 0; i < manifests.length; i++) {
- Map manifest = manifests[i];
- String value = (String) manifest.get(ECLIPSE_SOURCE_REFERENCES);
- if (value != null && value.length() > 8) {
- String prefix = value.substring(0, 8);
- if (SUPPORTED_VALUES.contains(prefix)) {
- try {
- ManifestElement[] elements = ManifestElement.parseHeader(ECLIPSE_SOURCE_REFERENCES, value);
- for (int j = 0; j < elements.length; j++) {
- ManifestElement element = elements[j];
- String url = element.getValue();
- //String tag = element.getAttribute(ATTR_TAG);
- String project = element.getAttribute(ATTR_PROJECT);
- if (project == null) {
- String bsn = (String) manifests[i].get(Constants.BUNDLE_SYMBOLICNAME);
- if (bsn != null) {
- ManifestElement[] bsnElement = ManifestElement.parseHeader(Constants.BUNDLE_SYMBOLICNAME, bsn);
- project = bsnElement[0].getValue();
- }
- }
- results[i] = new ScmUrlImportDescription(url, project);
- }
- } catch (BundleException e) {
- //TODO log exception
- //PDECore.log(e);
- }
- }
- }
- }
- }
- return results;
+
+ protected Set getSupportedValues() {
+ return SUPPORTED_VALUES;
}
-
- /* (non-Javadoc)
- * @see org.eclipse.pde.core.importing.IBundleImporterDelegate#performImport(org.eclipse.pde.core.importing.BundleImportDescription[], org.eclipse.core.runtime.IProgressMonitor)
- */
- public IProject[] performImport(ScmUrlImportDescription[] descriptions, IProgressMonitor monitor) throws CoreException {
- // TODO: import takes places when finishing contributed pages. this method can be removed
- List references = new ArrayList();
- ProjectSetCapability psfCapability = CVS_PROVIDER_TYPE.getProjectSetCapability();
- // collect and validate all header values
- for (int i = 0; i < descriptions.length; i++) {
- ScmUrlImportDescription description = (ScmUrlImportDescription) descriptions[i];
- references.add(psfCapability.asReference(description.getUri(), description.getProject()));
- }
- // create projects
- if (!references.isEmpty()) {
- SubMonitor subMonitor = SubMonitor.convert(monitor, references.size());
- if (psfCapability != null) {
- // TODO: specify shell
- psfCapability.addToWorkspace((String[]) references.toArray(new String[references.size()]), new ProjectSetSerializationContext(), subMonitor);
- } else {
- //TODO: error
- }
- subMonitor.done();
- }
- return null;
+
+ protected RepositoryProviderType getProviderType() {
+ if (providerType == null)
+ providerType = RepositoryProviderType.getProviderType("org.eclipse.team.cvs.core.cvsnature"); //$NON-NLS-1$
+ return providerType;
}
}

Back to the top