From 67e0c2ecefedd53eeede42bed42caa8ff32a3974 Mon Sep 17 00:00:00 2001 From: Dennis Lundberg Date: Sun, 30 Mar 2014 21:21:10 +0000 Subject: [PATCH] [MAPPASM-213] Allow generation of logs directory and temp directory for an assembled app Submitted by: Petar Tahchiev Reviewed by: Dennis Lundberg - Moved the configuration parameters up to the superclass, allowing it to be used for the assemble goal as well. - Added ITs to verify default behavior (no directories created) and configured behavior (empty directories created) - Changed to use Java 5 annotations for the parameters git-svn-id: file:///home/tiste/MOJOHAUS-TO-GIT/SVN-MOJO-WIP/trunk/mojo/appassembler@19596 52ab4f32-60fc-0310-b215-8acea882cd1b --- .../MAPPASM-213-extra-dirs/invoker.properties | 32 +++++++++ .../src/it/MAPPASM-213-extra-dirs/pom.xml | 68 +++++++++++++++++++ .../example/helloworld/HelloWorld.java | 41 +++++++++++ .../it/MAPPASM-213-extra-dirs/verify.groovy | 39 +++++++++++ .../invoker.properties | 32 +++++++++ .../src/it/MAPPASM-213-no-extra-dirs/pom.xml | 66 ++++++++++++++++++ .../example/helloworld/HelloWorld.java | 41 +++++++++++ .../MAPPASM-213-no-extra-dirs/verify.groovy | 39 +++++++++++ .../AbstractScriptGeneratorMojo.java | 41 +++++++++++ .../mojo/appassembler/AssembleMojo.java | 6 ++ .../appassembler/GenerateDaemonsMojo.java | 6 ++ 11 files changed, 411 insertions(+) create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/invoker.properties create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/pom.xml create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/verify.groovy create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/invoker.properties create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/pom.xml create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java create mode 100644 appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/verify.groovy diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/invoker.properties b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/invoker.properties new file mode 100644 index 00000000..9fef5aab --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/invoker.properties @@ -0,0 +1,32 @@ +# +# +# The MIT License +# +# Copyright 2006-2011 The Codehaus. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +invoker.name = MAPPASM-213 extra dirs + +invoker.goals = clean package + +invoker.debug = true + +debug = true diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/pom.xml b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/pom.xml new file mode 100644 index 00000000..e4beb50a --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + org.codehaus.mojo.appassembler.it + mappasm-213-extra-dirs + 1.0-SNAPSHOT + + + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + package + + assemble + + + + + ${project.build.directory}/appassembler + logs + + windows + unix + + + + hello_world + org.codehaus.mojo.appassembler.example.helloworld.HelloWorld + + + temp + + + + + diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java new file mode 100644 index 00000000..3228ef79 --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java @@ -0,0 +1,41 @@ +/** + * + * The MIT License + * + * Copyright 2006-2012 The Codehaus. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.mojo.appassembler.example.helloworld; + +public class HelloWorld +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + System.out.println( "Number of command line arguments: " + args.length ); + + for ( int i = 0; i < args.length; i++ ) + { + System.out.println( "Argument #" + i + ":" + args[ i ] ); + } + + System.out.println( "basedir: " + System.getProperty( "basedir" ) ); + } +} diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/verify.groovy b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/verify.groovy new file mode 100644 index 00000000..ddca8f5d --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-extra-dirs/verify.groovy @@ -0,0 +1,39 @@ +/** + * + * The MIT License + * + * Copyright 2006-2011 The Codehaus. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import java.io.* + +// The logs directory +File logsDirectory = new File( basedir, "target/appassembler/logs"); +if ( !logsDirectory.canRead() ) { + throw new FileNotFoundException( "Could not find the logs directory. " + logsDirectory ); +} + +// The temp directory +File tempDirectory = new File( basedir, "target/appassembler/temp"); +if ( !tempDirectory.canRead() ) { + throw new FileNotFoundException( "Could not find the temp directory. " + tempDirectory ); +} + +return true; diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/invoker.properties b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/invoker.properties new file mode 100644 index 00000000..393bb0a5 --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/invoker.properties @@ -0,0 +1,32 @@ +# +# +# The MIT License +# +# Copyright 2006-2011 The Codehaus. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +invoker.name = MAPPASM-213 no extra dirs + +invoker.goals = clean package + +invoker.debug = true + +debug = true diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/pom.xml b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/pom.xml new file mode 100644 index 00000000..00f08c92 --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.codehaus.mojo.appassembler.it + mappasm-213-no-extra-dirs + 1.0-SNAPSHOT + + + UTF-8 + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + package + + assemble + + + + + ${project.build.directory}/appassembler + + windows + unix + + + + hello_world + org.codehaus.mojo.appassembler.example.helloworld.HelloWorld + + + + + + + diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java new file mode 100644 index 00000000..3228ef79 --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/src/main/java/org/codehaus/mojo/appassembler/example/helloworld/HelloWorld.java @@ -0,0 +1,41 @@ +/** + * + * The MIT License + * + * Copyright 2006-2012 The Codehaus. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.codehaus.mojo.appassembler.example.helloworld; + +public class HelloWorld +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + System.out.println( "Number of command line arguments: " + args.length ); + + for ( int i = 0; i < args.length; i++ ) + { + System.out.println( "Argument #" + i + ":" + args[ i ] ); + } + + System.out.println( "basedir: " + System.getProperty( "basedir" ) ); + } +} diff --git a/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/verify.groovy b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/verify.groovy new file mode 100644 index 00000000..1c41ad3d --- /dev/null +++ b/appassembler-maven-plugin/src/it/MAPPASM-213-no-extra-dirs/verify.groovy @@ -0,0 +1,39 @@ +/** + * + * The MIT License + * + * Copyright 2006-2011 The Codehaus. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is furnished to do + * so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +import java.io.* + +// The logs directory +File logsDirectory = new File( basedir, "target/appassembler/logs"); +if ( logsDirectory.canRead() ) { + throw new Exception( "The logs directory should not be created. " + logsDirectory ); +} + +// The temp directory +File tempDirectory = new File( basedir, "target/appassembler/temp"); +if ( tempDirectory.canRead() ) { + throw new Exception( "The temp directory should not be created. " + tempDirectory ); +} + +return true; diff --git a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java index a88b2e03..adf67930 100644 --- a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java +++ b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AbstractScriptGeneratorMojo.java @@ -199,6 +199,24 @@ public abstract class AbstractScriptGeneratorMojo @Parameter( defaultValue = "${session}", readonly = true, required = true ) private MavenSession session; + /** + * The logs directory for the assembled project. + * If you specify a value for this parameter an empty directory with the name given will be created. + * + * @since 1.8 + */ + @Parameter( property = "logsDirectory" ) + protected String logsDirectory; + + /** + * The temp directory of the assembled project. + * If you specify a value for this parameter an empty directory with the name given will be created. + * + * @since 1.8 + */ + @Parameter( property = "tempDirectory" ) + protected String tempDirectory; + // ----------------------------------------------------------------------- // Components // ----------------------------------------------------------------------- @@ -270,6 +288,29 @@ protected void doCopyConfigurationDirectory( final String targetDirectory ) // Protected helper methods. // ----------------------------------------------------------------------- + protected void doCreateExtraDirectories( File targetDirectory ) + throws MojoFailureException + { + if ( this.logsDirectory != null ) + { + File logsDirectory = new File( targetDirectory, this.logsDirectory ); + boolean success = logsDirectory.mkdirs(); + if ( !success ) + { + throw new MojoFailureException( "Failed to create directory for log files." ); + } + } + if ( this.tempDirectory != null ) + { + File tempDirectory = new File( targetDirectory, this.tempDirectory ); + boolean success = tempDirectory.mkdirs(); + if ( !success ) + { + throw new MojoFailureException( "Failed to create directory for temp files." ); + } + } + } + protected void installDependencies( final String outputDirectory, final String repositoryName ) throws MojoExecutionException, MojoFailureException { diff --git a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java index 191eb918..478d2df5 100644 --- a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java +++ b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/AssembleMojo.java @@ -324,6 +324,12 @@ public void execute() { doCopyConfigurationDirectory( assembleDirectory.getAbsolutePath() ); } + + // ---------------------------------------------------------------------- + // Create logs and temp dirs if specified + // ---------------------------------------------------------------------- + + doCreateExtraDirectories( assembleDirectory ); } private org.codehaus.mojo.appassembler.model.Daemon programToDaemon( Program program, diff --git a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java index 9c17888f..7bc46409 100644 --- a/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java +++ b/appassembler-maven-plugin/src/main/java/org/codehaus/mojo/appassembler/GenerateDaemonsMojo.java @@ -263,6 +263,12 @@ public void execute() { doCopyConfigurationDirectory( outputDirectory.getAbsolutePath() ); } + + // ---------------------------------------------------------------------- + // Create logs and temp dirs if specified + // ---------------------------------------------------------------------- + + doCreateExtraDirectories( outputDirectory ); } }