You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by kw...@apache.org on 2022/08/09 18:22:18 UTC
[sling-maven-plugin] 01/01: SLING-11522 update Maven plugins, dependencies and parent
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/update-parent-plugins-deps
in repository https://gitbox.apache.org/repos/asf/sling-maven-plugin.git
commit 3bb282901e7d2871d356f2d18a599117a29e5ad9
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Tue Aug 9 20:22:11 2022 +0200
SLING-11522 update Maven plugins, dependencies and parent
Switch to Maven Resolver/Eclipse Aether API introduced with Maven 3.3.1
---
parent/pom.xml | 2 +-
sling-maven-plugin/pom.xml | 62 +++++++--------
.../bundlesupport/AbstractBundleInstallMojo.java | 10 +--
.../maven/bundlesupport/BundleInstallFileMojo.java | 93 +++++++---------------
.../maven/bundlesupport/BundleInstallMojo.java | 10 ++-
.../maven/bundlesupport/BundleUninstallMojo.java | 8 +-
6 files changed, 72 insertions(+), 113 deletions(-)
diff --git a/parent/pom.xml b/parent/pom.xml
index f73b1d6..baa2cb8 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>41</version>
+ <version>49</version>
<relativePath />
</parent>
diff --git a/sling-maven-plugin/pom.xml b/sling-maven-plugin/pom.xml
index fe8e523..31ef885 100644
--- a/sling-maven-plugin/pom.xml
+++ b/sling-maven-plugin/pom.xml
@@ -38,26 +38,17 @@
<url>https://sling.apache.org/components/sling-maven-plugin/</url>
<prerequisites>
- <maven>3.0.4</maven> <!-- still support older maven version than required in parent pom -->
+ <maven>${mavenVersion}</maven>
</prerequisites>
<properties>
<maven.site.path>${project.artifactId}-archives/${project.artifactId}-LATEST</maven.site.path>
+ <sling.java.version>8</sling.java.version>
+ <mavenVersion>3.3.1</mavenVersion><!-- minimum target Maven version this plugin is compatible with -->
+ <asmVersion>9.3</asmVersion>
</properties>
<build>
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-site-plugin</artifactId>
- <version>3.9.1</version>
- </plugin>
- <plugin>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <version>3.1.1</version>
- </plugin>
- </plugins>
- </pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -151,23 +142,22 @@
</exclusion>
</exclusions>
</dependency>
- <!-- Stick with json 1.0 specs until the plugin can be updated to Java 8 - json_1.1 spec requires Java 8 (SLING-7644) -->
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.0_spec</artifactId>
- <version>1.0-alpha-1</version>
+ <artifactId>geronimo-json_1.1_spec</artifactId>
+ <version>1.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-core</artifactId>
- <version>1.0.0</version>
+ <version>1.2.16</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit.vault</groupId>
<artifactId>org.apache.jackrabbit.vault</artifactId>
- <version>3.4.6</version>
+ <version>3.5.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -179,39 +169,38 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.framework</artifactId>
<version>1.8.0</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
<version>2.4.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>3.0.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-artifact</artifactId>
- <version>3.0.4</version>
- <scope>compile</scope>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-compat</artifactId>
- <version>3.0.4</version>
- <scope>compile</scope>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-archiver</artifactId>
- <version>2.6</version>
+ <artifactId>maven-artifact</artifactId>
+ <version>${mavenVersion}</version>
+ <scope>provided</scope>
</dependency>
+ <!-- use for evaluating Adapter annotations -->
<dependency>
<groupId>net.sf.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>1.0.2</version>
+ <scope>compile</scope>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
@@ -223,30 +212,33 @@
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>adapter-annotations</artifactId>
<version>1.0.0</version>
+ <scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.ow2.asm/asm -->
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
- <version>9.0</version>
+ <version>${asmVersion}</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-commons</artifactId>
- <version>9.0</version>
+ <version>${asmVersion}</version>
+ <scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
- <version>3.4</version>
<scope>provided</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.sonatype.plexus</groupId>
<artifactId>plexus-build-api</artifactId>
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
index dc20552..4ccab16 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
@@ -103,19 +103,17 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
super();
}
- protected abstract String getBundleFileName() throws MojoExecutionException;
+ protected abstract File getBundleFileName() throws MojoExecutionException;
@Override
public void execute() throws MojoExecutionException {
// get the file to upload
- String bundleFileName = getBundleFileName();
+ File bundleFile = getBundleFileName();
// only upload if packaging as an osgi-bundle
- File bundleFile = new File(bundleFileName);
-
- if(!bundleFile.exists()) {
- getLog().info(bundleFile + " does not exist, no uploading");
+ if (!bundleFile.exists()) {
+ getLog().info(bundleFile + " does not exist, not uploading");
return;
}
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java
index 2f33de2..36fe164 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java
@@ -17,24 +17,24 @@
package org.apache.sling.maven.bundlesupport;
-import java.util.ArrayList;
+import java.io.File;
import java.util.List;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.resolver.AbstractArtifactResolutionException;
-import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.StringUtils;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.repository.RemoteRepository;
+import org.eclipse.aether.resolution.ArtifactRequest;
+import org.eclipse.aether.resolution.ArtifactResolutionException;
+import org.eclipse.aether.resolution.ArtifactResult;
/**
- * Install an OSGi bundle to a running Sling instance.
+ * Install an OSGi bundle from a given file path or Maven coordinates (resolved from the repository) to a running Sling instance.
*/
@Mojo(name = "install-file", requiresProject = false)
public class BundleInstallFileMojo extends AbstractBundleInstallMojo {
@@ -43,7 +43,7 @@ public class BundleInstallFileMojo extends AbstractBundleInstallMojo {
* The name of the generated JAR file.
*/
@Parameter(property="sling.file")
- private String bundleFileName;
+ private File bundleFileName;
/**
* The groupId of the artifact to install
@@ -81,40 +81,18 @@ public class BundleInstallFileMojo extends AbstractBundleInstallMojo {
@Parameter(property="sling.artifact")
private String artifact;
- @Parameter(property="project.remoteArtifactRepositories", required = true, readonly = true)
- private List pomRemoteRepositories;
-
- /**
- * The id of the repository from which we'll download the artifact
- */
- @Parameter(property = "sling.repoId", defaultValue = "temp")
- private String repositoryId = "temp";
-
- /**
- * The url of the repository from which we'll download the artifact
- */
- @Parameter(property = "sling.repoUrl")
- private String repositoryUrl;
-
- @SuppressWarnings("deprecation")
@Component
- private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory;
+ private RepositorySystem repoSystem;
- @Component
- private ArtifactResolver artifactResolver;
-
- @Component
- private ArtifactRepositoryFactory artifactRepositoryFactory;
+ @Parameter( defaultValue = "${repositorySystemSession}", readonly = true, required = true )
+ private RepositorySystemSession repoSession;
- @Component(hint="default")
- private ArtifactRepositoryLayout repositoryLayout;
-
- @Parameter(property="localRepository", readonly = true)
- private ArtifactRepository localRepository;
+ @Parameter( defaultValue = "${project.remoteProjectRepositories}", readonly = true, required = true )
+ private List<RemoteRepository> repositories;
@Override
- protected String getBundleFileName() throws MojoExecutionException {
- String fileName = bundleFileName;
+ protected File getBundleFileName() throws MojoExecutionException {
+ File fileName = bundleFileName;
if (fileName == null) {
fileName = resolveBundleFileFromArtifact();
@@ -126,8 +104,7 @@ public class BundleInstallFileMojo extends AbstractBundleInstallMojo {
return fileName;
}
- @SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
- private String resolveBundleFileFromArtifact() throws MojoExecutionException {
+ private File resolveBundleFileFromArtifact() throws MojoExecutionException {
if (artifactId == null && artifact == null) {
return null;
}
@@ -145,31 +122,21 @@ public class BundleInstallFileMojo extends AbstractBundleInstallMojo {
if (tokens.length == 5)
classifier = tokens[4];
}
- Artifact packageArtifact = artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, packaging, classifier);
-
- if (pomRemoteRepositories == null) {
- pomRemoteRepositories = new ArrayList();
- }
-
- List repoList = new ArrayList(pomRemoteRepositories);
-
- if (repositoryUrl != null) {
- ArtifactRepositoryPolicy policy =
- new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
- ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
- ArtifactRepository remoteRepo = artifactRepositoryFactory.createArtifactRepository(repositoryId, repositoryUrl,
- repositoryLayout, policy, policy);
- repoList.add(remoteRepo);
- }
+ File resolvedArtifactFile = resolveArtifact(new DefaultArtifact(groupId, artifactId, classifier, packaging, version));
+ getLog().info("Resolved artifact to " + resolvedArtifactFile.getAbsolutePath());
+ return resolvedArtifactFile;
+ }
+ protected File resolveArtifact(org.eclipse.aether.artifact.Artifact artifact) throws MojoExecutionException {
+ ArtifactRequest req = new ArtifactRequest(artifact, repositories, null);
+ ArtifactResult resolutionResult;
try {
- artifactResolver.resolve(packageArtifact, repoList, localRepository);
- getLog().info("Resolved artifact to " + packageArtifact.getFile().getAbsolutePath());
- } catch (AbstractArtifactResolutionException e) {
- throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e);
+ resolutionResult = repoSystem.resolveArtifact(repoSession, req);
+ return resolutionResult.getArtifact().getFile();
+ } catch( ArtifactResolutionException e ) {
+ throw new MojoExecutionException("Artifact " + artifact + " could not be resolved.", e);
}
-
- return packageArtifact.getFile().getAbsolutePath();
}
+
}
\ No newline at end of file
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
index 6c5d5db..93e6900 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallMojo.java
@@ -17,13 +17,15 @@
package org.apache.sling.maven.bundlesupport;
+import java.io.File;
+
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
/**
- * Install an OSGi bundle to a running Sling instance.
+ * Install a local OSGi bundle file to a running Sling instance.
* The plugin places an HTTP POST request to
* <a href="http://felix.apache.org/documentation/subprojects/apache-felix-web-console/web-console-restful-api.html#post-requests">Felix Web Console</a>.
* It's also possible to HTTP PUT instead of POST leveraging the <a href="http://sling.apache.org/documentation/development/repository-based-development.html">WebDAV bundle from Sling</a>.
@@ -64,10 +66,10 @@ public class BundleInstallMojo extends AbstractBundleInstallMojo {
private boolean skip;
/**
- * The name of the generated JAR file.
+ * The file path of the bundle file to deploy.
*/
@Parameter(property = "sling.file", defaultValue = "${project.build.directory}/${project.build.finalName}.jar", required = true)
- private String bundleFileName;
+ private File bundleFileName;
@Override
public void execute() throws MojoExecutionException {
@@ -81,7 +83,7 @@ public class BundleInstallMojo extends AbstractBundleInstallMojo {
}
@Override
- protected String getBundleFileName() {
+ protected File getBundleFileName() {
return bundleFileName;
}
}
\ No newline at end of file
diff --git a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
index d6dc19e..b5b4699 100644
--- a/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
+++ b/sling-maven-plugin/src/main/java/org/apache/sling/maven/bundlesupport/BundleUninstallMojo.java
@@ -43,10 +43,10 @@ public class BundleUninstallMojo extends AbstractBundleInstallMojo {
* The name of the generated JAR file.
*/
@Parameter(property = "sling.file", defaultValue = "${project.build.directory}/${project.build.finalName}.jar")
- private String bundleFileName;
+ private File bundleFileName;
@Override
- protected String getBundleFileName() {
+ protected File getBundleFileName() {
return bundleFileName;
}
@@ -55,8 +55,8 @@ public class BundleUninstallMojo extends AbstractBundleInstallMojo {
*/
@Override
public void execute() throws MojoExecutionException {
- // only upload if packaging as an osgi-bundle
- final File bundleFile = new File(bundleFileName);
+ // only uninstall if packaging as an osgi-bundle
+ final File bundleFile = getBundleFileName();
final String bundleName = getBundleSymbolicName(bundleFile);
if (bundleName == null) {
getLog().info(bundleFile + " is not an OSGi Bundle, not uploading");