Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2010-01-13 17:29:41 +0000
committerPascal Rapicault2010-01-13 17:29:41 +0000
commit18189f0d42f7375660762dc6c885cf31683ae562 (patch)
tree17775d847bed9a33f3c68b74db2df75a2139c0bc /bundles/org.eclipse.equinox.p2.console
parentc363f2984a09b73c422e38f4556fd3b23eafe958 (diff)
downloadrt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.gz
rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.tar.xz
rt.equinox.p2-18189f0d42f7375660762dc6c885cf31683ae562.zip
Merging api branch back to HEADv20100113
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.console')
-rw-r--r--bundles/org.eclipse.equinox.p2.console/.classpath4
-rw-r--r--bundles/org.eclipse.equinox.p2.console/.settings/org.eclipse.jdt.core.prefs15
-rw-r--r--bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF21
-rw-r--r--bundles/org.eclipse.equinox.p2.console/build.properties2
-rw-r--r--bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/Activator.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java372
-rw-r--r--bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java170
7 files changed, 451 insertions, 156 deletions
diff --git a/bundles/org.eclipse.equinox.p2.console/.classpath b/bundles/org.eclipse.equinox.p2.console/.classpath
index 7cdeb7319..64c5e31b7 100644
--- a/bundles/org.eclipse.equinox.p2.console/.classpath
+++ b/bundles/org.eclipse.equinox.p2.console/.classpath
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/bundles/org.eclipse.equinox.p2.console/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.console/.settings/org.eclipse.jdt.core.prefs
index a455b6228..dd9ddfffa 100644
--- a/bundles/org.eclipse.equinox.p2.console/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.p2.console/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Thu Sep 13 22:02:41 EDT 2007
+#Mon Dec 28 17:08:33 CET 2009
eclipse.preferences.version=1
instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
@@ -8,24 +8,24 @@ org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch
org.eclipse.jdt.core.circularClasspath=error
org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=jsr14
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=1000
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=error
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
@@ -81,7 +81,7 @@ org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=en
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=enabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
@@ -153,7 +153,6 @@ org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true
org.eclipse.jdt.core.formatter.indentation.size=4
-org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
diff --git a/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF
index ad704999f..46f109c5d 100644
--- a/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.console/META-INF/MANIFEST.MF
@@ -7,20 +7,23 @@ Bundle-Localization: plugin
Bundle-Version: 1.0.100.qualifier
Bundle-Activator: org.eclipse.equinox.internal.p2.console.Activator
Bundle-ActivationPolicy: lazy
-Export-Package: org.eclipse.equinox.internal.p2.console;x-friends:="org.eclipse.equinox.p2.director.app,org.eclipse.equinox.p2.tools"
+Export-Package: org.eclipse.equinox.internal.p2.console;x-friends:="org.eclipse.equinox.p2.director.app"
Import-Package: org.eclipse.core.runtime;common=split,
org.eclipse.equinox.internal.p2.core.helpers,
- org.eclipse.equinox.internal.provisional.p2.artifact.repository,
- org.eclipse.equinox.internal.provisional.p2.core,
org.eclipse.equinox.internal.provisional.p2.director,
- org.eclipse.equinox.internal.provisional.p2.engine,
org.eclipse.equinox.internal.provisional.p2.metadata,
- org.eclipse.equinox.internal.provisional.p2.metadata.query,
- org.eclipse.equinox.internal.provisional.p2.metadata.repository,
- org.eclipse.equinox.internal.provisional.p2.repository,
+ org.eclipse.equinox.p2.core,
+ org.eclipse.equinox.p2.engine,
+ org.eclipse.equinox.p2.metadata,
+ org.eclipse.equinox.p2.metadata.query,
+ org.eclipse.equinox.p2.query,
+ org.eclipse.equinox.p2.repository,
+ org.eclipse.equinox.p2.repository.artifact,
+ org.eclipse.equinox.p2.repository.metadata,
org.eclipse.osgi.framework.console;version="1.0.0";resolution:=optional,
org.eclipse.osgi.service.environment;version="1.0.0",
org.osgi.framework;version="1.4.0",
org.osgi.util.tracker;version="1.3.0"
-Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
- J2SE-1.4
+Bundle-RequiredExecutionEnvironment: J2SE-1.5,
+ J2SE-1.4,
+ CDC-1.1/Foundation-1.1
diff --git a/bundles/org.eclipse.equinox.p2.console/build.properties b/bundles/org.eclipse.equinox.p2.console/build.properties
index a6b8330d2..246ea6cb7 100644
--- a/bundles/org.eclipse.equinox.p2.console/build.properties
+++ b/bundles/org.eclipse.equinox.p2.console/build.properties
@@ -15,3 +15,5 @@ bin.includes = META-INF/,\
about.html,\
plugin.properties
src.includes = about.html
+javacTarget=jsr14
+javacSource=1.5
diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/Activator.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/Activator.java
index 78398a0b0..42a465ee1 100644
--- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2008, 2009, IBM Corporation and others. All rights reserved. This
* 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
@@ -7,10 +7,11 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Composent, Inc. - additions
*******************************************************************************/
package org.eclipse.equinox.internal.p2.console;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -33,8 +34,8 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
super();
}
- public void start(BundleContext context) throws Exception {
- Activator.context = context;
+ public void start(BundleContext ctxt) throws Exception {
+ Activator.context = ctxt;
boolean registerCommands = true;
try {
Class.forName(PROVIDER_NAME);
@@ -43,12 +44,12 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
}
if (registerCommands) {
- profileTracker = new ServiceTracker(context, IProfileRegistry.class.getName(), this);
+ profileTracker = new ServiceTracker(context, IProfileRegistry.SERVICE_NAME, this);
profileTracker.open();
}
}
- public void stop(BundleContext context) throws Exception {
+ public void stop(BundleContext ctxt) throws Exception {
profileTracker.close();
if (providerRegistration != null)
providerRegistration.unregister();
@@ -57,15 +58,15 @@ public class Activator implements BundleActivator, ServiceTrackerCustomizer {
}
public Object addingService(ServiceReference reference) {
- BundleContext context = Activator.getContext();
- IProfileRegistry registry = (IProfileRegistry) context.getService(reference);
- provider = new ProvCommandProvider(context.getProperty("eclipse.p2.profile"), registry);
- providerRegistration = context.registerService(PROVIDER_NAME, provider, null);
+ BundleContext ctxt = Activator.getContext();
+ IProfileRegistry registry = (IProfileRegistry) ctxt.getService(reference);
+ provider = new ProvCommandProvider(ctxt.getProperty("eclipse.p2.profile"), registry); //$NON-NLS-1$
+ providerRegistration = ctxt.registerService(PROVIDER_NAME, provider, null);
return registry;
}
public void modifiedService(ServiceReference reference, Object service) {
- // TODO Auto-generated method stub
+ // nothing
}
public void removedService(ServiceReference reference, Object service) {
diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java
index 54b137b8a..83bb98ad9 100644
--- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java
+++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvCommandProvider.java
@@ -1,15 +1,17 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others. All rights reserved. This
+ * Copyright (c) 2007, 2008, 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
* Band XI - add more commands
+ * Composent, Inc. - command additions
******************************************************************************/
package org.eclipse.equinox.internal.p2.console;
-import org.eclipse.equinox.internal.provisional.p2.metadata.VersionRange;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.VersionRange;
import java.io.File;
import java.net.URI;
@@ -18,14 +20,17 @@ import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
-import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry;
-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.IMetadataRepositoryManager;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.query.GroupQuery;
+import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.IQueryable;
+import org.eclipse.equinox.p2.repository.artifact.*;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
@@ -55,60 +60,90 @@ public class ProvCommandProvider implements CommandProvider {
}
/**
- * Adds a metadata repository.
+ * Adds both a metadata repository and artifact repository
*/
public void _provaddrepo(CommandInterpreter interpreter) {
String urlString = interpreter.nextArgument();
if (urlString == null) {
- interpreter.print("Repository location must be provided");
- interpreter.println();
+ interpreter.println("Repository location must be provided");
return;
}
- URI repoURL = toURI(interpreter, urlString);
- if (repoURL == null)
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
return;
- if (ProvisioningHelper.addMetadataRepository(repoURL) == null)
- interpreter.println("Unable to add repository: " + repoURL);
+ // add metadata repo
+ if (ProvisioningHelper.addMetadataRepository(repoURI) == null) {
+ interpreter.println("Unable to add metadata repository: " + repoURI);
+ } else // add artifact repo at same URL
+ if (ProvisioningHelper.addArtifactRepository(repoURI) == null) {
+ interpreter.println("Unable to add artifact repository: " + repoURI);
+ }
}
public void _provdelrepo(CommandInterpreter interpreter) {
String urlString = interpreter.nextArgument();
if (urlString == null) {
- interpreter.print("Repository location must be provided");
- interpreter.println();
+ interpreter.println("Repository location must be provided");
return;
}
- URI repoURL = toURI(interpreter, urlString);
- if (repoURL == null)
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
+ return;
+ ProvisioningHelper.removeMetadataRepository(repoURI);
+ ProvisioningHelper.removeArtifactRepository(repoURI);
+ }
+
+ /**
+ * Adds a metadata repository.
+ */
+ public void _provaddmetadatarepo(CommandInterpreter interpreter) {
+ String urlString = interpreter.nextArgument();
+ if (urlString == null) {
+ interpreter.println("Repository location must be provided");
+ return;
+ }
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
return;
- ProvisioningHelper.removeMetadataRepository(repoURL);
+ if (ProvisioningHelper.addMetadataRepository(repoURI) == null)
+ interpreter.println("Unable to add repository: " + repoURI);
+ }
+
+ public void _provdelmetadatarepo(CommandInterpreter interpreter) {
+ String urlString = interpreter.nextArgument();
+ if (urlString == null) {
+ interpreter.println("Repository location must be provided");
+ return;
+ }
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
+ return;
+ ProvisioningHelper.removeMetadataRepository(repoURI);
}
public void _provaddartifactrepo(CommandInterpreter interpreter) {
String urlString = interpreter.nextArgument();
if (urlString == null) {
- interpreter.print("Repository location must be provided");
- interpreter.println();
+ interpreter.println("Repository location must be provided");
return;
}
- URI repoURL = toURI(interpreter, urlString);
- if (repoURL == null)
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
return;
- if (ProvisioningHelper.addArtifactRepository(repoURL) == null)
- interpreter.println("Unable to add repository: " + repoURL);
+ if (ProvisioningHelper.addArtifactRepository(repoURI) == null)
+ interpreter.println("Unable to add repository " + repoURI);
}
public void _provdelartifactrepo(CommandInterpreter interpreter) {
String urlString = interpreter.nextArgument();
if (urlString == null) {
- interpreter.print("Repository location must be provided");
- interpreter.println();
+ interpreter.println("Repository location must be provided");
return;
}
- URI repoURL = toURI(interpreter, urlString);
- if (repoURL == null)
+ URI repoURI = toURI(interpreter, urlString);
+ if (repoURI == null)
return;
- ProvisioningHelper.removeArtifactRepository(repoURL);
+ ProvisioningHelper.removeArtifactRepository(repoURI);
}
/**
@@ -118,24 +153,26 @@ public class ProvCommandProvider implements CommandProvider {
String iu = interpreter.nextArgument();
String version = interpreter.nextArgument();
String profileId = interpreter.nextArgument();
- if (profileId == null || profileId.equals("this"))
+ if (profileId == null || profileId.equals("this")) //$NON-NLS-1$
profileId = IProfileRegistry.SELF;
if (iu == null || version == null || profileId == null) {
- interpreter.println("Installable unit id, version, and profile Id must be provided");
+ interpreter.println("Installable unit id, version, and profileid must be provided");
return;
}
IStatus s = null;
try {
s = ProvisioningHelper.install(iu, version, ProvisioningHelper.getProfile(profileId), new NullProgressMonitor());
} catch (ProvisionException e) {
- interpreter.println("installation failed ");
- e.printStackTrace();
+ interpreter.println("Installation failed with ProvisionException for " + iu + " " + version);
+ interpreter.printStackTrace(e);
return;
}
if (s.isOK())
- interpreter.println("installation complete");
- else
- interpreter.println("installation failed " + s.getMessage());
+ interpreter.println("Installation complete for " + iu + " " + version);
+ else {
+ interpreter.println("Installation failed for " + iu + " " + version);
+ printErrorStatus(interpreter, s);
+ }
}
/**
@@ -150,16 +187,16 @@ public class ProvCommandProvider implements CommandProvider {
return;
}
String environments = interpreter.nextArgument();
- Properties props = new Properties();
- props.setProperty(IProfile.PROP_INSTALL_FOLDER, location);
- props.setProperty(IProfile.PROP_FLAVOR, flavor);
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(IProfile.PROP_INSTALL_FOLDER, location);
if (environments != null)
- props.setProperty(IProfile.PROP_ENVIRONMENTS, environments);
+ props.put(IProfile.PROP_ENVIRONMENTS, environments);
try {
ProvisioningHelper.addProfile(profileId, props);
} catch (ProvisionException e) {
- interpreter.println("add profile failed " + e.getMessage());
+ interpreter.println("Add profile failed. " + e.getMessage());
+ interpreter.printStackTrace(e);
}
}
@@ -169,7 +206,7 @@ public class ProvCommandProvider implements CommandProvider {
public void _provdelprofile(CommandInterpreter interpreter) {
String profileId = interpreter.nextArgument();
if (profileId == null) {
- interpreter.println("Id must be provided");
+ interpreter.println("profileid must be provided");
return;
}
ProvisioningHelper.removeProfile(profileId);
@@ -225,9 +262,9 @@ public class ProvCommandProvider implements CommandProvider {
*/
public void _provlg(CommandInterpreter interpreter) {
String urlString = processArgument(interpreter.nextArgument());
- IQueryable queryable = null;
+ IQueryable<IInstallableUnit> queryable = null;
if (urlString == null) {
- queryable = (IQueryable) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ queryable = (IQueryable<IInstallableUnit>) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
if (queryable == null)
return;
} else {
@@ -238,8 +275,7 @@ public class ProvCommandProvider implements CommandProvider {
if (queryable == null)
return;
}
- Query query = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_GROUP, Boolean.TRUE.toString());
- IInstallableUnit[] units = sort(queryable.query(query, new Collector(), null));
+ IInstallableUnit[] units = sort(queryable.query(new GroupQuery(), null));
for (int i = 0; i < units.length; i++)
println(interpreter, units[i]);
}
@@ -264,26 +300,27 @@ public class ProvCommandProvider implements CommandProvider {
if (repoURL == null)
return;
IArtifactRepository repo = ProvisioningHelper.getArtifactRepository(repoURL);
- IArtifactKey[] keys = null;
+ IQueryResult<IArtifactKey> keys = null;
try {
- keys = (repo != null) ? repo.getArtifactKeys() : null;
+ keys = (repo != null) ? repo.query(ArtifactKeyQuery.ALL_KEYS, null) : null;
} catch (UnsupportedOperationException e) {
- interpreter.println("Repository does not support list commands.");
+ interpreter.println("Repository does not support queries.");
return;
}
- if (keys == null || keys.length == 0) {
+ if (keys == null || keys.isEmpty()) {
interpreter.println("Repository has no artifacts");
return;
}
IFileArtifactRepository fileRepo = (IFileArtifactRepository) repo.getAdapter(IFileArtifactRepository.class);
- for (int i = 0; i < keys.length; i++) {
- IArtifactDescriptor[] descriptors = repo.getArtifactDescriptors(keys[i]);
+ for (Iterator<IArtifactKey> iterator = keys.iterator(); iterator.hasNext();) {
+ IArtifactKey key = iterator.next();
+ IArtifactDescriptor[] descriptors = repo.getArtifactDescriptors(key);
for (int j = 0; j < descriptors.length; j++) {
IArtifactDescriptor descriptor = descriptors[j];
File location = null;
if (fileRepo != null)
location = fileRepo.getArtifactFile(descriptor);
- println(interpreter, keys[i], location);
+ println(interpreter, key, location);
}
}
@@ -326,53 +363,238 @@ public class ProvCommandProvider implements CommandProvider {
}
// determine which profile is to be listed
IProfile target = null;
- if (profileId.equals("this"))
+ if (profileId.equals("this")) //$NON-NLS-1$
profileId = IProfileRegistry.SELF;
target = ProvisioningHelper.getProfile(profileId);
if (target == null)
return;
// list the profile contents
- IInstallableUnit[] result = sort(target.query(new InstallableUnitQuery(id, new VersionRange(range)), new Collector(), null));
+ IInstallableUnit[] result = sort(target.query(new InstallableUnitQuery(id, new VersionRange(range)), null));
for (int i = 0; i < result.length; i++)
interpreter.println(result[i]);
}
- private IInstallableUnit[] sort(Collector collector) {
- IInstallableUnit[] units = (IInstallableUnit[]) collector.toArray(IInstallableUnit.class);
- Arrays.sort(units, new Comparator() {
- public int compare(Object arg0, Object arg1) {
+ /**
+ * Lists the profile timestamps for a given profile id, if no profile id, the default profile
+ * is used.
+ *
+ * @param interpreter
+ */
+ public void _provlpts(CommandInterpreter interpreter) {
+ String profileId = processArgument(interpreter.nextArgument());
+ if (profileId == null || profileId.equals("this")) { //$NON-NLS-1$
+ profileId = IProfileRegistry.SELF;
+ }
+ long[] profileTimestamps = ProvisioningHelper.getProfileTimestamps(profileId);
+ // if no profile timestamps for given id, print that out and done
+ if (profileTimestamps == null || profileTimestamps.length == 0) {
+ interpreter.print("No timestamps found for profile ");
+ interpreter.println(profileId);
+ return;
+ }
+ // else if there are some timestamps then print them out on separate line
+ interpreter.print("Timestamps for profile ");
+ interpreter.println(profileId);
+ for (int i = 0; i < profileTimestamps.length; i++) {
+ interpreter.print("\t"); //$NON-NLS-1$
+ interpreter.println(new Long(profileTimestamps[i]));
+ }
+ }
+
+ /**
+ * Revert a profile to a given timestamp
+ */
+ public void _provrevert(CommandInterpreter interpreter) {
+ String timestamp = interpreter.nextArgument();
+ if (timestamp == null) {
+ interpreter.println("Valid timestamp must be provided. Timestamps can be retrieved via 'provlpts' command.");
+ return;
+ }
+ Long ts = null;
+ try {
+ ts = new Long(timestamp);
+ } catch (NumberFormatException e) {
+ interpreter.println("Timestamp " + timestamp + " not valid. Timestamps can be retrieved via 'provlpts' command.");
+ return;
+ }
+ String profileId = interpreter.nextArgument();
+ if (profileId == null || profileId.equals("this"))
+ profileId = IProfileRegistry.SELF;
+
+ IProfile profile = ProvisioningHelper.getProfile(profileId);
+ if (profile == null) {
+ interpreter.println("Profile " + profileId + " not found");
+ return;
+ }
+ IStatus s = null;
+ try {
+ s = ProvisioningHelper.revertToPreviousState(profile, ts.longValue());
+ } catch (ProvisionException e) {
+ interpreter.println("revert failed ");
+ interpreter.printStackTrace(e);
+ return;
+ }
+ if (s.isOK())
+ interpreter.println("revert completed");
+ else {
+ interpreter.println("revert failed ");
+ printErrorStatus(interpreter, s);
+ }
+ }
+
+ private IInstallableUnit[] sort(IQueryResult<IInstallableUnit> queryResult) {
+ IInstallableUnit[] units = queryResult.toArray(IInstallableUnit.class);
+ Arrays.sort(units, new Comparator<IInstallableUnit>() {
+ public int compare(IInstallableUnit arg0, IInstallableUnit arg1) {
return arg0.toString().compareTo(arg1.toString());
}
});
return units;
}
+ public void _provlgp(CommandInterpreter interpreter) {
+ String profileId = processArgument(interpreter.nextArgument());
+ if (profileId == null || profileId.equals("this")) {
+ profileId = IProfileRegistry.SELF;
+ }
+ IProfile profile = ProvisioningHelper.getProfile(profileId);
+ if (profile == null) {
+ interpreter.println("Profile " + profileId + " not found");
+ return;
+ }
+ IInstallableUnit[] units = sort(profile.query(new GroupQuery(), new NullProgressMonitor()));
+ // Now print out results
+ for (int i = 0; i < units.length; i++)
+ println(interpreter, units[i]);
+
+ }
+
+ public void _provremove(CommandInterpreter interpreter) {
+ String iu = interpreter.nextArgument();
+ String version = interpreter.nextArgument();
+ String profileId = interpreter.nextArgument();
+ if (profileId == null || profileId.equals("this"))
+ profileId = IProfileRegistry.SELF;
+ if (version == null) {
+ version = Version.emptyVersion.toString();
+ }
+ if (iu == null) {
+ interpreter.println("Installable unit id must be provided");
+ return;
+ }
+ IStatus s = null;
+ try {
+ s = ProvisioningHelper.uninstall(iu, version, ProvisioningHelper.getProfile(profileId), new NullProgressMonitor());
+ } catch (ProvisionException e) {
+ interpreter.println("Remove failed with ProvisionException for " + iu + " " + version);
+ interpreter.printStackTrace(e);
+ return;
+ }
+ if (s.isOK())
+ interpreter.println("Remove complete for " + iu + " " + version);
+ else {
+ interpreter.println("Remove failed for " + iu + " " + version);
+ printErrorStatus(interpreter, s);
+ }
+ }
+
+ private void printErrorStatus(CommandInterpreter interpreter, IStatus status) {
+ interpreter.print("--Error status ");
+ interpreter.print("message=" + status.getMessage());
+ interpreter.print(",code=" + status.getCode());
+ String severityString = null;
+ switch (status.getSeverity()) {
+ case IStatus.INFO :
+ severityString = "INFO";
+ break;
+ case IStatus.CANCEL :
+ severityString = "CANCEL";
+ break;
+ case IStatus.WARNING :
+ severityString = "WARNING";
+ break;
+ case IStatus.ERROR :
+ severityString = "ERROR";
+ break;
+ }
+ interpreter.print(",severity=" + severityString);
+ interpreter.print(",bundle=" + status.getPlugin());
+ interpreter.println("--");
+ Throwable t = status.getException();
+ if (t != null)
+ interpreter.printStackTrace(t);
+ IStatus[] children = status.getChildren();
+ if (children != null && children.length > 0) {
+ interpreter.println("Error status children:");
+ for (int i = 0; i < children.length; i++) {
+ printErrorStatus(interpreter, children[i]);
+ }
+ }
+ interpreter.println("--End Error Status--");
+ }
+
public String getHelp() {
StringBuffer help = new StringBuffer();
help.append(NEW_LINE);
- help.append("---"); //$NON-NLS-1$
- help.append("Provisioning Commands");
- help.append("---"); //$NON-NLS-1$
+ help.append("---");
+ help.append("P2 Provisioning Commands");
+ help.append("---");
help.append(NEW_LINE);
- help.append("\tprovlr [<repository URL> <iu id | *> <version range | *>] - Lists all metadata repositories, or the contents of a given metadata repository");
+
+ help.append("---");
+ help.append("Repository Commands");
+ help.append("---");
help.append(NEW_LINE);
- help.append("\tprovlar [<repository URL>] - Lists all artifact repositories, or the contents of a given artifact repository");
+ help.append("\tprovaddrepo <repository URI> - Adds a both a metadata and artifact repository at URI");
help.append(NEW_LINE);
- help.append("\tprovliu [<repository URL | *> <iu id | *> <version range | *>] - Lists the IUs that match the pattern in the given repo. * matches all");
+ help.append("\tprovdelrepo <repository URI> - Deletes a metadata and artifact repository at URI");
help.append(NEW_LINE);
- help.append("\tprovlp [<profile id | *> - Lists all profiles, or the contents of the profile at the given profile");
+ help.append("\tprovaddmetadatarepo <repository URI> - Adds a metadata repository at URI");
help.append(NEW_LINE);
- help.append("\tprovlg [<repository URL> <iu id | *> <version range | *>] - Lists all IUs with group capabilities in the given repo or in all repos if the URL is omitted");
+ help.append("\tprovdelmetadatarepo <repository URI> - Deletes a metadata repository at URI");
help.append(NEW_LINE);
- help.append("\tprovinstall <InstallableUnit> <version> <profileId> - Provisions an IU to the profile with the give id");
+ help.append("\tprovaddartifactrepo <repository URI> - Adds an artifact repository at URI");
help.append(NEW_LINE);
- help.append("\tprovaddrepo <repository URL> - Adds a metadata repository");
+ help.append("\tprovdelartifactrepo <repository URI> - Deletes an artifact repository URI");
help.append(NEW_LINE);
- help.append("\tprovaddartifactrepo <repository URL> - Adds an artifact repository");
+ help.append("\tprovlg [<repository URI> <iu id | *> <version range | *>] - Lists all IUs with group capabilities in the given repo or in all repos if URI is omitted");
help.append(NEW_LINE);
- help.append("\tprovaddprofile <profileId> <location> <flavor> - Adds a profile with the given id, location and flavor");
+ help.append("\tprovlr [<repository URI> <iu id | *> <version range | *>] - Lists all metadata repositories, or the contents of a given metadata repository");
help.append(NEW_LINE);
+ help.append("\tprovlar [<repository URI>] - Lists all artifact repositories, or the contents of a given artifact repository");
+ help.append(NEW_LINE);
+ help.append("\tprovliu [<repository URI | *> <iu id | *> <version range | *>] - Lists the IUs that match the pattern in the given repo. * matches all");
+ help.append(NEW_LINE);
+
+ help.append("---");
+ help.append("Profile Registry Commands");
+ help.append("---");
+ help.append(NEW_LINE);
+
+ help.append("\tprovaddprofile <profileid> <location> <flavor> - Adds a profile with the given profileid, location and flavor");
+ help.append(NEW_LINE);
+ help.append("\tprovdelprofile <profileid> - Deletes a profile with the given profileid");
+ help.append(NEW_LINE);
+ help.append("\tprovlp [<profileid | *>] - Lists all profiles, or the contents of the profile at the given profile");
+ help.append(NEW_LINE);
+ help.append("\tprovlgp [<profileid>] - Lists all IUs with group capabilities in the given profile, or current profile if profileid is omitted");
+ help.append(NEW_LINE);
+ help.append("\tprovlpts [<profileid>] - Lists timestamps for given profile, or if no profileid given then the default profile timestamps are reported");
+ help.append(NEW_LINE);
+
+ help.append("---");
+ help.append("Install Commands");
+ help.append("---");
+ help.append(NEW_LINE);
+
+ help.append("\tprovinstall <InstallableUnit> <version> <profileid> - installs an IU to the profileid. If no profileid is given, installs into default profile.");
+ help.append(NEW_LINE);
+ help.append("\tprovremove <InstallableUnit> <version> <profileid> - Removes an IU from the profileid. If no profileid is given, installs into default profile.");
+ help.append(NEW_LINE);
+ help.append("\tprovrevert <profileTimestamp> <profileid>] - Reverts to a given profileTimestamp for an optional profileId");
+ help.append(NEW_LINE);
+
return help.toString();
}
diff --git a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java
index 730e04c8c..02d9e1091 100644
--- a/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java
+++ b/bundles/org.eclipse.equinox.p2.console/src/org/eclipse/equinox/internal/p2/console/ProvisioningHelper.java
@@ -10,31 +10,32 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.console;
-import org.eclipse.equinox.internal.provisional.p2.metadata.Version;
+import org.eclipse.equinox.p2.metadata.Version;
import java.net.URI;
-import java.util.*;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
+import java.util.HashMap;
+import java.util.Map;
+import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
-import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
import org.eclipse.equinox.internal.provisional.p2.director.*;
-import org.eclipse.equinox.internal.provisional.p2.engine.*;
-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.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
-import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.engine.*;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.p2.query.*;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
public class ProvisioningHelper {
public static IMetadataRepository addMetadataRepository(URI location) {
- IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
if (manager == null)
- throw new IllegalStateException("No metadata repository manager found"); //$NON-NLS-1$
+ throw new IllegalStateException("No metadata repository manager found");
try {
return manager.loadRepository(location, null);
} catch (ProvisionException e) {
@@ -42,7 +43,7 @@ public class ProvisioningHelper {
}
// for convenience create and add a repository here
- String repositoryName = location + " - metadata"; //$NON-NLS-1$
+ String repositoryName = location + " - metadata";
try {
return manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
} catch (ProvisionException e) {
@@ -51,7 +52,7 @@ public class ProvisioningHelper {
}
public static IMetadataRepository getMetadataRepository(URI location) {
- IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
if (manager == null)
throw new IllegalStateException("No metadata repository manager found");
try {
@@ -62,14 +63,14 @@ public class ProvisioningHelper {
}
public static void removeMetadataRepository(URI location) {
- IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
if (manager == null)
throw new IllegalStateException("No metadata repository manager found");
manager.removeRepository(location);
}
public static IArtifactRepository addArtifactRepository(URI location) {
- IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
+ IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME);
if (manager == null)
// TODO log here
return null;
@@ -79,7 +80,7 @@ public class ProvisioningHelper {
//fall through and create a new repository
}
// could not load a repo at that location so create one as a convenience
- String repositoryName = location + " - artifacts"; //$NON-NLS-1$
+ String repositoryName = location + " - artifacts";
try {
return manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
} catch (ProvisionException e) {
@@ -88,32 +89,26 @@ public class ProvisioningHelper {
}
public static void removeArtifactRepository(URI location) {
- IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
+ IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME);
if (manager == null)
// TODO log here
return;
manager.removeRepository(location);
}
- public static IProfile addProfile(String profileId, Properties properties) throws ProvisionException {
- IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.class.getName());
+ public static IProfile addProfile(String profileId, Map<String, String> properties) throws ProvisionException {
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null)
return null;
IProfile profile = profileRegistry.getProfile(profileId);
if (profile != null)
return profile;
- Map profileProperties = new HashMap();
-
- for (Iterator it = properties.keySet().iterator(); it.hasNext();) {
- String key = (String) it.next();
- profileProperties.put(key, properties.getProperty(key));
- }
-
+ Map<String, String> profileProperties = new HashMap<String, String>(properties);
if (profileProperties.get(IProfile.PROP_ENVIRONMENTS) == null) {
EnvironmentInfo info = (EnvironmentInfo) ServiceHelper.getService(Activator.getContext(), EnvironmentInfo.class.getName());
if (info != null)
- profileProperties.put(IProfile.PROP_ENVIRONMENTS, "osgi.os=" + info.getOS() + ",osgi.ws=" + info.getWS() + ",osgi.arch=" + info.getOSArch());
+ profileProperties.put(IProfile.PROP_ENVIRONMENTS, "osgi.os=" + info.getOS() + ",osgi.ws=" + info.getWS() + ",osgi.arch=" + info.getOSArch()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
else
profileProperties.put(IProfile.PROP_ENVIRONMENTS, "");
}
@@ -122,21 +117,21 @@ public class ProvisioningHelper {
}
public static void removeProfile(String profileId) {
- IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.class.getName());
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null)
return;
profileRegistry.removeProfile(profileId);
}
public static IProfile[] getProfiles() {
- IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.class.getName());
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null)
return new IProfile[0];
return profileRegistry.getProfiles();
}
public static IProfile getProfile(String id) {
- IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.class.getName());
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
if (profileRegistry == null)
return null;
return profileRegistry.getProfile(id);
@@ -152,24 +147,20 @@ public class ProvisioningHelper {
* @param monitor A progress monitor, or <code>null</code>
* @return The IUs that match the query
*/
- public static Collector getInstallableUnits(URI location, Query query, IProgressMonitor monitor) {
- return getInstallableUnits(location, query, new Collector(), monitor);
- }
-
- public static Collector getInstallableUnits(URI location, Query query, Collector collector, IProgressMonitor monitor) {
- IQueryable queryable = null;
+ public static IQueryResult<IInstallableUnit> getInstallableUnits(URI location, IQuery<IInstallableUnit> query, IProgressMonitor monitor) {
+ IQueryable<IInstallableUnit> queryable = null;
if (location == null) {
- queryable = (IQueryable) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ queryable = (IQueryable<IInstallableUnit>) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
} else {
queryable = getMetadataRepository(location);
}
if (queryable != null)
- return queryable.query(query, collector, monitor);
- return collector;
+ return queryable.query(query, monitor);
+ return Collector.emptyCollector();
}
public static URI[] getMetadataRepositories() {
- IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
+ IMetadataRepositoryManager manager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.SERVICE_NAME);
if (manager == null)
// TODO log here
return null;
@@ -185,7 +176,7 @@ public class ProvisioningHelper {
public static IStatus install(String unitId, String version, IProfile profile, IProgressMonitor progress) throws ProvisionException {
if (profile == null)
return null;
- Collector units = getInstallableUnits(null, new InstallableUnitQuery(unitId, new Version(version)), progress);
+ IQueryResult<IInstallableUnit> units = getInstallableUnits((URI) null, new InstallableUnitQuery(unitId, Version.create(version)), progress);
if (units.isEmpty()) {
StringBuffer error = new StringBuffer();
error.append("Installable unit not found: " + unitId + ' ' + version + '\n');
@@ -198,23 +189,22 @@ public class ProvisioningHelper {
throw new ProvisionException(error.toString());
}
- IPlanner planner = (IPlanner) ServiceHelper.getService(Activator.getContext(), IPlanner.class.getName());
+ IPlanner planner = (IPlanner) ServiceHelper.getService(Activator.getContext(), IPlanner.SERVICE_NAME);
if (planner == null)
throw new ProvisionException("No planner service found.");
IEngine engine = (IEngine) ServiceHelper.getService(Activator.getContext(), IEngine.SERVICE_NAME);
if (engine == null)
throw new ProvisionException("No director service found.");
- IInstallableUnit[] toInstall = (IInstallableUnit[]) units.toArray(IInstallableUnit.class);
ProvisioningContext context = new ProvisioningContext();
ProfileChangeRequest request = new ProfileChangeRequest(profile);
- request.addInstallableUnits(toInstall);
- ProvisioningPlan result = planner.getProvisioningPlan(request, context, progress);
+ request.addInstallableUnits(units);
+ IProvisioningPlan result = planner.getProvisioningPlan(request, context, progress);
return PlanExecutionHelper.executePlan(result, engine, context, progress);
}
public static URI[] getArtifactRepositories() {
- IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
+ IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME);
if (manager == null)
// TODO log here
return null;
@@ -225,7 +215,7 @@ public class ProvisioningHelper {
}
public static IArtifactRepository getArtifactRepository(URI repoURL) {
- IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
+ IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME);
try {
if (manager != null)
return manager.loadRepository(repoURL, null);
@@ -234,4 +224,82 @@ public class ProvisioningHelper {
}
return null;
}
+
+ public static long[] getProfileTimestamps(String profileId) {
+ if (profileId == null) {
+ profileId = IProfileRegistry.SELF;
+ }
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
+ if (profileRegistry == null)
+ return null;
+ return profileRegistry.listProfileTimestamps(profileId);
+ }
+
+ public static IStatus revertToPreviousState(IProfile profile, long revertToPreviousState) throws ProvisionException {
+ IEngine engine = (IEngine) ServiceHelper.getService(Activator.getContext(), IEngine.SERVICE_NAME);
+ if (engine == null)
+ throw new ProvisionException("No p2 engine found.");
+ IPlanner planner = (IPlanner) ServiceHelper.getService(Activator.getContext(), IPlanner.SERVICE_NAME);
+ if (planner == null)
+ throw new ProvisionException("No planner found.");
+ IProfileRegistry profileRegistry = (IProfileRegistry) ServiceHelper.getService(Activator.getContext(), IProfileRegistry.SERVICE_NAME);
+ if (profileRegistry == null)
+ throw new ProvisionException("profile registry cannot be null");
+ // If given profile is null, then get/use the self profile
+ if (profile == null) {
+ profile = getProfile(IProfileRegistry.SELF);
+ }
+ IProfile targetProfile = null;
+ if (revertToPreviousState == 0) {
+ long[] profiles = profileRegistry.listProfileTimestamps(profile.getProfileId());
+ if (profiles.length == 0)
+ // Nothing to do, as the profile does not have any previous timestamps
+ return Status.OK_STATUS;
+ targetProfile = profileRegistry.getProfile(profile.getProfileId(), profiles[profiles.length - 1]);
+ } else {
+ targetProfile = profileRegistry.getProfile(profile.getProfileId(), revertToPreviousState);
+ }
+ if (targetProfile == null)
+ throw new ProvisionException("target profile with timestamp=" + revertToPreviousState + " not found");
+ URI[] artifactRepos = getArtifactRepositories();
+ URI[] metadataRepos = getMetadataRepositories();
+ IProvisioningPlan plan = planner.getDiffPlan(profile, targetProfile, new NullProgressMonitor());
+ ProvisioningContext context = new ProvisioningContext(metadataRepos);
+ context.setArtifactRepositories(artifactRepos);
+ return PlanExecutionHelper.executePlan(plan, engine, context, new NullProgressMonitor());
+ }
+
+ /**
+ * Install the described IU
+ */
+ public static IStatus uninstall(String unitId, String version, IProfile profile, IProgressMonitor progress) throws ProvisionException {
+ if (profile == null)
+ return null;
+ IQueryResult<IInstallableUnit> units = profile.query(new InstallableUnitQuery(unitId, Version.create(version)), progress);
+ if (units.isEmpty()) {
+ StringBuffer error = new StringBuffer();
+ error.append("Installable unit not found: " + unitId + ' ' + version + '\n');
+ error.append("Repositories searched:\n");
+ URI[] repos = getMetadataRepositories();
+ if (repos != null) {
+ for (int i = 0; i < repos.length; i++)
+ error.append(repos[i] + "\n"); //$NON-NLS-1$
+ }
+ throw new ProvisionException(error.toString());
+ }
+
+ IPlanner planner = (IPlanner) ServiceHelper.getService(Activator.getContext(), IPlanner.SERVICE_NAME);
+ if (planner == null)
+ throw new ProvisionException("No planner service found.");
+
+ IEngine engine = (IEngine) ServiceHelper.getService(Activator.getContext(), IEngine.SERVICE_NAME);
+ if (engine == null)
+ throw new ProvisionException("No engine service found.");
+ ProvisioningContext context = new ProvisioningContext();
+ ProfileChangeRequest request = new ProfileChangeRequest(profile);
+ request.removeInstallableUnits(units);
+ IProvisioningPlan result = planner.getProvisioningPlan(request, context, progress);
+ return PlanExecutionHelper.executePlan(result, engine, context, progress);
+ }
+
}

Back to the top