Index: src/test/java/org/apache/maven/plugin/ear/util/ExcludeFilterTest.java =================================================================== --- src/test/java/org/apache/maven/plugin/ear/util/ExcludeFilterTest.java (revision 0) +++ src/test/java/org/apache/maven/plugin/ear/util/ExcludeFilterTest.java (revision 0) @@ -0,0 +1,100 @@ +package org.apache.maven.plugin.ear.util; + +/* + * 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.ArtifactTestStub; +import org.apache.maven.plugin.ear.Exclude; +import org.apache.maven.plugin.ear.util.ExcludeFilter; + +import junit.framework.TestCase; + +public class ExcludeFilterTest extends TestCase { + + public String GROUPID = "test.groupid"; + + public String MATCHING_GROUPID = ".*groupid"; + + public String NONMATCHING_GROUPID = ".*group"; + + public String ARTIFACTID = "test.artifactid"; + + public String MATCHING_ARTIFACTID = ".*artifactid"; + + public String NONMATCHING_ARTIFACTID = ".*artifact"; + + public Artifact artifact; + + protected void setUp() throws Exception { + super.setUp(); + artifact = new ArtifactTestStub(GROUPID,ARTIFACTID,null,null); + } + + public void testMatchingArtifactId() { + Exclude matchingExclude = new Exclude(); + matchingExclude.setArtifactId(MATCHING_ARTIFACTID); + ExcludeFilter matchingFilter = new ExcludeFilter(matchingExclude); + assertFalse(matchingFilter.include(artifact)); + + Exclude nonMatchingExclude = new Exclude(); + nonMatchingExclude.setArtifactId(NONMATCHING_ARTIFACTID); + ExcludeFilter nonMatchingFilter = new ExcludeFilter(nonMatchingExclude); + assertTrue(nonMatchingFilter.include(artifact)); + } + + public void testMatchingGroupId() { + Exclude matchingExclude = new Exclude(); + matchingExclude.setGroupId(MATCHING_GROUPID); + ExcludeFilter matchingFilter = new ExcludeFilter(matchingExclude); + assertFalse(matchingFilter.include(artifact)); + + Exclude nonMatchingExclude = new Exclude(); + nonMatchingExclude.setGroupId(NONMATCHING_GROUPID); + ExcludeFilter nonMatchingFilter = new ExcludeFilter(nonMatchingExclude); + assertTrue(nonMatchingFilter.include(artifact)); + } + + public void testMatchingCombination() { + Exclude matchingExclude = new Exclude(); + matchingExclude.setGroupId(MATCHING_GROUPID); + matchingExclude.setArtifactId(MATCHING_ARTIFACTID); + ExcludeFilter matchingFilter = new ExcludeFilter(matchingExclude); + assertFalse(matchingFilter.include(artifact)); + + Exclude nonMatchingExclude1 = new Exclude(); + nonMatchingExclude1.setGroupId(NONMATCHING_GROUPID); + nonMatchingExclude1.setArtifactId(MATCHING_ARTIFACTID); + ExcludeFilter nonMatchingFilter1 = new ExcludeFilter(nonMatchingExclude1); + assertTrue(nonMatchingFilter1.include(artifact)); + + Exclude nonMatchingExclude2 = new Exclude(); + nonMatchingExclude2.setGroupId(MATCHING_GROUPID); + nonMatchingExclude2.setArtifactId(NONMATCHING_ARTIFACTID); + ExcludeFilter nonMatchingFilter2 = new ExcludeFilter(nonMatchingExclude2); + assertTrue(nonMatchingFilter2.include(artifact)); + + Exclude nonMatchingExclude3 = new Exclude(); + nonMatchingExclude3.setGroupId(NONMATCHING_GROUPID); + nonMatchingExclude3.setArtifactId(NONMATCHING_ARTIFACTID); + ExcludeFilter nonMatchingFilter3 = new ExcludeFilter(nonMatchingExclude3); + assertTrue(nonMatchingFilter3.include(artifact)); + } + +} Index: src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java =================================================================== --- src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (revision 672531) +++ src/main/java/org/apache/maven/plugin/ear/AbstractEarMojo.java (working copy) @@ -20,10 +20,12 @@ */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.ear.util.AggregatedExcludeFilter; import org.apache.maven.plugin.ear.util.ArtifactTypeMappingService; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.configuration.PlexusConfiguration; @@ -82,6 +84,13 @@ private EarModule[] modules; /** + * Exclude some artifacts from the ear. + * + * @parameter + */ + private List excludes; + + /** * The artifact type mappings. * * @parameter @@ -183,10 +192,18 @@ // Let's add other modules Set artifacts = project.getArtifacts(); + ArtifactFilter excludeFilter = null; + if (null != excludes) + excludeFilter = new AggregatedExcludeFilter(excludes); for ( Iterator iter = artifacts.iterator(); iter.hasNext(); ) { Artifact artifact = (Artifact) iter.next(); + if (null != excludeFilter && !excludeFilter.include(artifact)) { + getLog().debug("Excluding artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId()); + continue; + } + // If the artifact's type is POM, ignore and continue // since it's used for transitive deps only. if ( "pom".equals( artifact.getType() ) ) Index: src/main/java/org/apache/maven/plugin/ear/Exclude.java =================================================================== --- src/main/java/org/apache/maven/plugin/ear/Exclude.java (revision 0) +++ src/main/java/org/apache/maven/plugin/ear/Exclude.java (revision 0) @@ -0,0 +1,43 @@ +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. + */ + +public class Exclude { + + private String groupId; + + private String artifactId; + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } +} Index: src/main/java/org/apache/maven/plugin/ear/util/ExcludeFilter.java =================================================================== --- src/main/java/org/apache/maven/plugin/ear/util/ExcludeFilter.java (revision 0) +++ src/main/java/org/apache/maven/plugin/ear/util/ExcludeFilter.java (revision 0) @@ -0,0 +1,56 @@ +package org.apache.maven.plugin.ear.util; + +/* + * 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.util.regex.Pattern; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.plugin.ear.Exclude; + +public class ExcludeFilter implements ArtifactFilter { + + private Pattern groupIdPattern; + + private Pattern artifactIdPattern; + + public ExcludeFilter(Exclude exclude) { + if (null != exclude.getGroupId()) { + groupIdPattern = Pattern.compile(exclude.getGroupId()); + } + if (null != exclude.getArtifactId()) { + artifactIdPattern = Pattern.compile(exclude.getArtifactId()); + } + } + + public boolean include(Artifact artifact) { + boolean groupIdResult = true; + if (null != groupIdPattern) { + groupIdResult = groupIdPattern.matcher(artifact.getGroupId()).matches(); + } + + boolean artifactIdResult = true; + if (null != artifactIdPattern) { + artifactIdResult = artifactIdPattern.matcher(artifact.getArtifactId()).matches(); + } + return !(groupIdResult && artifactIdResult); + } + +} Index: src/main/java/org/apache/maven/plugin/ear/util/AggregatedExcludeFilter.java =================================================================== --- src/main/java/org/apache/maven/plugin/ear/util/AggregatedExcludeFilter.java (revision 0) +++ src/main/java/org/apache/maven/plugin/ear/util/AggregatedExcludeFilter.java (revision 0) @@ -0,0 +1,50 @@ +package org.apache.maven.plugin.ear.util; + +/* + * 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.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.plugin.ear.Exclude; + +public class AggregatedExcludeFilter implements ArtifactFilter { + + private List filters= new ArrayList(); + + public AggregatedExcludeFilter(List excludes) { + for (Iterator iter = excludes.iterator(); iter.hasNext();) { + filters.add(new ExcludeFilter((Exclude) iter.next())); + } + } + + public boolean include(Artifact artifact) { + for (Iterator iter = filters.iterator(); iter.hasNext();) { + ExcludeFilter filter = (ExcludeFilter) iter.next(); + if (false == filter.include(artifact)) { + return false; + } + } + return true; + } + +}