openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1834076 - in /openwebbeans/meecrowave/trunk: ./ meecrowave-maven-plugin/ meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/
Date Fri, 22 Jun 2018 07:07:35 GMT
Author: rmannibucau
Date: Fri Jun 22 07:07:34 2018
New Revision: 1834076

URL: http://svn.apache.org/viewvc?rev=1834076&view=rev
Log:
MEECROWAVE-119 MEECROWAVE-120 adding transitive support for libs in bundle mojo + system properties
support in run mojo

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/pom.xml
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
    openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
    openwebbeans/meecrowave/trunk/pom.xml

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/pom.xml?rev=1834076&r1=1834075&r2=1834076&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/pom.xml Fri Jun 22 07:07:34 2018
@@ -61,6 +61,11 @@
       <artifactId>maven-plugin-annotations</artifactId>
       <version>3.3</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-dependency-tree</artifactId>
+      <version>3.0.1</version>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.meecrowave</groupId>

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java?rev=1834076&r1=1834075&r2=1834076&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
Fri Jun 22 07:07:34 2018
@@ -18,6 +18,33 @@
  */
 package org.apache.meecrowave.maven;
 
+import static java.util.Arrays.asList;
+import static java.util.Locale.ENGLISH;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
+import java.util.stream.Stream;
+import java.util.zip.GZIPOutputStream;
+
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
@@ -38,6 +65,7 @@ import org.apache.maven.project.Dependen
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectHelper;
 import org.apache.maven.project.ProjectDependenciesResolver;
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder;
 import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.artifact.DefaultArtifact;
@@ -50,33 +78,6 @@ import org.eclipse.aether.resolution.Art
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.eclipse.aether.resolution.ArtifactResult;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.FileVisitResult;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.StandardOpenOption;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Properties;
-import java.util.stream.Stream;
-import java.util.zip.GZIPOutputStream;
-
-import static java.util.Arrays.asList;
-import static java.util.Locale.ENGLISH;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.toList;
-import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM;
-
 @Mojo(name = "bundle", requiresDependencyResolution = RUNTIME_PLUS_SYSTEM)
 public class MeecrowaveBundleMojo extends AbstractMojo {
     private static final String DELETE_TEXT = "Just there to not loose the folder cause it
is empty, you can safely delete.";
@@ -153,6 +154,9 @@ public class MeecrowaveBundleMojo extend
     @Component
     private ProjectDependenciesResolver dependenciesResolver;
 
+    @Component
+    private DependencyGraphBuilder graphBuilder;
+
     @Parameter(defaultValue = "${repositorySystemSession}")
     private RepositorySystemSession session;
 
@@ -203,42 +207,35 @@ public class MeecrowaveBundleMojo extend
         }
         if (libs != null) {
             libs.forEach(l -> {
-                final String[] c = l.split(":");
-                if (c.length != 3 && c.length != 4) {
-                    throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier]");
+                final boolean transitive = l.endsWith("?transitive");
+                final String coords = transitive ? l.substring(0, l.length() - "?transitive".length())
: l;
+                final String[] c = coords.split(":");
+                if (c.length < 3 || c.length > 5) {
+                    throw new IllegalArgumentException("libs syntax is groupId:artifactId:version[:classifier][:type[?transitive]]");
+                }
+                if (!transitive) {
+                    addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] :
""));
+                } else {
+                    addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency()
{{
+                        setGroupId(c[0]);
+                        setArtifactId(c[1]);
+                        setVersion(c[2]);
+                        if (c.length == 4 && !"-".equals(c[3])) {
+                            setClassifier(c[3]);
+                        }
+                        if (c.length == 5) {
+                            setType(c[4]);
+                        }
+                    }});
                 }
-                addLib(distroFolder, resolve(c[0], c[1], c[2], c.length == 4 ? c[3] : ""));
             });
         }
         if (enforceMeecrowave && !includedArtifacts.contains("meecrowave-core"))
{
-            final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
-            request.setMavenProject(new MavenProject() {{
-                getDependencies().add(new Dependency() {{
-                    setGroupId("org.apache.meecrowave");
-                    setArtifactId("meecrowave-core");
-                    setVersion(findVersion());
-                }});
+            addTransitiveDependencies(distroFolder, includedArtifacts, new Dependency() {{
+                setGroupId("org.apache.meecrowave");
+                setArtifactId("meecrowave-core");
+                setVersion(findVersion());
             }});
-            request.setRepositorySession(session);
-            try {
-                dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor()
{
-                    @Override
-                    public boolean visitEnter(final DependencyNode node) {
-                        return true;
-                    }
-
-                    @Override
-                    public boolean visitLeave(final DependencyNode node) {
-                        final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
-                        if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId()))
{
-                            addLib(distroFolder, artifact.getFile());
-                        }
-                        return true;
-                    }
-                });
-            } catch (final DependencyResolutionException e) {
-                throw new MojoExecutionException(e.getMessage(), e);
-            }
         }
 
         final Path prefix = skipArchiveRootFolder ? distroFolder.toPath() : distroFolder.getParentFile().toPath();
