You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2013/06/08 23:35:26 UTC
svn commit: r1491066 - in /maven/archetype/trunk/archetype-common/src:
main/java/org/apache/maven/archetype/creator/
test/java/org/apache/maven/archetype/creator/
test/resources/projects/create-4/
test/resources/projects/create-4/subModuleEAR/ test/res...
Author: aheritier
Date: Sat Jun 8 21:35:26 2013
New Revision: 1491066
URL: http://svn.apache.org/r1491066
Log:
ARCHETYPE-345 : archetype:create-from-project do not process modules into EAR's pom.xml
Added:
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/archetype.properties.sample
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/pom.xml.sample
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/pom.xml
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/
maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/pom.xml
Modified:
maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java?rev=1491066&r1=1491065&r2=1491066&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java Sat Jun 8 21:35:26 2013
@@ -58,6 +58,7 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
@@ -548,24 +549,7 @@ public class FilesetArchetypeCreator
{
for ( Iterator<Dependency> dependencies = pom.getDependencies().iterator(); dependencies.hasNext(); )
{
- Dependency dependency = dependencies.next();
-
- if ( dependency.getArtifactId() != null && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( dependency.getGroupId() != null )
- {
- dependency.setGroupId(
- StringUtils.replace( dependency.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}" ) );
- }
-
- dependency.setArtifactId(
- StringUtils.replace( dependency.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( dependency.getVersion() != null )
- {
- dependency.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewriteDependencyReferences(dependencies.next(), rootArtifactId, groupId);
}
}
@@ -576,24 +560,7 @@ public class FilesetArchetypeCreator
for ( Iterator<Dependency> dependencies = pom.getDependencyManagement().getDependencies().iterator();
dependencies.hasNext(); )
{
- Dependency dependency = dependencies.next();
-
- if ( dependency.getArtifactId() != null && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( dependency.getGroupId() != null )
- {
- dependency.setGroupId(
- StringUtils.replace( dependency.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}" ) );
- }
-
- dependency.setArtifactId(
- StringUtils.replace( dependency.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( dependency.getVersion() != null )
- {
- dependency.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewriteDependencyReferences(dependencies.next(), rootArtifactId, groupId);
}
}
@@ -602,24 +569,7 @@ public class FilesetArchetypeCreator
{
for ( Iterator<Plugin> plugins = pom.getBuild().getPlugins().iterator(); plugins.hasNext(); )
{
- Plugin plugin = plugins.next();
-
- if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( plugin.getGroupId() != null )
- {
- plugin.setGroupId(
- StringUtils.replace( plugin.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}" ) );
- }
-
- plugin.setArtifactId(
- StringUtils.replace( plugin.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( plugin.getVersion() != null )
- {
- plugin.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewritePluginReferences(plugins.next(), rootArtifactId, groupId);
}
}
@@ -631,24 +581,7 @@ public class FilesetArchetypeCreator
for ( Iterator<Plugin> plugins = pom.getBuild().getPluginManagement().getPlugins().iterator();
plugins.hasNext(); )
{
- Plugin plugin = plugins.next();
-
- if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( plugin.getGroupId() != null )
- {
- plugin.setGroupId(
- StringUtils.replace( plugin.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}" ) );
- }
-
- plugin.setArtifactId(
- StringUtils.replace( plugin.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( plugin.getVersion() != null )
- {
- plugin.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewritePluginReferences(plugins.next(), rootArtifactId, groupId);
}
}
@@ -665,25 +598,7 @@ public class FilesetArchetypeCreator
for ( Iterator<Dependency> dependencies = profile.getDependencies().iterator();
dependencies.hasNext(); )
{
- Dependency dependency = dependencies.next();
-
- if ( dependency.getArtifactId() != null
- && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( dependency.getGroupId() != null )
- {
- dependency.setGroupId( StringUtils.replace( dependency.getGroupId(), groupId,
- "${" + Constants.GROUP_ID + "}" ) );
- }
-
- dependency.setArtifactId( StringUtils.replace( dependency.getArtifactId(), rootArtifactId,
- "${rootArtifactId}" ) );
-
- if ( dependency.getVersion() != null )
- {
- dependency.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewriteDependencyReferences(dependencies.next(), rootArtifactId, groupId);
}
}
@@ -695,25 +610,7 @@ public class FilesetArchetypeCreator
for ( Iterator<Dependency> dependencies =
profile.getDependencyManagement().getDependencies().iterator(); dependencies.hasNext(); )
{
- Dependency dependency = dependencies.next();
-
- if ( dependency.getArtifactId() != null
- && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( dependency.getGroupId() != null )
- {
- dependency.setGroupId( StringUtils.replace( dependency.getGroupId(), groupId,
- "${" + Constants.GROUP_ID + "}" ) );
- }
-
- dependency.setArtifactId( StringUtils.replace( dependency.getArtifactId(), rootArtifactId,
- "${rootArtifactId}" ) );
-
- if ( dependency.getVersion() != null )
- {
- dependency.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewriteDependencyReferences(dependencies.next(), rootArtifactId, groupId);
}
}
@@ -723,24 +620,7 @@ public class FilesetArchetypeCreator
{
for ( Iterator<Plugin> plugins = profile.getBuild().getPlugins().iterator(); plugins.hasNext(); )
{
- Plugin plugin = plugins.next();
-
- if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( plugin.getGroupId() != null )
- {
- plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
- "${" + Constants.GROUP_ID + "}" ) );
- }
-
- plugin.setArtifactId(
- StringUtils.replace( plugin.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( plugin.getVersion() != null )
- {
- plugin.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewritePluginReferences(plugins.next(), rootArtifactId, groupId);
}
}
@@ -752,30 +632,95 @@ public class FilesetArchetypeCreator
for ( Iterator<Plugin> plugins = profile.getBuild().getPluginManagement().getPlugins().iterator();
plugins.hasNext(); )
{
- Plugin plugin = plugins.next();
-
- if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
- {
- if ( plugin.getGroupId() != null )
- {
- plugin.setGroupId( StringUtils.replace( plugin.getGroupId(), groupId,
- "${" + Constants.GROUP_ID + "}" ) );
- }
-
- plugin.setArtifactId(
- StringUtils.replace( plugin.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
-
- if ( plugin.getVersion() != null )
- {
- plugin.setVersion( "${" + Constants.VERSION + "}" );
- }
- }
+ rewritePluginReferences(plugins.next(), rootArtifactId, groupId);
}
}
}
}
}
+ private void rewriteDependencyReferences(Dependency dependency, String rootArtifactId, String groupId) {
+ if ( dependency.getArtifactId() != null && dependency.getArtifactId().indexOf( rootArtifactId ) >= 0 )
+ {
+ if ( dependency.getGroupId() != null )
+ {
+ dependency.setGroupId(
+ StringUtils.replace(dependency.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}") );
+ }
+
+ dependency.setArtifactId(
+ StringUtils.replace( dependency.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
+
+ if ( dependency.getVersion() != null )
+ {
+ dependency.setVersion( "${" + Constants.VERSION + "}" );
+ }
+ }
+ }
+
+ private void rewritePluginReferences(Plugin plugin, String rootArtifactId, String groupId) {
+ if ( plugin.getArtifactId() != null && plugin.getArtifactId().indexOf( rootArtifactId ) >= 0 )
+ {
+ if ( plugin.getGroupId() != null )
+ {
+ plugin.setGroupId(
+ StringUtils.replace(plugin.getGroupId(), groupId, "${" + Constants.GROUP_ID + "}") );
+ }
+
+ plugin.setArtifactId(
+ StringUtils.replace( plugin.getArtifactId(), rootArtifactId, "${rootArtifactId}" ) );
+
+ if ( plugin.getVersion() != null )
+ {
+ plugin.setVersion( "${" + Constants.VERSION + "}" );
+ }
+ }
+
+ if ( plugin.getArtifactId() != null && "maven-ear-plugin".equals( plugin.getArtifactId() ) )
+ {
+ rewriteEARPluginReferences(plugin, rootArtifactId, groupId);
+ }
+ }
+
+ private void rewriteEARPluginReferences(Plugin plugin, String rootArtifactId, String groupId) {
+ Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
+ Xpp3Dom[] modules = configuration.getChild("modules").getChildren();
+ for ( int i = 0; i < modules.length; i++ )
+ {
+ Xpp3Dom module = modules[i];
+ Xpp3Dom moduleGroupId = module.getChild( "groupId" );
+ Xpp3Dom moduleArtifactId = module.getChild( "artifactId" );
+ Xpp3Dom moduleBundleFileName = module.getChild( "bundleFileName" );
+ Xpp3Dom moduleModuleId = module.getChild( "moduleId" );
+ Xpp3Dom moduleContextRoot = module.getChild( "contextRoot" );
+
+ if (moduleGroupId != null)
+ {
+ moduleGroupId.setValue( StringUtils.replace(moduleGroupId.getValue(), groupId, "${" + Constants.GROUP_ID + "}") );
+ }
+
+ if (moduleArtifactId != null)
+ {
+ moduleArtifactId.setValue( StringUtils.replace( moduleArtifactId.getValue(), rootArtifactId, "${rootArtifactId}" ) );
+ }
+
+ if (moduleBundleFileName != null)
+ {
+ moduleBundleFileName.setValue( StringUtils.replace( moduleBundleFileName.getValue(), rootArtifactId, "${rootArtifactId}" ) );
+ }
+
+ if (moduleModuleId != null)
+ {
+ moduleModuleId.setValue( StringUtils.replace( moduleModuleId.getValue(), rootArtifactId, "${rootArtifactId}" ) );
+ }
+
+ if (moduleContextRoot != null)
+ {
+ moduleContextRoot.setValue( StringUtils.replace( moduleContextRoot.getValue(), rootArtifactId, "${rootArtifactId}" ) );
+ }
+ }
+ }
+
private void setArtifactId( Properties properties, String artifactId )
{
properties.setProperty( Constants.ARTIFACT_ID, artifactId );
Modified: maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java?rev=1491066&r1=1491065&r2=1491066&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java (original)
+++ maven/archetype/trunk/archetype-common/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorTest.java Sat Jun 8 21:35:26 2013
@@ -329,6 +329,23 @@ public class DefaultArchetypeCreatorTest
assertContent( template, "${packageInPathFormat}/test" );
}
+ public void testCreateFilesetArchetype4()
+ throws Exception
+ {
+ String project = "create-4";
+
+ createFilesetArchetype( project );
+
+ File template = getTemplateFile( project, "subModuleEAR/pom.xml" );
+ assertExists( template );
+ assertContent( template, "${groupId}" );
+ assertContent( template, "${artifactId}" );
+ assertContent( template, "${version}" );
+ assertContent( template, "Maven archetype Test create-4-subModuleEAR" );
+ assertContent( template, "<packaging>ear</packaging>" );
+ assertContent( template, "<parent>" );
+ }
+
protected void tearDown()
throws Exception
{
Added: maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/archetype.properties.sample
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/archetype.properties.sample?rev=1491066&view=auto
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/archetype.properties.sample (added)
+++ maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/archetype.properties.sample Sat Jun 8 21:35:26 2013
@@ -0,0 +1,8 @@
+archetype.groupId=org.codehaus.mojo.archetypes
+archetype.artifactId=maven-archetype-test
+archetype.version=1.0
+groupId=org.apache.maven.archetype.test
+artifactId=test-create-4
+version=1.0-SNAPSHOT
+package=org.apache.maven.archetype
+someProperty=A String to search for
\ No newline at end of file
Added: maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/pom.xml.sample
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/pom.xml.sample?rev=1491066&view=auto
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/pom.xml.sample (added)
+++ maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/pom.xml.sample Sat Jun 8 21:35:26 2013
@@ -0,0 +1,38 @@
+<?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.
+ -->
+<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.archetype.test</groupId>
+ <artifactId>test-create-4</artifactId>
+ <version>1.0-SNAPSHOT</version>
+
+ <name>Maven archetype Test create-4</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>subModuleWar</module>
+ <module>subModuleEAR</module>
+ </modules>
+</project>
Added: maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/pom.xml
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/pom.xml?rev=1491066&view=auto
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/pom.xml (added)
+++ maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleEAR/pom.xml Sat Jun 8 21:35:26 2013
@@ -0,0 +1,65 @@
+<?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.
+ -->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.archetype.test</groupId>
+ <artifactId>test-create-4-ear</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>test-create-4-ear</artifactId>
+ <name>Maven archetype Test create-4-subModuleEAR</name>
+ <packaging>ear</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.archetype.test</groupId>
+ <artifactId>test-create-4-war</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <type>war</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-ear-plugin</artifactId>
+ <configuration>
+ <modules>
+ <webModule>
+ <groupId>org.apache.maven.archetype.test</groupId>
+ <artifactId>test-create-4-war</artifactId>
+ <contextRoot>test-create-4</contextRoot>
+ <bundleFileName>test-create-4.war</bundleFileName>
+ </webModule>
+ </modules>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/pom.xml
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/pom.xml?rev=1491066&view=auto
==============================================================================
--- maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/pom.xml (added)
+++ maven/archetype/trunk/archetype-common/src/test/resources/projects/create-4/subModuleWar/pom.xml Sat Jun 8 21:35:26 2013
@@ -0,0 +1,37 @@
+<?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.
+ -->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.archetype.test</groupId>
+ <artifactId>test-create-4-war</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>test-create-4-war</artifactId>
+ <name>Maven archetype Test create-4-subModuleWar</name>
+ <packaging>war</packaging>
+
+</project>