diff --git a/pom.xml b/pom.xml
index d02c01811..5cdf2565d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,9 @@ under the License.
Maarten Mulders
+
+ Lisa Hardy
+
diff --git a/src/it/projects/mdep-689-apply-filtering-go-offline-goal/invoker.properties b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/invoker.properties
new file mode 100644
index 000000000..4623ccd63
--- /dev/null
+++ b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = clean ${project.groupId}:${project.artifactId}:${project.version}:go-offline
diff --git a/src/it/projects/mdep-689-apply-filtering-go-offline-goal/pom.xml b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/pom.xml
new file mode 100644
index 000000000..a41847d9e
--- /dev/null
+++ b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/pom.xml
@@ -0,0 +1,109 @@
+
+
+
+
+
+ 4.0.0
+ org.apache.maven.plugins.dependency
+ mdep-739-go-offline-respect-classifiers
+ 1.0.0-SNAPSHOT
+ Test that dependency:go-offline applies exclude filters
+
+
+ skip.this.groupid
+ dummy-artifact
+ 1.0
+
+
+ skip.this.groupid.too
+ dummy-artifact
+ 1.0
+
+
+ org.junit.jupiter
+ skip-this-artifact
+ 1.0
+
+
+ org.junit.jupiter
+ skip-this-artifact-too
+ 1.0-SNAPSHOT
+
+
+ ch.qos.logback
+ logback-access
+ 1.4.7
+ skipThisClassifier
+
+
+ ch.qos.logback
+ logback-core
+ 1.5.6
+ skipThisClassifierToo
+
+
+ org.slf4j
+ slf4j-api
+ 2.0.13
+ compile
+
+
+ ch.qos.logback
+ logback-classic
+ 1.5.4
+ system
+
+ ${project.build.directory}/local-repo/junit/junit/4.13.2/junit-4.13.2.jar
+
+
+ org.slf4j
+ slf4j-simple
+ 2.0.13
+
+
+ ch.qos.logback
+ logback-examples
+ 1.4.7
+ ear
+
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ skip.this.groupid,skip.this.groupid.too
+ skip-this-artifact,skip-this-artifact-too
+
+
+ system
+ ear
+ skipThisClassifier,skipThisClassifierToo
+
+
+
+
+
+
diff --git a/src/it/projects/mdep-689-apply-filtering-go-offline-goal/verify.groovy b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/verify.groovy
new file mode 100644
index 000000000..1bc9464f7
--- /dev/null
+++ b/src/it/projects/mdep-689-apply-filtering-go-offline-goal/verify.groovy
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+File file = new File( basedir, "build.log" )
+assert file.exists()
+
+String buildLog = file.getText( "UTF-8" )
+
+// Make sure non-exluded explicit dependencies are resolved
+assert buildLog.contains( 'Resolved dependency: slf4j-simple-2.0.13.jar' )
+assert buildLog.contains( 'Resolved dependency: slf4j-api-2.0.13.jar' )
+
+// Did group excludes work?
+assert !buildLog.contains( 'Resolving artifact skip.this.groupid' )
+
+// Did artifact excludes work?
+assert !buildLog.contains( 'Resolving artifact org.junit.jupiter:skip-this-artifact' )
+
+// Did scope exludes work?
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-classic' )
+
+// Did type excludes work?
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-examples' )
+
+// Did classifier excludes work?
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-core:jar:skipThisClassifierToo' )
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-core' )
+
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-access:jar:skipThisClassifier' )
+assert !buildLog.contains( 'Resolving artifact ch.qos.logback:logback-access' )
+
+
+
+return true
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
index 655458b5d..63a1cfa1b 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java
@@ -136,7 +136,9 @@ public abstract class AbstractDependencyFilterMojo extends AbstractDependencyMoj
/**
* Scope threshold to exclude, if no value is defined for include.
- * An empty string indicates no dependencies (default).
+ * An empty string indicates no dependencies (default). Unlike the other
+ * exclusion parameters, this property does not support a comma-delimited
+ * list of scope exclusions. Just one scope may be excluded at a time.
* The scope threshold value being interpreted is the scope as
* Maven filters for creating a classpath, not as specified in the pom. In summary:
*
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
index a452968ee..bf03a003f 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/AbstractResolveMojo.java
@@ -22,6 +22,13 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.dependency.fromDependencies.AbstractDependencyFilterMojo;
+import org.apache.maven.plugins.dependency.utils.DependencyUtil;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
+import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
+import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
+import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
+import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
+import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
/**
* @author Brian Fox
@@ -52,4 +59,38 @@ public abstract class AbstractResolveMojo extends AbstractDependencyFilterMojo {
*/
@Parameter(property = "excludeReactor", defaultValue = "true")
protected boolean excludeReactor;
+
+ /**
+ * @return {@link FilterArtifacts}
+ */
+ protected FilterArtifacts getArtifactsFilter() {
+ final FilterArtifacts filter = new FilterArtifacts();
+
+ if (excludeReactor) {
+
+ filter.addFilter(new ExcludeReactorProjectsArtifactFilter(reactorProjects, getLog()));
+ }
+
+ filter.addFilter(new ScopeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeScope),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
+
+ filter.addFilter(new TypeFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeTypes),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
+
+ filter.addFilter(new ClassifierFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
+
+ filter.addFilter(new GroupIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
+
+ filter.addFilter(new ArtifactIdFilter(
+ DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds),
+ DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
+
+ return filter;
+ }
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
index 1bc3e4d7a..6ca1c3968 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java
@@ -25,13 +25,17 @@
import java.util.stream.Collectors;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
+import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
@@ -43,6 +47,7 @@
*
* @author Brian Fox
* @author Maarten Mulders
+ * @author Lisa Hardy
* @since 2.0
*/
@Mojo(name = "go-offline", threadSafe = true)
@@ -71,7 +76,7 @@ protected void doExecute() throws MojoExecutionException {
}
}
- } catch (DependencyResolverException e) {
+ } catch (DependencyResolverException | ArtifactFilterException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
@@ -81,10 +86,13 @@ protected void doExecute() throws MojoExecutionException {
*
* @return set of resolved dependency artifacts.
* @throws DependencyResolverException in case of an error while resolving the artifacts.
+ * @throws ArtifactFilterException
*/
- protected Set resolveDependencyArtifacts() throws DependencyResolverException {
+ protected Set resolveDependencyArtifacts() throws DependencyResolverException, ArtifactFilterException {
Collection dependencies = getProject().getDependencies();
+ dependencies = filterDependencies(dependencies);
+
Set dependableCoordinates = dependencies.stream()
.map(this::createDependendableCoordinateFromDependency)
.collect(Collectors.toSet());
@@ -133,8 +141,9 @@ private TransformableFilter getTransformableFilter() {
*
* @return set of resolved plugin artifacts.
* @throws DependencyResolverException in case of an error while resolving the artifacts.
+ * @throws ArtifactFilterException
*/
- protected Set resolvePluginArtifacts() throws DependencyResolverException {
+ protected Set resolvePluginArtifacts() throws DependencyResolverException, ArtifactFilterException {
Set plugins = getProject().getPluginArtifacts();
Set reports = getProject().getReportArtifacts();
@@ -143,6 +152,9 @@ protected Set resolvePluginArtifacts() throws DependencyResolverExcept
artifacts.addAll(reports);
artifacts.addAll(plugins);
+ final FilterArtifacts filter = getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+
Set dependableCoordinates = artifacts.stream()
.map(this::createDependendableCoordinateFromArtifact)
.collect(Collectors.toSet());
@@ -152,6 +164,16 @@ protected Set resolvePluginArtifacts() throws DependencyResolverExcept
return resolveDependableCoordinate(buildingRequest, dependableCoordinates, "plugins");
}
+ private Collection filterDependencies(Collection deps) throws ArtifactFilterException {
+
+ Set artifacts = createArtifactSetFromDependencies(deps);
+
+ final FilterArtifacts filter = getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+
+ return createDependencySetFromArtifacts(artifacts);
+ }
+
private DependableCoordinate createDependendableCoordinateFromArtifact(final Artifact artifact) {
final DefaultDependableCoordinate result = new DefaultDependableCoordinate();
result.setGroupId(artifact.getGroupId());
@@ -174,6 +196,39 @@ private DependableCoordinate createDependendableCoordinateFromDependency(final D
return result;
}
+ private Set createArtifactSetFromDependencies(Collection deps) {
+ Set artifacts = new HashSet<>();
+ for (Dependency dep : deps) {
+ DefaultArtifactHandler handler = new DefaultArtifactHandler(dep.getType());
+ artifacts.add(new DefaultArtifact(
+ dep.getGroupId(),
+ dep.getArtifactId(),
+ dep.getVersion(),
+ dep.getScope(),
+ dep.getType(),
+ dep.getClassifier(),
+ handler));
+ }
+ return artifacts;
+ }
+
+ private Collection createDependencySetFromArtifacts(Set artifacts) {
+ Set dependencies = new HashSet<>();
+
+ for (Artifact artifact : artifacts) {
+ Dependency d = new Dependency();
+ d.setGroupId(artifact.getGroupId());
+ d.setArtifactId(artifact.getArtifactId());
+ d.setVersion(artifact.getVersion());
+ d.setType(artifact.getType());
+ d.setClassifier(artifact.getClassifier());
+ d.setScope(artifact.getScope());
+ dependencies.add(d);
+ }
+
+ return dependencies;
+ }
+
@Override
protected ArtifactsFilter getMarkedArtifactFilter() {
return null;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
index 4c6e91ac3..4a6a23782 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java
@@ -33,13 +33,8 @@
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
-import org.apache.maven.shared.artifact.filter.collection.ArtifactIdFilter;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
-import org.apache.maven.shared.artifact.filter.collection.ClassifierFilter;
import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
-import org.apache.maven.shared.artifact.filter.collection.GroupIdFilter;
-import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
-import org.apache.maven.shared.artifact.filter.collection.TypeFilter;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException;
import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult;
import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate;
@@ -174,40 +169,6 @@ private Set resolveArtifactDependencies(final DependableCoordinate art
return artifacts;
}
- /**
- * @return {@link FilterArtifacts}
- */
- private FilterArtifacts getArtifactsFilter() {
- final FilterArtifacts filter = new FilterArtifacts();
-
- if (excludeReactor) {
-
- filter.addFilter(new ExcludeReactorProjectsArtifactFilter(reactorProjects, getLog()));
- }
-
- filter.addFilter(new ScopeFilter(
- DependencyUtil.cleanToBeTokenizedString(this.includeScope),
- DependencyUtil.cleanToBeTokenizedString(this.excludeScope)));
-
- filter.addFilter(new TypeFilter(
- DependencyUtil.cleanToBeTokenizedString(this.includeTypes),
- DependencyUtil.cleanToBeTokenizedString(this.excludeTypes)));
-
- filter.addFilter(new ClassifierFilter(
- DependencyUtil.cleanToBeTokenizedString(this.includeClassifiers),
- DependencyUtil.cleanToBeTokenizedString(this.excludeClassifiers)));
-
- filter.addFilter(new GroupIdFilter(
- DependencyUtil.cleanToBeTokenizedString(this.includeGroupIds),
- DependencyUtil.cleanToBeTokenizedString(this.excludeGroupIds)));
-
- filter.addFilter(new ArtifactIdFilter(
- DependencyUtil.cleanToBeTokenizedString(this.includeArtifactIds),
- DependencyUtil.cleanToBeTokenizedString(this.excludeArtifactIds)));
-
- return filter;
- }
-
/**
* This method resolves the plugin artifacts from the project.
*
diff --git a/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java b/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java
new file mode 100644
index 000000000..caa00f160
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojoTest.java
@@ -0,0 +1,405 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugins.dependency.resolvers;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
+import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
+import org.junit.jupiter.api.Disabled;
+
+public class GoOfflineMojoTest extends AbstractDependencyMojoTestCase {
+ private GoOfflineMojo subject;
+
+ protected void setUp() throws Exception {
+ // required for mojo lookups to work
+ super.setUp("go-offline", true);
+ MavenProject project = new DependencyProjectStub();
+ getContainer().addComponent(project, MavenProject.class.getName());
+
+ MavenSession session = newMavenSession(project);
+ getContainer().addComponent(session, MavenSession.class.getName());
+ }
+
+ String GROUP_EXCLUDE_PREFIX = "skip.this.groupid";
+
+ String ARTIFACT_EXCLUDE_PREFIX = "skip-this-artifact";
+
+ String CLASSIFIER_EXCLUDE_PREFIX = "skipThisClassifier";
+
+ String DUMMY_ARTIFACT_NAME = "dummy-artifact";
+
+ String STUB_ARTIFACT_VERSION = "3.14";
+
+ String VALID_GROUP = "org.junit.jupiter";
+
+ public void test_excludeGroupIds() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(GROUP_EXCLUDE_PREFIX);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION);
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(GROUP_EXCLUDE_PREFIX + ".too");
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact2.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId("dont.skip.me");
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion("1.0");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(1, artifacts.size());
+ assertTrue(artifacts.contains(artifact3));
+ assertFalse(artifacts.contains(artifact1));
+ assertFalse(artifacts.contains(artifact2));
+ }
+
+ public void test_excludeArtifactIds() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(ARTIFACT_EXCLUDE_PREFIX);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(ARTIFACT_EXCLUDE_PREFIX + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId("dont.skip.me");
+ artifact3.setArtifactId("dummy-artifact");
+ artifact3.setVersion("1.0");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(1, artifacts.size());
+ assertTrue(artifacts.contains(artifact3));
+ assertFalse(artifacts.contains(artifact1));
+ assertFalse(artifacts.contains(artifact2));
+ }
+
+ public void test_excludeScope() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+ artifact2.setScope("system");
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion(STUB_ARTIFACT_VERSION);
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(2, artifacts.size());
+ assertTrue(artifacts.contains(artifact3));
+ assertTrue(artifacts.contains(artifact1));
+ assertFalse(artifacts.contains(artifact2));
+ }
+
+ public void test_excludeTypes() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ ArtifactStub artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+ artifact1.setType("ear");
+
+ ArtifactStub artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+ artifact2.setType("war");
+
+ ArtifactStub artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion(STUB_ARTIFACT_VERSION);
+ artifact3.setType("pom");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(1, artifacts.size());
+ assertFalse(artifacts.contains(artifact3));
+ assertTrue(artifacts.contains(artifact2));
+ assertFalse(artifacts.contains(artifact1));
+ }
+
+ /**
+ * Can't set a classifier on the ArtifactStub as of maven-plugin-testing-harness-3.3.0, there is a getter but no
+ * setter. If that ever gets implemented, comment in these two lines to support unit testing for this case, rename
+ * xtest to test and remove the Junit 5 Disabled annotation
+ *
+ * @throws Exception
+ */
+ @Disabled("Requires update to maven-plugin-test-harness to support this test")
+ public void xtest_excludeClassifiers() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/exclude-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ ArtifactStub artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+ // artifact1.setClassifier(CLASSIFIER_EXCLUDE_PREFIX);
+
+ ArtifactStub artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+ // artifact2.setClassifier(CLASSIFIER_EXCLUDE_PREFIX + "Too");
+
+ ArtifactStub artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion(STUB_ARTIFACT_VERSION);
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(1, artifacts.size());
+ assertFalse(artifacts.contains(artifact1));
+ assertFalse(artifacts.contains(artifact2));
+ assertTrue(artifacts.contains(artifact3));
+ }
+
+ String GROUP_INCLUDE_PREFIX = "include.this.groupid";
+
+ String ARTIFACT_INCLUDE_PREFIX = "include-this-artifact";
+
+ String CLASSIFIER_INCLUDE_PREFIX = "includeThisClassifier";
+
+ public void test_includeGroupIds() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-gid-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(GROUP_INCLUDE_PREFIX);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION);
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(GROUP_INCLUDE_PREFIX + ".too");
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact2.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId("skip.me");
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion("1.0");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+
+ assertEquals(2, artifacts.size());
+ assertFalse(artifacts.contains(artifact3));
+ assertTrue(artifacts.contains(artifact1));
+ assertTrue(artifacts.contains(artifact2));
+ }
+
+ public void test_includeArtifactIds() throws Exception {
+ File testPom = new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-aid-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(ARTIFACT_INCLUDE_PREFIX);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION);
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(ARTIFACT_INCLUDE_PREFIX + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion("1.0");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+
+ assertEquals(2, artifacts.size());
+ assertFalse(artifacts.contains(artifact3));
+ assertTrue(artifacts.contains(artifact1));
+ assertTrue(artifacts.contains(artifact2));
+ }
+
+ public void test_includeScope() throws Exception {
+ File testPom =
+ new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-scope-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ Artifact artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+ artifact1.setScope("provided");
+
+ Artifact artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+ artifact2.setScope("system");
+
+ Artifact artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion(STUB_ARTIFACT_VERSION);
+ artifact3.setScope("test");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(1, artifacts.size());
+
+ assertTrue(artifacts.contains(artifact1));
+ assertFalse(artifacts.contains(artifact2));
+ assertFalse(artifacts.contains(artifact3));
+ }
+
+ public void test_includeTypes() throws Exception {
+ File testPom =
+ new File(getBasedir(), "target/test-classes/unit/go-offline-test/include-types-plugin-config.xml");
+
+ subject = (GoOfflineMojo) lookupMojo("go-offline", testPom);
+ assertNotNull(subject);
+
+ ArtifactStub artifact1 = new ArtifactStub();
+ artifact1.setGroupId(VALID_GROUP);
+ artifact1.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact1.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+ artifact1.setType("ear");
+
+ ArtifactStub artifact2 = new ArtifactStub();
+ artifact2.setGroupId(VALID_GROUP);
+ artifact2.setArtifactId(DUMMY_ARTIFACT_NAME + "-too");
+ artifact2.setVersion(STUB_ARTIFACT_VERSION);
+ artifact2.setType("pom");
+
+ ArtifactStub artifact3 = new ArtifactStub();
+ artifact3.setGroupId(VALID_GROUP);
+ artifact3.setArtifactId(DUMMY_ARTIFACT_NAME);
+ artifact3.setVersion(STUB_ARTIFACT_VERSION + "-SNAPSHOT");
+ artifact3.setType("war");
+
+ Set artifacts = new HashSet<>();
+ artifacts.add(artifact1);
+ artifacts.add(artifact2);
+ artifacts.add(artifact3);
+
+ assertEquals(3, artifacts.size());
+ FilterArtifacts filter = subject.getArtifactsFilter();
+ artifacts = filter.filter(artifacts);
+ assertEquals(2, artifacts.size());
+
+ assertTrue(artifacts.contains(artifact1));
+ assertTrue(artifacts.contains(artifact2));
+ assertFalse(artifacts.contains(artifact3));
+ }
+}
diff --git a/src/test/resources/unit/go-offline-test/exclude-plugin-config.xml b/src/test/resources/unit/go-offline-test/exclude-plugin-config.xml
new file mode 100644
index 000000000..c80cf3433
--- /dev/null
+++ b/src/test/resources/unit/go-offline-test/exclude-plugin-config.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ skip.this.groupid,skip.this.groupid.too
+
+ skip-this-artifact,skip-this-artifact-too
+
+
+
+ system
+ ear,pom
+ skipThisClassifier,skipThisClassifierToo
+
+
+
+
+
+
diff --git a/src/test/resources/unit/go-offline-test/include-aid-plugin-config.xml b/src/test/resources/unit/go-offline-test/include-aid-plugin-config.xml
new file mode 100644
index 000000000..cd792ec85
--- /dev/null
+++ b/src/test/resources/unit/go-offline-test/include-aid-plugin-config.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ include-this-artifact,include-this-artifact-too
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/unit/go-offline-test/include-gid-plugin-config.xml b/src/test/resources/unit/go-offline-test/include-gid-plugin-config.xml
new file mode 100644
index 000000000..8d2c425a0
--- /dev/null
+++ b/src/test/resources/unit/go-offline-test/include-gid-plugin-config.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ include.this.groupid,include.this.groupid.too
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/unit/go-offline-test/include-scope-plugin-config.xml b/src/test/resources/unit/go-offline-test/include-scope-plugin-config.xml
new file mode 100644
index 000000000..2230d2a8b
--- /dev/null
+++ b/src/test/resources/unit/go-offline-test/include-scope-plugin-config.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ provided
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/resources/unit/go-offline-test/include-types-plugin-config.xml b/src/test/resources/unit/go-offline-test/include-types-plugin-config.xml
new file mode 100644
index 000000000..e7e2365ff
--- /dev/null
+++ b/src/test/resources/unit/go-offline-test/include-types-plugin-config.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+ maven-dependency-plugin
+ @project.version@
+
+ pom,ear
+
+
+
+
+
\ No newline at end of file