This closes #183 Maven Plugin changes
This commit is contained in:
commit
60ac5eebb2
|
@ -17,13 +17,50 @@
|
|||
|
||||
package org.apache.activemq.artemis.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.activemq.artemis.cli.commands.Configurable;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
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.Parameter;
|
||||
import org.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
import org.eclipse.aether.artifact.DefaultArtifact;
|
||||
import org.eclipse.aether.collection.CollectRequest;
|
||||
import org.eclipse.aether.collection.CollectResult;
|
||||
import org.eclipse.aether.collection.DependencyCollectionException;
|
||||
import org.eclipse.aether.graph.Dependency;
|
||||
import org.eclipse.aether.graph.DependencyNode;
|
||||
import org.eclipse.aether.graph.DependencyVisitor;
|
||||
import org.eclipse.aether.repository.RemoteRepository;
|
||||
import org.eclipse.aether.resolution.ArtifactRequest;
|
||||
import org.eclipse.aether.resolution.ArtifactResolutionException;
|
||||
import org.eclipse.aether.resolution.ArtifactResult;
|
||||
|
||||
public abstract class ArtemisAbstractPlugin extends AbstractMojo {
|
||||
|
||||
@Component
|
||||
protected RepositorySystem repositorySystem;
|
||||
|
||||
@Parameter(defaultValue = "${repositorySystemSession}")
|
||||
protected RepositorySystemSession repoSession;
|
||||
|
||||
@Parameter(defaultValue = "${project.remoteProjectRepositories}")
|
||||
protected List<RemoteRepository> remoteRepos;
|
||||
|
||||
@Parameter(defaultValue = "${localRepository}")
|
||||
protected ArtifactRepository localRepository;
|
||||
|
||||
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (isIgnore()) {
|
||||
|
@ -43,4 +80,69 @@ public abstract class ArtemisAbstractPlugin extends AbstractMojo {
|
|||
protected abstract boolean isIgnore();
|
||||
|
||||
protected abstract void doExecute() throws MojoExecutionException, MojoFailureException;
|
||||
|
||||
protected Artifact newArtifact(String artifactID) throws MojoFailureException {
|
||||
Artifact artifact;
|
||||
try {
|
||||
artifact = new DefaultArtifact(artifactID);
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new MojoFailureException(e.getMessage(), e);
|
||||
}
|
||||
return artifact;
|
||||
}
|
||||
|
||||
protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
|
||||
ArtifactRequest request = new ArtifactRequest();
|
||||
request.setArtifact(artifact);
|
||||
request.setRepositories(remoteRepos);
|
||||
|
||||
ArtifactResult result;
|
||||
try {
|
||||
result = repositorySystem.resolveArtifact(repoSession, request);
|
||||
}
|
||||
catch (ArtifactResolutionException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return result.getArtifact().getFile();
|
||||
}
|
||||
|
||||
protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
|
||||
final List<Artifact> dependencies = new LinkedList<Artifact>();
|
||||
|
||||
CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
|
||||
CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
|
||||
final AtomicInteger level = new AtomicInteger(0);
|
||||
DependencyNode node = result.getRoot();
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
final PrintWriter strPrint = new PrintWriter(writer);
|
||||
|
||||
strPrint.println("Dependencies explored for " + artifact + ":");
|
||||
if (node != null) {
|
||||
node.accept(new DependencyVisitor() {
|
||||
@Override
|
||||
public boolean visitEnter(DependencyNode node) {
|
||||
for (int i = 0; i < level.get(); i++) {
|
||||
strPrint.print("!...");
|
||||
}
|
||||
level.incrementAndGet();
|
||||
strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
|
||||
|
||||
dependencies.add(node.getArtifact());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitLeave(DependencyNode node) {
|
||||
level.decrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
getLog().info(writer.toString());
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,19 +34,11 @@ import org.apache.activemq.artemis.utils.FileUtil;
|
|||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
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.eclipse.aether.RepositorySystem;
|
||||
import org.eclipse.aether.RepositorySystemSession;
|
||||
import org.eclipse.aether.artifact.Artifact;
|
||||
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;
|
||||
|
||||
@Mojo(name = "create", defaultPhase = LifecyclePhase.VERIFY)
|
||||
public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
||||
|
@ -122,15 +114,6 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
|||
@Parameter(defaultValue = "ON_DEMAND")
|
||||
private String messageLoadBalancing;
|
||||
|
||||
@Component
|
||||
private RepositorySystem repositorySystem;
|
||||
|
||||
@Parameter(defaultValue = "${repositorySystemSession}")
|
||||
private RepositorySystemSession repoSession;
|
||||
|
||||
@Parameter(defaultValue = "${project.remoteProjectRepositories}")
|
||||
private List<RemoteRepository> remoteRepos;
|
||||
|
||||
/**
|
||||
* For extra stuff not covered by the properties
|
||||
*/
|
||||
|
@ -140,6 +123,12 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
|||
@Parameter
|
||||
private String[] libList;
|
||||
|
||||
/**
|
||||
* copy dependencies listed on libList.
|
||||
*/
|
||||
@Parameter
|
||||
private boolean copyDependencies;
|
||||
|
||||
@Parameter(defaultValue = "${localRepository}")
|
||||
private org.apache.maven.artifact.repository.ArtifactRepository localRepository;
|
||||
|
||||
|
@ -305,39 +294,26 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
|||
commandLineStream.println();
|
||||
commandLineStream.println("# This is a list of files that need to be installed under ./lib.");
|
||||
commandLineStream.println("# We are copying them from your maven lib home");
|
||||
|
||||
for (int i = 0; i < libList.length; i++) {
|
||||
String[] splitString = libList[i].split(":");
|
||||
|
||||
getLog().debug("********************" + splitString[0] + "/" + splitString[1] + "/" + splitString[2]);
|
||||
Artifact artifact = newArtifact(libList[i]);
|
||||
getLog().debug("******************** Artifact::" + artifact);
|
||||
|
||||
Artifact artifact;
|
||||
try {
|
||||
artifact = new DefaultArtifact(libList[i]);
|
||||
|
||||
if (copyDependencies) {
|
||||
getLog().debug("******************** exploring dependencies::" + artifact);
|
||||
List<Artifact> dependencies = explodeDependencies(artifact);
|
||||
for (Artifact artifactItem : dependencies) {
|
||||
File artifactFile = resolveArtifact(artifactItem);
|
||||
copyToLib(artifactFile, commandLineStream);
|
||||
}
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw new MojoFailureException(e.getMessage(), e);
|
||||
else {
|
||||
File artifactFile = resolveArtifact(artifact);
|
||||
getLog().debug("*********** coping Artifact:: " + artifact + " file = " + artifactFile);
|
||||
copyToLib(artifactFile, commandLineStream);
|
||||
}
|
||||
|
||||
ArtifactRequest request = new ArtifactRequest();
|
||||
request.setArtifact(artifact);
|
||||
request.setRepositories(remoteRepos);
|
||||
|
||||
getLog().debug("Resolving artifact " + artifact + " from " + remoteRepos);
|
||||
|
||||
ArtifactResult result;
|
||||
try {
|
||||
result = repositorySystem.resolveArtifact(repoSession, request);
|
||||
}
|
||||
catch (ArtifactResolutionException e) {
|
||||
throw new MojoExecutionException(e.getMessage(), e);
|
||||
}
|
||||
|
||||
File artifactFile = result.getArtifact().getFile();
|
||||
|
||||
getLog().debug("Artifact:: " + artifact + " file = " + artifactFile);
|
||||
|
||||
copyToLib(artifactFile, commandLineStream);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -368,7 +344,13 @@ public class ArtemisCreatePlugin extends ArtemisAbstractPlugin {
|
|||
|
||||
private void copyToLib(File projectLib, PrintStream commandLineStream) throws IOException {
|
||||
Path target = instance.toPath().resolve("lib").resolve(projectLib.getName());
|
||||
target.toFile().mkdirs();
|
||||
File file = target.toFile();
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
commandLineStream.println("mkdir " + file.getParent());
|
||||
}
|
||||
|
||||
|
||||
commandLineStream.println("cp " + projectLib.getAbsolutePath() + " " + target);
|
||||
getLog().debug("Copying " + projectLib.getName() + " as " + target.toFile().getAbsolutePath());
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF 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.apache.activemq.artemis.maven;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
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.eclipse.aether.artifact.Artifact;
|
||||
|
||||
@Mojo(name = "dependency-scan", defaultPhase = LifecyclePhase.VERIFY)
|
||||
public class ArtemisDependencyScanPlugin extends ArtemisAbstractPlugin {
|
||||
|
||||
@Parameter
|
||||
String name;
|
||||
|
||||
/**
|
||||
* The plugin descriptor
|
||||
*/
|
||||
private PluginDescriptor descriptor;
|
||||
|
||||
@Parameter
|
||||
private String[] dependencyList;
|
||||
|
||||
@Parameter
|
||||
private String[] individualList;
|
||||
|
||||
@Parameter(required = true)
|
||||
private String variableName;
|
||||
|
||||
@Parameter
|
||||
private String pathSeparator = ";";
|
||||
|
||||
protected boolean isIgnore() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute() throws MojoExecutionException, MojoFailureException {
|
||||
getLog().info("Local " + localRepository);
|
||||
MavenProject project = (MavenProject) getPluginContext().get("project");
|
||||
|
||||
Map properties = getPluginContext();
|
||||
|
||||
Set<Map.Entry> entries = properties.entrySet();
|
||||
|
||||
getLog().info("Entries.size " + entries.size());
|
||||
for (Map.Entry entry : entries) {
|
||||
getLog().info("... key=" + entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
|
||||
try {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
String separatorUsed = "";
|
||||
if (dependencyList != null) {
|
||||
for (String lib : dependencyList) {
|
||||
getLog().debug("********************" + lib);
|
||||
|
||||
List<Artifact> artifactsList = explodeDependencies(newArtifact(lib));
|
||||
|
||||
for (Artifact artifact : artifactsList) {
|
||||
File artifactFile = resolveArtifact(artifact);
|
||||
buffer.append(separatorUsed);
|
||||
buffer.append(artifactFile.getAbsolutePath());
|
||||
separatorUsed = pathSeparator;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (individualList != null) {
|
||||
for (String lib : individualList) {
|
||||
Artifact artifact = newArtifact(lib);
|
||||
getLog().info("Single dpendency resolved::" + artifact);
|
||||
File artifactFile = resolveArtifact(artifact);
|
||||
buffer.append(separatorUsed);
|
||||
buffer.append(artifactFile.getAbsolutePath());
|
||||
separatorUsed = pathSeparator;
|
||||
}
|
||||
}
|
||||
|
||||
String classPathGenerated = buffer.toString();
|
||||
project.getProperties().setProperty(variableName, classPathGenerated);
|
||||
getLog().info("dependency-scan setting: " + variableName + "=" + classPathGenerated);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
getLog().error(e);
|
||||
throw new MojoFailureException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -62,16 +62,8 @@ under the License.
|
|||
<!-- this list was extracted from mvn dependency:tree on integration/aerogear -->
|
||||
<libList>
|
||||
<param>org.apache.activemq:artemis-aerogear-integration:${project.version}</param>
|
||||
<param>org.jboss.aerogear:unifiedpush-java-client:1.0.0</param>
|
||||
<param>net.iharder:base64:2.3.8</param>
|
||||
<param>com.fasterxml.jackson.core:jackson-annotations:2.3.0</param>
|
||||
<param>com.fasterxml.jackson.core:jackson-core:2.3.0</param>
|
||||
<param>org.jboss.resteasy:resteasy-jackson-provider:2.3.2.Final</param>
|
||||
<param>org.codehaus.jackson:jackson-core-asl:1.8.5</param>
|
||||
<param>org.codehaus.jackson:jackson-mapper-asl:1.8.5</param>
|
||||
<param>org.codehaus.jackson:jackson-jaxrs:1.8.5</param>
|
||||
<param>org.codehaus.jackson:jackson-xc:1.8.5</param>
|
||||
</libList>
|
||||
<copyDependencies>true</copyDependencies>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
|
|
|
@ -65,19 +65,16 @@ under the License.
|
|||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-core</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-platform</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-hazelcast</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
|
@ -101,6 +98,8 @@ under the License.
|
|||
<libList>
|
||||
<arg>org.apache.activemq.examples.modules:artemis-vertx-example:${project.version}</arg>
|
||||
</libList>
|
||||
<copyDependencies>true</copyDependencies>
|
||||
|
||||
<instance>${basedir}/target/server0</instance>
|
||||
<configuration>${basedir}/target/classes/activemq/server0</configuration>
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue