].
+ */
+ @Parameter(property = "installIUs", alias = "installIU")
+ private String installIUs;
+
+ /**
+ * Alternative way to specify the IU to install in a more declarative (but also verbose) way,
+ * example:
+ *
+ *
+ * <install>
+ * <iu>
+ * <id>...</id>
+ * <version>...optional version...</id>
+ * <feature>true/false</feature> <!-- optional if true .feature.group is automatically added to the id -->
+ * </install>
+ *
+ */
+ @Parameter
+ private List install;
+
+ /**
+ * comma separated list of IUs to install, each entry in the list is in the form [ '/'
+ * ].
+ */
+ @Parameter(property = "uninstallIUs", alias = "uninstallIU")
+ private String uninstallIUs;
+
+ /**
+ * Alternative way to specify the IU to uninstall in a more declarative (but also verbose) way,
+ * example:
+ *
+ *
+ * <install>
+ * <iu>
+ * <id>...</id>
+ * <version>...optional version...</id>
+ * <feature>true/false</feature> <!-- optional if true .feature.group is automatically added to the id -->
+ * </install>
+ *
+ */
+ @Parameter
+ private List uninstall;
+
+ /**
+ * comma separated list of numbers, revert the installation to a previous state. The number
+ * representing the previous state of the profile as found in
+ * p2/org.eclipse.equinox.p2.engine//.
+ */
+ @Parameter(property = "revert")
+ private String revert;
+
+ /**
+ * Remove the history of the profile registry.
+ */
+ @Parameter(property = "purgeHistory")
+ private boolean purgeHistory;
+
+ /**
+ * Lists all IUs found in the given repositories. IUs can optionally be listed. Each entry in
+ * the list is in the form [ '/' ].
+ */
+ @Parameter(property = "list")
+ private boolean list;
+
+ /**
+ * List the tags available
+ */
+ @Parameter(property = "listTags")
+ private boolean listTags;
+
+ /**
+ * Lists all root IUs found in the given profile. Each entry in the list is in the form [
+ * '/' ].
+ */
+ @Parameter(property = "listInstalledRoots")
+ private boolean listInstalledRoots;
+
+ /**
+ * Formats the list of IUs according to the given string. Use ${property} for variable parts,
+ * e.g. ${org.eclipse.equinox.p2.name} for the IU's name. ID and version of an IU are available
+ * through ${id} and ${version}.
+ */
+ @Parameter(property = "listFormat")
+ private String listFormat;
+
+ /**
+ * Defines what profile to use for the actions.
+ */
+ @Parameter(property = "profile")
+ private String profile;
+
+ /**
+ * A list of properties in the form key=value pairs. Effective only when a new profile is
+ * created. For example org.eclipse.update.install.features=true to install the
+ * features into the product.
+ */
+ @Parameter(property = "profileproperties")
+ private String profileproperties;
+
+ @Parameter(property = "installFeatures")
+ private boolean installFeatures;
+
+ /**
+ * Additional profile properties to set when materializing the product
+ */
+ @Parameter
+ private Map properties;
+
+ /**
+ * Path to a properties file containing a list of IU profile properties to set.
+ */
+ @Parameter(property = "iuProfileproperties")
+ private File iuProfileproperties;
+
+ /**
+ * Defines what flavor to use for a newly created profile.
+ */
+ @Parameter(property = "flavor")
+ private String flavor;
+
+ /**
+ * The location where the plug-ins and features will be stored. Effective only when a new
+ * profile is created.
+ */
+ @Parameter(property = "bundlepool")
+ private File bundlepool;
+
+ /**
+ * The OS to use when the profile is created.
+ */
+ @Parameter(property = "p2.os")
+ private String p2os;
+
+ /**
+ * The windowing system to use when the profile is created.
+ */
+ @Parameter(property = "p2.ws")
+ private String p2ws;
+
+ /**
+ * The architecture to use when the profile is created.
+ */
+ @Parameter(property = "p2.arch")
+ private String p2arch;
+
+ /**
+ * The language to use when the profile is created.
+ */
+ @Parameter(property = "p2.nl")
+ private String p2nl;
+
+ /**
+ * Indicates that the product resulting from the installation can be moved. Effective only when
+ * a new profile is created.
+ */
+ @Parameter(property = "roaming")
+ private boolean roaming;
+
+ /**
+ * Use a shared location for the install. The defaults to ${user.home}/.p2
+ */
+ @Parameter(property = "shared")
+ private String shared;
+
+ /**
+ * Tag the provisioning operation for easy referencing when reverting.
+ */
+ @Parameter(property = "tag")
+ private String tag;
+
+ /**
+ * Only verify that the actions can be performed. Don't actually install or remove anything.
+ */
+ @Parameter(property = "verifyOnly")
+ private boolean verifyOnly;
+
+ /**
+ * Only download the artifacts.
+ */
+ @Parameter(property = "downloadOnly")
+ private boolean downloadOnly;
+
+ /**
+ * Follow repository references.
+ */
+ @Parameter(property = "followReferences")
+ private boolean followReferences;
+
+ /**
+ * Whether to print detailed information about the content trust.
+ */
+ @Parameter(property = "verboseTrust")
+ private boolean verboseTrust;
+
+ /**
+ * Whether to trust each artifact only if it is jar-signed or PGP-signed.
+ */
+ @Parameter(property = "trustSignedContentOnly")
+ private boolean trustSignedContentOnly;
+
+ /**
+ * comma separated list of the authorities from which repository content, including repository
+ * metadata, is trusted. An empty value will reject all remote connections.
+ */
+ @Parameter(property = "trustedAuthorities")
+ private String trustedAuthorities;
+
+ /**
+ * comma separated list of the fingerprints of PGP keys to trust as signers of artifacts. An
+ * empty value will reject all PGP keys.
+ */
+ @Parameter(property = "trustedPGPKeys")
+ private String trustedPGPKeys;
+
+ /**
+ * The SHA-256 'fingerprints' of unanchored certficates to trust as signers of artifacts. An
+ * empty value will reject all unanchored certificates.
+ */
+ @Parameter(property = "trustedCertificates")
+ private String trustedCertificates;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ //TODO should be able to control agent creation see https://github.com/eclipse-equinox/p2/pull/398
+ //Until now we need to fetch a service to trigger loading of the internal osgi framework...
+ agent.getService(IArtifactRepositoryManager.class);
+ CommandLineArguments args = new CommandLineArguments();
+ args.addNonNull("-destination", destination);
+ args.addNonNull("-metadatarepository", metadatarepositories);
+ args.addNonNull("-artifactrepository", artifactrepositories);
+ args.addNonNull("-repository", repositories);
+ args.addNotEmpty("-installIU", getUnitParameterList(installIUs, install), ",");
+ args.addNotEmpty("-uninstallIU", getUnitParameterList(uninstallIUs, uninstall), ",");
+ args.addNonNull("-revert", revert);
+ args.addFlagIfTrue("-purgeHistory", purgeHistory);
+ args.addFlagIfTrue("-list", list);
+ args.addFlagIfTrue("-listTags", listTags);
+ args.addFlagIfTrue("-listInstalledRoots", listInstalledRoots);
+ args.addNonNull("-listFormat", listFormat);
+ args.addNonNull("-profile", profile);
+ args.addNotEmpty("-profileproperties", getPropertyMap(profileproperties, properties), "=", ",");
+ args.addNonNull("-iuProfileproperties", iuProfileproperties);
+ args.addNonNull("-flavor", flavor);
+ args.addNonNull("-bundlepool", bundlepool);
+ args.addNonNull("-p2.os", p2os);
+ args.addNonNull("-p2.ws", p2ws);
+ args.addNonNull("-p2.arch", p2arch);
+ args.addNonNull("-p2.nl", p2nl);
+ args.addFlagIfTrue("-roaming", roaming);
+ args.addNonNull("-trustedAuthorities", trustedAuthorities);
+ if (shared != null) {
+ if (shared.isEmpty()) {
+ args.add("-shared");
+ } else {
+ args.addNonNull("-shared", new File(shared));
+ }
+ }
+ args.addNonNull("-tag", tag);
+ args.addFlagIfTrue("-verifyOnly", verifyOnly);
+ args.addFlagIfTrue("-downloadOnly", downloadOnly);
+ args.addFlagIfTrue("-followReferences", followReferences);
+ args.addFlagIfTrue("-verboseTrust", verboseTrust);
+ args.addFlagIfTrue("-trustSignedContentOnly", trustSignedContentOnly);
+ args.addNonNull("-trustedAuthorities", trustedAuthorities);
+ args.addNonNull("-trustedPGPKeys", trustedPGPKeys);
+ args.addNonNull("-trustedCertificates", trustedCertificates);
+ Object exitCode = new DirectorApplication().run(args.toArray());
+ if (!(IApplication.EXIT_OK.equals(exitCode))) {
+ throw new MojoFailureException("Call to p2 director application failed with exit code " + exitCode
+ + ". Program arguments were: '" + args + "'.");
+ }
+ }
+
+ private Map getPropertyMap(String csvPropertiesMap, Map properties) {
+ LinkedHashMap map = new LinkedHashMap();
+ if (csvPropertiesMap != null) {
+ for (String keyValue : csvPropertiesMap.split(",")) {
+ String[] split = keyValue.split("=");
+ map.put(split[0].trim(), split[1].trim());
+ }
+ }
+ if (properties != null) {
+ map.putAll(properties);
+ }
+ if (installFeatures) {
+ map.put("org.eclipse.update.install.features", "true");
+ }
+ return map;
+ }
+
+ private List getUnitParameterList(String csvlist, List units) {
+ List list = new ArrayList();
+ if (csvlist != null) {
+ for (String iu : csvlist.split(",")) {
+ list.add(iu.trim());
+ }
+ }
+ if (install != null) {
+ for (IU iu : install) {
+ String id = iu.id;
+ if (iu.feature) {
+ id += ".feature.group";
+ }
+ if (iu.version != null) {
+ id += "/" + iu.version;
+ }
+ list.add(id);
+ }
+ }
+ return list;
+ }
+
+ private void add(String key, String value, List args) {
+ if (metadatarepositories != null) {
+ args.add("-metadatarepository");
+ args.add(metadatarepositories);
+ }
+ }
+
+ public static final class IU {
+ String id;
+ String version;
+ boolean feature;
+ }
+
+}