Author: snicoll Date: Sun Sep 5 09:49:46 2010 New Revision: 992748 URL: http://svn.apache.org/viewvc?rev=992748&view=rev Log: MEAR-116: Harmonized build output be it invoked from the reactor or from the module directly, based on an initial patch made by Benjamin Bentmann.
Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactHandlerTestStub.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/AbstractFileNameMappingTest.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FullFileNameMappingTest.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/StandardFileNameMappingTest.java Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactTestStub.java Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java?rev=992748&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/AbstractFileNameMapping.java Sun Sep 5 09:49:46 2010 @@ -0,0 +1,61 @@ +package org.apache.maven.plugin.ear.output; + +import org.apache.maven.artifact.Artifact; + +/* + * 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. + */ + +/** + * A base class used to generate the standard name of an + * artifact instead of relying on the (potentially) wrong + * file name provided by {...@link org.apache.maven.artifact.Artifact#getFile()}. + * + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public abstract class AbstractFileNameMapping + implements FileNameMapping +{ + + + /** + * Generates a standard file name for the specified {...@link Artifact}. + * <p/> + * Returns something like <tt>artifactId-version[-classifier].extension</tt>. + * + * @param a the artifact to generate a filename from + * @return the filename, with a standard format + */ + protected String generateFileName( final Artifact a ) + { + final String extension = a.getArtifactHandler().getExtension(); + + final StringBuilder buffer = new StringBuilder( 128 ); + buffer.append( a.getArtifactId() ).append( '-' ).append( a.getBaseVersion() ); + if ( a.hasClassifier() ) + { + buffer.append( '-' ).append( a.getClassifier() ); + } + if ( extension != null && extension.length() > 0 ) + { + buffer.append( '.' ).append( extension ); + } + + return buffer.toString(); + } +} Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java?rev=992748&r1=992747&r2=992748&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/FullFileNameMapping.java Sun Sep 5 09:49:46 2010 @@ -29,12 +29,12 @@ import org.apache.maven.artifact.Artifac * @version $Id$ */ public class FullFileNameMapping - implements FileNameMapping + extends AbstractFileNameMapping { public String mapFileName( final Artifact a ) { final String dashedGroupId = a.getGroupId().replace( '.', '-' ); - return dashedGroupId + "-" + a.getFile().getName(); + return dashedGroupId + "-" + generateFileName( a ); } } Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java?rev=992748&r1=992747&r2=992748&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/output/StandardFileNameMapping.java Sun Sep 5 09:49:46 2010 @@ -29,11 +29,12 @@ import org.apache.maven.artifact.Artifac * @version $Id$ */ public class StandardFileNameMapping - implements FileNameMapping + extends AbstractFileNameMapping { public String mapFileName( final Artifact a ) { - return a.getFile().getName(); + return generateFileName( a ); } + } Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java?rev=992748&r1=992747&r2=992748&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java Sun Sep 5 09:49:46 2010 @@ -120,6 +120,4 @@ public abstract class AbstractEarTest return createArtifact( artifactId, type, null ); } - - } Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactHandlerTestStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactHandlerTestStub.java?rev=992748&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactHandlerTestStub.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactHandlerTestStub.java Sun Sep 5 09:49:46 2010 @@ -0,0 +1,73 @@ +package org.apache.maven.plugin.ear; + +/* + * 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.artifact.handler.ArtifactHandler; + +/** + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public class ArtifactHandlerTestStub + implements ArtifactHandler +{ + + private final String extension; + + public ArtifactHandlerTestStub( String extension ) + { + this.extension = extension; + } + + public String getExtension() + { + return extension; + } + + + public String getDirectory() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getClassifier() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getPackaging() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isIncludesDependencies() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getLanguage() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isAddedToClasspath() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } +} Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactTestStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactTestStub.java?rev=992748&r1=992747&r2=992748&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactTestStub.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/ArtifactTestStub.java Sun Sep 5 09:49:46 2010 @@ -42,6 +42,8 @@ public class ArtifactTestStub implements Artifact { + public static final String DEFAULT_VERSION = "1.0"; + private final String groupId; private final String artifactId; @@ -50,13 +52,21 @@ public class ArtifactTestStub private final String classifier; + private String version; - public ArtifactTestStub( String groupId, String artifactId, String type, String classifier ) + + public ArtifactTestStub( String groupId, String artifactId, String type, String classifier, String version ) { this.groupId = groupId; this.artifactId = artifactId; this.type = type; this.classifier = classifier; + this.version = version; + } + + public ArtifactTestStub( String groupId, String artifactId, String type, String classifier ) + { + this( groupId, artifactId, type, classifier, DEFAULT_VERSION ); } @@ -72,12 +82,12 @@ public class ArtifactTestStub public String getVersion() { - throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + return version; } - public void setVersion( String string ) + public void setVersion( String version ) { - throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + this.version = version; } public String getScope() @@ -112,7 +122,7 @@ public class ArtifactTestStub public String getBaseVersion() { - throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + return version; } public void setBaseVersion( String string ) @@ -177,7 +187,7 @@ public class ArtifactTestStub public ArtifactHandler getArtifactHandler() { - throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + return new ArtifactHandlerTestStub( "jar" ); } public List getDependencyTrail() Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/AbstractFileNameMappingTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/AbstractFileNameMappingTest.java?rev=992748&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/AbstractFileNameMappingTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/AbstractFileNameMappingTest.java Sun Sep 5 09:49:46 2010 @@ -0,0 +1,56 @@ +package org.apache.maven.plugin.ear.output; + +/* + * 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.artifact.Artifact; +import org.apache.maven.plugin.ear.AbstractEarTest; +import org.apache.maven.plugin.ear.ArtifactTestStub; + +/** + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public abstract class AbstractFileNameMappingTest + extends AbstractEarTest +{ + + + protected Artifact createArtifactWithGroupId( String groupId, String artifactId, String version, String type, + String classifier ) + { + return new ArtifactTestStub( groupId, artifactId, type, classifier, version ); + } + + + protected Artifact createArtifactWithGroupId( String groupId, String artifactId, String version, String type ) + { + return createArtifactWithGroupId( groupId, artifactId, version, type, null ); + } + + + protected Artifact createArtifact( String artifactId, String version, String type, String classifier ) + { + return new ArtifactTestStub( DEFAULT_GROUPID, artifactId, type, classifier, version ); + } + + protected Artifact createArtifact( String artifactId, String version, String type ) + { + return createArtifact( artifactId, version, type, null ); + } +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FullFileNameMappingTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FullFileNameMappingTest.java?rev=992748&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FullFileNameMappingTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/FullFileNameMappingTest.java Sun Sep 5 09:49:46 2010 @@ -0,0 +1,43 @@ +package org.apache.maven.plugin.ear.output; + +/* + * 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. + */ + +/** + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public class FullFileNameMappingTest + extends AbstractFileNameMappingTest +{ + + + private final FullFileNameMapping instance = new FullFileNameMapping(); + + public void testSimpleArtifact() + { + assertEquals( "org-apache-foo-1.0-SNAPSHOT.jar", + instance.mapFileName( createArtifactWithGroupId( "org.apache", "foo", "1.0-SNAPSHOT", "jar" ) ) ); + } + + public void testArtifactWithClassifier() + { + assertEquals( "org-apache-foo-1.0-SNAPSHOT-sources.jar", instance.mapFileName( + createArtifactWithGroupId( "org.apache", "foo", "1.0-SNAPSHOT", "jar", "sources" ) ) ); + } +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/StandardFileNameMappingTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/StandardFileNameMappingTest.java?rev=992748&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/StandardFileNameMappingTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/output/StandardFileNameMappingTest.java Sun Sep 5 09:49:46 2010 @@ -0,0 +1,42 @@ +package org.apache.maven.plugin.ear.output; + +/* + * 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. + */ + +/** + * @author <a href="snic...@apache.org">Stephane Nicoll</a> + */ +public class StandardFileNameMappingTest + extends AbstractFileNameMappingTest +{ + + private final StandardFileNameMapping instance = new StandardFileNameMapping(); + + public void testSimpleArtifact() + { + assertEquals( "foo-1.0-SNAPSHOT.jar", instance.mapFileName( createArtifact( "foo", "1.0-SNAPSHOT", "jar" ) ) ); + } + + public void testArtifactWithClassifier() + { + assertEquals( "foo-1.0-SNAPSHOT-sources.jar", + instance.mapFileName( createArtifact( "foo", "1.0-SNAPSHOT", "jar", "sources" ) ) ); + } + +}