From e054a2fa5a8424448d7c389dface3caf4e05e3b6 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Fri, 15 Apr 2005 07:31:40 +0000 Subject: [PATCH] resolve outstanding issues with scoping regarding tests. Algorithm to be documented in user's guide. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163953 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArtifactConstructionSupport.java | 19 +++++++------------ .../maven/project/ProjectClasspathTest.java | 11 ++++------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java b/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java index 518483ff4e..5b496cac92 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/construction/ArtifactConstructionSupport.java @@ -47,19 +47,16 @@ public class ArtifactConstructionSupport { // TODO: can refactor, use scope handler - // re-instate this if test deps are propogated -// if ( Artifact.SCOPE_TEST.equals( inheritedScope ) && Artifact.SCOPE_TEST.equals( scope ) ) - if ( Artifact.SCOPE_TEST.equals( inheritedScope ) ) + String desiredScope = Artifact.SCOPE_RUNTIME; + if ( inheritedScope == null ) + { + desiredScope = scope; + } + else if ( Artifact.SCOPE_TEST.equals( scope ) ) { return null; } - String desiredScope = Artifact.SCOPE_RUNTIME; - if ( Artifact.SCOPE_COMPILE.equals( scope ) && inheritedScope == null ) - { - desiredScope = Artifact.SCOPE_COMPILE; - } - // vvv added to retain compile scope. Remove if you want compile inherited as runtime else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) ) { @@ -67,9 +64,7 @@ public class ArtifactConstructionSupport } // ^^^ added to retain compile scope. Remove if you want compile inherited as runtime - // re-instate this if test deps are propogated -// if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_TEST.equals( inheritedScope ) ) - if ( Artifact.SCOPE_TEST.equals( scope ) ) + if ( Artifact.SCOPE_TEST.equals( inheritedScope ) ) { desiredScope = Artifact.SCOPE_TEST; } diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index fc00c0f2f1..dd1491fc35 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -66,14 +66,11 @@ public class ProjectClasspathTest artifact = getArtifact( project, "maven-test-test", "scope-test" ); assertNull( "Check no test dependencies are transitive", artifact ); artifact = getArtifact( project, "maven-test-test", "scope-compile" ); -// assertEquals( "Check scope", "test", artifact.getScope() ); - assertNull( "Check no test dependencies are transitive", artifact ); + assertEquals( "Check scope", "test", artifact.getScope() ); artifact = getArtifact( project, "maven-test-test", "scope-default" ); -// assertEquals( "Check scope", "test", artifact.getScope() ); - assertNull( "Check no test dependencies are transitive", artifact ); + assertEquals( "Check scope", "test", artifact.getScope() ); artifact = getArtifact( project, "maven-test-test", "scope-runtime" ); -// assertEquals( "Check scope", "test", artifact.getScope() ); - assertNull( "Check no test dependencies are transitive", artifact ); + assertEquals( "Check scope", "test", artifact.getScope() ); // check all transitive deps of a runtime dependency are runtime scope, except for test checkGroupIdScope( project, "runtime", "runtime" ); @@ -92,7 +89,7 @@ public class ProjectClasspathTest artifact = getArtifact( project, groupId, "scope-compile" ); assertEquals( "Check scope", scopeValue, artifact.getScope() ); artifact = getArtifact( project, groupId, "scope-test" ); - assertEquals( "Check scope", "test", artifact.getScope() ); + assertNull( "Check test dependency is not transitive", artifact ); artifact = getArtifact( project, groupId, "scope-default" ); assertEquals( "Check scope", scopeValue, artifact.getScope() ); artifact = getArtifact( project, groupId, "scope-runtime" );