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/19 15:27:26 UTC
[maven-jmod-plugin] branch master updated: Refactor code
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-jmod-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 02c2337 Refactor code
02c2337 is described below
commit 02c2337a92a96f6d3b1f72e2d55f903e051d3088
Author: rfscholte <rf...@apache.org>
AuthorDate: Sat Jan 19 16:27:18 2019 +0100
Refactor code
---
src/it/base-config-cmds/verify.groovy | 70 +++--------
src/it/base-config-headerfiles/verify.groovy | 72 ++++-------
src/it/base-config-legalnotices/verify.groovy | 68 +++-------
src/it/base-config-libs/verify.groovy | 68 +++-------
src/it/base-config/verify.groovy | 68 +++-------
src/it/base-it/verify.groovy | 65 +++-------
src/it/describe-base-config/verify.groovy | 78 ++----------
src/it/describe-plain/verify.groovy | 79 ++----------
src/it/list-base-config/verify.groovy | 80 ++----------
src/it/list-plain/verify.groovy | 80 ++----------
src/it/mjmod-20-set-main-class/verify.groovy | 6 +-
.../about-cli-app/pom.xml | 4 +-
.../verify.groovy | 6 +-
src/it/non-default-config-cmds/verify.groovy | 70 +++--------
.../non-default-config-headerfiles/verify.groovy | 72 ++++-------
.../non-default-config-legalnotices/verify.groovy | 68 +++-------
src/it/non-default-config-libs/verify.groovy | 68 +++-------
src/it/non-default-config/verify.groovy | 71 ++++-------
.../apache/maven/plugins/jmod/JModCreateMojo.java | 138 ++++++---------------
19 files changed, 313 insertions(+), 918 deletions(-)
diff --git a/src/it/base-config-cmds/verify.groovy b/src/it/base-config-cmds/verify.groovy
index 0afcfc2..3c38036 100644
--- a/src/it/base-config-cmds/verify.groovy
+++ b/src/it/base-config-cmds/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,60 +17,31 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-config-cmds.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "bin/first.sh",
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-config-cmds.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'bin/first.sh',
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
\ No newline at end of file
diff --git a/src/it/base-config-headerfiles/verify.groovy b/src/it/base-config-headerfiles/verify.groovy
index 4f8ae6e..0ee9554 100644
--- a/src/it/base-config-headerfiles/verify.groovy
+++ b/src/it/base-config-headerfiles/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,61 +17,32 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-config-headerfiles.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "include/first.h",
- "bin/first.sh",
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-config-headerfiles.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'include/first.h',
+ 'bin/first.sh',
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/base-config-legalnotices/verify.groovy b/src/it/base-config-legalnotices/verify.groovy
index c9a88f6..d6b1a01 100644
--- a/src/it/base-config-legalnotices/verify.groovy
+++ b/src/it/base-config-legalnotices/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,59 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-config-legalnotices.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "legal/first.md",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-config-legalnotices.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'legal/first.md',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/base-config-libs/verify.groovy b/src/it/base-config-libs/verify.groovy
index 7ad324a..b4a4b2c 100644
--- a/src/it/base-config-libs/verify.groovy
+++ b/src/it/base-config-libs/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,59 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-config-libs.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "lib/first.so",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-config-libs.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'lib/first.so',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/base-config/verify.groovy b/src/it/base-config/verify.groovy
index 705d500..55859ca 100644
--- a/src/it/base-config/verify.groovy
+++ b/src/it/base-config/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,59 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-config.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/base-it/verify.groovy b/src/it/base-it/verify.groovy
index 44159f3..f822434 100644
--- a/src/it/base-it/verify.groovy
+++ b/src/it/base-it/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,58 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
+import java.util.jar.*
-boolean result = true;
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+def artifact = new File( target, 'jmods/maven-jmod-plugin-base-it.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- File artifact = new File( target, "jmods/maven-jmod-plugin-base-it.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def resourceNames = [
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- String[] artifactNames = [
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
- Set contents = new HashSet();
+def contents = [] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ 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;
- }
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/describe-base-config/verify.groovy b/src/it/describe-base-config/verify.groovy
index 8b4f54b..cb61e39 100644
--- a/src/it/describe-base-config/verify.groovy
+++ b/src/it/describe-base-config/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,72 +17,19 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target directory is missing or not a directory." );
- return false;
- }
-
- File artifact = new File( target, "jmods/maven-jmod-plugin-describe-base-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "the resulting jmod file is missing or a directory." );
- return false;
- }
-
- String[] artifactNames = [
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
-
- Set contents = new HashSet();
-
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- 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;
- }
+def expectedDescriptorLines = [
+ 'org.apache.maven.plugins.jmod.it.first@99.0',
+ 'exports myproject',
+ 'requires java.base'
+] as Set
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
+def buildLog = new File (basedir, 'build.log')
- def buildLog = new File (basedir, "build.log")
+def describeLines = buildLog.readLines()
+ .dropWhile{ it != '[INFO] org.apache.maven.plugins.jmod.it.first@99.0' }
+ .takeWhile{ !it.startsWith('[INFO] ---') }
+ .grep()
+ .collect{ it - '[INFO] ' } as Set
- if (!buildLog.text.contains("[INFO] org.apache.maven.plugins.jmod.it.first@99.0")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] exports myproject")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] requires java.base")) {
- return false;
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
-}
+assert expectedDescriptorLines == describeLines
-return result;
diff --git a/src/it/describe-plain/verify.groovy b/src/it/describe-plain/verify.groovy
index 8b4f54b..9050b36 100644
--- a/src/it/describe-plain/verify.groovy
+++ b/src/it/describe-plain/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,72 +17,18 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target directory is missing or not a directory." );
- return false;
- }
-
- File artifact = new File( target, "jmods/maven-jmod-plugin-describe-base-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "the resulting jmod file is missing or a directory." );
- return false;
- }
-
- String[] artifactNames = [
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
-
- Set contents = new HashSet();
-
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- 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;
- }
-
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
+def expectedDescriptorLines = [
+ 'org.apache.maven.plugins.jmod.it.first@99.0',
+ 'exports myproject',
+ 'requires java.base'
+] as Set
- def buildLog = new File (basedir, "build.log")
+def buildLog = new File (basedir, 'build.log')
- if (!buildLog.text.contains("[INFO] org.apache.maven.plugins.jmod.it.first@99.0")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] exports myproject")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] requires java.base")) {
- return false;
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
-}
+def describeLines = buildLog.readLines()
+ .dropWhile{ it != '[INFO] org.apache.maven.plugins.jmod.it.first@99.0' }
+ .takeWhile{ !it.startsWith('[INFO] ---') }
+ .grep()
+ .collect{ it - '[INFO] ' } as Set
-return result;
+assert expectedDescriptorLines == describeLines
diff --git a/src/it/list-base-config/verify.groovy b/src/it/list-base-config/verify.groovy
index d3f9c0d..a854396 100644
--- a/src/it/list-base-config/verify.groovy
+++ b/src/it/list-base-config/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,72 +17,19 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target directory is missing or not a directory." );
- return false;
- }
-
- File artifact = new File( target, "jmods/maven-jmod-plugin-list-base-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "the resulting jmod file is missing or a directory." );
- return false;
- }
-
- String[] artifactNames = [
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
-
- Set contents = new HashSet();
-
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- 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;
- }
-
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
+def resourceNames = [
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- def buildLog = new File (basedir, "build.log")
+def buildLog = new File (basedir, 'build.log')
- if (!buildLog.text.contains("[INFO] classes/module-info.class")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] classes/myproject/HelloWorld.class")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] conf/config.test")) {
- return false;
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
-}
+def listLines = buildLog.readLines()
+ .dropWhile{ !it.startsWith('[INFO] The following files are contained in the module file') }
+ .drop(1)
+ .takeWhile{ !it.startsWith('[INFO] ---') }
+ .findAll{ it.startsWith('[INFO] ')}
+ .collect{ it - '[INFO] ' } as Set
-return result;
+assert listLines == resourceNames
diff --git a/src/it/list-plain/verify.groovy b/src/it/list-plain/verify.groovy
index d3f9c0d..a854396 100644
--- a/src/it/list-plain/verify.groovy
+++ b/src/it/list-plain/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,72 +17,19 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target directory is missing or not a directory." );
- return false;
- }
-
- File artifact = new File( target, "jmods/maven-jmod-plugin-list-base-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "the resulting jmod file is missing or a directory." );
- return false;
- }
-
- String[] artifactNames = [
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
-
- Set contents = new HashSet();
-
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- 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;
- }
-
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
+def resourceNames = [
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- def buildLog = new File (basedir, "build.log")
+def buildLog = new File (basedir, 'build.log')
- if (!buildLog.text.contains("[INFO] classes/module-info.class")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] classes/myproject/HelloWorld.class")) {
- return false;
- }
- if (!buildLog.text.contains("[INFO] conf/config.test")) {
- return false;
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
-}
+def listLines = buildLog.readLines()
+ .dropWhile{ !it.startsWith('[INFO] The following files are contained in the module file') }
+ .drop(1)
+ .takeWhile{ !it.startsWith('[INFO] ---') }
+ .findAll{ it.startsWith('[INFO] ')}
+ .collect{ it - '[INFO] ' } as Set
-return result;
+assert listLines == resourceNames
diff --git a/src/it/mjmod-20-set-main-class/verify.groovy b/src/it/mjmod-20-set-main-class/verify.groovy
index 62d0712..2e4af4e 100644
--- a/src/it/mjmod-20-set-main-class/verify.groovy
+++ b/src/it/mjmod-20-set-main-class/verify.groovy
@@ -40,7 +40,7 @@ def expectedLines = [
assert describeLines == expectedLines
-def validateArtifact(module, artifactNames)
+def validateArtifact(module, resourceNames)
{
println( "Checking if ${basedir}/${module}/target exists." )
def targetDir = new File( basedir, "/${module}/target" )
@@ -64,9 +64,9 @@ def validateArtifact(module, artifactNames)
}
}
- assert artifactNames.size() == contents.size()
+ assert resourceNames.size() == contents.size()
- artifactNames.each{ artifactName ->
+ resourceNames.each{ artifactName ->
assert contents.contains( artifactName )
}
}
diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml
index 3c55696..5a2928b 100644
--- a/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml
+++ b/src/it/mjmod-8-generate-jmod-in-other-project/about-cli-app/pom.xml
@@ -28,16 +28,14 @@
<artifactId>maven-jmod-plugin-mjmod-8</artifactId>
<version>99.0</version>
</parent>
-
<artifactId>about-cli-app</artifactId>
- <packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>2.0.0</version>
- <type>jar</type>
+ <optional>true</optional>
</dependency>
</dependencies>
diff --git a/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy b/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy
index 7ca4e3d..eda2a6d 100644
--- a/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy
+++ b/src/it/mjmod-8-generate-jmod-in-other-project/verify.groovy
@@ -28,7 +28,7 @@ assert target.isDirectory()
File artifact = new File( basedir, "/about-cli-distribution-jmod/target/jmods/about-cli-distribution-jmod.jmod" )
assert artifact.isFile()
-String[] artifactNames = [
+String[] resourceNames = [
"classes/module-info.class",
"classes/META-INF/MANIFEST.MF",
"classes/mymodule/about/cli/Main.class",
@@ -54,9 +54,9 @@ while ( jarEntries.hasMoreElements() )
}
println( "Comparing the expected number of files with the actual number of files" )
-assert artifactNames.length == contents.size()
+assert resourceNames.length == contents.size()
-artifactNames.each{ artifactName ->
+resourceNames.each{ artifactName ->
println( "Does ${artifactName} exist in content." )
assert contents.contains( artifactName )
}
diff --git a/src/it/non-default-config-cmds/verify.groovy b/src/it/non-default-config-cmds/verify.groovy
index 39da642..4f3ef6d 100644
--- a/src/it/non-default-config-cmds/verify.groovy
+++ b/src/it/non-default-config-cmds/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,60 +17,31 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-non-default-config-cmds.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "bin/non-default-first.sh",
- "bin/non-default-sub-first.sh",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-non-default-config-cmds.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'bin/non-default-first.sh',
+ 'bin/non-default-sub-first.sh',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/non-default-config-headerfiles/verify.groovy b/src/it/non-default-config-headerfiles/verify.groovy
index b421925..3c6f276 100644
--- a/src/it/non-default-config-headerfiles/verify.groovy
+++ b/src/it/non-default-config-headerfiles/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,61 +17,32 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-non-default-config-headerfiles.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "include/non-first.h",
- "bin/first.sh",
- "conf/config.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-non-default-config-headerfiles.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'include/non-first.h',
+ 'bin/first.sh',
+ 'conf/config.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/non-default-config-legalnotices/verify.groovy b/src/it/non-default-config-legalnotices/verify.groovy
index aa3590f..f2e3f70 100644
--- a/src/it/non-default-config-legalnotices/verify.groovy
+++ b/src/it/non-default-config-legalnotices/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,59 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-non-default-config-legalnotices.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "legal/non-first.md",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-non-default-config-legalnotices.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'legal/non-first.md',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/non-default-config-libs/verify.groovy b/src/it/non-default-config-libs/verify.groovy
index 1d1fc99..4e064a5 100644
--- a/src/it/non-default-config-libs/verify.groovy
+++ b/src/it/non-default-config-libs/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,59 +17,30 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
-
-boolean result = true;
-
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+import java.util.jar.*
- File artifact = new File( target, "jmods/maven-jmod-plugin-non-default-config-libs.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
- String[] artifactNames = [
- "lib/non-first.so",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def artifact = new File( target, 'jmods/maven-jmod-plugin-non-default-config-libs.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- Set contents = new HashSet();
+def resourceNames = [
+ 'lib/non-first.so',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- if ( !entry.isDirectory() ) {
- // Only compare files
- contents.add( entry.getName() );
- }
- }
+def contents = [] as Set
- if ( artifactNames.length != contents.size() ) {
- System.err.println( "jar content size is different from the expected content size" );
- return false;
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
- }
-}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
}
-return result;
+assert resourceNames == contents
diff --git a/src/it/non-default-config/verify.groovy b/src/it/non-default-config/verify.groovy
index c4f044e..628bb20 100644
--- a/src/it/non-default-config/verify.groovy
+++ b/src/it/non-default-config/verify.groovy
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,60 +17,32 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.jar.*;
-import org.codehaus.plexus.util.*;
+import java.util.jar.*
-boolean result = true;
+def target = new File( basedir, 'target' )
+assert ( target.exists() && target.isDirectory() ) : 'target file is missing or not a directory.'
-try {
- File target = new File( basedir, "target" );
- if ( !target.exists() || !target.isDirectory() ) {
- System.err.println( "target file is missing or not a directory." );
- return false;
- }
+def artifact = new File( target, 'jmods/maven-jmod-plugin-non-default-config.jmod' )
+assert ( artifact.exists() && artifact.isFile() ) : 'target file is missing or a directory.'
- File artifact = new File( target, "jmods/maven-jmod-plugin-non-default-config.jmod" );
- if ( !artifact.exists() || artifact.isDirectory() ) {
- System.err.println( "target file is missing or a directory." );
- return false;
- }
+def resourceNames = [
+ 'conf/config.test',
+ 'conf/config-sub.test',
+ 'classes/module-info.class',
+ 'classes/myproject/HelloWorld.class',
+] as Set
- String[] artifactNames = [
- "conf/config.test",
- "conf/config-sub.test",
- "classes/module-info.class",
- "classes/myproject/HelloWorld.class",
- ]
+def contents = [] as Set
- Set contents = new HashSet();
-
- JarFile jar = new JarFile( artifact );
- Enumeration jarEntries = jar.entries();
- while ( jarEntries.hasMoreElements() ) {
- JarEntry entry = (JarEntry) jarEntries.nextElement();
- 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;
- }
- for ( int i = 0; i < artifactNames.length; i++ ) {
- String artifactName = artifactNames[i];
- if ( !contents.contains( artifactName ) ) {
- System.err.println( "Artifact[" + artifactName + "] not found in jar archive" );
- return false;
- }
+def jar = new JarFile( artifact )
+def jarEntries = jar.entries()
+while ( jarEntries.hasMoreElements() ) {
+ def entry = (JarEntry) jarEntries.nextElement()
+ if ( !entry.isDirectory() ) {
+ // Only compare files
+ contents.add( entry.getName() )
}
}
-catch( Throwable e ) {
- e.printStackTrace();
- result = false;
-}
-return result;
+assert resourceNames == contents
+
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 37a5fdd..295b079 100644
--- a/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jmod/JModCreateMojo.java
@@ -25,12 +25,9 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -60,7 +57,7 @@ import org.codehaus.plexus.util.cli.Commandline;
* @author Karl Heinz Marbaise <a href="mailto:khmarbaise@apache.org">khmarbaise@apache.org</a>
*/
// CHECKSTYLE_OFF: LineLength
-@Mojo( name = "create", requiresDependencyResolution = ResolutionScope.COMPILE, defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true )
+@Mojo( name = "create", requiresDependencyResolution = ResolutionScope.RUNTIME, defaultPhase = LifecyclePhase.PACKAGE, requiresProject = true )
// CHECKSTYLE_ON: LineLength
public class JModCreateMojo
extends AbstractJModMojo
@@ -71,8 +68,6 @@ public class JModCreateMojo
private List<String> modulepathElements;
- private Map<String, JavaModuleDescriptor> pathElements;
-
@Parameter( defaultValue = "${project.compileClasspathElements}", readonly = true, required = true )
private List<String> compilePath;
@@ -282,17 +277,9 @@ public class JModCreateMojo
@Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true )
private File outputDirectory;
- private List<String> modulePaths;
-
- /**
- * Define the value for the parameter <code>--class-path <path></code>, which is used when generating
- * a jmod file from a JAR.
- *
- * Example: <code>jmod create --class-path <JAR location> <full jmod destination path></code>
- */
- // @Parameter
- private String classPath = "";
-
+ // calculated based on jmod(.exe)/../..
+ private File javaHome;
+
public void execute()
throws MojoExecutionException, MojoFailureException
{
@@ -308,9 +295,9 @@ public class JModCreateMojo
}
File jModExecuteableFile = new File( jModExecutable );
- File jModExecutableParent = jModExecuteableFile.getParentFile().getParentFile();
- File jmodsFolderJDK = new File( jModExecutableParent, JMODS );
- getLog().debug( "Parent: " + jModExecutableParent.getAbsolutePath() );
+ javaHome = jModExecuteableFile.getParentFile().getParentFile();
+ File jmodsFolderJDK = new File( javaHome, JMODS );
+ getLog().debug( "Parent: " + javaHome.getAbsolutePath() );
getLog().debug( "jmodsFolder: " + jmodsFolderJDK.getAbsolutePath() );
preparePaths();
@@ -330,56 +317,6 @@ public class JModCreateMojo
// create the jmods folder...
modsFolder.mkdirs();
- this.modulePaths = new ArrayList<>();
-
- if ( pathElements != null && !pathElements.isEmpty() )
- {
- for ( Entry<String, JavaModuleDescriptor> item : pathElements.entrySet() )
- {
- // Isn't there a better solution?
- if ( item.getValue() == null )
- {
- String message = "The given dependency " + item.getKey()
- + " does not have a module-info.java file. So it can't be linked.";
- getLog().error( message );
- throw new MojoFailureException( message );
- }
- getLog().debug( "pathElements Item:" + item.getKey() + " v:" + item.getValue().name() );
- getLog().info( " -> module: " + item.getValue().name() + " ( " + item.getKey() + " )" );
- // We use the real module name and not the artifact Id...
- this.modulePaths.add( item.getKey() );
- }
- }
- /* else if ( classPath == null || classPath.trim().isEmpty() )
- {
- throw new MojoExecutionException( "You must either have a module in your project or the "
- + "'classPath' configuration set in 'maven-jmod-plugin' configuration section." );
- } */
- else
- {
- // TODO: can I improve this?
- if ( getProject().getDependencyArtifacts().isEmpty() )
- {
- throw new MojoExecutionException( "You must either have a module in your project or at "
- + "least one JAR/JMOD in the dependency's list." );
- }
- String separator = SystemUtils.IS_OS_WINDOWS ? ";" : ":";
- StringBuilder builder = new StringBuilder();
- int i = 0;
- for ( Artifact artifact : getProject().getDependencyArtifacts() )
- {
- builder.append( artifact.getFile().getAbsolutePath() );
- if ( ++i < getProject().getDependencyArtifacts().size() )
- {
- builder.append( separator );
- }
- }
- classPath = builder.toString();
- }
-
- // The jmods directory of the JDK
- this.modulePaths.add( jmodsFolderJDK.getAbsolutePath() );
-
Commandline cmd;
try
{
@@ -475,7 +412,10 @@ public class JModCreateMojo
{
List<File> list = new ArrayList<File>( project.getArtifacts().size() + 1 );
- list.add( new File( project.getBuild().getOutputDirectory() ) );
+ if ( targetClassesDirectory.exists() )
+ {
+ list.add( new File( project.getBuild().getOutputDirectory() ) );
+ }
for ( Artifact a : project.getArtifacts() )
{
@@ -486,9 +426,8 @@ public class JModCreateMojo
private void preparePaths()
{
- assert compilePath != null;
-
boolean hasModuleDescriptor = false;
+
// Assuming that the module-info.java is already compiled by compiler plugin so only
// check if the module-info.class file exists.
File moduleInfo = new File( targetClassesDirectory, "module-info.class" );
@@ -499,6 +438,8 @@ public class JModCreateMojo
hasModuleDescriptor = true;
}
+ Collection<File> dependencyArtifacts = getCompileClasspathElements( getProject() );
+
if ( hasModuleDescriptor )
{
// For now only allow named modules. Once we can create a graph with ASM we can specify exactly the modules
@@ -507,14 +448,13 @@ public class JModCreateMojo
modulepathElements = new ArrayList<String>();
classpathElements = new ArrayList<String>();
- pathElements = new LinkedHashMap<String, JavaModuleDescriptor>();
ResolvePathsResult<File> resolvePathsResult;
try
{
- Collection<File> dependencyArtifacts = getCompileClasspathElements( getProject() );
- ResolvePathsRequest<File> request = ResolvePathsRequest.withFiles( dependencyArtifacts );
+ ResolvePathsRequest<File> request =
+ ResolvePathsRequest.ofFiles( dependencyArtifacts ).setMainModuleDescriptor( moduleInfo );
Toolchain toolchain = getToolchain();
if ( toolchain != null && toolchain instanceof DefaultJavaToolChain )
@@ -548,12 +488,6 @@ public class JModCreateMojo
}
}
- for ( Map.Entry<File, JavaModuleDescriptor> entry : resolvePathsResult.getPathElements().entrySet() )
- {
- getLog().debug( "pathElements: " + entry.getKey().getPath() + " " + entry.getValue().name() );
- pathElements.put( entry.getKey().getPath(), entry.getValue() );
- }
-
for ( File file : resolvePathsResult.getClasspathElements() )
{
getLog().debug( "classpathElements: File: " + file.getPath() );
@@ -570,12 +504,16 @@ public class JModCreateMojo
{
getLog().warn( e.getMessage() );
}
-
}
else
{
- classpathElements = compilePath;
modulepathElements = Collections.emptyList();
+
+ classpathElements = new ArrayList<String>();
+ for ( File file : dependencyArtifacts )
+ {
+ classpathElements.add( file.getPath() );
+ }
}
}
@@ -600,23 +538,24 @@ public class JModCreateMojo
argsFile.println( moduleVersion );
}
- if ( classPath != null && !classPath.trim().isEmpty() )
+ List<String> classPaths;
+ if ( classpathElements != null )
+ {
+ classPaths = new ArrayList<>( classpathElements );
+ }
+ else
{
- argsFile.println( "--class-path" );
- argsFile.println( classPath );
+ classPaths = new ArrayList<>( 1 );
}
- else if ( !pathElements.isEmpty() )
+ if ( targetClassesDirectory.exists() )
{
- argsFile.println( "--class-path" );
- //TODO: Can't this be achieved in a more elegant way?
- // the classpathElements do not contain the needed information?
- ArrayList<String> x = new ArrayList<>();
- for ( String string : pathElements.keySet() )
- {
- x.add( string );
- }
- argsFile.println( getPlatformSeparatedList( x ) );
+ classPaths.add( targetClassesDirectory.getAbsolutePath() );
}
+
+ argsFile.println( "--class-path" );
+ argsFile .append( '"' )
+ .append( getPlatformSeparatedList( classPaths ).replace( "\\", "\\\\" ) )
+ .println( '"' );
if ( excludes != null && !excludes.isEmpty() )
{
@@ -676,6 +615,9 @@ public class JModCreateMojo
argsFile.println( getPlatformSeparatedList( manPagesList ) );
}
+ List<String> modulePaths = new ArrayList<>( modulepathElements );
+ modulePaths.add( new File( javaHome, JMODS ).getAbsolutePath() );
+
if ( modulePaths != null )
{
//@formatter:off
@@ -760,7 +702,7 @@ public class JModCreateMojo
return result;
}
- private String getPlatformSeparatedList( List<String> paths )
+ private String getPlatformSeparatedList( Collection<String> paths )
{
StringBuilder sb = new StringBuilder();
for ( String module : paths )