Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 569391805A for ; Thu, 7 Jan 2016 08:05:01 +0000 (UTC) Received: (qmail 83794 invoked by uid 500); 7 Jan 2016 08:05:01 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 83730 invoked by uid 500); 7 Jan 2016 08:05:01 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 83719 invoked by uid 99); 7 Jan 2016 08:05:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Jan 2016 08:05:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 06373E0AF0; Thu, 7 Jan 2016 08:05:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ptahchiev@apache.org To: commits@maven.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: maven-archetype git commit: ARCHETYPE-491 as a single commit Date: Thu, 7 Jan 2016 08:05:01 +0000 (UTC) Repository: maven-archetype Updated Branches: refs/heads/ARCHETYPE-494-1 [created] 61263a78f ARCHETYPE-491 as a single commit Project: http://git-wip-us.apache.org/repos/asf/maven-archetype/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-archetype/commit/61263a78 Tree: http://git-wip-us.apache.org/repos/asf/maven-archetype/tree/61263a78 Diff: http://git-wip-us.apache.org/repos/asf/maven-archetype/diff/61263a78 Branch: refs/heads/ARCHETYPE-494-1 Commit: 61263a78f9fcb9049d6546707f816ce3ff80c1c9 Parents: dafa0d8 Author: Petar Tahchiev Authored: Thu Jan 7 10:04:40 2016 +0200 Committer: Petar Tahchiev Committed: Thu Jan 7 10:04:40 2016 +0200 ---------------------------------------------------------------------- archetype-common/pom.xml | 28 +++++ .../common/ArchetypeArtifactManager.java | 2 + .../maven/archetype/common/Constants.java | 2 + .../common/DefaultArchetypeArtifactManager.java | 20 +++ .../creator/FilesetArchetypeCreator.java | 17 +++ .../DefaultFilesetArchetypeGenerator.java | 29 ++++- .../META-INF/archetype-post-generate.groovy | 6 + .../META-INF/maven/archetype-metadata.xml | 121 +++++++++++++++++++ .../archetypes/fileset_with_postscript/pom.xml | 27 +++++ .../archetype-resources/pom.xml | 38 ++++++ .../archetype-resources/profiles.xml | 13 ++ .../archetype-resources/src/main/java/App.java | 13 ++ .../archetype-resources/src/main/java/App.ogg | 13 ++ .../src/main/java/ToDelete.java | 1 + .../src/main/java/inner/package/App2.java | 13 ++ .../src/main/resources/App.properties | 13 ++ .../src/main/resources/__artifactId__/touch.txt | 13 ++ .../resources/__rootArtifactId__/touch_root.txt | 13 ++ .../src/main/resources/some-dir/App.png | 13 ++ .../archetype-resources/src/site/apt/usage.apt | 13 ++ .../archetype-resources/src/site/site.xml | 13 ++ .../archetype-resources/subproject/pom.xml | 44 +++++++ .../subproject/src/main/java/App.java | 13 ++ .../subproject/subsubproject/pom.xml | 40 ++++++ .../subsubproject/src/main/java/App.java | 13 ++ ...aryProperty-__property-with-default-1__.java | 14 +++ ...-property__-__property-with-default-2__.java | 14 +++ ...me__rootArtifactId__Class__artifactId__.java | 14 +++ .../DefaultArchetypeGeneratorTest.java | 85 +++++++++++++ 29 files changed, 656 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-common/pom.xml b/archetype-common/pom.xml index a0b4efc..33d2ad4 100644 --- a/archetype-common/pom.xml +++ b/archetype-common/pom.xml @@ -164,6 +164,11 @@ war test + + org.codehaus.groovy + groovy + 1.8.3 + @@ -361,7 +366,30 @@ run + + archetype-test-fileset-with-postscript + process-test-resources + + + + + + + + + + + + + + + + + + run + + repository-metadata process-test-resources http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java index 529f0e3..5fdaab1 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/common/ArchetypeArtifactManager.java @@ -81,6 +81,8 @@ public interface ArchetypeArtifactManager ArtifactRepository archetypeRepository, ArtifactRepository localRepository, List repos ); + String getPostGenerationScript( File archetypeFile ) throws UnknownArchetype; + /** */ ArchetypeDescriptor getFileSetArchetypeDescriptor( File archetypeFile ) http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java b/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java index 9015c62..db5ce46 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/common/Constants.java @@ -36,6 +36,8 @@ public interface Constants String ARCHETYPE_POST_GENERATION_GOALS = "archetype.goals"; + String ARCHETYPE_POST_GENERATION_SCRIPT = "META-INF/archetype-post-generate.groovy"; + String ARCHETYPE_POM = "pom.xml"; String ARCHETYPE_RESOURCES = "archetype-resources"; http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java index a3de790..6c35f18 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/common/DefaultArchetypeArtifactManager.java @@ -19,6 +19,7 @@ package org.apache.maven.archetype.common; * under the License. */ +import org.apache.commons.io.IOUtils; import org.apache.maven.archetype.downloader.DownloadException; import org.apache.maven.archetype.downloader.DownloadNotFoundException; import org.apache.maven.archetype.downloader.Downloader; @@ -299,6 +300,25 @@ public class DefaultArchetypeArtifactManager } } + public String getPostGenerationScript( File archetypeFile ) throws UnknownArchetype + { + ZipFile zipFile = null; + try + { + zipFile = getArchetypeZipFile( archetypeFile ); + Reader reader = getDescriptorReader( zipFile, Constants.ARCHETYPE_POST_GENERATION_SCRIPT ); + return reader == null ? null : IOUtils.toString( reader ); + } + catch ( IOException e ) + { + throw new UnknownArchetype( e ); + } + finally + { + closeZipFile( zipFile ); + } + } + public ArchetypeDescriptor getFileSetArchetypeDescriptor( File archetypeFile ) throws UnknownArchetype { http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java index 304a2a8..e755749 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java @@ -19,6 +19,7 @@ package org.apache.maven.archetype.creator; * under the License. */ +import org.apache.commons.collections.CollectionUtils; import org.apache.maven.archetype.ArchetypeCreationRequest; import org.apache.maven.archetype.ArchetypeCreationResult; import org.apache.maven.archetype.common.ArchetypeFilesResolver; @@ -147,6 +148,22 @@ public class FilesetArchetypeCreator File archetypeDescriptorFile = new File( archetypeResourcesDirectory, Constants.ARCHETYPE_DESCRIPTOR ); archetypeDescriptorFile.getParentFile().mkdirs(); + File archetypePostGenerationScript = + new File( archetypeResourcesDirectory, Constants.ARCHETYPE_POST_GENERATION_SCRIPT ); + archetypePostGenerationScript.getParentFile().mkdirs(); + + if ( request.getProject().getBuild() != null && CollectionUtils.isNotEmpty( + request.getProject().getBuild().getResources() ) ) + { + File inputFile = new File( + request.getProject().getBuild().getResources().get( 0 ).getDirectory() + File.separator + + Constants.ARCHETYPE_POST_GENERATION_SCRIPT ); + if ( inputFile.exists() ) + { + FileUtils.copyFile( inputFile, archetypePostGenerationScript ); + } + } + getLogger().debug( "Starting archetype's descriptor " + project.getArtifactId() ); ArchetypeDescriptor archetypeDescriptor = new ArchetypeDescriptor(); http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java b/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java index 7ebe3c8..154015f 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/generator/DefaultFilesetArchetypeGenerator.java @@ -19,6 +19,8 @@ package org.apache.maven.archetype.generator; * under the License. */ +import groovy.lang.Binding; +import groovy.lang.GroovyShell; import org.apache.maven.archetype.ArchetypeGenerationRequest; import org.apache.maven.archetype.common.ArchetypeArtifactManager; import org.apache.maven.archetype.common.ArchetypeFilesResolver; @@ -59,6 +61,7 @@ import java.io.OutputStreamWriter; import java.io.StringWriter; import java.io.Writer; import java.util.ArrayList; +import java.util.Enumeration; import java.util.Iterator; import java.util.List; import java.util.regex.Pattern; @@ -204,12 +207,34 @@ public class DefaultFilesetArchetypeGenerator outputDirectoryFile, packageName, archetypeDescriptor, context ); } + String postGenerationScript = archetypeArtifactManager.getPostGenerationScript( archetypeFile ); + if ( postGenerationScript != null ) + { + getLogger().info( "Executing post-generation script" ); + Binding binding = new Binding(); + + if ( request.getProperties() != null ) + { + + request.getProperties().putAll( System.getProperties() ); + Enumeration e = request.getProperties().propertyNames(); + while ( e.hasMoreElements() ) + { + String key = (String) e.nextElement(); + binding.setVariable( key, request.getProperties().getProperty( key ) ); + } + } + + GroovyShell shell = new GroovyShell( binding ); + shell.evaluate( postGenerationScript ); + } + // ---------------------------------------------------------------------- // Log message on OldArchetype creation // ---------------------------------------------------------------------- if ( getLogger().isInfoEnabled() ) { - getLogger().info( "project created from Archetype in dir: " + outputDirectoryFile.getAbsolutePath() ); + getLogger().info( "Project created from Archetype in dir: " + outputDirectoryFile.getAbsolutePath() ); } } catch ( FileNotFoundException ex ) @@ -468,7 +493,7 @@ public class DefaultFilesetArchetypeGenerator if ( maybeVelocityExpression( value ) ) { - value = evaluateExpression( context, key, value ); + value = evaluateExpression( context, key, value ); } context.put( key, value ); http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/archetype-post-generate.groovy ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/archetype-post-generate.groovy b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/archetype-post-generate.groovy new file mode 100644 index 0000000..7b01980 --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/archetype-post-generate.groovy @@ -0,0 +1,6 @@ +println "Executing the post_create script..."; + +def projectFolder = this.'user.dir' + this.'file.separator' + "target/test-classes/projects" + this.'file.separator' + "generate-13" + this.'file.separator' + "file-value" + this.'file.separator'; + +println "Removing file: ${projectFolder}src/main/java/file/value/package/ToDelete.java"; +new File(projectFolder + "src/main/java/file/value/package/ToDelete.java").delete(); http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetype-metadata.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetype-metadata.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..6b2523a --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,121 @@ + + + + + + + default-value + + + default-value + + + default-value + + + default-value + + + + + + + + + + src/main/java + + **/*.java + + + + src/main/java + + **/*.ogg + + + + src/main/resources + + **/*.properties + **/*.txt + + + + src/main/resources + + **/*.png + + + + src/site + + **/*.xml + **/*.apt + + + + + + .classpath + *.xml + + + + src/main/toto + + **/* + + + + + + + + + src/main/java + + **/*.java + + + + src/main/toto + + **/* + + + + + + + + + src/main/java + + **/*.java + + + + + + + + + http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetypes/fileset_with_postscript/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetypes/fileset_with_postscript/pom.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetypes/fileset_with_postscript/pom.xml new file mode 100644 index 0000000..b7422de --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/META-INF/maven/archetypes/fileset_with_postscript/pom.xml @@ -0,0 +1,27 @@ + + + + + 4.0.0 + + archetypes + fileset + 1.0 + http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/pom.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/pom.xml new file mode 100644 index 0000000..6c34c7b --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + ${groupId} + ${artifactId} + ${version} + + Maven archetype Test + pom + + + subproject + + + http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/profiles.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/profiles.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/profiles.xml new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/profiles.xml @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.java @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.ogg ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.ogg b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.ogg new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/App.ogg @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/ToDelete.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/ToDelete.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/ToDelete.java new file mode 100644 index 0000000..3c74a80 --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/ToDelete.java @@ -0,0 +1 @@ +This file must be deleted by the post-create script. http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/inner/package/App2.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/inner/package/App2.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/inner/package/App2.java new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/java/inner/package/App2.java @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/App.properties ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/App.properties b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/App.properties new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/App.properties @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__artifactId__/touch.txt ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__artifactId__/touch.txt b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__artifactId__/touch.txt new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__artifactId__/touch.txt @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__rootArtifactId__/touch_root.txt ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__rootArtifactId__/touch_root.txt b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__rootArtifactId__/touch_root.txt new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/__rootArtifactId__/touch_root.txt @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/some-dir/App.png ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/some-dir/App.png b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/some-dir/App.png new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/main/resources/some-dir/App.png @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/apt/usage.apt ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/apt/usage.apt b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/apt/usage.apt new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/apt/usage.apt @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/site.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/site.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/site.xml new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/src/site/site.xml @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/pom.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/pom.xml new file mode 100644 index 0000000..f74a253 --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + + ${groupId} + ${parentArtifactId} + ${version} + + + ${groupId} + ${artifactId} + ${version} + + Maven archetype Test Subfolder + pom + + + subsubproject + + + http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/src/main/java/App.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/src/main/java/App.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/src/main/java/App.java new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/src/main/java/App.java @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/pom.xml b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/pom.xml new file mode 100644 index 0000000..dfbf01b --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + + ${groupId} + ${parentArtifactId} + ${version} + + + ${groupId} + ${artifactId} + ${version} + + Maven archetype Test Subsubfolder + jar + + http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/App.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/App.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/App.java new file mode 100644 index 0000000..d34de6e --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/App.java @@ -0,0 +1,13 @@ +groupId=${groupId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/ArbitraryProperty-__property-with-default-1__.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/ArbitraryProperty-__property-with-default-1__.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/ArbitraryProperty-__property-with-default-1__.java new file mode 100644 index 0000000..c6837ac --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/ArbitraryProperty-__property-with-default-1__.java @@ -0,0 +1,14 @@ +groupId=${groupId} +rootArtifactId=${rootArtifactId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/SkipsUndefinedProperty-__undefined-property__-__property-with-default-2__.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/SkipsUndefinedProperty-__undefined-property__-__property-with-default-2__.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/SkipsUndefinedProperty-__undefined-property__-__property-with-default-2__.java new file mode 100644 index 0000000..c6837ac --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/SkipsUndefinedProperty-__undefined-property__-__property-with-default-2__.java @@ -0,0 +1,14 @@ +groupId=${groupId} +rootArtifactId=${rootArtifactId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/__rootArtifactId__/inner/__artifactId__/innest/Some__rootArtifactId__Class__artifactId__.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/__rootArtifactId__/inner/__artifactId__/innest/Some__rootArtifactId__Class__artifactId__.java b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/__rootArtifactId__/inner/__artifactId__/innest/Some__rootArtifactId__Class__artifactId__.java new file mode 100644 index 0000000..c6837ac --- /dev/null +++ b/archetype-common/src/test/archetypes/fileset_with_postscript-1.0/archetype-resources/subproject/subsubproject/src/main/java/__rootArtifactId__/inner/__artifactId__/innest/Some__rootArtifactId__Class__artifactId__.java @@ -0,0 +1,14 @@ +groupId=${groupId} +rootArtifactId=${rootArtifactId} +artifactId=${artifactId} +version=${version} +package=${package} +packageInPathFormat=${packageInPathFormat} +property-without-default-1=${property-without-default-1} +property-without-default-2=${property-without-default-2} +property-without-default-3=${property-without-default-3} +property-without-default-4=${property-without-default-4} +property-with-default-1=${property-with-default-1} +property-with-default-2=${property-with-default-2} +property-with-default-3=${property-with-default-3} +property-with-default-4=${property-with-default-4} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/61263a78/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java ---------------------------------------------------------------------- diff --git a/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java b/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java index 284f80d..c74f8ea 100644 --- a/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java +++ b/archetype-common/src/test/java/org/apache/maven/archetype/generator/DefaultArchetypeGeneratorTest.java @@ -57,6 +57,9 @@ public class DefaultArchetypeGeneratorTest private final static Archetype ARCHETYPE_OLD = new Archetype( "archetypes", "old", "1.0" ); + private final static Archetype ARCHETYPE_FILESET_WITH_POSTCREATE_SCRIPT = + new Archetype( "archetypes", "fileset_with_postscript", "1.0" ); + private final static Properties ADDITIONAL_PROPERTIES = new Properties(); static { @@ -421,6 +424,88 @@ public class DefaultArchetypeGeneratorTest && result.getCause().getMessage().endsWith( "Property property-without-default-4 is missing." ) ); } + public void testGenerateArchetypeWithPostScriptIncluded() + throws Exception + { + System.out.println( "testGenerateArchetypeWithPostScriptIncluded" ); + + ArchetypeGenerationRequest request = + createArchetypeGenerationRequest( "generate-13", ARCHETYPE_FILESET_WITH_POSTCREATE_SCRIPT ); + + File projectFile = new File( projectDirectory, "pom.xml" ); + + FileUtils.forceDelete( projectDirectory ); + + generateProjectFromArchetype( request ); + + assertTemplateContentGeneratedWithFileSetArchetype( "src/main/java/file/value/package/App.java", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( "src/main/java/file/value/package/inner/package/App2.java", + "file-value" ); + + assertTemplateCopiedWithFileSetArchetype( "src/main/java/file/value/package/App.ogg" ); + + File templateFile = new File( projectDirectory, "src/main/java/file/value/package/ToDelete.java" ); + assertFalse( templateFile.exists() ); + + assertTemplateContentGeneratedWithFileSetArchetype( "src/main/resources/App.properties", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( "src/main/resources/file-value/touch.txt", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( "src/main/resources/file-value/touch_root.txt", + "file-value" ); + + assertTemplateCopiedWithFileSetArchetype( "src/main/resources/some-dir/App.png" ); + + assertTemplateContentGeneratedWithFileSetArchetype( "src/site/site.xml", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( "src/site/apt/usage.apt", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( ".classpath", "file-value" ); + assertTemplateContentGeneratedWithFileSetArchetype( "profiles.xml", "file-value" ); + + Model model = readPom( projectFile ); + assertNull( model.getParent() ); + assertEquals( "file-value", model.getGroupId() ); + assertEquals( "file-value", model.getArtifactId() ); + assertEquals( "file-value", model.getVersion() ); + + assertTemplateContentGeneratedWithFileSetArchetype( "subproject/src/main/java/file/value/package/App.java", + "subproject" ); + + model = readPom( new File( projectDirectory, "subproject/pom.xml" ) ); + assertNotNull( model.getParent() ); + assertEquals( "file-value", model.getParent().getGroupId() ); + assertEquals( "file-value", model.getParent().getArtifactId() ); + assertEquals( "file-value", model.getParent().getVersion() ); + assertEquals( "file-value", model.getGroupId() ); + assertEquals( "subproject", model.getArtifactId() ); + assertEquals( "file-value", model.getVersion() ); + + assertTemplateContentGeneratedWithFileSetArchetype( + "subproject/subsubproject/src/main/java/file/value/package/App.java", "subsubproject" ); + + assertTemplateContentGeneratedWithFileSetArchetype( "subproject/subsubproject/src/main/java/file/value/package/" + + "file-value/inner/subsubproject/innest/Somefile-valueClasssubsubproject.java", + "subsubproject" ); + + assertTemplateContentGeneratedWithFileSetArchetype( "subproject/subsubproject/src/main/java/file/value/package/" + /* + "file-value/inner/subsubproject/innest/" + */ + + "ArbitraryProperty-file-value.java", + "subsubproject" ); + + // Test that undefined properties are safely ignored (and skipped) + assertTemplateContentGeneratedWithFileSetArchetype( "subproject/subsubproject/src/main/java/file/value/package/" + /* + "file-value/inner/subsubproject/innest/" + */ + + "SkipsUndefinedProperty-__undefined-property__-file-value.java", + "subsubproject" ); + + model = readPom( new File( projectDirectory, "subproject/subsubproject/pom.xml" ) ); + assertNotNull( model.getParent() ); + assertEquals( "file-value", model.getParent().getGroupId() ); + assertEquals( "subproject", model.getParent().getArtifactId() ); + assertEquals( "file-value", model.getParent().getVersion() ); + assertEquals( "file-value", model.getGroupId() ); + assertEquals( "subsubproject", model.getArtifactId() ); + assertEquals( "file-value", model.getVersion() ); + + } + protected void tearDown() throws Exception {