svn commit: r1804774 - in /maven/plugins/trunk/maven-dependency-plugin/src: it/projects/mdep-580_display-manifest-automodules/ main/java/org/apache/maven/plugins/dependency/resolvers/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

svn commit: r1804774 - in /maven/plugins/trunk/maven-dependency-plugin/src: it/projects/mdep-580_display-manifest-automodules/ main/java/org/apache/maven/plugins/dependency/resolvers/

rfscholte
Author: rfscholte
Date: Fri Aug 11 10:54:08 2017
New Revision: 1804774

URL: http://svn.apache.org/viewvc?rev=1804774&view=rev
Log:
[MDEP-580] Recognize source of name for automatic modules
Use (auto) for filename based and [auto] for manifest based automatic module names

Added:
    maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/
    maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/invoker.properties
    maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/pom.xml
    maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/verify.groovy
Modified:
    maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/invoker.properties?rev=1804774&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/invoker.properties (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/invoker.properties Fri Aug 11 10:54:08 2017
@@ -0,0 +1,19 @@
+# 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.
+
+invoker.java.version = 9+
+invoker.goals = dependency:resolve

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/pom.xml?rev=1804774&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/pom.xml Fri Aug 11 10:54:08 2017
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<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">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.its.dependency</groupId>
+  <artifactId>mdep-578</artifactId>
+  <version>1.0</version>
+  
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-dependency-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+  
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven.resolver</groupId>
+      <artifactId>maven-resolver-api</artifactId>
+      <version>1.1.0</version>
+    </dependency>
+  </dependencies>
+</project>

Added: maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/verify.groovy?rev=1804774&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/verify.groovy (added)
+++ maven/plugins/trunk/maven-dependency-plugin/src/it/projects/mdep-580_display-manifest-automodules/verify.groovy Fri Aug 11 10:54:08 2017
@@ -0,0 +1,27 @@
+/*
+ * 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.
+ */
+
+File file = new File( basedir, "build.log" );
+assert file.exists();
+
+String buildLog = file.getText( "UTF-8" );
+
+assert buildLog.contains( "org.apache.maven.resolver:maven-resolver-api:jar:1.1.0:compile -- module org.apache.maven.resolver [auto]" );
+
+return true;

Modified: maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java?rev=1804774&r1=1804773&r2=1804774&view=diff
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java (original)
+++ maven/plugins/trunk/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolveDependenciesMojo.java Fri Aug 11 10:54:08 2017
@@ -41,6 +41,7 @@ import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.jar.JarFile;
 
 /**
  * Goal that resolves the project dependencies from the repository.
@@ -210,7 +211,14 @@ public class ResolveDependenciesMojo
 
                     if ( moduleDescriptor.automatic )
                     {
-                        moduleNameMarker += " (auto)";
+                        if ( "MANIFEST".equals( moduleDescriptor.moduleNameSource ) )
+                        {
+                            moduleNameMarker += " [auto]";
+                        }
+                        else
+                        {
+                            moduleNameMarker += " (auto)";
+                        }
                     }
                 }
             }
@@ -263,6 +271,45 @@ public class ResolveDependenciesMojo
                 
                 Method isAutomaticMethod = moduleDescriptorInstance.getClass().getMethod( "isAutomatic" );
                 moduleDescriptor.automatic = (Boolean) isAutomaticMethod.invoke( moduleDescriptorInstance );
+                
+                if ( moduleDescriptor.automatic )
+                {
+                    if ( artifactFile.isFile() )
+                    {
+                        JarFile jarFile = null;
+                        try
+                        {
+                            jarFile = new JarFile( artifactFile );
+                            
+                            if ( jarFile.getManifest().getMainAttributes().getValue( "Automatic-Module-Name" ) != null )
+                            {
+                                moduleDescriptor.moduleNameSource = "MANIFEST";
+                            }
+                            else
+                            {
+                                moduleDescriptor.moduleNameSource = "FILENAME";
+                            }
+                        }
+                        catch ( IOException e )
+                        {
+                            // noop
+                        }
+                        finally
+                        {
+                            if ( jarFile != null )
+                            {
+                                try
+                                {
+                                    jarFile.close();
+                                }
+                                catch ( IOException e )
+                                {
+                                 // noop
+                                }
+                            }
+                        }
+                    }
+                }
             }
         }
         catch ( ClassNotFoundException e )
@@ -302,5 +349,7 @@ public class ResolveDependenciesMojo
         String name;
         
         boolean automatic = true;
+
+        String moduleNameSource;
     }
 }


Loading...