Author: gboue Date: Tue Oct 4 22:47:32 2016 New Revision: 1763333 URL: http://svn.apache.org/viewvc?rev=1763333&view=rev Log: [MEAR-243] Skinny WARs - JAR not removed from WAR if scope in EAR is set to provided
When creating skinny wars, only JAR runtime modules were considered when removing libraries from WEB-INF/lib of an EarModule. If a JAR dependency is provided, it should also remove it from WEB-INF/lib. Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml (with props) maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml (with props) maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh (with props) maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml (with props) maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml (with props) Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/EarMojo.java Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml?rev=1763333&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml Tue Oct 4 22:47:32 2016 @@ -0,0 +1,57 @@ +<?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> + <scope>provided</scope> + </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> + <skinnyWars>true</skinnyWars> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/ear-module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml?rev=1763333&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml Tue Oct 4 22:47:32 2016 @@ -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> + <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 that provided JAR dependencies in EAR are removed from skinny WAR</description> + <url>https://issues.apache.org/jira/browse/MEAR-243</url> + + <modules> + <module>ear-module</module> + <module>war-module</module> + </modules> +</project> Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh?rev=1763333&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh Tue Oct 4 22:47:32 2016 @@ -0,0 +1,113 @@ +/* + * 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.contains("commons-lang-2.5.jar") ) +{ + throw new IllegalStateException( "Surplus 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(); + +File earFile = new File( basedir, "ear-module/target/ear-module-1.0.ear" ); + +JarFile ear = new JarFile( earFile ); + +String[] excludedEntries = { + "commons-lang-2.5.jar", + "lib/commons-lang-2.5.jar", +}; +for ( String excluded : excludedEntries ) +{ + System.out.println( "Checking for excluded artifact " + excluded ); + if ( ear.getEntry( excluded ) != null ) + { + throw new IllegalStateException( "Archive entry should be excluded: " + excluded ); + } +} + +ear.close(); + +return true; Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/verify.bsh ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml?rev=1763333&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml Tue Oct 4 22:47:32 2016 @@ -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.1.1</version> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml?rev=1763333&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml (added) +++ maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml Tue Oct 4 22:47:32 2016 @@ -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> Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-ear-plugin/src/it/MEAR-243-skinny-wars-provided/war-module/src/main/webapp/WEB-INF/web.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java?rev=1763333&r1=1763332&r2=1763333&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/AbstractEarMojo.java Tue Oct 4 22:47:32 2016 @@ -165,7 +165,7 @@ public abstract class AbstractEarMojo private List<EarModule> earModules; - private List<EarModule> allModules; + private List<JarModule> allJarModules; private JbossConfiguration jbossConfiguration; @@ -211,7 +211,7 @@ public abstract class AbstractEarMojo } getLog().debug( "Resolving ear modules ..." ); - allModules = new ArrayList<EarModule>(); + List<EarModule> allModules = new ArrayList<EarModule>(); try { if ( modules != null && modules.length > 0 ) @@ -240,9 +240,8 @@ public abstract class AbstractEarMojo continue; } - // Artifact is not yet registered and it has neither test, nor a - // provided scope, not is it optional - ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + // Artifact is not yet registered and it has not test scope, nor is it optional + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE_PLUS_RUNTIME ); if ( !isArtifactRegistered( artifact, allModules ) && !artifact.isOptional() && filter.include( artifact ) ) { @@ -259,6 +258,8 @@ public abstract class AbstractEarMojo } // Now we have everything let's built modules which have not been excluded + ScopeArtifactFilter filter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME ); + allJarModules = new ArrayList<JarModule>(); earModules = new ArrayList<EarModule>(); for ( EarModule earModule : allModules ) { @@ -268,14 +269,21 @@ public abstract class AbstractEarMojo } else { - earModules.add( earModule ); + if ( earModule instanceof JarModule ) + { + allJarModules.add( (JarModule) earModule ); + } + if ( filter.include( earModule.getArtifact() ) ) + { + earModules.add( earModule ); + } } } } /** - * @return The list of {@link #earModules}. + * @return The list of {@link #earModules}. This corresponds to modules needed at runtime. */ protected List<EarModule> getModules() { @@ -285,6 +293,18 @@ public abstract class AbstractEarMojo } return earModules; } + + /** + * @return The list of {@link #allJarModules}. This corresponds to all JAR modules (compile + runtime). + */ + protected List<JarModule> getAllJarModules() + { + if ( allJarModules == null ) + { + throw new IllegalStateException( "Jar modules have not been initialized" ); + } + return allJarModules; + } /** * @return {@link MavenProject} Modified: maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/EarMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/EarMojo.java?rev=1763333&r1=1763332&r2=1763333&view=diff ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/EarMojo.java (original) +++ maven/plugins/trunk/maven-ear-plugin/src/main/java/org/apache/maven/plugins/ear/EarMojo.java Tue Oct 4 22:47:32 2016 @@ -803,32 +803,35 @@ public class EarMojo classPath = new Attribute( "Class-Path", "" ); } - // Modify the classpath entries in the manifest - for ( EarModule o : getModules() ) + // Remove JAR modules + for ( JarModule jm : getAllJarModules() ) { - if ( o instanceof JarModule ) + if ( module.getLibDir() != null ) { - JarModule jm = (JarModule) o; + // MEAR-189: + // We use the original name, cause in case of fileNameMapping to no-version/full + // we could not not delete it and it will end up in the resulting EAR and the WAR + // will not be cleaned up. + File artifact = + new File( new File( workDirectory, module.getLibDir() ), jm.getOriginalBundleFileName() ); - if ( module.getLibDir() != null ) + if ( artifact.exists() ) { - // MEAR-189: - // We use the original name, cause in case of fileNameMapping to no-version/full - // we could not not delete it and it will end up in the resulting EAR and the WAR - // will not be cleaned up. - File artifact = - new File( new File( workDirectory, module.getLibDir() ), jm.getOriginalBundleFileName() ); - - if ( artifact.exists() ) + getLog().debug( " -> Artifact to delete: " + artifact ); + if ( !artifact.delete() ) { - getLog().debug( " -> Artifact to delete: " + artifact ); - if ( !artifact.delete() ) - { - getLog().error( "Could not delete '" + artifact + "'" ); - } + getLog().error( "Could not delete '" + artifact + "'" ); } } + } + } + // Modify the classpath entries in the manifest + for ( EarModule o : getModules() ) + { + if ( o instanceof JarModule ) + { + JarModule jm = (JarModule) o; if ( classPathElements.contains( jm.getBundleFileName() ) ) { classPathElements.set( classPathElements.indexOf( jm.getBundleFileName() ), jm.getUri() );