Author: khmarbaise Date: Fri Dec 12 20:18:48 2014 New Revision: 1645058 URL: http://svn.apache.org/r1645058 Log: [MEAR-182] Skinny WAR's - Skip Class-Path Modification in Manifest Applied patch of Mario Däpp with slight enhancement by using the option skipClassPathModification which is defined to true by default to keep backward compatibility.
Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/pom.xml maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/pom.xml maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/verify.bsh maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/pom.xml maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugin/ear/EarMojo.java Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/pom.xml?rev=1645058&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/ear-module/pom.xml Fri Dec 12 20:18:48 2014 @@ -0,0 +1,58 @@ +<?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> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.ear.skinnywars</groupId> + <artifactId>ear-module</artifactId> + <version>1.0</version> + <packaging>ear</packaging> + + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.5</version> + </dependency> + <dependency> + <groupId>org.apache.maven.its.ear.skinnywars</groupId> + <artifactId>war-module</artifactId> + <version>1.0</version> + <type>war</type> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-ear-plugin</artifactId> + <version>@project.version@</version> + <configuration> + <version>5</version> + <defaultLibBundleDir>lib</defaultLibBundleDir> + <skinnyWars>true</skinnyWars> + </configuration> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/pom.xml?rev=1645058&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/pom.xml Fri Dec 12 20:18:48 2014 @@ -0,0 +1,36 @@ +<?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> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.ear.skinnywars</groupId> + <artifactId>pom</artifactId> + <version>1.0</version> + <packaging>pom</packaging> + + <description>Test Skinny WAR generation</description> + + <modules> + <module>ear-module</module> + <module>war-module</module> + </modules> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/verify.bsh?rev=1645058&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/verify.bsh (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/verify.bsh Fri Dec 12 20:18:48 2014 @@ -0,0 +1,94 @@ +/* + * 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.*; +import java.util.*; +import java.util.jar.*; +import java.util.regex.*; + +File jarFile = new File( basedir, "ear-module/target/ear-module-1.0/war-module-1.0.war" ); +System.out.println( "Checking for existence of " + jarFile ); +if ( !jarFile.isFile() ) +{ + throw new IllegalStateException( "Missing file: " + jarFile ); +} + +JarFile jar = new JarFile( jarFile ); + +String[] includedEntries = { + "WEB-INF/web.xml", + "META-INF/MANIFEST.MF" +}; +for ( String included : includedEntries ) +{ + System.out.println( "Checking for included archive entry " + included ); + if ( jar.getEntry( included ) == null ) + { + throw new IllegalStateException( "Missing archive entry: " + included ); + } +} + +Manifest manifest = jar.getManifest(); +String manifestClassPath = manifest.getMainAttributes().getValue("Class-Path"); +if ( manifestClassPath != null && manifestClassPath.equals("lib/commons-lang-2.5.jar") ) +{ + throw new IllegalStateException( "Superfluous entry in war MANIFEST.MF: commons-lang-2.5.jar"); +} + +String[] excludedEntries = { + "WEB-INF/lib/commons-lang-2.5.jar" +}; +for ( String excluded : excludedEntries ) +{ + System.out.println( "Checking for excluded artifact " + excluded ); + if ( jar.getEntry( excluded ) != null ) + { + throw new IllegalStateException( "Archive entry should be excluded: " + excluded ); + } +} + +jar.close(); + + +File jarFile = new File( basedir, "war-module/target/war-module-1.0.war" ); +System.out.println( "Checking for existence of " + jarFile ); +if ( !jarFile.isFile() ) +{ + throw new IllegalStateException( "Missing file: " + jarFile ); +} + +JarFile jar = new JarFile( jarFile ); + +String[] includedEntries = { + "WEB-INF/web.xml", + "META-INF/MANIFEST.MF", + "WEB-INF/lib/commons-lang-2.5.jar" +}; +for ( String included : includedEntries ) +{ + System.out.println( "Checking for included archive entry " + included ); + if ( jar.getEntry( included ) == null ) + { + throw new IllegalStateException( "Missing archive entry: " + included ); + } +} + +jar.close(); + +return true; Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/pom.xml?rev=1645058&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/pom.xml Fri Dec 12 20:18:48 2014 @@ -0,0 +1,47 @@ +<?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> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.ear.skinnywars</groupId> + <artifactId>war-module</artifactId> + <version>1.0</version> + <packaging>war</packaging> + + <dependencies> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.5</version> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + <version>2.5</version> + </plugin> + </plugins> + </build> +</project> Added: maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml?rev=1645058&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/skinny-wars-javaee5/war-module/src/main/webapp/WEB-INF/web.xml Fri Dec 12 20:18:48 2014 @@ -0,0 +1,23 @@ +<?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. +--> +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> + +<web-app > +</web-app> 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=1645058&r1=1645057&r2=1645058&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 Fri Dec 12 20:18:48 2014 @@ -134,6 +134,18 @@ public class EarMojo protected String escapeString; /** + * In case of using the {@link #skinnyWars} and {@link #defaultLibBundleDir} usually the + * classpath will be modified. + * By using this option you can change this and keep the classpath untouched. + * This option has been introduced to keep the backward compatibility with earlier versions + * of the plugin. + * + * @since 2.10 + */ + @Parameter( defaultValue = "true" ) + private boolean skipClassPathModification; + + /** * The location of the manifest file to be used within the EAR file. If no value if specified, the default location * in the workDirectory is taken. If the file does not exist, a manifest will be generated automatically. */ @@ -374,7 +386,7 @@ public class EarMojo if ( skinnyWars && module.changeManifestClasspath() ) { - changeManifestClasspath( module, destinationFile ); + changeManifestClasspath( module, destinationFile, javaEEVersion ); } } else @@ -386,7 +398,7 @@ public class EarMojo if ( skinnyWars && module.changeManifestClasspath() ) { - changeManifestClasspath( module, destinationFile ); + changeManifestClasspath( module, destinationFile, javaEEVersion ); } } else @@ -702,7 +714,7 @@ public class EarMojo return filterWrappers; } - private void changeManifestClasspath( EarModule module, File original ) + private void changeManifestClasspath( EarModule module, File original, JavaEEVersion javaEEVersion ) throws MojoFailureException { try @@ -792,7 +804,17 @@ public class EarMojo } else { - classPathElements.add( jm.getUri() ); + if ( skipClassPathModification ) + { + classPathElements.add( jm.getUri() ); + } + else + { + if ( javaEEVersion.lt( JavaEEVersion.FIVE ) || defaultLibBundleDir == null ) + { + classPathElements.add( jm.getUri() ); + } + } } } }