From 603d7a37d21fa4db7512a81b8b09571ffd1e68ce Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Fri, 8 Mar 2024 18:14:19 +0530 Subject: [PATCH 1/3] Attempt to compile product with Java 21 --- carbon-p2-plugin/pom.xml | 194 +++++---- .../java/org/wso2/maven/p2/CatFeature.java | 15 +- .../main/java/org/wso2/maven/p2/Category.java | 15 +- .../org/wso2/maven/p2/EquinoxLauncher.java | 7 +- .../main/java/org/wso2/maven/p2/Feature.java | 9 +- .../org/wso2/maven/p2/FeatureArtifact.java | 12 +- .../wso2/maven/p2/MaterializeProductMojo.java | 94 ++--- .../java/org/wso2/maven/p2/P2Profile.java | 19 +- .../java/org/wso2/maven/p2/P2Repository.java | 16 +- .../org/wso2/maven/p2/ProfileGenMojo.java | 117 +++--- .../org/wso2/maven/p2/PublishProductMojo.java | 85 ++-- .../org/wso2/maven/p2/RepositoryGenMojo.java | 151 +++---- .../maven/p2/generate/feature/AdviceFile.java | 54 +-- .../maven/p2/generate/feature/Bundle.java | 12 +- .../maven/p2/generate/feature/Feature.java | 10 +- .../p2/generate/feature/FeatureGenMojo.java | 92 ++--- .../p2/generate/feature/ImportBundle.java | 11 +- .../p2/generate/feature/ImportFeature.java | 11 +- .../p2/generate/feature/IncludedFeature.java | 15 +- .../maven/p2/generate/feature/Property.java | 9 +- .../CarbonMavenLifecycleParticipant.java | 385 ++++++++++++++++++ .../resources/META-INF/plexus/components.xml | 43 +- pom.xml | 27 +- 23 files changed, 893 insertions(+), 510 deletions(-) create mode 100644 carbon-p2-plugin/src/main/java/org/wso2/maven/p2/maven/CarbonMavenLifecycleParticipant.java diff --git a/carbon-p2-plugin/pom.xml b/carbon-p2-plugin/pom.xml index dd0361d5..af442eb5 100755 --- a/carbon-p2-plugin/pom.xml +++ b/carbon-p2-plugin/pom.xml @@ -27,110 +27,156 @@ 4.0.0 - org.wso2.maven carbon-p2-plugin maven-plugin 5.2.50-SNAPSHOT Maven P2 Profile Generation Plugin - - org.apache.maven - maven-plugin-api - ${org.apache.maven.plugin.api.version} - - - org.apache.maven - maven-core - ${org.apache.maven.core.version} - - org.eclipse.tycho - sisu-equinox-embedder - ${tycho.version} + org.apache.maven + maven-plugin-api + 3.9.6 + + + org.apache.maven + maven-core + 3.9.6 + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.11.0 org.eclipse.tycho sisu-equinox-launching - ${tycho.version} + 4.0.6 org.eclipse.tycho - tycho-p2-facade - ${tycho.version} + tycho-artifactcomparator + 4.0.6 + + + org.apache.commons + commons-lang3 + 3.14.0 + + + org.eclipse.tycho + tycho-core + 4.0.6 org.apache.maven maven-compat - ${org.apache.maven.compat.version} + 3.9.6 + + + junit + junit + ${junit.version} + test - - org.apache.maven - maven-project - ${org.apache.maven.project.version} - - - junit - junit - ${junit.version} - test - - - org.jvnet.maven.incrementalbuild - incremental-build-plugin - 1.3 - - - - incremental-build - - - - + + + + + + + + + + + + + + org.eclipse.sisu + sisu-maven-plugin + 0.9.0.M2 + + + index-project + + main-index + test-index + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.11.0 + + carbon-p2-plugin + true + + java-annotations + + + + + default-descriptor + + descriptor + + process-classes + + + org.apache.maven.plugins maven-compiler-plugin + 3.12.1 - 1.8 - 1.8 + 21 + 21 + + false - - org.apache.rat - apache-rat-plugin - - - src/**/* - pom.xml - - - - - - verify - - check - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/CatFeature.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/CatFeature.java index eff99143..792fb32f 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/CatFeature.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/CatFeature.java @@ -20,6 +20,7 @@ import java.util.regex.Pattern; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.wso2.maven.p2.generate.feature.Bundle; @@ -27,23 +28,17 @@ public class CatFeature { /** * Id of the feature - * - * @parameter - * @required */ + @Parameter(name = "id", required = true) private String id; /** * version of the feature - * - * @parameter - * @required */ + @Parameter(name = "version", required = true) private String version; - - /** - * @parameter default-value="${project}" - */ + + @Parameter(name = "project", defaultValue = "${project}") private MavenProject project; private boolean versionReplaced = false; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Category.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Category.java index b9ccdadd..ec23d9a7 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Category.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Category.java @@ -25,38 +25,33 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; public class Category { /** * Category Id - * - * @parameter - * @required */ + @Parameter(name = "id", required = true) private String id; /** * Category Label - * - * @parameter */ + @Parameter(name = "label") private String label; /** * Category description - * - * @parameter */ + @Parameter(name = "description") private String description; /** * List of features contained in the category - * - * @parameter - * @required */ + @Parameter(name = "features", required = true) private ArrayList features; private ArrayList processedFeatures; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/EquinoxLauncher.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/EquinoxLauncher.java index 57febf1e..e32fee8a 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/EquinoxLauncher.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/EquinoxLauncher.java @@ -17,22 +17,21 @@ import java.util.ArrayList; +import org.apache.maven.plugins.annotations.Parameter; import org.wso2.maven.p2.generate.utils.P2Constants; public class EquinoxLauncher { /** * Name of the launcher jar - * - * @parameter */ + @Parameter(name = "launcherJar") private String launcherJar; /** * launcherFiles - * - * @parameter */ + @Parameter(name = "launcherFiles") private ArrayList launcherFiles; public EquinoxLauncher(){ diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Feature.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Feature.java index 46c3c124..42014b38 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Feature.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/Feature.java @@ -16,6 +16,7 @@ package org.wso2.maven.p2; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.wso2.maven.p2.generate.feature.Bundle; import org.wso2.maven.p2.generate.feature.ImportFeature; @@ -23,18 +24,14 @@ public class Feature { /** * Id of the feature - * - * @parameter - * @required */ + @Parameter(name = "id", required = true) private String id; /** * version of the feature - * - * @parameter - * @required */ + @Parameter(name = "version", required = true) private String version; public Feature(){ diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/FeatureArtifact.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/FeatureArtifact.java index 10424bdb..e22e362e 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/FeatureArtifact.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/FeatureArtifact.java @@ -25,30 +25,26 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; public class FeatureArtifact { /** * Group Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "groupId", required = true) private String groupId; /** * Artifact Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "artifactId", required = true) private String artifactId; /** * Version of the Bundle - * - * @parameter default-value="" */ + @Parameter(name = "version") private String version; private Artifact artifact; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java index 572c67a8..b173ffe2 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java @@ -20,9 +20,12 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.internal.p2.director.app.DirectorApplication; import org.eclipse.tycho.model.ProductConfiguration; -import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; import org.wso2.maven.p2.generate.utils.FileManagementUtil; import org.wso2.maven.p2.generate.utils.P2Constants; @@ -30,29 +33,24 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; +import java.util.ArrayList; +import java.util.List; import java.util.Properties; - - - -/** - * @goal materialize-product - */ +@Mojo(name = "materialize-product") public class MaterializeProductMojo extends AbstractMojo { - /** - * @parameter expression="${project}" - * @required - */ + + @Parameter(name = "project", property = "project", required = true) protected MavenProject project; /** * Metadata repository name - * @parameter */ + @Parameter(name = "metadataRepository") private URL metadataRepository; /** * Artifact repository name - * @parameter */ + @Parameter(name = "artifactRepository") private URL artifactRepository; @@ -61,12 +59,11 @@ public class MaterializeProductMojo extends AbstractMojo { * The product configuration, a .product file. This file manages all aspects * of a product definition from its constituent plug-ins to configuration * files to branding. - * - * @parameter expression="${productConfiguration}" */ + @Parameter(name = "productConfigurationFile", property = "productConfiguration") private File productConfigurationFile; - /** @parameter */ + @Parameter(name = "targetPath") private URL targetPath; /** * Parsed product configuration file @@ -76,21 +73,15 @@ public class MaterializeProductMojo extends AbstractMojo { /** * The new profile to be created during p2 Director install & * the default profile for the the application which is set in config.ini - * - * @parameter expression="${profile}" */ + @Parameter(name = "profile", property = "profile") private String profile; - - /** @component */ - private P2ApplicationLauncher launcher; - /** * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for * the process, never timing out. - * - * @parameter expression="${p2.timeout}" */ + @Parameter(name = "forkedProcessTimeoutInSeconds", property = "p2.timeout") private int forkedProcessTimeoutInSeconds; public void execute() throws MojoExecutionException, MojoFailureException { @@ -154,36 +145,45 @@ private String getFeaturesOsgiBundles() { private void deployRepository() throws Exception{ productConfiguration = ProductConfiguration.read( productConfigurationFile ); - P2ApplicationLauncher launcher = this.launcher; - - launcher.setWorkingDirectory(project.getBasedir()); - launcher.setApplicationName("org.eclipse.equinox.p2.director"); - - launcher.addArguments( - "-metadataRepository", metadataRepository.toExternalForm(), - "-artifactRepository", metadataRepository.toExternalForm(), - "-installIU",productConfiguration.getId(), - "-profileProperties", "org.eclipse.update.install.features=true", - "-profile",profile.toString(), - "-bundlepool",targetPath.toExternalForm(), + List arguments = new ArrayList<>(); + + arguments.add("-metadataRepository"); + arguments.add(metadataRepository.toExternalForm()); + arguments.add("-artifactRepository"); + arguments.add(metadataRepository.toExternalForm()); + arguments.add("-installIU"); + arguments.add(productConfiguration.getId()); + arguments.add("-profileProperties"); + arguments.add("org.eclipse.update.install.features=true"); + arguments.add("-profile"); + arguments.add(profile.toString()); + arguments.add("-bundlepool"); + arguments.add(targetPath.toExternalForm()); //to support shared installation in carbon - "-shared" , targetPath.toExternalForm() + File.separator + "p2", + arguments.add("-shared"); + arguments.add(targetPath.toExternalForm() + File.separator + "p2"); //target is set to a separate directory per Profile - "-destination", targetPath.toExternalForm() + File.separator + profile, - "-p2.os", "linux", - "-p2.ws", "gtk", - "-p2.arch", "x86", - "-roaming" - ); - - int result = launcher.execute(forkedProcessTimeoutInSeconds); - - if (result != 0) { + arguments.add("-destination"); + arguments.add(targetPath.toExternalForm() + File.separator + profile); + arguments.add("-p2.os"); + arguments.add("linux"); + arguments.add("-p2.ws"); + arguments.add("gtk"); + arguments.add("-p2.arch"); + arguments.add("x86"); + arguments.add("-roaming"); + + Object result = getPublisherApplication().run(arguments.toArray(String[]::new)); + if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); } } + protected DirectorApplication getPublisherApplication() { + return new DirectorApplication(); + } + private void setPropertyIfNotNull( Properties properties, String key, String value ) { if ( value != null ) diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Profile.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Profile.java index 83d4a35d..63c4e7f0 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Profile.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Profile.java @@ -25,30 +25,27 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; public class P2Profile { - /** - * Group Id of the Bundle - * - * @parameter - * @required - */ + + /** + * Group Id of the Bundle + */ + @Parameter(name = "groupId", required = true) private String groupId; /** * Artifact Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "artifactId", required = true) private String artifactId; /** * Version of the Bundle - * - * @parameter */ + @Parameter(name = "version") private String version; private Artifact artifact; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Repository.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Repository.java index 5f5e4072..80b466e6 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Repository.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/P2Repository.java @@ -17,35 +17,33 @@ */ package org.wso2.maven.p2; +import org.apache.maven.plugins.annotations.Parameter; + import java.net.URL; public class P2Repository { /** * URL of the Metadata Repository - * - * @parameter */ + @Parameter(name = "metadataRepository") private URL metadataRepository; /** * URL of the Artifact Repository - * - * @parameter */ + @Parameter(name = "artifactRepository") private URL artifactRepository; /** * URL of the P2 Repository - * - * @parameter */ + @Parameter(name = "repository") private URL repository; /** - * Genrate P2 Repository on the fly - * - * @parameter + * Generate P2 Repository on the fly */ + @Parameter(name = "generateRepo") private RepositoryGenMojo generateRepo; public void setGenerateRepo(RepositoryGenMojo generateRepo) { diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/ProfileGenMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/ProfileGenMojo.java index 7cbe7ceb..09da6d3f 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/ProfileGenMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/ProfileGenMojo.java @@ -26,10 +26,15 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.internal.p2.director.app.DirectorApplication; import org.wso2.maven.p2.generate.utils.FileManagementUtil; import org.wso2.maven.p2.generate.utils.MavenUtils; import org.wso2.maven.p2.generate.utils.P2Constants; @@ -37,115 +42,84 @@ /** * Write environment information for the current build to file. - * - * @goal p2-profile-gen - * @phase package */ +@Mojo(name = "p2-profile-gen", defaultPhase = LifecyclePhase.PACKAGE) public class ProfileGenMojo extends AbstractMojo { - /** * Destination to which the features should be installed - * - * @parameter - * @required */ + @Parameter(name = "destination", required = true) private String destination; /** * target profile - * - * @parameter - * @required */ + @Parameter(name = "profile", required = true) private String profile; - - /** * URL of the Metadata Repository - * - * @parameter */ + @Parameter(name = "metadataRepository") private URL metadataRepository; /** * URL of the Artifact Repository - * - * @parameter */ + @Parameter(name = "artifactRepository") private URL artifactRepository; /** * List of features - * - * @parameter - * @required */ + @Parameter(name = "features", required = true) private ArrayList features; /** * Flag to indicate whether to delete old profile files - * - * @parameter default-value="true" */ + @Parameter(name = "deleteOldProfileFiles", defaultValue = "true") private boolean deleteOldProfileFiles = true; /** * Location of the p2 repository - * - * @parameter */ + @Parameter(name = "p2Repository") private P2Repository p2Repository; - /** - * @parameter default-value="${project}" - */ + @Parameter(name = "project", defaultValue = "${project}") private MavenProject project; - /** - * @component - */ + @Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory; - /** - * @component - */ + @Component private org.apache.maven.artifact.resolver.ArtifactResolver resolver; - /** - * @parameter default-value="${localRepository}" - */ + @Parameter(name = "localRepository", defaultValue = "${localRepository}") private org.apache.maven.artifact.repository.ArtifactRepository localRepository; - /** - * @parameter default-value="${project.remoteArtifactRepositories}" - */ + @Parameter(name = "remoteRepositories", defaultValue = "${project.remoteArtifactRepositories}") private java.util.List remoteRepositories; /** * Equinox p2 configuration path - * - * @parameter */ + @Parameter(name = "p2Profile") private P2Profile p2Profile; /** * Maven ProjectHelper. - * - * @component */ + @Component private MavenProjectHelper projectHelper; - /** @component */ - private P2ApplicationLauncher launcher; - /** * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for * the process, never timing out. - * - * @parameter expression="${p2.timeout}" */ + @Parameter(name = "forkedProcessTimeoutInSeconds", property = "p2.timeout") private int forkedProcessTimeoutInSeconds; @@ -203,40 +177,41 @@ private String getIUsToInstall() throws MojoExecutionException { return installUIs; } - private String getPublisherApplication() { - return "org.eclipse.equinox.p2.director"; + protected DirectorApplication getPublisherApplication() { + return new DirectorApplication(); } private void installFeatures(String installUIs) throws Exception { - P2ApplicationLauncher launcher = this.launcher; - - launcher.setWorkingDirectory(project.getBasedir()); - launcher.setApplicationName(getPublisherApplication()); - - addArguments(launcher,installUIs); - + List arguments = new ArrayList<>(); + addArguments(arguments, installUIs); - int result = launcher.execute(forkedProcessTimeoutInSeconds); - if (result != 0) { + Object result = getPublisherApplication().run(arguments.toArray(String[]::new)); + if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); } } - private void addArguments(P2ApplicationLauncher launcher, String installUIs) throws IOException, MalformedURLException { - launcher.addArguments( - "-metadataRepository", metadataRepository.toExternalForm(), // - "-artifactRepository", artifactRepository.toExternalForm(), // - "-profileProperties", "org.eclipse.update.install.features=true", - "-installIU", installUIs, - "-bundlepool", destination, + private void addArguments(List arguments, String installUIs) throws IOException, MalformedURLException { + arguments.add("-metadataRepository"); + arguments.add(metadataRepository.toExternalForm()); + arguments.add("-artifactRepository"); + arguments.add(artifactRepository.toExternalForm()); + arguments.add("-profileProperties"); + arguments.add("org.eclipse.update.install.features=true"); + arguments.add("-installIU"); + arguments.add(installUIs); + arguments.add("-bundlepool"); + arguments.add(destination); //to support shared installation in carbon - "-shared" , destination + File.separator + "p2", + arguments.add("-shared"); + arguments.add(destination + File.separator + "p2"); //target is set to a separate directory per Profile - "-destination", destination + File.separator + profile, - "-profile", profile.toString(), - "-roaming" - ); + arguments.add("-destination"); + arguments.add(destination + File.separator + profile); + arguments.add("-profile"); + arguments.add(profile.toString()); + arguments.add("-roaming"); } public class InputStreamHandler implements Runnable { diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java index 5d2e6e2c..0658dd9c 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java @@ -21,44 +21,45 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.UnArchiver; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.p2.publisher.eclipse.ProductPublisherApplication; import org.eclipse.tycho.model.ProductConfiguration; -import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; import java.io.File; import java.net.URL; +import java.util.ArrayList; +import java.util.List; -/** - * @goal publish-product - */ +@Mojo(name = "publish-product") public class PublishProductMojo extends AbstractMojo { - /** - * @parameter expression="${project}" - * @required - */ + + @Parameter(name = "project", property = "project", required = true) protected MavenProject project; /** * Metadata repository name - * @parameter */ + @Parameter(name = "metadataRepository") private URL metadataRepository; /** * Artifact repository name - * @parameter */ + @Parameter(name = "artifactRepository") private URL artifactRepository; /** * executable - * @parameter */ + @Parameter(name = "executable") private String executable; - /** - * @component role="org.codehaus.plexus.archiver.UnArchiver" role-hint="zip" - */ + @Component(role = org.codehaus.plexus.archiver.UnArchiver.class, hint = "zip") private UnArchiver deflater; @@ -66,25 +67,19 @@ public class PublishProductMojo extends AbstractMojo { * The product configuration, a .product file. This file manages all aspects * of a product definition from its constituent plug-ins to configuration * files to branding. - * - * @parameter expression="${productConfiguration}" */ + @Parameter(name = "productConfigurationFile", property = "productConfiguration") private File productConfigurationFile; /** * Parsed product configuration file */ private ProductConfiguration productConfiguration; - - /** @component */ - private P2ApplicationLauncher launcher; - /** * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for * the process, never timing out. - * - * @parameter expression="${p2.timeout}" */ + @Parameter(name = "forkedProcessTimeoutInSeconds", property = "p2.timeout") private int forkedProcessTimeoutInSeconds; @@ -101,27 +96,31 @@ public void execute() throws MojoExecutionException, MojoFailureException { private void publishProduct() throws Exception{ productConfiguration = ProductConfiguration.read( productConfigurationFile ); - P2ApplicationLauncher launcher = this.launcher; - - launcher.setWorkingDirectory(project.getBasedir()); - launcher.setApplicationName("org.eclipse.equinox.p2.publisher.ProductPublisher"); - - launcher.addArguments( - "-metadataRepository", metadataRepository.toString(), - "-artifactRepository", metadataRepository.toString(), - "-productFile", productConfigurationFile.getCanonicalPath(), - "-executables", executable.toString(), - "-publishArtifacts", - "-configs", "gtk.linux.x86", - "-flavor", "tooling", - "-append"); - - int result = launcher.execute(forkedProcessTimeoutInSeconds); - if (result != 0) { - throw new MojoFailureException("P2 publisher return code was " + result); - } + List arguments = new ArrayList<>(); + + arguments.add("-metadataRepository"); + arguments.add(metadataRepository.toString()); + arguments.add("-artifactRepository"); + arguments.add(metadataRepository.toString()); + arguments.add("-productFile"); + arguments.add(productConfigurationFile.getCanonicalPath()); + arguments.add("-executables"); + arguments.add(executable.toString()); + arguments.add("-publishArtifacts"); + arguments.add("-configs"); + arguments.add("gtk.linux.x86"); + arguments.add("-flavor"); + arguments.add("tooling"); + arguments.add("-append"); + + Object result = getPublisherApplication().run(arguments.toArray(String[]::new)); + if (result != IApplication.EXIT_OK) { + throw new MojoFailureException("P2 publisher return code was " + result); + } } + protected ProductPublisherApplication getPublisherApplication() { + return new ProductPublisherApplication(); + } - -} \ No newline at end of file +} diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java index 8160509e..765c83ab 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java @@ -33,19 +33,24 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.FileUtils; -import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.internal.p2.updatesite.CategoryPublisherApplication; +import org.eclipse.equinox.p2.core.IProvisioningAgent; +import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAndBundlesPublisherApplication; import org.wso2.maven.p2.generate.utils.FileManagementUtil; import org.wso2.maven.p2.generate.utils.MavenUtils; import org.wso2.maven.p2.generate.utils.P2Utils; /** * Write environment information for the current build to file. - * - * @goal p2-repo-gen - * @phase package */ +@Mojo(name = "p2-repo-gen", defaultPhase = LifecyclePhase.PACKAGE) public class RepositoryGenMojo extends AbstractMojo { // /** @@ -57,45 +62,38 @@ public class RepositoryGenMojo extends AbstractMojo { /** * Name of the repository - * - * @parameter */ + @Parameter(name = "name") private String name; /** * URL of the Metadata Repository - * - * @parameter */ + @Parameter(name = "metadataRepository") private URL metadataRepository; /** * URL of the Artifact Repository - * - * @parameter */ + @Parameter(name = "artifactRepository") private URL artifactRepository; /** * Source folder - * - * @parameter - * @required */ + @Parameter(name = "featureArtifacts", required = true) private ArrayList featureArtifacts; /** * Source folder - * - * @parameter */ + @Parameter(name = "bundleArtifacts") private ArrayList bundleArtifacts; /** * Source folder - * - * @parameter */ + @Parameter(name = "categories") private ArrayList categories; /** @@ -103,75 +101,57 @@ public class RepositoryGenMojo extends AbstractMojo { * the actual bytes underlying the artifact will not be copied, but the repository index will be created. * When this option is not specified, it is recommended to set the artifactRepository to be in the same location * as the source (-source) - * - * @parameter */ + @Parameter(name = "publishArtifacts") private boolean publishArtifacts; /** * Type of Artifact (War,Jar,etc) - * - * @parameter */ + @Parameter(name = "publishArtifactRepository") private boolean publishArtifactRepository; /** * Equinox Launcher - * - * @parameter */ + @Parameter(name = "equinoxLauncher") private EquinoxLauncher equinoxLauncher; /** * Equinox p2 configuration path - * - * @parameter */ + @Parameter(name = "p2Profile") private P2Profile p2Profile; - /** - * @parameter default-value="${project}" - */ + @Parameter(name = "project", defaultValue = "${project}") private MavenProject project; - - /** - * @parameter default-value="false" - */ + + @Parameter(name = "archive", defaultValue = "false") private boolean archive; - /** - * @component - */ + @Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory; - /** - * @component - */ + @Component private org.apache.maven.artifact.resolver.ArtifactResolver resolver; - /** - * @parameter default-value="${localRepository}" - */ + @Parameter(name = "localRepository", defaultValue = "${localRepository}") private org.apache.maven.artifact.repository.ArtifactRepository localRepository; - /** - * @parameter default-value="${project.remoteArtifactRepositories}" - */ + @Parameter(name = "remoteRepositories", defaultValue = "${project.remoteArtifactRepositories}") private List remoteRepositories; - - /** @component */ - private P2ApplicationLauncher launcher; - /** * Kill the forked test process after a certain number of seconds. If set to 0, wait forever for * the process, never timing out. - * - * @parameter expression="${p2.timeout}" */ + @Parameter(name = "forkedProcessTimeoutInSeconds", property = "p2.timeout") private int forkedProcessTimeoutInSeconds; + @Component + private IProvisioningAgent agent; + private ArrayList processedFeatureArtifacts; private ArrayList processedP2LauncherFiles; private File targetDir; @@ -235,37 +215,38 @@ private void copyResources() throws MojoExecutionException { } - private String getPublisherApplication() { - return "org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher"; + protected FeaturesAndBundlesPublisherApplication getPublisherApplication() { + return new FeaturesAndBundlesPublisherApplication(); } private void generateRepository() throws Exception { - P2ApplicationLauncher launcher = this.launcher; - - launcher.setWorkingDirectory(project.getBasedir()); - launcher.setApplicationName(getPublisherApplication()); - - addArguments(launcher); + List arguments = new ArrayList<>(); + addArguments(arguments); - - int result = launcher.execute(forkedProcessTimeoutInSeconds); - if (result != 0) { + // TODO org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher + Object result = getPublisherApplication().run(arguments.toArray(String[]::new)); + if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); } } - private void addArguments(P2ApplicationLauncher launcher) throws IOException, MalformedURLException { - launcher.addArguments("-source", sourceDir.getAbsolutePath(), // - "-metadataRepository", metadataRepository.toString(), // - "-metadataRepositoryName", getRepositoryName(), // - "-artifactRepository", metadataRepository.toString(), // - "-artifactRepositoryName", getRepositoryName(), // - "-publishArtifacts", - "-publishArtifactRepository", - "-compress", - "-append"); + private void addArguments(List arguments) throws IOException, MalformedURLException { + arguments.add("-source"); + arguments.add(sourceDir.getAbsolutePath()); + arguments.add("-metadataRepository"); + arguments.add(metadataRepository.toString()); + arguments.add("-metadataRepositoryName"); + arguments.add(getRepositoryName()); + arguments.add("-artifactRepository"); + arguments.add(metadataRepository.toString()); + arguments.add("-artifactRepositoryName"); + arguments.add(getRepositoryName()); + arguments.add("-publishArtifacts"); + arguments.add("-publishArtifactRepository"); + arguments.add("-compress"); + arguments.add("-append"); } private void extractFeatures() throws MojoExecutionException { @@ -384,19 +365,21 @@ private void updateRepositoryWithCategories() throws Exception { P2Utils.createCategoryFile(getProject(), categories, categoryDeinitionFile, getArtifactFactory(), getRemoteRepositories(), getLocalRepository(), getResolver()); - P2ApplicationLauncher launcher = this.launcher; - launcher.setWorkingDirectory(project.getBasedir()); - launcher.setApplicationName("org.eclipse.equinox.p2.publisher.CategoryPublisher"); - launcher.addArguments("-metadataRepository", metadataRepository.toString(), - "-categoryDefinition", categoryDeinitionFile.toURI().toString(), - "-categoryQualifier", - "-compress", - "-append"); - - int result = launcher.execute(forkedProcessTimeoutInSeconds); - if (result != 0) { - throw new MojoFailureException("P2 publisher return code was " + result); - } + List arguments = new ArrayList<>(); + arguments.add("-metadataRepository"); + arguments.add(metadataRepository.toString()); + arguments.add("-categoryDefinition"); + arguments.add(categoryDeinitionFile.toURI().toString()); + arguments.add("-categoryQualifier"); + arguments.add("-compress"); + arguments.add("-append"); + + //TODO is there a usage in forkedProcessTimeoutInSeconds + // org.eclipse.equinox.p2.publisher.CategoryPublisher + Object result = new CategoryPublisherApplication().run(arguments.toArray(String[]::new)); + if (result != IApplication.EXIT_OK) { + throw new MojoFailureException("P2 publisher return code was " + result); + } } } diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/AdviceFile.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/AdviceFile.java index c3140adf..2b834d53 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/AdviceFile.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/AdviceFile.java @@ -1,37 +1,39 @@ /* -* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ + * Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.wso2.maven.p2.generate.feature; +import org.apache.maven.plugins.annotations.Parameter; + import java.util.ArrayList; public class AdviceFile { - - /** + + /** * define properties - * @parameter */ - private ArrayList properties; + @Parameter(name = "properties") + private ArrayList properties; - public void setProperties(ArrayList properties) { - this.properties = properties; - } + public void setProperties(ArrayList properties) { + this.properties = properties; + } - public ArrayList getProperties() { - return properties; - } + public ArrayList getProperties() { + return properties; + } } diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Bundle.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Bundle.java index 3fd1a958..efdc8471 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Bundle.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Bundle.java @@ -31,6 +31,7 @@ import org.apache.maven.model.Dependency; import org.apache.maven.model.DependencyManagement; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.wso2.maven.p2.generate.utils.P2Utils; @@ -39,25 +40,20 @@ public class Bundle{ /** * Group Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "groupId", required = true) private String groupId; /** * Artifact Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "artifactId", required = true) private String artifactId; /** * Version of the Bundle - * - * @parameter default-value="" */ + @Parameter(name = "version", defaultValue = "") private String version; private Artifact artifact; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Feature.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Feature.java index 28fed7b9..29cf3b50 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Feature.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Feature.java @@ -17,21 +17,19 @@ */ package org.wso2.maven.p2.generate.feature; +import org.apache.maven.plugins.annotations.Parameter; + public class Feature { /** * Feature Id of the Feature - * - * @parameter - * @required */ + @Parameter(name = "featureId", required = true) public String featureId; /** * Version of the Feature - * - * @parameter - * @required */ + @Parameter(name = "version", required = true) public String version; } diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/FeatureGenMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/FeatureGenMojo.java index 54617644..6ee45793 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/FeatureGenMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/FeatureGenMojo.java @@ -40,6 +40,10 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.util.DirectoryScanner; @@ -55,124 +59,105 @@ /** * Write environment information for the current build to file. - * - * @goal p2-feature-gen - * @phase package */ +@Mojo(name = "p2-feature-gen", defaultPhase = LifecyclePhase.PACKAGE) public class FeatureGenMojo extends AbstractMojo { /** * feature id - * - * @parameter - * @required */ + @Parameter(name="id", required = true) private String id; /** * version - * - * @parameter default-value="${project.version}" */ + @Parameter(name="version", defaultValue = "${project.version}") private String version; /** * label of the feature - * - * @parameter default-value="${project.name}" */ + @Parameter(name="label", defaultValue="${project.name}") private String label; /** * description of the feature - * - * @parameter default-value="${project.description}" */ + @Parameter(name="description", defaultValue = "${project.description}") private String description; /** * provider name - * - * @parameter default-value="%providerName" */ + @Parameter(name="providerName", defaultValue = "%providerName") private String providerName; /** - * copyrite - * - * @parameter default-value="%copyright" + * copyright */ + @Parameter(name="copyright", defaultValue = "%copyright") private String copyright; /** * licence url - * - * @parameter default-value="%licenseURL" */ + @Parameter(name="licenceUrl", defaultValue = "%licenseURL") private String licenceUrl; /** * licence - * - * @parameter default-value="%license" */ + @Parameter(name="licence", defaultValue = "%license") private String licence; /** * path to manifest file - * - * @parameter */ + @Parameter(name="manifest") private File manifest; /** * path to properties file - * - * @parameter */ + @Parameter(name = "propertiesFile") private File propertiesFile; /** * list of properties - * precedance over propertiesFile - * - * @parameter + * precedence over propertiesFile */ + @Parameter(name = "properties") private Properties properties; /** * Collection of bundles - * - * @parameter */ + @Parameter(name = "bundles") private ArrayList bundles; /** * Collection of import bundles - * - * @parameter */ + @Parameter(name = "importBundles") private ArrayList importBundles; /** * Collection of required Features - * - * @parameter */ + @Parameter(name = "importFeatures") private ArrayList importFeatures; /** * Collection of required Features - * - * @parameter */ + @Parameter(name = "includedFeatures") private ArrayList includedFeatures; /** * define advice file content - * - * @parameter */ + @Parameter(name = "adviceFile") private AdviceFile adviceFile; // /** @@ -181,46 +166,31 @@ public class FeatureGenMojo extends AbstractMojo { // */ // private String category; // - /** - * @component - */ + @Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory; - /** - * @component - */ + @Component private org.apache.maven.artifact.resolver.ArtifactResolver resolver; - /** - * @parameter default-value="${localRepository}" - */ + @Parameter(name = "localRepository", defaultValue = "${localRepository}") private org.apache.maven.artifact.repository.ArtifactRepository localRepository; - /** - * @parameter default-value="${project.remoteArtifactRepositories}" - */ + @Parameter(name = "remoteRepositories", defaultValue = "${project.remoteArtifactRepositories}") private java.util.List remoteRepositories; - /** - * @parameter default-value="${project.distributionManagementArtifactRepository}" - */ + @Parameter(name = "deploymentRepository", defaultValue = "${project.distributionManagementArtifactRepository}") private ArtifactRepository deploymentRepository; - /** - * @component - */ + @Component private ArtifactMetadataSource artifactMetadataSource; - /** - * @parameter default-value="${project}" - */ + @Parameter(name = "project", defaultValue = "${project}") private MavenProject project; /** * Maven ProjectHelper. - * - * @component */ + @Component private MavenProjectHelper projectHelper; private ArrayList processedBundles; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportBundle.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportBundle.java index ab582beb..92454af5 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportBundle.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportBundle.java @@ -18,30 +18,27 @@ package org.wso2.maven.p2.generate.feature; import org.apache.maven.plugin.MojoExecutionException; - +import org.apache.maven.plugins.annotations.Parameter; public class ImportBundle extends Bundle{ /** * Version Compatibility of the Bundle - * - * @parameter default-value="false" */ + @Parameter(name = "exclude", defaultValue = "false") private boolean exclude; /** * OSGI Symbolic name - * - * @parameter */ + @Parameter(name = "bundleSymbolicName") private String bundleSymbolicName; /** * OSGI Version - * - * @parameter */ + @Parameter(name = "bundleVersion") private String bundleVersion; public void setExclude(boolean exclude) { diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportFeature.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportFeature.java index 165005fb..92943820 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportFeature.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/ImportFeature.java @@ -33,6 +33,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.model.Dependency; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.w3c.dom.Document; import org.wso2.maven.p2.generate.utils.P2Utils; @@ -41,24 +42,20 @@ public class ImportFeature{ /** * Feature Id of the feature - * - * @parameter */ - + @Parameter(name = "featureId") private String featureId; /** * Version of the feature - * - * @parameter default-value="" */ + @Parameter(name = "featureVersion", defaultValue = "") private String featureVersion; /** * Version Compatibility of the Feature - * - * @parameter */ + @Parameter(name = "compatibility") private String compatibility; private Artifact artifact; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/IncludedFeature.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/IncludedFeature.java index 6214098b..1530ef77 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/IncludedFeature.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/IncludedFeature.java @@ -16,37 +16,32 @@ package org.wso2.maven.p2.generate.feature; import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugins.annotations.Parameter; public class IncludedFeature { /** * Group Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "groupId", required = true) private String groupId; /** * Artifact Id of the Bundle - * - * @parameter - * @required */ + @Parameter(name = "artifactId", required = true) private String artifactId; /** * Version of the Bundle - * - * @parameter default-value="" */ + @Parameter(name = "artifactVersion", defaultValue = "") private String artifactVersion; /** * Optionality of the included feature - * - * @parameter default-value="" */ + @Parameter(name = "optionality", defaultValue = "") private String optionality; private boolean optional = false; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Property.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Property.java index e1ca222e..11520c03 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Property.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/generate/feature/Property.java @@ -18,22 +18,19 @@ package org.wso2.maven.p2.generate.feature; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; public class Property { /** * property key - * - * @parameter - * @required */ + @Parameter(name = "key", required = true) private String key; /** * property value - * - * @parameter - * @required */ + @Parameter(name = "value", required = true) private String value; diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/maven/CarbonMavenLifecycleParticipant.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/maven/CarbonMavenLifecycleParticipant.java new file mode 100644 index 00000000..99d39f13 --- /dev/null +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/maven/CarbonMavenLifecycleParticipant.java @@ -0,0 +1,385 @@ +/******************************************************************************* + * Copyright (c) 2008, 2022 Sonatype Inc. and others. + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Sonatype Inc. - initial API and implementation + * Bachmann electronic GmbH - Bug 457314 - handle null as tycho version + * Christoph Läubrich - Bug 569829 - TychoMavenLifecycleParticipant should respect fail-at-end flag / error output is missing + * - Issue 557 - BuildPropertiesParser should use reactor project instead of basedir + *******************************************************************************/ +package org.wso2.maven.p2.maven; + +import org.apache.maven.AbstractMavenLifecycleParticipant; +import org.apache.maven.MavenExecutionException; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.io.ModelWriter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IRequirement; +import org.eclipse.sisu.equinox.EquinoxServiceFactory; +import org.eclipse.tycho.BuildFailureException; +import org.eclipse.tycho.DependencyResolutionException; +import org.eclipse.tycho.TychoConstants; +import org.eclipse.tycho.build.BuildListeners; +import org.eclipse.tycho.core.TychoProjectManager; +import org.eclipse.tycho.core.maven.MavenDependencyInjector; +import org.eclipse.tycho.core.osgitools.BundleReader; +import org.eclipse.tycho.core.osgitools.DefaultBundleReader; +import org.eclipse.tycho.p2maven.MavenProjectDependencyProcessor; +import org.eclipse.tycho.p2maven.MavenProjectDependencyProcessor.ProjectDependencyClosure; +import org.eclipse.tycho.resolver.TychoResolver; +import org.eclipse.tycho.version.TychoVersion; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ForkJoinTask; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +@Named("CarbonMavenLifecycleListener") +@Singleton +public class CarbonMavenLifecycleParticipant extends AbstractMavenLifecycleParticipant { + + static final boolean DUMP_DATA = Boolean.getBoolean("tycho.p2.dump") || Boolean.getBoolean("tycho.p2.dump.model"); + + private static final String GROUPID = "org.wso2.maven"; + private static final Set PLUGIN_IDS = new HashSet<>( + Arrays.asList("carbon-p2-plugin")); + private static final String P2_USER_AGENT_KEY = "p2.userAgent"; + private static final String P2_USER_AGENT_VALUE = "tycho/"; + + @Inject + private BundleReader bundleReader; + + @Inject + private TychoResolver resolver; + + @Inject + private PlexusContainer plexus; + + @Inject + private Logger log; + +// @Requirement + @Inject + MavenProjectDependencyProcessor dependencyProcessor; + + @Inject + private ModelWriter modelWriter; + + @Inject + BuildListeners buildListeners; + + @Inject + TychoProjectManager projectManager; + + public CarbonMavenLifecycleParticipant() { + // needed for plexus + } + + // needed for unit tests + protected CarbonMavenLifecycleParticipant(Logger log) { + this.log = log; + } + + @Override + public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + log.info("Tycho Version: " + TychoVersion.getTychoVersion() + " (" + TychoVersion.getSCMInfo() + ")"); + log.info("Tycho Mode: " + + session.getUserProperties().getProperty(TychoConstants.SESSION_PROPERTY_TYCHO_MODE, "project")); + log.info("Tycho Builder: " + + session.getUserProperties().getProperty(TychoConstants.SESSION_PROPERTY_TYCHO_BUILDER, "maven")); + log.info("Build Threads: " + session.getRequest().getDegreeOfConcurrency()); + if (disableLifecycleParticipation(session)) { + buildListeners.notifyBuildStart(session); + return; + } + List projects = session.getProjects(); + try { + validate(projects); + + // setting this system property to let EF figure out where the traffic + // is coming from (#467418) + System.setProperty(P2_USER_AGENT_KEY, P2_USER_AGENT_VALUE + TychoVersion.getTychoVersion()); + + configureComponents(session); + + for (MavenProject project : projects) { + resolver.setupProject(session, project); + } + Map> partition = projects.stream().collect(Collectors.partitioningBy( + project -> projectManager.getTargetPlatformConfiguration(project).isRequireEagerResolve())); + List eagerProjects = partition.get(true); + List lazyProjects = partition.get(false); + + if (eagerProjects.size() > 0) { + resolveProjects(session, eagerProjects); + } + if (lazyProjects.size() > 0) { + try { + ProjectDependencyClosure closure = dependencyProcessor.computeProjectDependencyClosure(projects, + session); + for (MavenProject project : lazyProjects) { + if (projectManager.getTychoProject(project).isEmpty()) { + //do not inject additional dependencies for non Tycho managed projects! + continue; + } + Collection dependencyProjects = closure.getDependencyProjects(project, + projectManager.getContextIUs(project)); + MavenDependencyInjector.injectMavenProjectDependencies(project, dependencyProjects); + if (DUMP_DATA) { + try { + Set visited = new HashSet<>(); + modelWriter.write(new File(project.getBasedir(), "pom-model.xml"), Map.of(), + project.getModel()); + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(new File(project.getBasedir(), "requirements.txt"))))) { + writer.write(project.getId() + ":\r\n"); + dumpProjectRequirements(project, writer, closure, dependencyProjects, "\t", + visited); + } + } catch (IOException e) { + } + } + } + } catch (CoreException e) { + throw new MavenExecutionException(e.getMessage(), e); + } + } + } catch (BuildFailureException e) { + // build failure is not an internal (unexpected) error, so avoid printing a stack + // trace by wrapping it in MavenExecutionException + throw new MavenExecutionException(e.getMessage(), e); + } + buildListeners.notifyBuildStart(session); + } + + private void dumpProjectRequirements(MavenProject project, BufferedWriter writer, ProjectDependencyClosure closure, + Collection dependencyProjects, String indent, Set visited) throws IOException { + if (visited.add(project)) { + List projectRequirements = closure.getProjectUnits(project).stream() + .flatMap(iu -> iu.getRequirements().stream()).toList(); + String indent2 = indent + "\t"; + for (MavenProject dependency : dependencyProjects) { + writer.write(indent + " depends on " + dependency.getId() + ":\r\n"); + for (IRequirement requirement : projectRequirements) { + List satisfies = closure.getProjectUnits(dependency).stream() + .filter(iu -> iu.satisfies(requirement)).toList(); + for (IInstallableUnit satIU : satisfies) { + writer.write(indent2 + "provides " + satIU + " that satisfies " + requirement + "\r\n"); + } + } + dumpProjectRequirements(dependency, writer, closure, + closure.getDependencyProjects(dependency, projectManager.getContextIUs(project)), indent2, + visited); + } + } + } + + @Override + public void afterSessionEnd(MavenSession session) throws MavenExecutionException { + buildListeners.notifyBuildEnd(session); + if (plexus.hasComponent(EquinoxServiceFactory.class)) { + try { + EquinoxServiceFactory factory = plexus.lookup(EquinoxServiceFactory.class); + // do not use plexus.dispose() as this only works once and we + // want to reuse the factory multiple times but make sure the + // equinox framework is fully recreated + if (factory instanceof Disposable disposable) { + disposable.dispose(); + } + } catch (ComponentLookupException e) { + throw new MavenExecutionException(e.getMessage(), e); + } + } + } + + private void validate(List projects) throws MavenExecutionException { + validateConsistentTychoVersion(projects); + validateUniqueBaseDirs(projects); + } + + private void resolveProjects(MavenSession session, List projects) { + + MavenExecutionRequest request = session.getRequest(); + boolean failFast = MavenExecutionRequest.REACTOR_FAIL_FAST.equals(request.getReactorFailureBehavior()); + Map resolutionErrors = new ConcurrentHashMap<>(); + Consumer resolveProject = project -> { + if (failFast && !resolutionErrors.isEmpty()) { + //short circuit + return; + } + try { + MavenSession clone = session.clone(); + clone.setCurrentProject(project); + resolver.resolveProject(clone, project); + if (DUMP_DATA) { + try { + modelWriter.write(new File(project.getBasedir(), "pom-model-classic.xml"), Map.of(), + project.getModel()); + } catch (IOException e) { + } + } + } catch (BuildFailureException e) { + resolutionErrors.put(project, e); + if (failFast) { + throw e; + } + } + }; + + int degreeOfConcurrency = request.getDegreeOfConcurrency(); + Predicate takeWhile = Predicate.not(p -> failFast && !resolutionErrors.isEmpty()); + if (degreeOfConcurrency > 1) { + ForkJoinPool executor = new ForkJoinPool(degreeOfConcurrency); + ForkJoinTask future = executor + .submit(() -> projects.parallelStream().takeWhile(takeWhile).forEach(resolveProject)); + try { + future.get(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } catch (ExecutionException e) { + Throwable cause = e.getCause(); + throw cause instanceof RuntimeException ex // + ? ex + : new RuntimeException("resolve dependencies failed", cause); + } finally { + executor.shutdown(); + } + + } else { + projects.stream().takeWhile(takeWhile).forEach(resolveProject); + } + + reportResolutionErrors(resolutionErrors, projects, failFast); + } + + private void reportResolutionErrors(Map resolutionErrors, + List projects, boolean failFast) { + if (resolutionErrors.isEmpty()) { + return; + } + + if (resolutionErrors.size() == 1 || failFast) { + //The idea is if user want to fail-fast he would expect to get exactly one error (the first one), + //while if parallel execution is enabled it might report an (incomplete) list of other failures that happened due to the parallel processing. + throw resolutionErrors.values().iterator().next(); + } + + DependencyResolutionException exception = new DependencyResolutionException( + String.format("Cannot resolve dependencies of %d/%d projects, see log for details", + resolutionErrors.size(), projects.size())); + resolutionErrors.values().forEach(exception::addSuppressed); + resolutionErrors.forEach((project, error) -> log.error(project.getName() + ": " + error.getMessage())); + + throw exception; + } + + protected void validateConsistentTychoVersion(List projects) throws MavenExecutionException { + Map> versionToProjectsMap = new HashMap<>(); + for (MavenProject project : projects) { + for (Plugin plugin : project.getBuild().getPlugins()) { + if (GROUPID.equals(plugin.getGroupId()) && PLUGIN_IDS.contains(plugin.getArtifactId())) { + String version = plugin.getVersion(); + // Skip checking plug ins that do not have a version + if (version == null) { + continue; + } + log.debug( + GROUPID + ":" + plugin.getArtifactId() + ":" + version + " configured in " + project); + Set projectSet = versionToProjectsMap.get(version); + if (projectSet == null) { + projectSet = new LinkedHashSet<>(); + versionToProjectsMap.put(version, projectSet); + } + projectSet.add(project); + } + } + } + if (versionToProjectsMap.size() > 1) { + List versions = new ArrayList<>(versionToProjectsMap.keySet()); + Collections.sort(versions); + log.error("Several versions of Tycho plugins are configured " + versions + ":"); + for (String version : versions) { + log.error(version + ":"); + for (MavenProject project : versionToProjectsMap.get(version)) { + log.error("\t" + project.toString()); + } + } + throw new MavenExecutionException("All tycho plugins configured in one reactor must use the same version", + projects.get(0).getFile()); + } + } + + private void validateUniqueBaseDirs(List projects) throws MavenExecutionException { + // we store intermediate build results in the target/ folder and use the baseDir as unique key + // so multiple modules in the same baseDir would lead to irreproducible/unexpected results + // e.g. with mvn clean. This should really not be supported by maven core + Set baseDirs = new HashSet<>(); + for (MavenProject project : projects) { + File basedir = project.getBasedir(); + if (baseDirs.contains(basedir)) { + throw new MavenExecutionException( + "Multiple modules within the same basedir are not supported: " + basedir, project.getFile()); + } else { + baseDirs.add(basedir); + } + } + } + + private static final Set CLEAN_PHASES = Set.of("pre-clean", "clean", "post-clean"); + + private boolean disableLifecycleParticipation(MavenSession session) { + return isM2E(session) || isCleanOnly(session); + } + + private boolean isCleanOnly(MavenSession session) { + // disable for 'clean-only' builds. Consider that Maven can be invoked without explicit goals, if default goals are specified + return !session.getGoals().isEmpty() && CLEAN_PHASES.containsAll(session.getGoals()); + } + + private boolean isM2E(MavenSession session) { + return session.getUserProperties().containsKey("m2e.version"); + } + + private void configureComponents(MavenSession session) { + // TODO why does the bundle reader need to cache stuff in the local maven repository? + File localRepository = new File(session.getLocalRepository().getBasedir()); + ((DefaultBundleReader) bundleReader).setLocationRepository(localRepository); + } + +} diff --git a/carbon-p2-plugin/src/main/resources/META-INF/plexus/components.xml b/carbon-p2-plugin/src/main/resources/META-INF/plexus/components.xml index 712842cb..fe2bbf2b 100755 --- a/carbon-p2-plugin/src/main/resources/META-INF/plexus/components.xml +++ b/carbon-p2-plugin/src/main/resources/META-INF/plexus/components.xml @@ -51,5 +51,46 @@ + + org.apache.maven.AbstractMavenLifecycleParticipant + CarbonMavenLifecycleListener + org.wso2.maven.p2.maven.CarbonMavenLifecycleParticipant + + false + + + org.eclipse.tycho.core.osgitools.BundleReader + bundleReader + + + org.eclipse.tycho.resolver.TychoResolver + resolver + + + org.codehaus.plexus.PlexusContainer + plexus + + + org.codehaus.plexus.logging.Logger + log + + + org.eclipse.tycho.p2maven.MavenProjectDependencyProcessor + dependencyProcessor + + + org.apache.maven.model.io.ModelWriter + modelWriter + + + org.eclipse.tycho.build.BuildListeners + buildListeners + + + org.eclipse.tycho.core.TychoProjectManager + projectManager + + + - \ No newline at end of file + diff --git a/pom.xml b/pom.xml index 4aa96756..f84b5ae2 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,35 @@ Maven Commons Tools Aggregator Pom http://wso2.org + + wso2.releases + WSO2 Releases Repository + https://maven.wso2.org/nexus/content/repositories/releases/ + + true + daily + ignore + + + + + + wso2.snapshots + WSO2 Snapshot Repository + https://maven.wso2.org/nexus/content/repositories/snapshots/ + + true + daily + + + false + + + wso2-nexus WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ + https://maven.wso2.org/nexus/content/groups/wso2-public/ true daily From 43c0676241a5fbd9cb43dee6a08e0b65b6f3289f Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Wed, 20 Mar 2024 18:27:19 +0530 Subject: [PATCH 2/3] Add changes to compile product with Java 17 --- carbon-p2-plugin/pom.xml | 4 ++-- .../src/main/java/org/wso2/maven/p2/PublishProductMojo.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/carbon-p2-plugin/pom.xml b/carbon-p2-plugin/pom.xml index af442eb5..290d0561 100755 --- a/carbon-p2-plugin/pom.xml +++ b/carbon-p2-plugin/pom.xml @@ -136,8 +136,8 @@ maven-compiler-plugin 3.12.1 - 21 - 21 + 17 + 17 false diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java index 0658dd9c..249df477 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java @@ -104,8 +104,8 @@ private void publishProduct() throws Exception{ arguments.add(metadataRepository.toString()); arguments.add("-productFile"); arguments.add(productConfigurationFile.getCanonicalPath()); - arguments.add("-executables"); - arguments.add(executable.toString()); +// arguments.add("-executables"); +// arguments.add(executable.toString()); arguments.add("-publishArtifacts"); arguments.add("-configs"); arguments.add("gtk.linux.x86"); From 33632fe19007ee53b6a33c9d92f317932bb3b122 Mon Sep 17 00:00:00 2001 From: Maduranga Siriwardena Date: Fri, 19 Apr 2024 10:06:17 +0530 Subject: [PATCH 3/3] Add formatting changes and change version to Java 21 --- carbon-p2-plugin/pom.xml | 58 +++---------------- .../wso2/maven/p2/MaterializeProductMojo.java | 27 +++------ .../org/wso2/maven/p2/PublishProductMojo.java | 15 +---- .../org/wso2/maven/p2/RepositoryGenMojo.java | 32 +++------- 4 files changed, 27 insertions(+), 105 deletions(-) diff --git a/carbon-p2-plugin/pom.xml b/carbon-p2-plugin/pom.xml index 290d0561..2b422539 100755 --- a/carbon-p2-plugin/pom.xml +++ b/carbon-p2-plugin/pom.xml @@ -48,6 +48,12 @@ maven-plugin-annotations 3.11.0 + + + org.eclipse.platform + org.eclipse.equinox.p2.publisher + 1.9.100 + org.eclipse.tycho sisu-equinox-launching @@ -83,19 +89,6 @@ - - - - - - - - - - - - - org.eclipse.sisu sisu-maven-plugin @@ -136,47 +129,12 @@ maven-compiler-plugin 3.12.1 - 17 - 17 + 21 + 21 false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java index b173ffe2..2b4070eb 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/MaterializeProductMojo.java @@ -42,19 +42,19 @@ public class MaterializeProductMojo extends AbstractMojo { @Parameter(name = "project", property = "project", required = true) protected MavenProject project; + /** * Metadata repository name */ @Parameter(name = "metadataRepository") private URL metadataRepository; + /** * Artifact repository name */ @Parameter(name = "artifactRepository") private URL artifactRepository; - - /** * The product configuration, a .product file. This file manages all aspects * of a product definition from its constituent plug-ins to configuration @@ -86,28 +86,27 @@ public class MaterializeProductMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { try { - if (profile == null){ + if (profile == null) { profile = P2Constants.DEFAULT_PROFILE_ID; } deployRepository(); //updating profile's config.ini p2.data.area property using relative path File profileConfigIni = FileManagementUtil.getProfileConfigIniFile(targetPath.getPath(), profile); FileManagementUtil.changeConfigIniProperty(profileConfigIni, "eclipse.p2.data.area", "@config.dir/../../p2/"); - }catch (Exception e) { + } catch (Exception e) { throw new MojoExecutionException("Cannot generate P2 metadata", e); } } - private void regenerateCUs() - throws MojoExecutionException, MojoFailureException - { + private void regenerateCUs() throws MojoExecutionException, MojoFailureException { + getLog().debug( "Regenerating config.ini" ); Properties props = new Properties(); String id = productConfiguration.getId(); setPropertyIfNotNull(props, "osgi.bundles", getFeaturesOsgiBundles()); setPropertyIfNotNull( props, "osgi.bundles.defaultStartLevel", "4" ); - if(profile == null){ + if (profile == null) { profile = "profile"; } setPropertyIfNotNull( props, "eclipse.p2.profile", profile); @@ -115,24 +114,18 @@ private void regenerateCUs() setPropertyIfNotNull( props, "eclipse.p2.data.area", "@config.dir/../p2/"); setPropertyIfNotNull( props, "eclipse.application", productConfiguration.getApplication() ); - - - File configsFolder = new File( targetPath.toString(), "configuration" ); configsFolder.mkdirs(); File configIni = new File( configsFolder, "config.ini" ); - try - { + try { FileOutputStream fos = new FileOutputStream( configIni ); props.store( fos, "Product Runtime Configuration File" ); fos.close(); } - catch ( IOException e ) - { + catch ( IOException e ) { throw new MojoExecutionException( "Error creating .eclipseproduct file.", e ); } - } private String getFeaturesOsgiBundles() { @@ -177,7 +170,6 @@ private void deployRepository() throws Exception{ if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); } - } protected DirectorApplication getPublisherApplication() { @@ -191,5 +183,4 @@ private void setPropertyIfNotNull( Properties properties, String key, String val properties.setProperty( key, value ); } } - } diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java index 249df477..6b0733a1 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/PublishProductMojo.java @@ -47,22 +47,16 @@ public class PublishProductMojo extends AbstractMojo { */ @Parameter(name = "metadataRepository") private URL metadataRepository; + /** * Artifact repository name */ @Parameter(name = "artifactRepository") private URL artifactRepository; - /** - * executable - */ - @Parameter(name = "executable") - private String executable; - @Component(role = org.codehaus.plexus.archiver.UnArchiver.class, hint = "zip") private UnArchiver deflater; - /** * The product configuration, a .product file. This file manages all aspects * of a product definition from its constituent plug-ins to configuration @@ -84,11 +78,10 @@ public class PublishProductMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { - try { + try { publishProduct(); - - }catch (Exception e) { + } catch (Exception e) { throw new MojoExecutionException("Cannot generate P2 metadata", e); } } @@ -104,8 +97,6 @@ private void publishProduct() throws Exception{ arguments.add(metadataRepository.toString()); arguments.add("-productFile"); arguments.add(productConfigurationFile.getCanonicalPath()); -// arguments.add("-executables"); -// arguments.add(executable.toString()); arguments.add("-publishArtifacts"); arguments.add("-configs"); arguments.add("gtk.linux.x86"); diff --git a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java index 765c83ab..53917ff4 100755 --- a/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java +++ b/carbon-p2-plugin/src/main/java/org/wso2/maven/p2/RepositoryGenMojo.java @@ -15,10 +15,8 @@ */ package org.wso2.maven.p2; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; -import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; @@ -38,7 +36,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.FileUtils; import org.eclipse.equinox.app.IApplication; import org.eclipse.equinox.internal.p2.updatesite.CategoryPublisherApplication; import org.eclipse.equinox.p2.core.IProvisioningAgent; @@ -53,13 +50,6 @@ @Mojo(name = "p2-repo-gen", defaultPhase = LifecyclePhase.PACKAGE) public class RepositoryGenMojo extends AbstractMojo { -// /** -// * URL of the Metadata Repository -// * -// * @parameter -// */ -// private URL repository; - /** * Name of the repository */ @@ -191,8 +181,6 @@ public void createRepo() throws MojoExecutionException, MojoFailureException { } } - - private void copyResources() throws MojoExecutionException { List resources = project.getResources(); if (resources != null) { @@ -225,7 +213,6 @@ private void generateRepository() throws Exception { addArguments(arguments); - // TODO org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher Object result = getPublisherApplication().run(arguments.toArray(String[]::new)); if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); @@ -256,10 +243,12 @@ private void extractFeatures() throws MojoExecutionException { .hasNext();) { FeatureArtifact featureArtifact = (FeatureArtifact) iterator.next(); try { - getLog().info("Extracting feature "+featureArtifact.getGroupId()+":"+featureArtifact.getArtifactId()); + getLog().info("Extracting feature " + featureArtifact.getGroupId() + + ":" + featureArtifact.getArtifactId()); FileManagementUtil.unzip(featureArtifact.getArtifact().getFile(), sourceDir); } catch (Exception e) { - throw new MojoExecutionException("Error occured when extracting the Feature Artifact: " + featureArtifact.toString(), e); + throw new MojoExecutionException( + "Error occured when extracting the Feature Artifact: " + featureArtifact.toString(), e); } } } @@ -275,7 +264,8 @@ private void copyBundleArtifacts()throws MojoExecutionException { File file = bundleArtifact.getArtifact().getFile(); FileManagementUtil.copy(file, new File(pluginsDir,file.getName())); } catch (Exception e) { - throw new MojoExecutionException("Error occured when extracting the Feature Artifact: " + bundleArtifact.toString(), e); + throw new MojoExecutionException("Error occurred when extracting the Feature Artifact: " + + bundleArtifact.toString(), e); } } } @@ -307,7 +297,7 @@ private ArrayList getProcessedFeatureArtifacts() throws MojoExecutionException { } private void archiveRepo() throws MojoExecutionException { - if (isArchive()){ + if (isArchive()) { getLog().info("Generating repository archive..."); FileManagementUtil.zipFolder(REPO_GEN_LOCATION.toString(), ARCHIVE_FILE.toString()); getLog().info("Repository Archive: "+ARCHIVE_FILE.toString()); @@ -337,8 +327,6 @@ private ArrayList getProcessedBundleArtifacts() throws MojoExecutionException { return processedBundleArtifacts; } - - private void createAndSetupPaths() throws Exception { targetDir = new File(getProject().getBasedir(), "target"); String timestampVal = String.valueOf((new Date()).getTime()); @@ -374,8 +362,6 @@ private void updateRepositoryWithCategories() throws Exception { arguments.add("-compress"); arguments.add("-append"); - //TODO is there a usage in forkedProcessTimeoutInSeconds - // org.eclipse.equinox.p2.publisher.CategoryPublisher Object result = new CategoryPublisherApplication().run(arguments.toArray(String[]::new)); if (result != IApplication.EXIT_OK) { throw new MojoFailureException("P2 publisher return code was " + result); @@ -400,18 +386,14 @@ private void performMopUp() { } } - - public void setP2Profile(P2Profile p2Profile) { this.p2Profile = p2Profile; } - public P2Profile getP2Profile() { return p2Profile; } - public void setProject(MavenProject project) { this.project = project; }