Squashed commit of the following: commit a02e9922c62313ffa147b4f63d125f4dc41f7280 Author: rfscholte <rfscho...@apache.org> Date: Mon Jan 23 21:55:42 2017 +0100
[ARCHETYPE-514] Tests fail with empty repository and 'mvn verify' Switch from surefire to failsafe to ensure jars have been created let maven-invoker-plugin prepare local repo for failsafe ITs commit afdf0a2c4ff57632044099b852b1d116531f81c2 Author: rfscholte <rfscho...@apache.org> Date: Mon Jan 23 20:46:47 2017 +0100 Move ITS to plugin Project: http://git-wip-us.apache.org/repos/asf/maven-archetype/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-archetype/commit/741f432b Tree: http://git-wip-us.apache.org/repos/asf/maven-archetype/tree/741f432b Diff: http://git-wip-us.apache.org/repos/asf/maven-archetype/diff/741f432b Branch: refs/heads/master Commit: 741f432b806c0089e4a23ced80694b0e837122ee Parents: 44e7ed6 Author: rfscholte <rfscho...@apache.org> Authored: Mon Jan 23 22:03:23 2017 +0100 Committer: rfscholte <rfscho...@apache.org> Committed: Mon Jan 23 22:03:23 2017 +0100 ---------------------------------------------------------------------- .../creator/FilesetArchetypeCreator.java | 88 ++-- archetype-testing/archetype-final/pom.xml | 64 +-- .../archetype.properties | 1 - .../invoker.properties | 1 - .../pom.xml | 30 -- .../src/main/resources/file.txt | 0 .../src/main/resources/file.xml | 0 .../src/main/resources/toexclude/file.txt | 0 .../src/main/resources/toexclude/file.xml | 0 .../src/main/toexclude/file.txt | 0 .../src/main/toexclude/file.xml | 0 .../src/toexclude/file.txt | 0 .../src/toexclude/file.xml | 0 .../toexclude/file.txt | 0 .../toexclude/file.xml | 0 .../verify.bsh | 46 -- .../it/create-from-project/archetype.properties | 1 - .../it/create-from-project/invoker.properties | 1 - .../src/it/create-from-project/pom.xml | 30 -- .../src/main/java/foo/bar/App.java | 32 -- .../src/it/create-from-project/verify.bsh | 38 -- .../archetype-final/src/it/settings.xml | 55 -- .../creator/DefaultArchetypeCreatorIT.java | 511 +++++++++++++++++++ .../creator/DefaultArchetypeCreatorTest.java | 510 ------------------ .../archetype/test/ArchetyperRoundtripIT.java | 245 +++++++++ .../archetype/test/ArchetyperRoundtripTest.java | 245 --------- .../test/ArchetyperRoundtripWithProxyIT.java | 246 +++++++++ .../test/ArchetyperRoundtripWithProxyTest.java | 246 --------- .../archetype/test/RoundtripMultiModuleIT.java | 317 ++++++++++++ .../test/RoundtripMultiModuleTest.java | 317 ------------ .../archetype.properties | 1 + .../invoker.properties | 1 + .../pom.xml | 30 ++ .../src/main/resources/file.txt | 0 .../src/main/resources/file.xml | 0 .../src/main/resources/toexclude/file.txt | 0 .../src/main/resources/toexclude/file.xml | 0 .../src/main/toexclude/file.txt | 0 .../src/main/toexclude/file.xml | 0 .../src/toexclude/file.txt | 0 .../src/toexclude/file.xml | 0 .../toexclude/file.txt | 0 .../toexclude/file.xml | 0 .../verify.bsh | 46 ++ .../it/create-from-project/archetype.properties | 1 + .../it/create-from-project/invoker.properties | 1 + .../src/it/create-from-project/pom.xml | 30 ++ .../src/main/java/foo/bar/App.java | 32 ++ .../src/it/create-from-project/verify.bsh | 38 ++ 49 files changed, 1556 insertions(+), 1648 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/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 22465fd..576d33b 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 @@ -48,7 +48,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.shared.invoker.DefaultInvocationRequest; -import org.apache.maven.shared.invoker.DefaultInvoker; import org.apache.maven.shared.invoker.InvocationRequest; import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.Invoker; @@ -104,6 +103,9 @@ public class FilesetArchetypeCreator @Requirement private MavenProjectBuilder projectBuilder; + + @Requirement + private Invoker invoker; public void createArchetype( ArchetypeCreationRequest request, ArchetypeCreationResult result ) { @@ -216,9 +218,8 @@ public class FilesetArchetypeCreator setParentArtifactId( reverseProperties, configurationProperties.getProperty( Constants.ARTIFACT_ID ) ); - for ( Iterator<String> modules = pom.getModules().iterator(); modules.hasNext(); ) + for ( String moduleId : pom.getModules() ) { - String moduleId = (String) modules.next(); String rootArtifactId = configurationProperties.getProperty( Constants.ARTIFACT_ID ); String moduleIdDirectory = moduleId; @@ -287,8 +288,11 @@ public class FilesetArchetypeCreator InvocationRequest internalRequest = new DefaultInvocationRequest(); internalRequest.setPomFile( archetypePomFile ); internalRequest.setGoals( Collections.singletonList( request.getPostPhase() ) ); + if ( request.getLocalRepository() != null ) + { + internalRequest.setLocalRepositoryDirectory( new File( request.getLocalRepository().getBasedir() ) ); + } - Invoker invoker = new DefaultInvoker(); InvocationResult invokerResult = invoker.execute( internalRequest ); if ( invokerResult.getExitCode() != 0 ) { @@ -541,10 +545,8 @@ public class FilesetArchetypeCreator setParentArtifactId( pomReversedProperties, pomReversedProperties.getProperty( Constants.ARTIFACT_ID ) ); setArtifactId( pomReversedProperties, pom.getArtifactId() ); - for ( Iterator<String> modules = pom.getModules().iterator(); modules.hasNext(); ) + for ( String subModuleId : pom.getModules() ) { - String subModuleId = modules.next(); - String subModuleIdDirectory = subModuleId; if ( subModuleId.indexOf( rootArtifactId ) >= 0 ) @@ -571,10 +573,8 @@ public class FilesetArchetypeCreator { setArtifactId( pomReversedProperties, pom.getArtifactId() ); - for ( Iterator<String> modules = pom.getModules().iterator(); modules.hasNext(); ) + for ( String moduleId : pom.getModules() ) { - String moduleId = modules.next(); - String moduleIdDirectory = moduleId; if ( moduleId.indexOf( rootArtifactId ) >= 0 ) @@ -604,9 +604,9 @@ public class FilesetArchetypeCreator // rewrite Dependencies if ( pom.getDependencies() != null && !pom.getDependencies().isEmpty() ) { - for ( Iterator<Dependency> dependencies = pom.getDependencies().iterator(); dependencies.hasNext(); ) + for ( Dependency dependency : pom.getDependencies() ) { - rewriteDependencyReferences( dependencies.next(), rootArtifactId, groupId ); + rewriteDependencyReferences( dependency, rootArtifactId, groupId ); } } @@ -614,19 +614,18 @@ public class FilesetArchetypeCreator if ( pom.getDependencyManagement() != null && pom.getDependencyManagement().getDependencies() != null && !pom.getDependencyManagement().getDependencies().isEmpty() ) { - for ( Iterator<Dependency> dependencies = pom.getDependencyManagement().getDependencies().iterator(); - dependencies.hasNext(); ) + for ( Dependency dependency : pom.getDependencyManagement().getDependencies() ) { - rewriteDependencyReferences( dependencies.next(), rootArtifactId, groupId ); + rewriteDependencyReferences( dependency, rootArtifactId, groupId ); } } // rewrite Plugins if ( pom.getBuild() != null && pom.getBuild().getPlugins() != null && !pom.getBuild().getPlugins().isEmpty() ) { - for ( Iterator<Plugin> plugins = pom.getBuild().getPlugins().iterator(); plugins.hasNext(); ) + for ( Plugin plugin : pom.getBuild().getPlugins() ) { - rewritePluginReferences( plugins.next(), rootArtifactId, groupId ); + rewritePluginReferences( plugin, rootArtifactId, groupId ); } } @@ -635,27 +634,23 @@ public class FilesetArchetypeCreator && pom.getBuild().getPluginManagement().getPlugins() != null && !pom.getBuild().getPluginManagement().getPlugins().isEmpty() ) { - for ( Iterator<Plugin> plugins = pom.getBuild().getPluginManagement().getPlugins().iterator(); - plugins.hasNext(); ) + for ( Plugin plugin : pom.getBuild().getPluginManagement().getPlugins() ) { - rewritePluginReferences( plugins.next(), rootArtifactId, groupId ); + rewritePluginReferences( plugin, rootArtifactId, groupId ); } } // rewrite Profiles if ( pom.getProfiles() != null ) { - for ( Iterator<Profile> profiles = pom.getProfiles().iterator(); profiles.hasNext(); ) + for ( Profile profile : pom.getProfiles() ) { - Profile profile = profiles.next(); - // rewrite Dependencies if ( profile.getDependencies() != null && !profile.getDependencies().isEmpty() ) { - for ( Iterator<Dependency> dependencies = profile.getDependencies().iterator(); - dependencies.hasNext(); ) + for ( Dependency dependency : profile.getDependencies() ) { - rewriteDependencyReferences( dependencies.next(), rootArtifactId, groupId ); + rewriteDependencyReferences( dependency, rootArtifactId, groupId ); } } @@ -664,10 +659,9 @@ public class FilesetArchetypeCreator && profile.getDependencyManagement().getDependencies() != null && !profile.getDependencyManagement().getDependencies().isEmpty() ) { - for ( Iterator<Dependency> dependencies = - profile.getDependencyManagement().getDependencies().iterator(); dependencies.hasNext(); ) + for ( Dependency dependency : profile.getDependencyManagement().getDependencies() ) { - rewriteDependencyReferences( dependencies.next(), rootArtifactId, groupId ); + rewriteDependencyReferences( dependency, rootArtifactId, groupId ); } } @@ -675,9 +669,9 @@ public class FilesetArchetypeCreator if ( profile.getBuild() != null && profile.getBuild().getPlugins() != null && !profile.getBuild().getPlugins().isEmpty() ) { - for ( Iterator<Plugin> plugins = profile.getBuild().getPlugins().iterator(); plugins.hasNext(); ) + for ( Plugin plugin : profile.getBuild().getPlugins() ) { - rewritePluginReferences( plugins.next(), rootArtifactId, groupId ); + rewritePluginReferences( plugin, rootArtifactId, groupId ); } } @@ -686,10 +680,9 @@ public class FilesetArchetypeCreator && profile.getBuild().getPluginManagement().getPlugins() != null && !profile.getBuild().getPluginManagement().getPlugins().isEmpty() ) { - for ( Iterator<Plugin> plugins = profile.getBuild().getPluginManagement().getPlugins().iterator(); - plugins.hasNext(); ) + for ( Plugin plugin : profile.getBuild().getPluginManagement().getPlugins() ) { - rewritePluginReferences( plugins.next(), rootArtifactId, groupId ); + rewritePluginReferences( plugin, rootArtifactId, groupId ); } } } @@ -1075,10 +1068,8 @@ public class FilesetArchetypeCreator String parentArtifactId = reverseProperties.getProperty( Constants.PARENT_ARTIFACT_ID ); setParentArtifactId( reverseProperties, pom.getArtifactId() ); - for ( Iterator<String> modules = pom.getModules().iterator(); modules.hasNext(); ) + for ( String subModuleId : pom.getModules() ) { - String subModuleId = modules.next(); - String subModuleIdDirectory = subModuleId; if ( subModuleId.indexOf( rootArtifactId ) >= 0 ) { @@ -1365,25 +1356,6 @@ public class FilesetArchetypeCreator } } - private List<String> removePackage( List<String> sources, String packageAsDirectory ) - { - if ( sources == null ) - { - return null; - } - - List<String> unpackagedSources = new ArrayList<String>( sources.size() ); - - for ( String source : sources ) - { - String unpackagedSource = StringUtils.replace( source, packageAsDirectory, "" ); - - unpackagedSources.add( unpackagedSource ); - } - - return unpackagedSources; - } - private Properties getReversedProperties( ArchetypeDescriptor archetypeDescriptor, Properties properties ) { Properties reversedProperties = new Properties(); @@ -1412,9 +1384,9 @@ public class FilesetArchetypeCreator getLogger().debug( "Resolving files for " + pom.getId() + " in " + basedir ); StringBuffer buff = new StringBuffer( "pom.xml*,archetype.properties*,target/**," ); - for ( Iterator<String> modules = pom.getModules().iterator(); modules.hasNext(); ) + for ( String module : pom.getModules() ) { - buff.append( ',' ).append( modules.next() ).append( "/**" ); + buff.append( ',' ).append( module ).append( "/**" ); } for ( String defaultExclude : ListScanner.DEFAULTEXCLUDES ) http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/pom.xml b/archetype-testing/archetype-final/pom.xml index cff290d..5420802 100644 --- a/archetype-testing/archetype-final/pom.xml +++ b/archetype-testing/archetype-final/pom.xml @@ -30,7 +30,7 @@ </parent> <artifactId>archetype-final</artifactId> - <packaging>jar</packaging> + <packaging>jar</packaging> <!-- to compile test-classes --> <name>Maven Archetype Testing Final</name> @@ -38,7 +38,6 @@ <cargoVersion>1.0-alpha-6</cargoVersion> </properties> - <dependencies> <dependency> <groupId>junit</groupId> @@ -113,40 +112,7 @@ <scope>test</scope> </dependency> </dependencies> - <profiles> - <profile> - <id>run-its</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <configuration> - <debug>true</debug> - <projectsDirectory>src/it</projectsDirectory> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <pomIncludes> - <pomInclude>*</pomInclude> - </pomIncludes> - <preBuildHookScript>setup</preBuildHookScript> - <postBuildHookScript>verify</postBuildHookScript> - <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> - <settingsFile>src/it/settings.xml</settingsFile> - </configuration> - <executions> - <execution> - <id>integration-test</id> - <goals> - <goal>install</goal> - <goal>run</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> + <build> <plugins> <plugin> @@ -171,7 +137,31 @@ </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> + <artifactId>maven-invoker-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>install</goal> + </goals> + </execution> + </executions> + <configuration> + <localRepositoryPath>target/test-classes/repositories/local</localRepositoryPath> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-failsafe-plugin</artifactId> + <version>2.19.1</version> + <executions> + <execution> + <goals> + <goal>integration-test</goal> + <goal>verify</goal> + </goals> + </execution> + </executions> <configuration> <systemPropertyVariables> <maven.home>${maven.home}</maven.home> http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties deleted file mode 100644 index 19f85bb..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/archetype.properties +++ /dev/null @@ -1 +0,0 @@ -excludePatterns=**/toexclude/** \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties deleted file mode 100644 index dac2cd9..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/invoker.properties +++ /dev/null @@ -1 +0,0 @@ -invoker.goals = clean org.apache.maven.plugins:maven-archetype-plugin:${project.version}:create-from-project -Darchetype.properties=archetype.properties http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml deleted file mode 100644 index 7a173a0..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.archetype.its</groupId> - <artifactId>create-from-project</artifactId> - <version>1.0-SNAPSHOT</version> - - <name>archetype:create-from-project It</name> -</project> http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.txt deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/file.xml deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.txt deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/resources/toexclude/file.xml deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.txt deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/main/toexclude/file.xml deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.txt deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/src/toexclude/file.xml deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.txt deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/toexclude/file.xml deleted file mode 100644 index e69de29..0000000 http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh b/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh deleted file mode 100644 index 1021842..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project-exclude-patterns/verify.bsh +++ /dev/null @@ -1,46 +0,0 @@ - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.*; - -File archetype = new File( basedir, "target/generated-sources/archetype/src/main/resources/archetype-resources/" ); - -// ARCHETYPE-513 -String[] excluded = new String[] { "/", "src/", "src/main/", "src/main/resources/" }; -for ( String exclude : excluded ) -{ - File app = new File( archetype, exclude + "toexclude" ); - if ( app.exists() ) - { - throw new Exception( app + " folder exists when it should have been excluded." ); - } -} - -String[] included = new String[] { "file.txt", "file.xml" }; -for ( String include : included ) -{ - File app = new File( archetype, "src/main/resources/" + include ); - if ( !app.isFile() ) - { - throw new Exception( app + " file does not exist when it should have been included." ); - } -} - -return true; http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project/archetype.properties ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project/archetype.properties b/archetype-testing/archetype-final/src/it/create-from-project/archetype.properties deleted file mode 100644 index 0aa486a..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project/archetype.properties +++ /dev/null @@ -1 +0,0 @@ -AppName App \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project/invoker.properties ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project/invoker.properties b/archetype-testing/archetype-final/src/it/create-from-project/invoker.properties deleted file mode 100644 index dac2cd9..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project/invoker.properties +++ /dev/null @@ -1 +0,0 @@ -invoker.goals = clean org.apache.maven.plugins:maven-archetype-plugin:${project.version}:create-from-project -Darchetype.properties=archetype.properties http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project/pom.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project/pom.xml b/archetype-testing/archetype-final/src/it/create-from-project/pom.xml deleted file mode 100644 index 7a173a0..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.archetype.its</groupId> - <artifactId>create-from-project</artifactId> - <version>1.0-SNAPSHOT</version> - - <name>archetype:create-from-project It</name> -</project> http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project/src/main/java/foo/bar/App.java ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project/src/main/java/foo/bar/App.java b/archetype-testing/archetype-final/src/it/create-from-project/src/main/java/foo/bar/App.java deleted file mode 100644 index 5d59afd..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project/src/main/java/foo/bar/App.java +++ /dev/null @@ -1,32 +0,0 @@ -package foo.bar; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/** - * Hello world! - * package foo.bar from foo/bar directory - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/create-from-project/verify.bsh ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/create-from-project/verify.bsh b/archetype-testing/archetype-final/src/it/create-from-project/verify.bsh deleted file mode 100644 index 84a5f1e..0000000 --- a/archetype-testing/archetype-final/src/it/create-from-project/verify.bsh +++ /dev/null @@ -1,38 +0,0 @@ - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.*; - -File archetype = new File( basedir, "target/generated-sources/archetype" ); - -File pom = new File( archetype, "pom.xml" ); -if ( !pom.isFile() ) -{ - throw new Exception( pom + " file is missing or not a file." ); -} - -// ARCHETYPE-462 filter file name with archetype.properties properties -File app = new File( archetype, "src/main/resources/archetype-resources/src/main/java/__AppName__.java" ); -if ( !app.isFile() ) -{ - throw new Exception( app + " file is missing or not a file." ); -} - -return true; http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/it/settings.xml ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/it/settings.xml b/archetype-testing/archetype-final/src/it/settings.xml deleted file mode 100644 index c8f77f0..0000000 --- a/archetype-testing/archetype-final/src/it/settings.xml +++ /dev/null @@ -1,55 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<settings> - <profiles> - <profile> - <id>it-repo</id> - <activation> - <activeByDefault>true</activeByDefault> - </activation> - <repositories> - <repository> - <id>local.central</id> - <url>@localRepositoryUrl@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> - <pluginRepositories> - <pluginRepository> - <id>local.central</id> - <url>@localRepositoryUrl@</url> - <releases> - <enabled>true</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </pluginRepository> - </pluginRepositories> - </profile> - </profiles> -</settings> http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java new file mode 100644 index 0000000..bd21568 --- /dev/null +++ b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java @@ -0,0 +1,511 @@ +package org.apache.maven.archetype.creator; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.maven.archetype.ArchetypeCreationRequest; +import org.apache.maven.archetype.ArchetypeCreationResult; +import org.apache.maven.archetype.common.Constants; +import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.apache.maven.plugin.testing.AbstractMojoTestCase; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.MavenProjectBuildingResult; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.PropertyUtils; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class DefaultArchetypeCreatorIT + extends AbstractMojoTestCase +{ + private List<String> filtereds; + + private List<String> languages; + + private DefaultArtifactRepository localRepository; + + protected void createFilesetArchetype( String project ) + throws Exception + { + System.out.println( ">>>>>> testCreateFilesetArchetype( \"" + project + "\" )" ); + + MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); + + File projectFile = getProjectFile( project ); + + File projectFileSample = getProjectSampleFile( project ); + + copy( projectFileSample, projectFile ); + + FileUtils.deleteDirectory( new File( projectFile.getParentFile(), "target" ) ); + + File propertyFile = getPropertiesFile( project ); + + File propertyFileSample = getPropertiesSampleFile( project ); + + copy( propertyFileSample, propertyFile ); + + Properties p = PropertyUtils.loadProperties( propertyFile ); + + MavenProject mavenProject = null; + + { + Object result = builder.buildWithDependencies( projectFile, localRepository, null ); + if ( result instanceof MavenProject ) + { // Using Maven 2.0.x / x >= 7 + mavenProject = (MavenProject) result; + } + else if ( result instanceof MavenProjectBuildingResult ) + { // Using Maven 3 + mavenProject = ( (MavenProjectBuildingResult) result ).getProject(); + } + else + { + fail( "Wrong result class" ); + } + } + + FilesetArchetypeCreator instance = + (FilesetArchetypeCreator) lookup( ArchetypeCreator.class.getName(), "fileset" ); + + languages = new ArrayList<String>(); + languages.add( "java" ); + languages.add( "aspectj" ); + languages.add( "csharp" ); + languages.add( "groovy" ); + languages.add( "resources" ); + + filtereds = new ArrayList<String>(); + filtereds.add( "java" ); + filtereds.add( "xml" ); + filtereds.add( "txt" ); + filtereds.add( "groovy" ); + filtereds.add( "cs" ); + filtereds.add( "mdo" ); + filtereds.add( "aj" ); + filtereds.add( "jsp" ); + filtereds.add( "js" ); + filtereds.add( "gsp" ); + filtereds.add( "vm" ); + filtereds.add( "html" ); + filtereds.add( "xhtml" ); + filtereds.add( "properties" ); + filtereds.add( ".classpath" ); + filtereds.add( ".project" ); + filtereds.add( "MF" ); + + ArchetypeCreationRequest request = new ArchetypeCreationRequest() + .setProject( mavenProject ) + .setPackageName( p.getProperty( Constants.PACKAGE ) ) + .setProperties( p ) + .setLanguages( languages ) + .setFiltereds( filtereds ) + .setDefaultEncoding( "UTF-8" ) + .setPartialArchetype( false ) + .setPreserveCData( false ) + .setKeepParent( false ) + .setPostPhase( "verify" ) + .setLocalRepository( localRepository ); + + ArchetypeCreationResult result = new ArchetypeCreationResult(); + + instance.createArchetype( request, result ); + + if ( result.getCause() != null ) + { + throw result.getCause(); + } + + System.out.println( "<<<<<< testCreateFilesetArchetype( \"" + project + "\" )" ); + } + + public void testChangeJavaFilenameWhenCustomPropertyEqualsClassName() + throws Exception + { + String project = "change-file-with-property"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, "src/main/java/__someProperty__.java" ); + assertExists( template ); + assertContent( template, "class ${someProperty}" ); + } + + public void testExcludePatternsMustExcludeDirectory() + throws Exception + { + String project = "exclude-patterns"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, ".toexclude/dummy.file"); + assertNotExists(template); + + File template1 = getTemplateFile( project, "nottoexclude/dummy.file" ); + assertExists(template1); + } + + public void testExcludePatternsContainingFilesSameExtension() + throws Exception + { + String project = "exclude-patterns-2"; + + createFilesetArchetype( project ); + + assertNotExists( getTemplateFile( project, ".sonar/file.txt" ) ); + assertNotExists( getTemplateFile( project, "folder/.sonar/file.txt" ) ); + assertExists( getTemplateFile( project, "folder/file.txt" ) ); + } + + public void testIncludeFileWithNoExtension() + throws Exception + { + String project = "include-file-with-no-extension"; + + createFilesetArchetype( project ); + + File template1 = getTemplateFile( project, "src/main/csharp/filewithnoextension" ); + assertExists(template1); + } + + public void testCreateFilesetArchetype1() + throws Exception + { + String project = "create-1"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, "src/main/java/subfolder1/App.java" ); + assertExists( template ); + assertContent( template, "// ${someProperty}" ); + assertContent( template, "package ${package}.subfolder1;" ); + assertNotContent( template, "${packageInPathFormat}" ); + } + + public void testCreateFilesetArchetype2() + throws Exception + { + String project = "create-2"; + + createFilesetArchetype( project ); + } + + public void testCreateFilesetArchetype3() + throws Exception + { + String project = "create-3"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, "pom.xml" ); + assertExists( template ); + assertContent( template, "${groupId}" ); + assertContent( template, "${artifactId}" ); + assertContent( template, "${version}" ); + assertContent( template, "Maven archetype Test create-3" ); + assertContent( template, "<packaging>pom</packaging>" ); + assertNotContent( template, "<parent>" ); + + template = getTemplateFile( project, "src/site/site.xml" ); + assertExists( template ); + assertContent( template, "<!-- ${packageInPathFormat}/test" ); + assertContent( template, "${someProperty} -->" ); + + template = getTemplateFile( project, "src/site/resources/site.png" ); + assertExists( template ); + assertNotContent( template, "${someProperty}" ); + + template = getTemplateFile( project, ".classpath" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + + template = getTemplateFile( project, "profiles.xml" ); + assertExists( template ); + assertContent( template, "<!-- ${packageInPathFormat}/test" ); + assertContent( template, "${someProperty} -->" ); + + template = getTemplateFile( project, "libs/pom.xml" ); + assertExists( template ); + assertContent( template, "${groupId}" ); + assertContent( template, "${artifactId}" ); + assertContent( template, "${version}" ); + assertContent( template, "Maven archetype Test create-3-libraries" ); + assertContent( template, "<packaging>pom</packaging>" ); + assertContent( template, "<parent>" ); + + template = getTemplateFile( project, "libs/prj-a/pom.xml" ); + assertExists( template ); + assertContent( template, "${groupId}" ); + assertContent( template, "${artifactId}" ); + assertContent( template, "${version}" ); + assertContent( template, "Maven archetype Test create-3-libraries-project-a" ); + assertNotContent( template, "<packaging>pom</packaging>" ); + assertContent( template, "<parent>" ); + + template = getTemplateFile( project, "libs/prj-a/src/main/mdo/descriptor.xml" ); + assertExists( template ); + assertContent( template, "<!-- ${packageInPathFormat}/test" ); + assertContent( template, "${someProperty} -->" ); + + template = getTemplateFile( project, "libs/prj-b/pom.xml" ); + assertExists( template ); + assertContent( template, "${groupId}" ); + assertContent( template, "${artifactId}" ); + assertContent( template, "${version}" ); + assertContent( template, "Maven archetype Test create-3-libraries-project-b" ); + assertNotContent( template, "<packaging>pom</packaging>" ); + assertContent( template, "<parent>" ); + + template = getTemplateFile( project, "libs/prj-b/src/main/java/test/com/Component.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}" ); + + template = getTemplateFile( project, "libs/prj-b/src/main/java/test/com/package.html" ); + assertExists( template ); + assertContent( template, "<!-- ${packageInPathFormat}/test" ); + assertContent( template, "${someProperty} -->" ); + + template = getTemplateFile( project, "libs/prj-b/src/test/java/test/common/ComponentTest.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}" ); + + template = getTemplateFile( project, "application/pom.xml" ); + assertExists( template ); + assertContent( template, "${groupId}" ); + assertContent( template, "${artifactId}" ); + assertContent( template, "${version}" ); + assertContent( template, "Maven archetype Test create-3-application" ); + assertNotContent( template, "<packaging>pom</packaging>" ); + assertContent( template, "<parent>" ); + + template = getTemplateFile( project, "application/src/main/java/Main.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/main/java/test/application/Application.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}" ); + + template = getTemplateFile( project, "application/src/main/java/test/application/audios/Application.ogg" ); + assertExists( template ); + assertNotContent( template, "${someProperty}" ); + + template = getTemplateFile( project, "application/src/main/java/test/application/images/Application.png" ); + assertExists( template ); + assertNotContent( template, "${someProperty}" ); + + template = getTemplateFile( project, "application/src/main/resources/log4j.properties" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/main/resources/META-INF/MANIFEST.MF" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/main/resources/test/application/some/Gro.groovy" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/main/resources/splash.png" ); + assertExists( template ); + assertNotContent( template, "${someProperty}" ); + + template = getTemplateFile( project, "application/src/test/java/TestAll.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/test/java/test/application/ApplicationTest.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertContent( template, "package ${package}.test.application;" ); + assertContent( template, "${packageInPathFormat}/test/application" ); + + template = getTemplateFile( project, "application/src/it-test/java/test/ItTest1.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertContent( template, "package ${package}.test;" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/it-test/java/ItTestAll.java" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + + template = getTemplateFile( project, "application/src/it-test/resources/ItTest1Result.txt" ); + assertExists( template ); + assertContent( template, "${someProperty}" ); + assertNotContent( template, "${package}" ); + assertContent( template, "${packageInPathFormat}/test" ); + } + + public void testCreateFilesetArchetype4() + throws Exception + { + String project = "create-4"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, "pom.xml" ); + assertExists( template ); + assertContent( template, "Maven archetype Test create-4 ${someProperty}" ); + assertContent( template, "<packaging>pom</packaging>" ); + + File earTemplate = getTemplateFile( project, "subModuleEAR/pom.xml" ); + assertExists( earTemplate ); + assertContent( earTemplate, "${groupId}" ); + assertContent( earTemplate, "${artifactId}" ); + assertContent( earTemplate, "${version}" ); + assertContent( earTemplate, "Maven archetype Test create-4-subModuleEAR" ); + assertContent( earTemplate, "<packaging>ear</packaging>" ); + assertContent( earTemplate, "<parent>" ); + + File warTemplate = getTemplateFile( project, "subModuleWar/pom.xml" ); + assertExists( warTemplate ); + assertContent( warTemplate, "${groupId}" ); + assertContent( warTemplate, "${artifactId}" ); + assertContent( warTemplate, "${version}" ); + assertContent( warTemplate, "Maven archetype Test create-4-subModuleWar ${someProperty}" ); + assertContent( warTemplate, "<packaging>war</packaging>" ); + assertContent( warTemplate, "<parent>" ); + } + + public void testCreateFilesetArchetype5() + throws Exception + { + String project = "create-5"; + + createFilesetArchetype( project ); + + File template = getTemplateFile( project, "dummy.file" ); + assertExists( template ); + } + + protected void tearDown() + throws Exception + { + super.tearDown(); + } + + protected void setUp() + throws Exception + { + super.setUp(); + + localRepository = new DefaultArtifactRepository( "local", + new File( getBasedir(), "target/test-classes/repositories/local" ).toURI().toString(), + new DefaultRepositoryLayout() ); + } + + private void assertContent( File template, String content ) + throws FileNotFoundException, IOException + { + String templateContent = FileUtils.fileRead( template, "UTF-8" ); + assertTrue( "File " + template + " does not contain " + content, + StringUtils.countMatches( templateContent, content ) > 0 ); + } + + private void assertExists( File file ) + { + assertTrue( "File doesn't exist: " + file.getAbsolutePath(), file.exists() ); + } + + private void assertNotContent( File template, String content ) + throws FileNotFoundException, IOException + { + String templateContent = FileUtils.fileRead( template, "UTF-8" ); + assertFalse( "File " + template + " contains " + content, + StringUtils.countMatches( templateContent, content ) > 0 ); + } + + private void copy( File in, File out ) + throws IOException, FileNotFoundException + { + assertTrue( !out.exists() || out.delete() ); + assertFalse( out.exists() ); + FileUtils.copyFile( in, out ); + assertTrue( out.exists() ); + assertTrue( in.exists() ); + } + + private File getDescriptorFile( String project ) + { + return getFile( project, "target/generated-sources/archetype/src/main/resources/META-INF/maven/archetype.xml" ); + } + + private void assertNotExists( File file ) + { + assertFalse( "File exists: " + file.getAbsolutePath(), file.exists() ); + } + + private File getFile( String project, String file ) + { + return new File( getBasedir(), "target/test-classes/projects/" + project + "/" + file ); + } + + private File getProjectFile( String project ) + { + return getFile( project, "pom.xml" ); + } + + private File getProjectSampleFile( String project ) + { + return getFile( project, "pom.xml.sample" ); + } + + private File getPropertiesFile( String project ) + { + return getFile( project, "archetype.properties" ); + } + + private File getPropertiesSampleFile( final String project ) + { + return getFile( project, "archetype.properties.sample" ); + } + + private File getTemplateFile( String project, String template ) + { + return getFile( project, "target/generated-sources/archetype/src/main/resources/archetype-resources/" + + template ); + } +} http://git-wip-us.apache.org/repos/asf/maven-archetype/blob/741f432b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java ---------------------------------------------------------------------- diff --git a/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java b/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java deleted file mode 100644 index c011498..0000000 --- a/archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java +++ /dev/null @@ -1,510 +0,0 @@ -package org.apache.maven.archetype.creator; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.maven.archetype.ArchetypeCreationRequest; -import org.apache.maven.archetype.ArchetypeCreationResult; -import org.apache.maven.archetype.common.Constants; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; -import org.apache.maven.plugin.testing.AbstractMojoTestCase; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectBuilder; -import org.apache.maven.project.MavenProjectBuildingResult; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.PropertyUtils; -import org.codehaus.plexus.util.StringUtils; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - -public class DefaultArchetypeCreatorTest - extends AbstractMojoTestCase -{ - private List<String> filtereds; - - private List<String> languages; - - private DefaultArtifactRepository localRepository; - - protected void createFilesetArchetype( String project ) - throws Exception - { - System.out.println( ">>>>>> testCreateFilesetArchetype( \"" + project + "\" )" ); - - MavenProjectBuilder builder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); - - File projectFile = getProjectFile( project ); - - File projectFileSample = getProjectSampleFile( project ); - - copy( projectFileSample, projectFile ); - - FileUtils.deleteDirectory( new File( projectFile.getParentFile(), "target" ) ); - - File propertyFile = getPropertiesFile( project ); - - File propertyFileSample = getPropertiesSampleFile( project ); - - copy( propertyFileSample, propertyFile ); - - Properties p = PropertyUtils.loadProperties( propertyFile ); - - MavenProject mavenProject = null; - - { - Object result = builder.buildWithDependencies( projectFile, localRepository, null ); - if ( result instanceof MavenProject ) - { // Using Maven 2.0.x / x >= 7 - mavenProject = (MavenProject) result; - } - else if ( result instanceof MavenProjectBuildingResult ) - { // Using Maven 3 - mavenProject = ( (MavenProjectBuildingResult) result ).getProject(); - } - else - { - fail( "Wrong result class" ); - } - } - - FilesetArchetypeCreator instance = - (FilesetArchetypeCreator) lookup( ArchetypeCreator.class.getName(), "fileset" ); - - languages = new ArrayList<String>(); - languages.add( "java" ); - languages.add( "aspectj" ); - languages.add( "csharp" ); - languages.add( "groovy" ); - languages.add( "resources" ); - - filtereds = new ArrayList<String>(); - filtereds.add( "java" ); - filtereds.add( "xml" ); - filtereds.add( "txt" ); - filtereds.add( "groovy" ); - filtereds.add( "cs" ); - filtereds.add( "mdo" ); - filtereds.add( "aj" ); - filtereds.add( "jsp" ); - filtereds.add( "js" ); - filtereds.add( "gsp" ); - filtereds.add( "vm" ); - filtereds.add( "html" ); - filtereds.add( "xhtml" ); - filtereds.add( "properties" ); - filtereds.add( ".classpath" ); - filtereds.add( ".project" ); - filtereds.add( "MF" ); - - ArchetypeCreationRequest request = new ArchetypeCreationRequest() - .setProject( mavenProject ) - .setPackageName( p.getProperty( Constants.PACKAGE ) ) - .setProperties( p ) - .setLanguages( languages ) - .setFiltereds( filtereds ) - .setDefaultEncoding( "UTF-8" ) - .setPartialArchetype( false ) - .setPreserveCData( false ) - .setKeepParent( false ) - .setPostPhase( "verify" ); - - ArchetypeCreationResult result = new ArchetypeCreationResult(); - - instance.createArchetype( request, result ); - - if ( result.getCause() != null ) - { - throw result.getCause(); - } - - System.out.println( "<<<<<< testCreateFilesetArchetype( \"" + project + "\" )" ); - } - - public void testChangeJavaFilenameWhenCustomPropertyEqualsClassName() - throws Exception - { - String project = "change-file-with-property"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, "src/main/java/__someProperty__.java" ); - assertExists( template ); - assertContent( template, "class ${someProperty}" ); - } - - public void testExcludePatternsMustExcludeDirectory() - throws Exception - { - String project = "exclude-patterns"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, ".toexclude/dummy.file"); - assertNotExists(template); - - File template1 = getTemplateFile( project, "nottoexclude/dummy.file" ); - assertExists(template1); - } - - public void testExcludePatternsContainingFilesSameExtension() - throws Exception - { - String project = "exclude-patterns-2"; - - createFilesetArchetype( project ); - - assertNotExists( getTemplateFile( project, ".sonar/file.txt" ) ); - assertNotExists( getTemplateFile( project, "folder/.sonar/file.txt" ) ); - assertExists( getTemplateFile( project, "folder/file.txt" ) ); - } - - public void testIncludeFileWithNoExtension() - throws Exception - { - String project = "include-file-with-no-extension"; - - createFilesetArchetype( project ); - - File template1 = getTemplateFile( project, "src/main/csharp/filewithnoextension" ); - assertExists(template1); - } - - public void testCreateFilesetArchetype1() - throws Exception - { - String project = "create-1"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, "src/main/java/subfolder1/App.java" ); - assertExists( template ); - assertContent( template, "// ${someProperty}" ); - assertContent( template, "package ${package}.subfolder1;" ); - assertNotContent( template, "${packageInPathFormat}" ); - } - - public void testCreateFilesetArchetype2() - throws Exception - { - String project = "create-2"; - - createFilesetArchetype( project ); - } - - public void testCreateFilesetArchetype3() - throws Exception - { - String project = "create-3"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, "pom.xml" ); - assertExists( template ); - assertContent( template, "${groupId}" ); - assertContent( template, "${artifactId}" ); - assertContent( template, "${version}" ); - assertContent( template, "Maven archetype Test create-3" ); - assertContent( template, "<packaging>pom</packaging>" ); - assertNotContent( template, "<parent>" ); - - template = getTemplateFile( project, "src/site/site.xml" ); - assertExists( template ); - assertContent( template, "<!-- ${packageInPathFormat}/test" ); - assertContent( template, "${someProperty} -->" ); - - template = getTemplateFile( project, "src/site/resources/site.png" ); - assertExists( template ); - assertNotContent( template, "${someProperty}" ); - - template = getTemplateFile( project, ".classpath" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - - template = getTemplateFile( project, "profiles.xml" ); - assertExists( template ); - assertContent( template, "<!-- ${packageInPathFormat}/test" ); - assertContent( template, "${someProperty} -->" ); - - template = getTemplateFile( project, "libs/pom.xml" ); - assertExists( template ); - assertContent( template, "${groupId}" ); - assertContent( template, "${artifactId}" ); - assertContent( template, "${version}" ); - assertContent( template, "Maven archetype Test create-3-libraries" ); - assertContent( template, "<packaging>pom</packaging>" ); - assertContent( template, "<parent>" ); - - template = getTemplateFile( project, "libs/prj-a/pom.xml" ); - assertExists( template ); - assertContent( template, "${groupId}" ); - assertContent( template, "${artifactId}" ); - assertContent( template, "${version}" ); - assertContent( template, "Maven archetype Test create-3-libraries-project-a" ); - assertNotContent( template, "<packaging>pom</packaging>" ); - assertContent( template, "<parent>" ); - - template = getTemplateFile( project, "libs/prj-a/src/main/mdo/descriptor.xml" ); - assertExists( template ); - assertContent( template, "<!-- ${packageInPathFormat}/test" ); - assertContent( template, "${someProperty} -->" ); - - template = getTemplateFile( project, "libs/prj-b/pom.xml" ); - assertExists( template ); - assertContent( template, "${groupId}" ); - assertContent( template, "${artifactId}" ); - assertContent( template, "${version}" ); - assertContent( template, "Maven archetype Test create-3-libraries-project-b" ); - assertNotContent( template, "<packaging>pom</packaging>" ); - assertContent( template, "<parent>" ); - - template = getTemplateFile( project, "libs/prj-b/src/main/java/test/com/Component.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}" ); - - template = getTemplateFile( project, "libs/prj-b/src/main/java/test/com/package.html" ); - assertExists( template ); - assertContent( template, "<!-- ${packageInPathFormat}/test" ); - assertContent( template, "${someProperty} -->" ); - - template = getTemplateFile( project, "libs/prj-b/src/test/java/test/common/ComponentTest.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}" ); - - template = getTemplateFile( project, "application/pom.xml" ); - assertExists( template ); - assertContent( template, "${groupId}" ); - assertContent( template, "${artifactId}" ); - assertContent( template, "${version}" ); - assertContent( template, "Maven archetype Test create-3-application" ); - assertNotContent( template, "<packaging>pom</packaging>" ); - assertContent( template, "<parent>" ); - - template = getTemplateFile( project, "application/src/main/java/Main.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/main/java/test/application/Application.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}" ); - - template = getTemplateFile( project, "application/src/main/java/test/application/audios/Application.ogg" ); - assertExists( template ); - assertNotContent( template, "${someProperty}" ); - - template = getTemplateFile( project, "application/src/main/java/test/application/images/Application.png" ); - assertExists( template ); - assertNotContent( template, "${someProperty}" ); - - template = getTemplateFile( project, "application/src/main/resources/log4j.properties" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/main/resources/META-INF/MANIFEST.MF" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/main/resources/test/application/some/Gro.groovy" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/main/resources/splash.png" ); - assertExists( template ); - assertNotContent( template, "${someProperty}" ); - - template = getTemplateFile( project, "application/src/test/java/TestAll.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/test/java/test/application/ApplicationTest.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertContent( template, "package ${package}.test.application;" ); - assertContent( template, "${packageInPathFormat}/test/application" ); - - template = getTemplateFile( project, "application/src/it-test/java/test/ItTest1.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertContent( template, "package ${package}.test;" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/it-test/java/ItTestAll.java" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - - template = getTemplateFile( project, "application/src/it-test/resources/ItTest1Result.txt" ); - assertExists( template ); - assertContent( template, "${someProperty}" ); - assertNotContent( template, "${package}" ); - assertContent( template, "${packageInPathFormat}/test" ); - } - - public void testCreateFilesetArchetype4() - throws Exception - { - String project = "create-4"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, "pom.xml" ); - assertExists( template ); - assertContent( template, "Maven archetype Test create-4 ${someProperty}" ); - assertContent( template, "<packaging>pom</packaging>" ); - - File earTemplate = getTemplateFile( project, "subModuleEAR/pom.xml" ); - assertExists( earTemplate ); - assertContent( earTemplate, "${groupId}" ); - assertContent( earTemplate, "${artifactId}" ); - assertContent( earTemplate, "${version}" ); - assertContent( earTemplate, "Maven archetype Test create-4-subModuleEAR" ); - assertContent( earTemplate, "<packaging>ear</packaging>" ); - assertContent( earTemplate, "<parent>" ); - - File warTemplate = getTemplateFile( project, "subModuleWar/pom.xml" ); - assertExists( warTemplate ); - assertContent( warTemplate, "${groupId}" ); - assertContent( warTemplate, "${artifactId}" ); - assertContent( warTemplate, "${version}" ); - assertContent( warTemplate, "Maven archetype Test create-4-subModuleWar ${someProperty}" ); - assertContent( warTemplate, "<packaging>war</packaging>" ); - assertContent( warTemplate, "<parent>" ); - } - - public void testCreateFilesetArchetype5() - throws Exception - { - String project = "create-5"; - - createFilesetArchetype( project ); - - File template = getTemplateFile( project, "dummy.file" ); - assertExists( template ); - } - - protected void tearDown() - throws Exception - { - super.tearDown(); - } - - protected void setUp() - throws Exception - { - super.setUp(); - - localRepository = new DefaultArtifactRepository( "local", - new File( getBasedir(), "target/test-classes/repositories/local" ).toURI().toString(), - new DefaultRepositoryLayout() ); - } - - private void assertContent( File template, String content ) - throws FileNotFoundException, IOException - { - String templateContent = FileUtils.fileRead( template, "UTF-8" ); - assertTrue( "File " + template + " does not contain " + content, - StringUtils.countMatches( templateContent, content ) > 0 ); - } - - private void assertExists( File file ) - { - assertTrue( "File doesn't exist: " + file.getAbsolutePath(), file.exists() ); - } - - private void assertNotContent( File template, String content ) - throws FileNotFoundException, IOException - { - String templateContent = FileUtils.fileRead( template, "UTF-8" ); - assertFalse( "File " + template + " contains " + content, - StringUtils.countMatches( templateContent, content ) > 0 ); - } - - private void copy( File in, File out ) - throws IOException, FileNotFoundException - { - assertTrue( !out.exists() || out.delete() ); - assertFalse( out.exists() ); - FileUtils.copyFile( in, out ); - assertTrue( out.exists() ); - assertTrue( in.exists() ); - } - - private File getDescriptorFile( String project ) - { - return getFile( project, "target/generated-sources/archetype/src/main/resources/META-INF/maven/archetype.xml" ); - } - - private void assertNotExists( File file ) - { - assertFalse( "File exists: " + file.getAbsolutePath(), file.exists() ); - } - - private File getFile( String project, String file ) - { - return new File( getBasedir(), "target/test-classes/projects/" + project + "/" + file ); - } - - private File getProjectFile( String project ) - { - return getFile( project, "pom.xml" ); - } - - private File getProjectSampleFile( String project ) - { - return getFile( project, "pom.xml.sample" ); - } - - private File getPropertiesFile( String project ) - { - return getFile( project, "archetype.properties" ); - } - - private File getPropertiesSampleFile( final String project ) - { - return getFile( project, "archetype.properties.sample" ); - } - - private File getTemplateFile( String project, String template ) - { - return getFile( project, "target/generated-sources/archetype/src/main/resources/archetype-resources/" - + template ); - } -}