activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-240 Changing Maven plugin to explore dependencies
Date Fri, 02 Oct 2015 17:46:41 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master a45f89bb8 -> 60ac5eebb


ARTEMIS-240 Changing Maven plugin to explore dependencies


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/275c63e2
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/275c63e2
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/275c63e2

Branch: refs/heads/master
Commit: 275c63e273182e62721f3b9c6fb84ed87f954a5b
Parents: a45f89b
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Thu Oct 1 18:36:06 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Oct 2 12:31:57 2015 -0400

----------------------------------------------------------------------
 .../artemis/maven/ArtemisAbstractPlugin.java    | 102 +++++++++++++++++
 .../artemis/maven/ArtemisCreatePlugin.java      |  72 +++++-------
 .../maven/ArtemisDependencyScanPlugin.java      | 114 +++++++++++++++++++
 examples/features/sub-modules/aerogear/pom.xml  |  10 +-
 examples/features/sub-modules/vertx/pom.xml     |   5 +-
 5 files changed, 246 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/275c63e2/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java
----------------------------------------------------------------------
diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java
b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java
index 2906e84..49f1bf7 100644
--- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java
+++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisAbstractPlugin.java
@@ -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;
+   }
+
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/275c63e2/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java
----------------------------------------------------------------------
diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java
b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java
index 7974526..e9f4535 100644
--- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java
+++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisCreatePlugin.java
@@ -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;
-               try {
-                  artifact = new DefaultArtifact(libList[i]);
-               }
-               catch (IllegalArgumentException e) {
-                  throw new MojoFailureException(e.getMessage(), e);
-               }
+            for (int i = 0; i < libList.length; i++) {
 
-               ArtifactRequest request = new ArtifactRequest();
-               request.setArtifact(artifact);
-               request.setRepositories(remoteRepos);
+               Artifact artifact = newArtifact(libList[i]);
+               getLog().debug("******************** Artifact::" + artifact);
 
-               getLog().debug("Resolving artifact " + artifact + " from " + remoteRepos);
 
-               ArtifactResult result;
-               try {
-                  result = repositorySystem.resolveArtifact(repoSession, request);
+               if (copyDependencies) {
+                  getLog().debug("******************** exploring dependencies::" + artifact);
+                  List<Artifact> dependencies = explodeDependencies(artifact);
+                  for (Artifact artifactItem : dependencies) {
+                     File artifactFile = resolveArtifact(artifactItem);
+                     copyToLib(artifactFile, commandLineStream);
+                  }
                }
-               catch (ArtifactResolutionException e) {
-                  throw new MojoExecutionException(e.getMessage(), e);
+               else {
+                  File artifactFile = resolveArtifact(artifact);
+                  getLog().debug("*********** coping Artifact:: " + artifact + " file = "
+ artifactFile);
+                  copyToLib(artifactFile, commandLineStream);
                }
-
-               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());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/275c63e2/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java
----------------------------------------------------------------------
diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java
b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java
new file mode 100644
index 0000000..879167c
--- /dev/null
+++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/ArtemisDependencyScanPlugin.java
@@ -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());
+      }
+   }
+
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/275c63e2/examples/features/sub-modules/aerogear/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/sub-modules/aerogear/pom.xml b/examples/features/sub-modules/aerogear/pom.xml
index f217664..6614782 100644
--- a/examples/features/sub-modules/aerogear/pom.xml
+++ b/examples/features/sub-modules/aerogear/pom.xml
@@ -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>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/275c63e2/examples/features/sub-modules/vertx/pom.xml
----------------------------------------------------------------------
diff --git a/examples/features/sub-modules/vertx/pom.xml b/examples/features/sub-modules/vertx/pom.xml
index bc52248..a93923b 100644
--- a/examples/features/sub-modules/vertx/pom.xml
+++ b/examples/features/sub-modules/vertx/pom.xml
@@ -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>


Mime
View raw message