diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java | 60 |
1 files changed, 53 insertions, 7 deletions
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; + } } |