This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 5477af2b401ce55d7eebed90fbfd83e324597107
Author: lburgazzoli <lburgazz...@gmail.com>
AuthorDate: Thu Sep 20 15:25:24 2018 +0200

    maven: plugin to generate detailed project dependencies
---
 runtime/dependency-lister/.gitignore               |  10 ++
 runtime/dependency-lister/pom.xml                  |  99 ++++++++++++++++++++
 .../maven/dependency/DependencyListerMojo.java     | 101 +++++++++++++++++++++
 runtime/pom.xml                                    |   1 +
 4 files changed, 211 insertions(+)

diff --git a/runtime/dependency-lister/.gitignore 
b/runtime/dependency-lister/.gitignore
new file mode 100644
index 0000000..ed92983
--- /dev/null
+++ b/runtime/dependency-lister/.gitignore
@@ -0,0 +1,10 @@
+target
+
+*.iml
+
+.idea
+.project
+.metadata
+.settings
+.factorypath
+.classpath
diff --git a/runtime/dependency-lister/pom.xml 
b/runtime/dependency-lister/pom.xml
new file mode 100644
index 0000000..0bd8e91
--- /dev/null
+++ b/runtime/dependency-lister/pom.xml
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <parent>
+    <groupId>org.apache.camel.k</groupId>
+    <artifactId>camel-k-runtime-parent</artifactId>
+    <version>0.0.3-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>maven-plugin</packaging>
+
+  <artifactId>camel-k-runtime-dependency-lister</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>3.5.2</version>
+      <exclusions>
+        <exclusion>
+          <groupId>*</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <version>3.5.2</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-utils</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-common-artifact-filters</artifactId>
+      <version>3.0.1</version>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.maven</groupId>
+          <artifactId>maven-repository-metadata</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-utils</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>3.5.2</version>
+      <exclusions>
+        <exclusion>
+          <groupId>*</groupId>
+          <artifactId>*</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.yaml</groupId>
+      <artifactId>snakeyaml</artifactId>
+      <version>${snakeyaml.version}</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <version>3.5.2</version>
+        <configuration>
+          <mojoDependencies/>
+        </configuration>
+        <executions>
+          <execution>
+            <id>default-descriptor</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>help-goal</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git 
a/runtime/dependency-lister/src/main/java/org/apache/camel/k/tooling/maven/dependency/DependencyListerMojo.java
 
b/runtime/dependency-lister/src/main/java/org/apache/camel/k/tooling/maven/dependency/DependencyListerMojo.java
new file mode 100644
index 0000000..780c9e8
--- /dev/null
+++ 
b/runtime/dependency-lister/src/main/java/org/apache/camel/k/tooling/maven/dependency/DependencyListerMojo.java
@@ -0,0 +1,101 @@
+/**
+ * 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.camel.k.tooling.maven.dependency;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+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.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.utils.StringUtils;
+import org.yaml.snakeyaml.DumperOptions;
+import org.yaml.snakeyaml.Yaml;
+
+@Mojo(
+    name = "generate-dependency-list",
+    defaultPhase = LifecyclePhase.PREPARE_PACKAGE,
+    requiresProject = true,
+    threadSafe = true,
+    requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
+    requiresDependencyCollection = ResolutionScope.COMPILE_PLUS_RUNTIME)
+@SuppressWarnings({ "PMD.GodClass", "PMD.TooManyFields", "PMD.TooManyMethods" 
})
+public class DependencyListerMojo extends AbstractMojo {
+
+    @Component
+    private ArtifactFactory artifactFactory;
+
+    @Parameter(readonly = true, defaultValue = "${project}")
+    private MavenProject project;
+
+    @Parameter(readonly = true, defaultValue = 
"${project.build.directory}/dependencies.yaml")
+    private String destination;
+
+    @Override
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        List<Map<String, String>> deps = new ArrayList<>();
+
+        
project.getArtifacts().stream().filter(this::isCompileOrRuntime).forEach(artifact
 -> {
+                Map<String, String> dep = new HashMap<>();
+                dep.put("id", artifact.getId());
+
+                if (artifact.getFile() != null) {
+                    dep.put("location", artifact.getFile().getAbsolutePath());
+                }
+
+                deps.add(dep);
+            }
+        );
+
+        File dest = new File(destination);
+        if (!dest.getParentFile().exists()) {
+            dest.getParentFile().mkdirs();
+        }
+
+        try (Writer writer = new FileWriter(dest)) {
+
+            DumperOptions options = new DumperOptions();
+            options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+
+            Yaml yaml = new Yaml(options);
+            yaml.dump(Collections.singletonMap("dependencies", deps), writer);
+        } catch (IOException e) {
+            throw new MojoExecutionException("Exception while generating 
dependencies list", e);
+        }
+    }
+
+    private boolean isCompileOrRuntime(Artifact artifact) {
+        return StringUtils.equals(artifact.getScope(), 
DefaultArtifact.SCOPE_COMPILE)
+            || StringUtils.equals(artifact.getScope(), 
DefaultArtifact.SCOPE_RUNTIME);
+    }
+}
diff --git a/runtime/pom.xml b/runtime/pom.xml
index 74cd8aa..0948ca3 100644
--- a/runtime/pom.xml
+++ b/runtime/pom.xml
@@ -56,6 +56,7 @@
     <modules>
         <module>jvm</module>
         <module>catalog-builder</module>
+        <module>dependency-lister</module>
     </modules>
 
 </project>

Reply via email to