path alignment for files in dependency

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163401 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-02-24 04:37:54 +00:00
parent fd8d091275
commit dac661c709
3 changed files with 75 additions and 6 deletions

View File

@ -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 ) )

View File

@ -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() ) );
}
}

View File

@ -64,6 +64,7 @@
<artifactId>d1</artifactId>
<version>1.0</version>
<url>d1-url</url>
<file>foo/bar</file>
</dependency>
<dependency>
@ -71,10 +72,28 @@
<artifactId>d2</artifactId>
<version>2.0</version>
<url>d2-url</url>
<file>/top/level/path</file>
</dependency>
<dependency>
<groupId>g3</groupId>
<artifactId>d3</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>g3</groupId>
<artifactId>d3</artifactId>
<version>3.0</version>
<url>d3-url</url>
<file>g3/d3</file>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<nagEmailAddress>jason@maven.org</nagEmailAddress>
<sourceDirectory>sourceDirectory</sourceDirectory>