Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java81
1 files changed, 81 insertions, 0 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
new file mode 100644
index 000000000..ccf1032b1
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RemoveIUTask.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.equinox.p2.internal.repository.tools.tasks;
+
+import java.util.Iterator;
+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.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.repository.IMetadataRepository;
+import org.eclipse.equinox.internal.provisional.p2.query.Collector;
+import org.eclipse.equinox.internal.provisional.p2.query.Query;
+import org.eclipse.equinox.p2.internal.repository.tools.AbstractApplication;
+import org.eclipse.equinox.p2.internal.repository.tools.Messages;
+import org.eclipse.osgi.util.NLS;
+
+public class RemoveIUTask extends AbstractRepositoryTask {
+
+ public RemoveIUTask() {
+ application = new AbstractApplication() {
+ public IStatus run(IProgressMonitor monitor) {
+ return null;
+ }
+
+ public IMetadataRepository getCompositeMetadataRepository() {
+ return destinationMetadataRepository;
+ }
+
+ public IArtifactRepository getCompositeArtifactRepository() {
+ return destinationArtifactRepository;
+ }
+ };
+ }
+
+ public void execute() throws BuildException {
+ try {
+ if (iuTasks == null || iuTasks.isEmpty())
+ return; //nothing to do
+
+ application.initializeRepos(null);
+ if (application.getCompositeMetadataRepository() == null)
+ throw new BuildException(Messages.AbstractApplication_no_valid_destinations); //need a repo
+
+ IMetadataRepository repository = application.getCompositeMetadataRepository();
+ IArtifactRepository artifacts = application.getCompositeArtifactRepository();
+
+ for (Iterator iter = iuTasks.iterator(); iter.hasNext();) {
+ IUDescription iu = (IUDescription) iter.next();
+ Query iuQuery = iu.createQuery();
+
+ Collector collector = new Collector();
+ repository.query(iuQuery, collector, null);
+
+ if (collector.isEmpty())
+ getProject().log(NLS.bind(Messages.AbstractRepositoryTask_unableToFind, iu.toString()));
+ else if (repository.removeInstallableUnits(iuQuery, null) && artifacts != null) {
+ for (Iterator iterator = collector.iterator(); iterator.hasNext();) {
+ IInstallableUnit unit = (IInstallableUnit) iterator.next();
+ IArtifactKey[] keys = unit.getArtifacts();
+ for (int i = 0; i < keys.length; i++) {
+ artifacts.removeDescriptor(keys[i]);
+ }
+ }
+ }
+ }
+ } catch (ProvisionException e) {
+ throw new BuildException(e);
+ }
+ }
+}

Back to the top