Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2008-11-28 20:57:50 +0000
committerAndrew Niefer2008-11-28 20:57:50 +0000
commit4ee4fc0cf716bf84561bcdd42571fa87bae76ec7 (patch)
tree8983af4e87db2013855d81123f8f64451e35eafa /bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox
parentbb09f708c706da7b9b8499edb4d50f9724ad8fa7 (diff)
downloadrt.equinox.p2-4ee4fc0cf716bf84561bcdd42571fa87bae76ec7.tar.gz
rt.equinox.p2-4ee4fc0cf716bf84561bcdd42571fa87bae76ec7.tar.xz
rt.equinox.p2-4ee4fc0cf716bf84561bcdd42571fa87bae76ec7.zip
bug 255678 - compare while mirroring
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java68
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties3
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java52
4 files changed, 87 insertions, 38 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java
index ebd803f29..a589cba7b 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/mirror/Mirroring.java
@@ -30,47 +30,14 @@ public class Mirroring {
private boolean raw;
private boolean compare = false;
private IArtifactComparator comparator;
- private String comparatorID = null;
-
- private static final String comparatorPoint = "org.eclipse.equinox.p2.artifact.repository.comparators"; //$NON-NLS-1$
- private static final String ATTR_ID = "id"; //$NON-NLS-1$
- private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+ private String comparatorID;
private IArtifactComparator getComparator() {
if (comparator == null)
- comparator = computeComparators();
+ comparator = ArtifactComparatorFactory.getArtifactComparator(comparatorID);
return comparator;
}
- private IArtifactComparator computeComparators() {
- IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(comparatorPoint);
-
- IConfigurationElement element = null;
- if (comparatorID == null && extensions.length > 0) {
- element = extensions[0]; //just take the first one
- } else {
- for (int i = 0; i < extensions.length; i++) {
- if (extensions[i].getAttribute(ATTR_ID).equals(comparatorID)) {
- element = extensions[i];
- break;
- }
- }
- }
- if (element != null) {
- try {
- Object execExt = element.createExecutableExtension(ATTR_CLASS);
- if (execExt instanceof IArtifactComparator)
- return (IArtifactComparator) execExt;
- } catch (Exception e) {
- //fall through
- }
- }
-
- if (comparatorID != null)
- throw new IllegalArgumentException(NLS.bind(Messages.exception_comparatorNotFound, comparatorID));
- throw new IllegalArgumentException(Messages.exception_noComparators);
- }
-
public Mirroring(IArtifactRepository source, IArtifactRepository destination, boolean raw) {
this.source = source;
this.destination = destination;
@@ -89,7 +56,7 @@ public class Mirroring {
if (!destination.isModifiable())
throw new IllegalStateException(NLS.bind(Messages.exception_destinationNotModifiable, destination.getLocation()));
if (compare)
- getComparator(); //initialize the comparator. Only needed if we're comparing.
+ getComparator(); //initialize the comparator. Only needed if we're comparing. Used to force error if comparatorID is invalid.
IArtifactKey[] keys = source.getArtifactKeys();
MultiStatus multiStatus = new MultiStatus(Activator.ID, IStatus.OK, Messages.message_mirroringStatus, null);
for (int i = 0; i < keys.length; i++) {
@@ -113,6 +80,7 @@ public class Mirroring {
if (verbose)
System.out.println("Mirroring: " + descriptor.getArtifactKey() + " (Descriptor: " + descriptor + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
repositoryStream = destination.getOutputStream(newDescriptor);
+
return source.getRawArtifact(descriptor, repositoryStream, new NullProgressMonitor());
} finally {
if (repositoryStream != null) {
@@ -129,10 +97,36 @@ public class Mirroring {
String message = NLS.bind(Messages.mirror_alreadyExists, descriptor, destination);
if (!compare)
return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, message, e);
- return getComparator().compare(source, descriptor, destination, newDescriptor);
+ return compareToDestination(descriptor, e);
}
return e.getStatus();
}
}
+
+ /**
+ * Takes an IArtifactDescriptor descriptor and the ProvisionException that was thrown when destination.getOutputStream(descriptor)
+ * and compares descriptor to the duplicate descriptor in the destination.
+ *
+ * Callers should verify the ProvisionException was thrown due to the artifact existing in the destination before invoking this method.
+ * @param descriptor
+ * @param e
+ * @return the status of the compare
+ */
+ private IStatus compareToDestination(IArtifactDescriptor descriptor, ProvisionException e) {
+ IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor.getArtifactKey());
+ IArtifactDescriptor destDescriptor = null;
+ boolean descriptorMatched = false;
+ for (int i = 0; i < destDescriptors.length && !descriptorMatched; i++) {
+ if (destDescriptors[i].equals(descriptor)) {
+ destDescriptor = destDescriptors[i];
+ descriptorMatched = true;
+ }
+ }
+
+ if (descriptorMatched)
+ return getComparator().compare(source, descriptor, destination, destDescriptor);
+
+ return new Status(IStatus.INFO, Activator.ID, ProvisionException.ARTIFACT_EXISTS, Messages.Mirroring_NO_MATCHING_DESCRIPTOR, e);
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
index d756b9ac6..002a04798 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java
@@ -45,6 +45,8 @@ public class Messages extends NLS {
public static String exception_needSourceDestination;
public static String exception_malformedRepoURI;
+ public static String Mirroring_NO_MATCHING_DESCRIPTOR;
+
static {
// initialize resource bundles
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
index d98487b53..23f08888d 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties
@@ -43,4 +43,5 @@ exception_comparatorNotFound = The Artifact Comparator {0} was not found.
exception_noComparators = No Artifact Comparators are available.
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
exception_needSourceDestination = Must specify a source and destination.
-exception_malformedRepoURI = The repository location ({0}) must be a URI. \ No newline at end of file
+exception_malformedRepoURI = The repository location ({0}) must be a URI.
+Mirroring_NO_MATCHING_DESCRIPTOR=Could not match descriptor for compare
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java
new file mode 100644
index 000000000..e65e32903
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/ArtifactComparatorFactory.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * compeople AG (Stefan Liebig) - various ongoing maintenance
+ *******************************************************************************/
+package org.eclipse.equinox.internal.provisional.p2.artifact.repository;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
+import org.eclipse.osgi.util.NLS;
+
+public class ArtifactComparatorFactory {
+ private static final String comparatorPoint = "org.eclipse.equinox.p2.artifact.repository.artifactComparators"; //$NON-NLS-1$
+ private static final String ATTR_ID = "id"; //$NON-NLS-1$
+ private static final String ATTR_CLASS = "class"; //$NON-NLS-1$
+
+ public static IArtifactComparator getArtifactComparator(String comparatorID) {
+ IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(comparatorPoint);
+
+ IConfigurationElement element = null;
+ if (comparatorID == null && extensions.length > 0) {
+ element = extensions[0]; //just take the first one
+ } else {
+ for (int i = 0; i < extensions.length; i++) {
+ if (extensions[i].getAttribute(ATTR_ID).equals(comparatorID)) {
+ element = extensions[i];
+ break;
+ }
+ }
+ }
+ if (element != null) {
+ try {
+ Object execExt = element.createExecutableExtension(ATTR_CLASS);
+ if (execExt instanceof IArtifactComparator)
+ return (IArtifactComparator) execExt;
+ } catch (Exception e) {
+ //fall through
+ }
+ }
+
+ if (comparatorID != null)
+ throw new IllegalArgumentException(NLS.bind(Messages.exception_comparatorNotFound, comparatorID));
+ throw new IllegalArgumentException(Messages.exception_noComparators);
+ }
+}

Back to the top