@@ -281,6 +278,33 @@ public class MeecrowaveBundleMojo extend
         }
     }
 
+    private void addTransitiveDependencies(final File distroFolder, final Collection<String>
includedArtifacts, final Dependency dependency) {
+        final DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
+        request.setMavenProject(new MavenProject() {{
+            getDependencies().add(dependency);
+        }});
+        request.setRepositorySession(session);
+        try {
+            dependenciesResolver.resolve(request).getDependencyGraph().accept(new DependencyVisitor()
{
+                @Override
+                public boolean visitEnter(final DependencyNode node) {
+                    return true;
+                }
+
+                @Override
+                public boolean visitLeave(final DependencyNode node) {
+                    final org.eclipse.aether.artifact.Artifact artifact = node.getArtifact();
+                    if (artifact != null && !includedArtifacts.contains(artifact.getArtifactId()))
{
+                        addLib(distroFolder, artifact.getFile());
+                    }
+                    return true;
+                }
+            });
+        } catch (final DependencyResolutionException e) {
+            throw new IllegalStateException(e.getMessage(), e);
+        }
+    }
+
 
     /**
      * Copy over all files from src/meecrowave/*

Modified: openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java?rev=1834076&r1=1834075&r2=1834076&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveRunMojo.java
Fri Jun 22 07:07:34 2018
@@ -45,12 +45,15 @@ import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Scanner;
 
 import static java.util.Collections.singletonList;
 import static java.util.Collections.singletonMap;
 import static java.util.Optional.ofNullable;
+import static java.util.function.Function.identity;
 import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toMap;
 import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME_PLUS_SYSTEM;
 
 @Mojo(name = "run", requiresDependencyResolution = RUNTIME_PLUS_SYSTEM)
@@ -92,6 +95,9 @@ public class MeecrowaveRunMojo extends A
     private Map<String, String> properties;
 
     @Parameter
+    private Map<String, String> systemProperties;
+
+    @Parameter
     private Map<String, String> cxfServletParams;
 
     @Parameter(property = "meecrowave.tomcatNoJmx", defaultValue = "true")
@@ -302,6 +308,15 @@ public class MeecrowaveRunMojo extends A
             getLog().warn("Mojo skipped");
             return;
         }
+        final Map<String, String> originalSystemProps;
+        if (systemProperties != null) {
+            originalSystemProps = systemProperties.keySet().stream()
+                                                  .filter(System.getProperties()::containsKey)
+                                                  .collect(toMap(identity(), System::getProperty));
+            systemProperties.forEach(System::setProperty);
+        } else {
+            originalSystemProps = null;
+        }
 
         final Thread thread = Thread.currentThread();
         final ClassLoader loader = thread.getContextClassLoader();
@@ -342,6 +357,16 @@ public class MeecrowaveRunMojo extends A
                 }
             }
             thread.setContextClassLoader(loader);
+            if (originalSystemProps != null) {
+                systemProperties.keySet().forEach(k -> {
+                    final Optional<String> originalValue = ofNullable(originalSystemProps.get(k));
+                    if (originalValue.isPresent()) {
+                        System.setProperty(k, originalValue.get());
+                    } else {
+                        System.clearProperty(k);
+                    }
+                });
+            }
         }
     }
 

Modified: openwebbeans/meecrowave/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/pom.xml?rev=1834076&r1=1834075&r2=1834076&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/pom.xml (original)
+++ openwebbeans/meecrowave/trunk/pom.xml Fri Jun 22 07:07:34 2018
@@ -49,7 +49,7 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
     <junit.version>4.12</junit.version>
-    <tomcat.version>9.0.8</tomcat.version>
+    <tomcat.version>9.0.10</tomcat.version>
     <openwebbeans.version>2.0.6</openwebbeans.version>
     <cxf.version>3.2.5</cxf.version>
     <johnzon.version>1.1.7</johnzon.version>
@@ -80,7 +80,6 @@
     <module>sample</module>
   </modules>
 
-
   <dependencyManagement>
     <dependencies>
       <dependency>
@@ -162,6 +161,16 @@
     </plugins>
   </build>
 
+  <repositories>
+    <repository>
+      <id>tomcat-staging</id>
+      <url>https://repository.apache.org/content/repositories/orgapachetomcat-1186/</url>
+    </repository>
+    <repository>
+      <id>cxf-staging</id>
+      <url>https://repository.apache.org/content/repositories/orgapachecxf-1117/</url>
+    </repository>
+  </repositories>
 <!-- only needed when under development
   <repositories>
     <repository>



Mime
View raw message