mirror of
https://github.com/apache/maven.git
synced 2025-03-06 16:49:27 +00:00
[MNG-4933] With a resource directory as . maven raise an java.lang.StringIndexOutOfBoundsException:217
o Aligned code with r1050425 of https://svn.apache.org/repos/asf/maven/maven-2/branches/maven-2.2.x/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java o Fixed special case of path=${basedir} to yield valid/non-empty path "." git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1054712 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8cbfa31252
commit
469d0096fd
@ -38,6 +38,11 @@ public class DefaultPathTranslator
|
||||
|
||||
public void alignToBaseDirectory( Model model, File basedir )
|
||||
{
|
||||
if ( basedir == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
if ( build != null )
|
||||
@ -83,6 +88,11 @@ public void alignToBaseDirectory( Model model, File basedir )
|
||||
|
||||
public String alignToBaseDirectory( String path, File basedir )
|
||||
{
|
||||
if ( basedir == null )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
if ( path == null )
|
||||
{
|
||||
return null;
|
||||
@ -166,6 +176,11 @@ private String chopLeadingFileSeparator( String path )
|
||||
|
||||
public void unalignFromBaseDirectory( Model model, File basedir )
|
||||
{
|
||||
if ( basedir == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Build build = model.getBuild();
|
||||
|
||||
if ( build != null )
|
||||
@ -209,14 +224,37 @@ public void unalignFromBaseDirectory( Model model, File basedir )
|
||||
}
|
||||
}
|
||||
|
||||
public String unalignFromBaseDirectory( String directory, File basedir )
|
||||
public String unalignFromBaseDirectory( String path, File basedir )
|
||||
{
|
||||
String path = basedir.getPath();
|
||||
if ( directory.startsWith( path ) )
|
||||
if ( basedir == null )
|
||||
{
|
||||
directory = directory.substring( path.length() + 1 ).replace( '\\', '/' );
|
||||
return path;
|
||||
}
|
||||
return directory;
|
||||
|
||||
if ( path == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
path = path.trim();
|
||||
|
||||
String base = basedir.getAbsolutePath();
|
||||
if ( path.startsWith( base ) )
|
||||
{
|
||||
path = chopLeadingFileSeparator( path.substring( base.length() ) );
|
||||
}
|
||||
|
||||
if ( path.length() <= 0 )
|
||||
{
|
||||
path = ".";
|
||||
}
|
||||
|
||||
if ( !new File( path ).isAbsolute() )
|
||||
{
|
||||
path = path.replace( '\\', '/' );
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
package org.apache.maven.project.path;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@ -17,12 +19,11 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.maven.project.path;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@SuppressWarnings( "deprecation" )
|
||||
public class DefaultPathTranslatorTest
|
||||
extends TestCase
|
||||
{
|
||||
@ -45,4 +46,13 @@ public void testAlignToBasedirWhereBasedirExpressionIsTheValuePrefix()
|
||||
assertEquals( new File( basedir, "dir" ).getAbsolutePath(), aligned );
|
||||
}
|
||||
|
||||
public void testUnalignToBasedirWherePathEqualsBasedir()
|
||||
{
|
||||
File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile();
|
||||
|
||||
String unaligned = new DefaultPathTranslator().unalignFromBaseDirectory( basedir.getAbsolutePath(), basedir );
|
||||
|
||||
assertEquals( ".", unaligned );
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user