Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ public DependencyManager getDependencyManager(boolean transitive) {
}

public DependencySelector getDependencySelector() {
DependencySelector scopeSelector = ScopeDependencySelector.legacy(
null, Arrays.asList(DependencyScope.TEST.id(), DependencyScope.PROVIDED.id()));
if (!mavenMaven3Personality) {
scopeSelector = new TestJarDependencySelector(scopeSelector);
}
return new AndDependencySelector(
ScopeDependencySelector.legacy(
null, Arrays.asList(DependencyScope.TEST.id(), DependencyScope.PROVIDED.id())),
OptionalDependencySelector.fromDirect(),
new ExclusionDependencySelector());
scopeSelector, OptionalDependencySelector.fromDirect(), new ExclusionDependencySelector());
}

public DependencyGraphTransformer getDependencyGraphTransformer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*/
package org.apache.maven.impl.resolver;

import java.util.Objects;

import org.apache.maven.api.DependencyScope;
import org.apache.maven.api.Type;
import org.eclipse.aether.artifact.ArtifactProperties;
import org.eclipse.aether.collection.DependencyCollectionContext;
import org.eclipse.aether.collection.DependencySelector;
import org.eclipse.aether.graph.Dependency;

import static java.util.Objects.requireNonNull;

/**
* Preserves Maven's normal non-transitive test-scope semantics while allowing the direct test-scoped dependencies of
* a test JAR to participate in dependency collection. Those dependencies are part of the test artifact's classpath
* contract, not the producer's main artifact contract.
*/
final class TestJarDependencySelector implements DependencySelector {
private final DependencySelector delegate;
private final boolean testJarParent;

TestJarDependencySelector(DependencySelector delegate) {
this(delegate, false);
}

private TestJarDependencySelector(DependencySelector delegate, boolean testJarParent) {
this.delegate = requireNonNull(delegate, "delegate cannot be null");
this.testJarParent = testJarParent;
}

@Override
public boolean selectDependency(Dependency dependency) {
requireNonNull(dependency, "dependency cannot be null");
if (testJarParent && DependencyScope.TEST.id().equals(dependency.getScope())) {
return true;
}
return delegate.selectDependency(dependency);
}

@Override
public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
requireNonNull(context, "context cannot be null");

DependencySelector childDelegate = delegate.deriveChildSelector(context);
Dependency parent = context.getDependency();
boolean childOfTestJar = parent != null
&& Type.TEST_JAR.equals(parent.getArtifact().getProperty(ArtifactProperties.TYPE, ""));

if (childDelegate == delegate && childOfTestJar == testJarParent) {
return this;
}
return new TestJarDependencySelector(childDelegate, childOfTestJar);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof TestJarDependencySelector that)) {
return false;
}
return testJarParent == that.testJarParent && delegate.equals(that.delegate);
}

@Override
public int hashCode() {
return Objects.hash(delegate, testJarParent);
}

@Override
public String toString() {
return getClass().getSimpleName() + "[delegate=" + delegate + ", testJarParent=" + testJarParent + ']';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.it;

import java.nio.file.Path;
import java.util.List;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Integration test for <a href="https://issues.apache.org/jira/browse/MNG-1378">MNG-1378</a>.
*/
public class MavenITmng1378TestJarTransitiveDependenciesTest extends AbstractMavenIntegrationTestCase {

@Test
public void testTestJarCarriesProducerTestDependencies() throws Exception {
Path testDir = extractResources("mng-1378");

Verifier producer = newVerifier(testDir);
producer.setAutoclean(false);
producer.deleteArtifacts("org.apache.maven.its.mng1378");
producer.addCliArgument("-pl");
producer.addCliArgument("support,test-jar");
producer.addCliArgument("validate");
producer.execute();
producer.verifyErrorFreeLog();

Verifier consumer = newVerifier(testDir.resolve("consumer"));
consumer.setAutoclean(false);
consumer.addCliArgument("validate");
consumer.execute();
consumer.verifyErrorFreeLog();

List<String> testClasspath = consumer.loadLines("target/test.txt");
assertTrue(testClasspath.contains("test-jar-1.0-tests.jar"), testClasspath.toString());
assertTrue(testClasspath.contains("support-1.0.jar"), testClasspath.toString());

Verifier regularConsumer = newVerifier(testDir.resolve("regular-consumer"));
regularConsumer.setAutoclean(false);
regularConsumer.addCliArgument("validate");
regularConsumer.execute();
regularConsumer.verifyErrorFreeLog();

List<String> regularTestClasspath = regularConsumer.loadLines("target/test.txt");
assertTrue(regularTestClasspath.contains("test-jar-1.0.jar"), regularTestClasspath.toString());
assertFalse(regularTestClasspath.contains("support-1.0.jar"), regularTestClasspath.toString());
}
}
61 changes: 61 additions & 0 deletions its/core-it-suite/src/test/resources/mng-1378/consumer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>consumer</artifactId>
<version>1.0</version>

<name>Maven Integration Test :: MNG-1378 :: Test JAR Consumer</name>

<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>test-jar</artifactId>
<version>1.0</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
<phase>validate</phase>
<configuration>
<testClassPath>target/test.txt</testClassPath>
<significantPathLevels>1</significantPathLevels>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
37 changes: 37 additions & 0 deletions its/core-it-suite/src/test/resources/mng-1378/pom.xml
Original file line number Diff line number Diff line change
@@ -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 xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<name>Maven Integration Test :: MNG-1378</name>
<description>Verify that dependencies required by a producer's test JAR are transitively available to test-JAR consumers.</description>

<modules>
<module>support</module>
<module>test-jar</module>
<module>consumer</module>
<module>regular-consumer</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>regular-consumer</artifactId>
<version>1.0</version>

<name>Maven Integration Test :: MNG-1378 :: Regular JAR Consumer</name>

<dependencies>
<dependency>
<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>test-jar</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-dependency-resolution</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>test</goal>
</goals>
<phase>validate</phase>
<configuration>
<testClassPath>target/test.txt</testClassPath>
<significantPathLevels>1</significantPathLevels>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
51 changes: 51 additions & 0 deletions its/core-it-suite/src/test/resources/mng-1378/support/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng1378</groupId>
<artifactId>support</artifactId>
<version>1.0</version>

<name>Maven Integration Test :: MNG-1378 :: Test Support</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-artifact</artifactId>
<version>2.1-SNAPSHOT</version>
<configuration>
<mainFile>pom.xml</mainFile>
</configuration>
<executions>
<execution>
<id>install</id>
<goals>
<goal>set</goal>
<goal>install</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Loading
Loading