You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/01/18 12:21:47 UTC

[maven-jmod-plugin] 05/06: Clean up pom.xml to remove Maven plugins from pluginManagement section to use the default ones. Refactor test to become more Groovyish. Set 9+ in invoker.java.version, replacing 1.9+. Set invoker.goals to 'package' only. Use StringUtils.isNotBlank instead of manual check for 'mainClass' parameter.

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

rfscholte pushed a commit to branch JMOD-20
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git

commit 762d6f4c2b4f141fdf05607ddde5a3f0bc220980
Author: Andre Tadeu de Carvalho <an...@gmail.com>
AuthorDate: Thu Jan 17 18:13:36 2019 -0200

    Clean up pom.xml to remove Maven plugins from pluginManagement section to use the default ones. Refactor test to become more Groovyish. Set 9+ in invoker.java.version, replacing 1.9+. Set invoker.goals to 'package' only. Use StringUtils.isNotBlank instead of manual check for 'mainClass' parameter.
---
 src/it/mjmod-20-set-main-class/invoker.properties  |   4 +-
 src/it/mjmod-20-set-main-class/pom.xml             |  26 +---
 src/it/mjmod-20-set-main-class/verify.groovy       | 160 +++++++--------------
 .../apache/maven/plugins/jmod/JModCreateMojo.java  |   2 +-
 4 files changed, 57 insertions(+), 135 deletions(-)

diff --git a/src/it/mjmod-20-set-main-class/invoker.properties b/src/it/mjmod-20-set-main-class/invoker.properties
index 8948d9b..eb94c3e 100644
--- a/src/it/mjmod-20-set-main-class/invoker.properties
+++ b/src/it/mjmod-20-set-main-class/invoker.properties
@@ -14,5 +14,5 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-invoker.java.version = 1.9+
-invoker.goals = clean package
+invoker.java.version = 9+
+invoker.goals = package
diff --git a/src/it/mjmod-20-set-main-class/pom.xml b/src/it/mjmod-20-set-main-class/pom.xml
index bfbde9b..6a52afe 100644
--- a/src/it/mjmod-20-set-main-class/pom.xml
+++ b/src/it/mjmod-20-set-main-class/pom.xml
@@ -30,8 +30,6 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <maven.compiler.source>1.9</maven.compiler.source>
-        <maven.compiler.target>1.9</maven.compiler.target>
     </properties>
 
     <dependencyManagement>
@@ -49,35 +47,13 @@
         <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
             <plugins>
                 <plugin>
-                    <artifactId>maven-clean-plugin</artifactId>
-                    <version>3.0.0</version>
-                </plugin>
-                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
-                <plugin>
-                    <artifactId>maven-resources-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-compiler-plugin</artifactId>
                     <version>3.8.0</version>
                     <configuration>
-                        <target>1.9</target>
-                        <source>1.9</source>
+                        <release>9</release>
                     </configuration>
                 </plugin>
-                <plugin>
-                    <artifactId>maven-jar-plugin</artifactId>
-                    <version>3.0.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-install-plugin</artifactId>
-                    <version>2.5.2</version>
-                </plugin>
-                <plugin>
-                    <artifactId>maven-deploy-plugin</artifactId>
-                    <version>2.8.2</version>
-                </plugin>
             </plugins>
         </pluginManagement>
         <plugins>
diff --git a/src/it/mjmod-20-set-main-class/verify.groovy b/src/it/mjmod-20-set-main-class/verify.groovy
index 1b72b80..1b74c30 100644
--- a/src/it/mjmod-20-set-main-class/verify.groovy
+++ b/src/it/mjmod-20-set-main-class/verify.groovy
@@ -20,133 +20,79 @@
 import java.util.jar.JarEntry
 import java.util.jar.JarFile
 
