Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2009-10-09 16:49:13 -0400
committerAndrew Niefer2009-10-09 16:49:13 -0400
commitbe70c40f6a0c18c8909db78b889cdaa4fb4158fb (patch)
treeac4c26a01e0cd8e61a40ff460ccd04aae09bc642 /bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse
parentc33eff97a04c3e8251f7e227927427dc2b9e3fde (diff)
downloadrt.equinox.p2-be70c40f6a0c18c8909db78b889cdaa4fb4158fb.tar.gz
rt.equinox.p2-be70c40f6a0c18c8909db78b889cdaa4fb4158fb.tar.xz
rt.equinox.p2-be70c40f6a0c18c8909db78b889cdaa4fb4158fb.zip
bug 291424 - option to remove only some descriptorsv20091010
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java22
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java60
2 files changed, 69 insertions, 13 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
index 1da4d098e..70a91b01c 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
@@ -10,15 +10,13 @@
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
-import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.CompositeQuery;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query;
-
import java.util.*;
import org.apache.tools.ant.types.DataType;
+import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
+import org.eclipse.equinox.p2.internal.repository.tools.Activator;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
/**
* @since 1.0
@@ -32,6 +30,7 @@ public class IUDescription extends DataType {
private String version;
private String queryString;
private boolean required = true;
+ private String artifactFilter = null;
public IUDescription() {
super();
@@ -52,6 +51,17 @@ public class IUDescription extends DataType {
this.queryString = query;
}
+ public void setArtifacts(String filter) {
+ if (filter != null && !filter.startsWith(ANT_PREFIX))
+ this.artifactFilter = filter;
+ }
+
+ public Filter getArtifactFilter() throws InvalidSyntaxException {
+ if (artifactFilter != null)
+ return Activator.getBundleContext().createFilter(artifactFilter);
+ return null;
+ }
+
public void setRequired(boolean required) {
this.required = required;
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java
index ce40d6dcf..c766504b8 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java
@@ -10,24 +10,27 @@
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Collector;
-
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.Query;
-
-import java.util.Iterator;
+import java.util.*;
import org.apache.tools.ant.BuildException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.internal.provisional.p2.metadata.query.*;
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication;
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
import org.eclipse.osgi.util.NLS;
+import org.osgi.framework.Filter;
+import org.osgi.framework.InvalidSyntaxException;
public class RemoveIUTask extends AbstractRepositoryTask {
+ private static final String CLASSIFIER = "classifier"; //$NON-NLS-1$
+ private static final String ID = "id"; //$NON-NLS-1$
+ private static final String VERSION = "version"; //$NON-NLS-1$
protected static class RemoveIUApplication extends AbstractApplication {
//Only need the application to reuse super's repo management.
@@ -56,6 +59,7 @@ public class RemoveIUTask extends AbstractRepositoryTask {
IMetadataRepository repository = application.getDestinationMetadataRepository();
IArtifactRepository artifacts = application.getDestinationArtifactRepository();
+ final Set toRemove = new HashSet();
for (Iterator iter = iuTasks.iterator(); iter.hasNext();) {
IUDescription iu = (IUDescription) iter.next();
Query iuQuery = iu.createQuery();
@@ -65,16 +69,48 @@ public class RemoveIUTask extends AbstractRepositoryTask {
if (collector.isEmpty())
getProject().log(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString()));
- else if (repository.removeInstallableUnits(iuQuery, null) && artifacts != null) {
+ else {
for (Iterator iterator = collector.iterator(); iterator.hasNext();) {
IInstallableUnit unit = (IInstallableUnit) iterator.next();
IArtifactKey[] keys = unit.getArtifacts();
+ Filter filter = null;
+ try {
+ filter = iu.getArtifactFilter();
+ } catch (InvalidSyntaxException e) {
+ getProject().log(NLS.bind(Messages.skippingInvalidFilter, iu.toString()));
+ continue;
+ }
+
+ //we will only remove the metadata if all artifacts were removed
+ boolean removeMetadata = true;
for (int i = 0; i < keys.length; i++) {
- artifacts.removeDescriptor(keys[i]);
+ if (filter == null) {
+ artifacts.removeDescriptor(keys[i]);
+ } else {
+ IArtifactDescriptor[] descriptors = artifacts.getArtifactDescriptors(keys[i]);
+ for (int j = 0; j < descriptors.length; j++) {
+ if (filter.match(createDictionary(descriptors[j]))) {
+ artifacts.removeDescriptor(descriptors[j]);
+ } else {
+ removeMetadata = false;
+ }
+ }
+ }
}
+ if (removeMetadata)
+ toRemove.add(unit);
}
}
}
+
+ if (toRemove.size() > 0) {
+ Query removeQuery = new MatchQuery() {
+ public boolean isMatch(Object candidate) {
+ return toRemove.contains(candidate);
+ }
+ };
+ repository.removeInstallableUnits(removeQuery, null);
+ }
} catch (ProvisionException e) {
throw new BuildException(e);
} finally {
@@ -85,4 +121,14 @@ public class RemoveIUTask extends AbstractRepositoryTask {
}
}
}
+
+ private Dictionary createDictionary(IArtifactDescriptor descriptor) {
+ Hashtable result = new Hashtable(5);
+ result.putAll(descriptor.getProperties());
+ IArtifactKey key = descriptor.getArtifactKey();
+ result.put(CLASSIFIER, key.getClassifier());
+ result.put(ID, key.getId());
+ result.put(VERSION, key.getVersion());
+ return result;
+ }
}

Back to the top