This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git
commit e232ff7f741ed94713aa049294d24eced23ed306 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Wed Nov 25 22:57:20 2026 +0000 Modernize Groovy IT scripts See https://github.com/apache/maven-invoker-plugin/issues/811. --- src/it/MJAR-183/verify.groovy | 34 ++------------ src/it/MJAR-70-no-recreation/verify.groovy | 25 ++-------- src/it/MJAR-82/verify.groovy | 73 +++++++++--------------------- 3 files changed, 29 insertions(+), 103 deletions(-) diff --git a/src/it/MJAR-183/verify.groovy b/src/it/MJAR-183/verify.groovy index a024918..78c9ef2 100644 --- a/src/it/MJAR-183/verify.groovy +++ b/src/it/MJAR-183/verify.groovy @@ -18,34 +18,8 @@ * under the License. */ -import java.io.*; -import java.util.*; -import java.util.jar.*; +File target = new File( basedir, "target" ); +assert target.exists() && target.isDirectory() : "target file is missing or not a directory." -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; - } - - File artifact = new File( target, "maven-jar-plugin-test-mjar-183-1.0-SNAPSHOT.jar" ); - if ( !artifact.exists() ) - { - System.err.println( "default artifact should exist." ); - return false; - } - - return true; -} -catch( Throwable e ) -{ - e.printStackTrace(); - return false; -} - -return false; +File artifact = new File( target, "maven-jar-plugin-test-mjar-183-1.0-SNAPSHOT.jar" ); +assert artifact.exists() : "default artifact should exist." diff --git a/src/it/MJAR-70-no-recreation/verify.groovy b/src/it/MJAR-70-no-recreation/verify.groovy index bcc0469..9c37f6d 100644 --- a/src/it/MJAR-70-no-recreation/verify.groovy +++ b/src/it/MJAR-70-no-recreation/verify.groovy @@ -18,26 +18,14 @@ * under the License. */ -import java.io.*; -import java.util.*; - File target = new File( basedir, "target" ); -if ( !target.isDirectory() ) -{ - throw new IOException( "target file is missing or not a directory: " + target ); -} +assert target.isDirectory() : "target file is missing or not a directory: " + target File jarFile = new File( target, "MJAR-70-no-recreation-1.0-SNAPSHOT.jar" ); -if ( !jarFile.isFile() ) -{ - throw new IOException( "artifact file is missing or a directory: " + jarFile ); -} +assert jarFile.isFile() : "artifact file is missing or a directory: " + jarFile File refFile = new File( target, "reference.jar" ); -if ( !refFile.isFile() ) -{ - throw new IOException( "reference file is missing or a directory: " + refFile ); -} +assert refFile.isFile() : "reference file is missing or a directory: " + refFile long referenceTimestamp = refFile.lastModified(); System.out.println( "Reference timestamp: " + referenceTimestamp ); @@ -45,9 +33,4 @@ System.out.println( "Reference timestamp: " + referenceTimestamp ); long actualTimestamp = jarFile.lastModified(); System.out.println( "Actual timestamp : " + actualTimestamp ); -if ( referenceTimestamp != actualTimestamp) -{ - throw new Exception( "Timestamps don't match, JAR was recreated although contents has not changed" ); -} - -return true; +assert referenceTimestamp == actualTimestamp : "Timestamps don't match, JAR was recreated although contents has not changed" diff --git a/src/it/MJAR-82/verify.groovy b/src/it/MJAR-82/verify.groovy index acdbfd9..89be5e1 100644 --- a/src/it/MJAR-82/verify.groovy +++ b/src/it/MJAR-82/verify.groovy @@ -18,58 +18,27 @@ * under the License. */ -import java.io.*; -import java.util.*; -import java.util.jar.*; import org.codehaus.plexus.util.cli.*; import org.codehaus.plexus.util.FileUtils; -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; - } - - File artifact = new File( target, "MJAR-82-1.0-SNAPSHOT.jar" ); - if ( !artifact.exists() || artifact.isDirectory() ) - { - System.err.println( "artifact file is missing or a directory." ); - return false; - } - - String localRepoPath = basedir.getParentFile().getParentFile().getParentFile().getPath() + "/target/local-repo"; - FileUtils.copyFile( artifact, new File( localRepoPath, "MJAR-82-1.0-SNAPSHOT.jar" ) ); - Commandline commandline = new Commandline(); - commandline.setExecutable( "java" ); - commandline.setWorkingDirectory( localRepoPath ); - System.out.println(" localRepoPath " + localRepoPath ); - commandline.createArg().setLine( "-jar MJAR-82-1.0-SNAPSHOT.jar" ); - CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer(); - int res = CommandLineUtils.executeCommandLine( commandline, consumer, consumer ); - String output = consumer.getOutput(); - System.out.println( "res " + res ); - System.out.println( output ); - if ( res != 0 ) - { - System.err.println( "commandline execution return code != 0 " + res ); - return false; - } - - if ( output.indexOf("great it works") < 0 ) - { - System.err.println( "output not contains great it works" ); - return false; - } -} -catch( Throwable e ) -{ - e.printStackTrace(); - result = false; -} - -return result; +File target = new File( basedir, "target" ); +assert target.exists() && target.isDirectory() : "target file is missing or not a directory." + +File artifact = new File( target, "MJAR-82-1.0-SNAPSHOT.jar" ); +assert artifact.exists() && !artifact.isDirectory() : "artifact file is missing or a directory." + +String localRepoPath = basedir.getParentFile().getParentFile().getParentFile().getPath() + "/target/local-repo"; +FileUtils.copyFile( artifact, new File( localRepoPath, "MJAR-82-1.0-SNAPSHOT.jar" ) ); +Commandline commandline = new Commandline(); +commandline.setExecutable( "java" ); +commandline.setWorkingDirectory( localRepoPath ); +System.out.println(" localRepoPath " + localRepoPath ); +commandline.createArg().setLine( "-jar MJAR-82-1.0-SNAPSHOT.jar" ); +CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer(); +int res = CommandLineUtils.executeCommandLine( commandline, consumer, consumer ); +String output = consumer.getOutput(); +System.out.println( "res " + res ); +System.out.println( output ); +assert res == 0 : "commandline execution return code != 0 " + res + +assert output.indexOf("great it works") >= 0 : "output not contains great it works"
