You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sn...@apache.org on 2009/04/25 09:55:51 UTC
svn commit: r768494 - in /maven/plugins/trunk/maven-ear-plugin/src:
main/java/org/apache/maven/plugin/ear/
main/java/org/apache/maven/plugin/ear/util/
test/java/org/apache/maven/plugin/ear/
test/java/org/apache/maven/plugin/ear/util/
Author: snicoll
Date: Sat Apr 25 07:55:50 2009
New Revision: 768494
URL: http://svn.apache.org/viewvc?rev=768494&view=rev
Log:
MEAR-75: Class-Path entry in manifest is now generated according what EarModule#getUri() returns.
Added:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.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/util/EarMavenArchiverTest.java
Modified:
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java
Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java?rev=768494&r1=768493&r2=768494&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/AbstractEarModule.java Sat Apr 25 07:55:50 2009
@@ -308,4 +308,14 @@
return second == null;
}
}
+
+ /**
+ * Sets the URI of the module explicitely for testing purposes.
+ *
+ * @param uri the uri
+ */
+ void setUri(String uri) {
+ this.uri = uri;
+
+ }
}
Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java?rev=768494&r1=768493&r2=768494&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Sat Apr 25 07:55:50 2009
@@ -23,6 +23,7 @@
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.ear.util.EarMavenArchiver;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.filtering.MavenFileFilter;
import org.apache.maven.shared.filtering.MavenResourcesExecution;
@@ -392,7 +393,7 @@
try
{
File earFile = getEarFile( outputDirectory, finalName, classifier );
- MavenArchiver archiver = new MavenArchiver();
+ final MavenArchiver archiver = new EarMavenArchiver(getModules());
final JarArchiver jarArchiver = getJarArchiver();
getLog().debug( "Jar archiver implementation[" + jarArchiver.getClass().getName() + "]" );
archiver.setArchiver( jarArchiver );
Added: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java?rev=768494&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/util/EarMavenArchiver.java Sat Apr 25 07:55:50 2009
@@ -0,0 +1,131 @@
+package org.apache.maven.plugin.ear.util;
+
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.ear.EarModule;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.archiver.jar.Manifest;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/*
+ * 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 custom {@link MavenArchiver} implementation that takes care
+ * of setting the right classpath value according to the actual
+ * path of bundled files.
+ *
+ * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EarMavenArchiver
+ extends MavenArchiver
+{
+ public static final String CLASS_PATH_KEY = "Class-Path";
+
+ private final List earModules;
+
+
+ /**
+ * Creates an instance with the ear modules that will be packaged
+ * in the EAR archive.
+ *
+ * @param earModules the intitialized list of ear modules
+ */
+ public EarMavenArchiver( List earModules )
+ {
+ this.earModules = earModules;
+ }
+
+ public Manifest getManifest( MavenProject project, MavenArchiveConfiguration config )
+ throws ManifestException, DependencyResolutionRequiredException
+ {
+ final Manifest manifest = super.getManifest( project, config );
+ if ( config.getManifest().isAddClasspath() )
+ {
+ String earManifestClassPathEntry = generateClassPathEntry( config.getManifest().getClasspathPrefix() );
+ // Class-path can be customized. Let's make sure we don't overwrite this
+ // with our custom change!
+ final String userSuppliedClassPathEntry = getUserSuppliedClassPathEntry( config );
+ if ( userSuppliedClassPathEntry != null )
+ {
+ earManifestClassPathEntry = userSuppliedClassPathEntry + " " + earManifestClassPathEntry;
+ }
+
+ // Overwrite the existing one, if any
+ final Manifest.Attribute classPathAttr = manifest.getMainSection().getAttribute( CLASS_PATH_KEY );
+ if ( classPathAttr != null )
+ {
+ classPathAttr.setValue( earManifestClassPathEntry );
+ }
+ else
+ {
+ final Manifest.Attribute attr = new Manifest.Attribute( CLASS_PATH_KEY, earManifestClassPathEntry );
+ manifest.addConfiguredAttribute( attr );
+ }
+ }
+ return manifest;
+ }
+
+ /**
+ * Generates the <tt>Class-Path</tt> entry of the manifest according to
+ * the list of ear modules.
+ *
+ * @param classPathPrefix the classpath prefix to use
+ * @return the <tt>Class-Path</tt> entry
+ */
+ protected String generateClassPathEntry( String classPathPrefix )
+ {
+ final StringBuffer classpath = new StringBuffer();
+ final Iterator it = earModules.iterator();
+ while ( it.hasNext() )
+ {
+ final EarModule earModule = (EarModule) it.next();
+ if ( !earModule.isExcluded() )
+ {
+ classpath.append( classPathPrefix ).append( earModule.getUri() ).append( " " );
+ }
+ }
+ return classpath.toString().trim();
+ }
+
+ protected String getUserSuppliedClassPathEntry( MavenArchiveConfiguration config )
+ {
+ if ( config.getManifestEntries() != null )
+ {
+ final Set keys = config.getManifestEntries().keySet();
+ for ( Iterator iter = keys.iterator(); iter.hasNext(); )
+ {
+ String key = (String) iter.next();
+ String value = (String) config.getManifestEntries().get( key );
+ if ( "Class-Path".equals( key ) && value != null )
+ {
+ return value;
+
+ }
+
+ }
+ }
+ return null;
+ }
+}
Added: 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=768494&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/AbstractEarTest.java Sat Apr 25 07:55:50 2009
@@ -0,0 +1,125 @@
+package org.apache.maven.plugin.ear;
+
+import junit.framework.TestCase;
+import org.apache.maven.artifact.Artifact;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+/*
+* 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="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public abstract class AbstractEarTest
+ extends TestCase
+{
+
+ public static final String DEFAULT_GROUPID = "eartest";
+
+ public static final String DEFAULT_TYPE = "jar";
+
+
+ protected void setUri( EarModule module, String uri )
+ {
+ ( (AbstractEarModule) module ).setUri( uri );
+ }
+
+
+ protected Set createArtifacts( String[] artifactsId )
+ {
+ return createArtifacts( artifactsId, null );
+ }
+
+ protected Set createArtifacts( String[] artifactsId, String[] types )
+ {
+ return createArtifacts( artifactsId, types, null );
+ }
+
+ protected Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId )
+ {
+ return createArtifacts( artifactsId, types, groupsId, null );
+ }
+
+ protected Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId, String[] classifiers )
+ {
+ Set result = new TreeSet();
+ if ( artifactsId == null || artifactsId.length == 0 )
+ {
+ return result;
+ }
+ for ( int i = 0; i < artifactsId.length; i++ )
+ {
+ String artifactId = artifactsId[i];
+ String type = getData( types, i, DEFAULT_TYPE );
+ String groupId = getData( groupsId, i, DEFAULT_GROUPID );
+ String classifier = getData( classifiers, i, null );
+ result.add( new ArtifactTestStub( groupId, artifactId, type, classifier ) );
+
+ }
+ return result;
+ }
+
+ protected String getData( String[] data, int i, String defaultValue )
+ {
+ if ( data == null || data[i] == null )
+ {
+ return defaultValue;
+ }
+ else
+ {
+ return data[i];
+
+ }
+ }
+
+ protected String getDefaultValue( String t, String defaultValue )
+ {
+ if ( t == null )
+ {
+ return defaultValue;
+ }
+ else
+ {
+ return t;
+ }
+ }
+
+ protected Artifact createArtifact( String artifactId, String type, String groupId, String classifier )
+ {
+ return new ArtifactTestStub( getDefaultValue( groupId, DEFAULT_GROUPID ), artifactId,
+ getDefaultValue( type, DEFAULT_TYPE ), classifier );
+ }
+
+
+ protected Artifact createArtifact( String artifactId, String type, String groupId )
+ {
+ return createArtifact( artifactId, type, groupId, null );
+
+ }
+
+ protected Artifact createArtifact( String artifactId, String type )
+ {
+ return createArtifact( artifactId, type, null );
+
+ }
+
+
+}
Modified: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java?rev=768494&r1=768493&r2=768494&view=diff
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java (original)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/ArtifactRepositoryTest.java Sat Apr 25 07:55:50 2009
@@ -19,18 +19,14 @@
* under the License.
*/
-import junit.framework.TestCase;
-import org.apache.maven.plugin.ear.ArtifactTestStub;
-
-import java.util.Set;
-import java.util.TreeSet;
+import org.apache.maven.plugin.ear.AbstractEarTest;
/**
* @author <a href="snicoll@apache.org">Stephane Nicoll</a>
* @version $Id$
*/
public class ArtifactRepositoryTest
- extends TestCase
+ extends AbstractEarTest
{
@@ -41,9 +37,6 @@
ArtifactTypeMappingService.getInstance().configure( null );
}
- public static final String DEFAULT_GROUPID = "eartest";
-
- public static final String DEFAULT_TYPE = "jar";
public static final String MAIN_ARTIFACT_ID = "none";
@@ -74,9 +67,9 @@
public void testRepositoryWithMultipleClassifiedArtifacts()
{
- ArtifactRepository repo = new ArtifactRepository( createArtifacts(
- new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
- new String[]{"class1", "class2", "class3"} ), MAIN_ARTIFACT_ID );
+ ArtifactRepository repo = new ArtifactRepository(
+ createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
+ new String[]{"class1", "class2", "class3"} ), MAIN_ARTIFACT_ID );
assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
@@ -87,9 +80,9 @@
public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()
{
- ArtifactRepository repo = new ArtifactRepository( createArtifacts(
- new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
- new String[]{"class1", "class2", null} ), MAIN_ARTIFACT_ID );
+ ArtifactRepository repo = new ArtifactRepository(
+ createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
+ new String[]{"class1", "class2", null} ), MAIN_ARTIFACT_ID );
assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
@@ -97,54 +90,4 @@
assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", MAIN_ARTIFACT_ID ) );
assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
}
-
-
- private Set createArtifacts( String[] artifactsId )
- {
- return createArtifacts( artifactsId, null );
- }
-
- private Set createArtifacts( String[] artifactsId, String[] types )
- {
- return createArtifacts( artifactsId, types, null );
- }
-
- private Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId )
- {
- return createArtifacts( artifactsId, types, groupsId, null );
- }
-
- private Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId, String[] classifiers )
- {
- Set result = new TreeSet();
- if ( artifactsId == null || artifactsId.length == 0 )
- {
- return result;
- }
- for ( int i = 0; i < artifactsId.length; i++ )
- {
- String artifactId = artifactsId[i];
- String type = getData( types, i, DEFAULT_TYPE );
- String groupId = getData( groupsId, i, DEFAULT_GROUPID );
- String classifier = getData( classifiers, i, null );
- result.add( new ArtifactTestStub( groupId, artifactId, type, classifier ) );
-
- }
- return result;
- }
-
- private String getData( String[] data, int i, String defaultValue )
- {
- if ( data == null || data[i] == null )
- {
- return defaultValue;
- }
- else
- {
- return data[i];
-
- }
- }
-
-
}
Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/EarMavenArchiverTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/EarMavenArchiverTest.java?rev=768494&view=auto
==============================================================================
--- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/EarMavenArchiverTest.java (added)
+++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugin/ear/util/EarMavenArchiverTest.java Sat Apr 25 07:55:50 2009
@@ -0,0 +1,77 @@
+package org.apache.maven.plugin.ear.util;
+
+import org.apache.maven.plugin.ear.AbstractEarTest;
+import org.apache.maven.plugin.ear.EarModule;
+import org.apache.maven.plugin.ear.EjbModule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/*
+ * 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="snicoll@apache.org">Stephane Nicoll</a>
+ */
+public class EarMavenArchiverTest
+ extends AbstractEarTest
+{
+
+
+ public void testSimpleEjbModule()
+ {
+ final List modules = new ArrayList();
+ final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) );
+ setUri( module, "foo-1.0.jar" );
+ modules.add( module );
+
+ final EarMavenArchiver archiver = new EarMavenArchiver( modules );
+ assertEquals( "foo-1.0.jar", archiver.generateClassPathEntry( "" ));
+
+ }
+
+ public void testSimpleJarModuleWithCustomBundleDir()
+ {
+ final List modules = new ArrayList();
+ final EarModule module = new EjbModule( createArtifact( "foo", "jar" ) );
+ setUri( module, "libs/foo-1.0.jar" );
+ modules.add( module );
+
+ final EarMavenArchiver archiver = new EarMavenArchiver( modules );
+ assertEquals( "libs/foo-1.0.jar", archiver.generateClassPathEntry( "" ));
+
+ }
+
+ public void testTwoModules()
+ {
+ final List modules = new ArrayList();
+ final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) );
+ setUri( module, "foo-1.0.jar" );
+ modules.add( module );
+
+ final EarModule module2 = new EjbModule( createArtifact( "bar", "war" ) );
+ setUri( module2, "bar-2.0.1.war" );
+ modules.add( module2 );
+
+ final EarMavenArchiver archiver = new EarMavenArchiver( modules );
+ assertEquals( "foo-1.0.jar bar-2.0.1.war", archiver.generateClassPathEntry( "" ));
+
+ }
+
+}