From dac661c7099727a43c025ce0011cf9e00c50236b Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 24 Feb 2005 04:37:54 +0000 Subject: [PATCH] path alignment for files in dependency git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163401 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/path/DefaultPathTranslator.java | 20 +++++++++ .../ProjectBaseDirectoryAlignmentTest.java | 42 ++++++++++++++++--- ...roject-which-needs-directory-alignment.xml | 19 +++++++++ 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java b/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java index e859f63508..42629cf8d8 100644 --- a/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java +++ b/maven-core/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java @@ -18,6 +18,7 @@ package org.apache.maven.project.path; */ import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.Resource; @@ -95,6 +96,25 @@ public class DefaultPathTranslator } } + List dependencies = model.getDependencies(); + + for ( Iterator i = dependencies.iterator(); i.hasNext(); ) + { + Dependency dependency = (Dependency) i.next(); + + s = dependency.getFile(); + + if ( s != null ) + { + s = stripBasedirToken( s ); + + if ( requiresBaseDirectoryAlignment( s ) ) + { + dependency.setFile( new File( projectFile.getParentFile(), s ).getPath() ); + } + } + } + s = stripBasedirToken( build.getOutput() ); if ( requiresBaseDirectoryAlignment( s ) ) diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectBaseDirectoryAlignmentTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectBaseDirectoryAlignmentTest.java index 70565b9a44..e08fcd8a31 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectBaseDirectoryAlignmentTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectBaseDirectoryAlignmentTest.java @@ -1,22 +1,24 @@ package org.apache.maven.project; -import org.apache.maven.model.Build; -import org.apache.maven.model.Resource; import org.apache.maven.MavenTestCase; +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Resource; import java.io.File; +import java.util.Iterator; public class ProjectBaseDirectoryAlignmentTest extends MavenTestCase -{ - +{ + private String dir = "src/test/resources/projects/base-directory-alignment/"; - + public void testProjectDirectoryBaseDirectoryAlignment() throws Exception { File f = getTestFile( dir + "project-which-needs-directory-alignment.xml" ); - + MavenProject project = getProject( f, false ); assertNotNull( "Test project can't be null!", project ); @@ -30,5 +32,33 @@ public class ProjectBaseDirectoryAlignmentTest Resource resource = (Resource) build.getResources().get( 0 ); assertTrue( resource.getDirectory().startsWith( getBasedir() ) ); + + String relativeFile = null; + String absoluteFile = null; + String managedDependencyFile = null; + for ( Iterator i = project.getDependencies().iterator(); i.hasNext(); ) + { + Dependency d = (Dependency) i.next(); + if ( d.getGroupId().equals( "g1" ) ) + { + relativeFile = d.getFile(); + } + else if ( d.getGroupId().equals( "g2" ) ) + { + absoluteFile = d.getFile(); + } + else if ( d.getGroupId().equals( "g3" ) ) + { + managedDependencyFile = d.getFile(); + } + } + + assertNotNull( "Required dependency missing: g1:d1", relativeFile ); + assertNotNull( "Required dependency missing: g2:d2", absoluteFile ); + assertNotNull( "Required dependency missing: g3:d3", managedDependencyFile ); + + assertTrue( "Relative file not adjusted", relativeFile.startsWith( getBasedir() ) ); + assertEquals( "Absolute file was incorrectly modified", "/top/level/path", absoluteFile ); + assertTrue( "Managed dependency not adjusted", managedDependencyFile.startsWith( getBasedir() ) ); } } diff --git a/maven-core/src/test/resources/projects/base-directory-alignment/project-which-needs-directory-alignment.xml b/maven-core/src/test/resources/projects/base-directory-alignment/project-which-needs-directory-alignment.xml index 5f9f8f7146..eca1c9ddfd 100644 --- a/maven-core/src/test/resources/projects/base-directory-alignment/project-which-needs-directory-alignment.xml +++ b/maven-core/src/test/resources/projects/base-directory-alignment/project-which-needs-directory-alignment.xml @@ -64,6 +64,7 @@ d1 1.0 d1-url + foo/bar @@ -71,10 +72,28 @@ d2 2.0 d2-url + /top/level/path + + + + g3 + d3 + + + + g3 + d3 + 3.0 + d3-url + g3/d3 + + + + jason@maven.org sourceDirectory