+def validateArtifact( String module, List<String> artifactNames )
+{
+    println( "Checking if ${basedir}/${module}/target exists." )
+    File target = new File( basedir, "/${module}/target" )
+    assert target.isDirectory()
 
-try {
-    println("Checking if ${basedir}/world/target exists.")
-    File target = new File( basedir, "/world/target" )
-    if ( !target.exists() || !target.isDirectory() ) {
-        System.err.println( "${target.getAbsolutePath()} folder is missing or not a directory." )
-        return false
-    }
-
-    File artifact = new File( target, "/jmods/myproject.world.jmod" )
-    if ( !artifact.exists() || artifact.isDirectory() ) {
-        System.err.println( "${artifact.getAbsolutePath()} file is missing or a directory." )
-        return false
-    }
-
-    String[] artifactNames = [
-            "classes/module-info.class",
-            "classes/myproject/world/World.class"
-    ]
+    File artifact = new File( target, "/jmods/myproject.${module}.jmod" )
+    assert artifact.isFile()
 
     Set contents = new HashSet()
 
     JarFile jar = new JarFile( artifact )
     Enumeration jarEntries = jar.entries()
-    while ( jarEntries.hasMoreElements() ) {
+    while ( jarEntries.hasMoreElements() )
+    {
         JarEntry entry = (JarEntry) jarEntries.nextElement()
-        println("Current entry: ${entry}")
-        if ( !entry.isDirectory() ) {
+        println( "Current entry: ${entry}" )
+        if ( !entry.isDirectory() )
+        {
             // Only compare files
             contents.add( entry.getName() )
         }
     }
 
-    if  ( artifactNames.length != contents.size() ) {
-        System.err.println( "jar content size is different from the expected content size" )
-        return false
-    }
+    assert artifactNames.size() == contents.size()
+
     artifactNames.each{ artifactName ->
-        if ( !contents.contains( artifactName ) ) {
-            System.err.println( "Artifact[" + artifactName + "] not found in jar archive" )
-            return false
-        }
+        assert contents.contains( artifactName )
     }
-} catch ( Throwable e ) {
-    e.printStackTrace()
-    return false
 }
 
-try {
-    println("Checking if ${basedir}/greetings/target exists.")
-    File target = new File( basedir, "/greetings/target" )
-    if ( !target.exists() || !target.isDirectory() ) {
-        System.err.println( "${target.getAbsolutePath()} folder is missing or not a directory." )
-        return false
-    }
-
-    File artifact = new File( target, "/jmods/myproject.greetings.jmod" )
-    if ( !artifact.exists() || artifact.isDirectory() ) {
-        System.err.println( "${artifact.getAbsolutePath()} file is missing or a directory." )
-        return false
-    }
-
-    String[] artifactNames = [
-            "classes/module-info.class",
-            "classes/myproject/greetings/Main.class"
-    ]
-
-    Set contents = new HashSet()
-
-    JarFile jar = new JarFile( artifact )
-    Enumeration jarEntries = jar.entries()
-    while ( jarEntries.hasMoreElements() ) {
-        JarEntry entry = (JarEntry) jarEntries.nextElement()
-        println("Current entry: ${entry}")
-        if ( !entry.isDirectory() ) {
-            // Only compare files
-            contents.add( entry.getName() )
-        }
-    }
-
-    if  ( artifactNames.length != contents.size() ) {
-        System.err.println( "jar content size is different from the expected content size" )
-        return false
-    }
-    artifactNames.each{ artifactName ->
-        if ( !contents.contains( artifactName ) ) {
-            System.err.println( "Artifact[" + artifactName + "] not found in jar archive" )
+validateArtifact( "world", [ "classes/module-info.class", "classes/myproject/world/World.class" ] )
+validateArtifact( "greetings", [ "classes/module-info.class", "classes/myproject/greetings/Main.class" ] )
+
+def sout = new StringBuilder(), serr = new StringBuilder()
+def proc = "jmod describe ${basedir}/greetings/target/jmods/myproject.greetings.jmod".execute()
+proc.consumeProcessOutput( sout, serr )
+proc.waitForOrKill( 1000 )
+if ( ! sout.toString().trim().isEmpty() && serr.toString().trim().isEmpty() )
+{
+    Set<String> expectedLines = new HashSet(
+            Arrays.asList(
+                    "myproject.greetings@99.0",
+                    "requires java.base mandated",
+                    "requires myproject.world",
+                    "contains myproject.greetings",
+                    "main-class myproject.greetings.Main" ) )
+    String[] lines = sout.toString().split("\n")
+    for ( String line : lines )
+    {
+        if ( ! line.trim().isEmpty() && !expectedLines.contains(line) )
+        {
+            System.err.println( "This line was not returned from jmod: ${line}" )
             return false
         }
-    }
-
-    def sout = new StringBuilder(), serr = new StringBuilder()
-    def proc = "jmod describe ${target}/jmods/myproject.greetings.jmod".execute()
-    proc.consumeProcessOutput(sout, serr)
-    proc.waitForOrKill(1000)
-    if (!sout.toString().trim().isEmpty() && serr.toString().trim().isEmpty()) {
-        Set<String> expectedLines = new HashSet(Arrays.asList("myproject.greetings@99.0",
-                "requires java.base mandated",
-                "requires myproject.world",
-                "contains myproject.greetings",
-                "main-class myproject.greetings.Main"))
-        String[] lines = sout.toString().split("\n")
-        for (String line : lines) {
-            if (!line.trim().isEmpty() && !expectedLines.contains(line)) {
-                System.err.println( "This line was not returned from jmod: ${line}" )
-                return false
-            } else {
-                expectedLines.remove(line)
-            }
+        else
+        {
+            expectedLines.remove(line)
         }
-        if (!expectedLines.isEmpty()) {
-            System.err.println( "This module does not the following items:" )
-            for (String line : expectedLines) {
-                System.err.println( line )
-            }
-            return false
+    }
+    if (!expectedLines.isEmpty()) {
+        System.err.println( "This module does not the following items:" )
+        for ( String line : expectedLines )
+        {
+            System.err.println( line )
         }
-        return true
-    } else {
-        System.err.println( "Some error happened while trying to run 'jmod describe "
-                + "${target}/jmods/myproject.greetings.jmod'" )
-        System.err.println(serr)
         return false
     }
-} catch ( Throwable e ) {
-    e.printStackTrace()
-    return false
 }
-
-return true
\ No newline at end of file
+else
+{
+    System.err.println( "Some error happened while trying to run 'jmod describe "
+            + "${target}/jmods/myproject.greetings.jmod'" )
+    System.err.println( serr )
+    return false
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
index f8ae235..24589a0 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
@@ -587,7 +587,7 @@ public class JModCreateMojo
             argsFile.println( getPlatformSeparatedList( configList ) );
         }
 
-        if ( mainClass != null && !mainClass.trim().isEmpty() )
+        if ( StringUtils.isNotBlank( mainClass ) )
         {
             argsFile.println( "--main-class" );
             argsFile.println( mainClass );