This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag maven-sling-plugin-2.0.6 in repository https://gitbox.apache.org/repos/asf/sling-maven-sling-plugin.git
commit 99e4bfe63dbca864f1a6581c4f6921fc13ac2a83 Author: Justin Edelson <[email protected]> AuthorDate: Thu Sep 15 13:25:58 2011 +0000 SLING-2098 - allow the use of an artifact coordinates to be specified instead of a file path git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/maven-sling-plugin@1171090 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/bundlesupport/BundleInstallFileMojo.java | 150 ++++++++++++++++++++- 1 file changed, 147 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java index 1d7e584..2169e4d 100644 --- a/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java +++ b/src/main/java/org/apache/sling/maven/bundlesupport/BundleInstallFileMojo.java @@ -17,7 +17,21 @@ package org.apache.sling.maven.bundlesupport; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +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.plugin.MojoFailureException; +import org.codehaus.plexus.util.StringUtils; /** * Install an OSGi bundle to a running Sling instance. @@ -34,13 +48,143 @@ public class BundleInstallFileMojo extends AbstractBundleInstallMojo { * @parameter expression="${sling.file}" */ private String bundleFileName; + + /** + * The groupId of the artifact to install + * @parameter expression="${sling.groupId}" + */ + private String groupId; + + /** + * The artifactId of the artifact to install + * @parameter expression="${sling.artifactId}" + */ + private String artifactId; + + /** + * The version of the artifact to install + * @parameter expression="${sling.version}" + */ + private String version; + + /** + * The packaging of the artifact to install + * @parameter expression="${sling.packaging}" default-value="jar" + */ + private String packaging = "jar"; + + /** + * A string of the form groupId:artifactId:version[:packaging]. + * @parameter expression="${sling.artifact}" + */ + private String artifact; + + /** + * + * @parameter expression="${project.remoteArtifactRepositories}" + * @required + * @readonly + */ + private List pomRemoteRepositories; + + /** + * The id of the repository from which we'll download the artifact + * @parameter expression="${sling.repoId}" default-value="temp" + */ + private String repositoryId = "temp"; + + /** + * The url of the repository from which we'll download the artifact + * @parameter expression="${sling.repoUrl}" + */ + private String repositoryUrl; + + /** + * @component + * @readonly + */ + private ArtifactFactory artifactFactory; + + /** + * @component + * @readonly + */ + private ArtifactResolver artifactResolver; + + /** + * @component + * @readonly + */ + private ArtifactRepositoryFactory artifactRepositoryFactory; + + /** + * @component roleHint="default" + */ + private ArtifactRepositoryLayout repositoryLayout; + + /** + * + * @parameter expression="${localRepository}" + * @readonly + */ + private ArtifactRepository localRepository; @Override protected String getBundleFileName() throws MojoExecutionException { - if (bundleFileName == null) { - throw new MojoExecutionException("Missing sling.file parameter"); + String fileName = bundleFileName; + if (fileName == null) { + fileName = resolveBundleFileFromArtifact(); + + if (fileName == null) { + throw new MojoExecutionException("Must provide either sling.file or sling.artifact parameters"); + } } - return bundleFileName; + return fileName; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private String resolveBundleFileFromArtifact() throws MojoExecutionException { + if (artifactId == null && artifact == null) { + return null; + } + if (artifactId == null) { + String[] tokens = StringUtils.split(artifact, ":"); + if (tokens.length != 3 && tokens.length != 4) { + throw new MojoExecutionException("Invalid artifact, you must specify " + + "groupId:artifactId:version[:packaging] " + artifact); + } + groupId = tokens[0]; + artifactId = tokens[1]; + version = tokens[2]; + if (tokens.length == 4) + packaging = tokens[3]; + } + Artifact packageArtifact = artifactFactory.createBuildArtifact(groupId, artifactId, version, packaging); + + 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); + } + + 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); + } + + return packageArtifact.getFile().getAbsolutePath(); } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
