mirror of https://github.com/apache/maven.git
[MNG-5075] MavenProject.getParent throws undocumented ISE
Submitted by Jesse Glick
This commit is contained in:
parent
93d07bdf99
commit
2eb419ed95
|
@ -102,6 +102,8 @@ public class MavenProject
|
||||||
|
|
||||||
public static final String EMPTY_PROJECT_VERSION = "0";
|
public static final String EMPTY_PROJECT_VERSION = "0";
|
||||||
|
|
||||||
|
private static final MavenProject ERROR_BUILDING_PARENT = new MavenProject();
|
||||||
|
|
||||||
private Model model;
|
private Model model;
|
||||||
|
|
||||||
private MavenProject parent;
|
private MavenProject parent;
|
||||||
|
@ -343,6 +345,10 @@ public class MavenProject
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the project corresponding to a declared parent.
|
||||||
|
* @return the parent, or null if no parent is declared or there was an error building it
|
||||||
|
*/
|
||||||
public MavenProject getParent()
|
public MavenProject getParent()
|
||||||
{
|
{
|
||||||
if ( parent == null )
|
if ( parent == null )
|
||||||
|
@ -363,7 +369,11 @@ public class MavenProject
|
||||||
}
|
}
|
||||||
catch ( ProjectBuildingException e )
|
catch ( ProjectBuildingException e )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Failed to build parent project for " + getId(), e );
|
if ( logger != null )
|
||||||
|
{
|
||||||
|
logger.error( "Failed to build parent project for " + getId(), e );
|
||||||
|
}
|
||||||
|
parent = ERROR_BUILDING_PARENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( model.getParent() != null )
|
else if ( model.getParent() != null )
|
||||||
|
@ -378,11 +388,15 @@ public class MavenProject
|
||||||
}
|
}
|
||||||
catch ( ProjectBuildingException e )
|
catch ( ProjectBuildingException e )
|
||||||
{
|
{
|
||||||
throw new IllegalStateException( "Failed to build parent project for " + getId(), e );
|
if ( logger != null )
|
||||||
|
{
|
||||||
|
logger.error( "Failed to build parent project for " + getId(), e );
|
||||||
|
}
|
||||||
|
parent = ERROR_BUILDING_PARENT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parent;
|
return parent == ERROR_BUILDING_PARENT ? null : parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParent( MavenProject parent )
|
public void setParent( MavenProject parent )
|
||||||
|
|
|
@ -23,7 +23,9 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.apache.maven.lifecycle.internal.stub.LoggerStub;
|
||||||
import org.apache.maven.model.DependencyManagement;
|
import org.apache.maven.model.DependencyManagement;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Parent;
|
import org.apache.maven.model.Parent;
|
||||||
|
@ -177,6 +179,32 @@ public class MavenProjectTest
|
||||||
activeProfilesClone );
|
activeProfilesClone );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInvalidParent() throws Exception
|
||||||
|
{
|
||||||
|
Parent parent = new Parent();
|
||||||
|
parent.setGroupId( "test-group" );
|
||||||
|
parent.setArtifactId( "parent-artifact" );
|
||||||
|
parent.setVersion( "1.0" );
|
||||||
|
Model model = new Model();
|
||||||
|
model.setParent( parent );
|
||||||
|
model.setArtifactId( "child-artifact" );
|
||||||
|
final AtomicInteger logged = new AtomicInteger();
|
||||||
|
class L extends LoggerStub
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void error( String s, Throwable throwable )
|
||||||
|
{
|
||||||
|
logged.incrementAndGet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MavenProject project = new MavenProject( repositorySystem, projectBuilder, newBuildingRequest(), new L() );
|
||||||
|
project.setModel( model );
|
||||||
|
assertNull( project.getParent() );
|
||||||
|
assertEquals( 1, logged.get() );
|
||||||
|
assertNull( project.getParent() );
|
||||||
|
assertEquals( 1, logged.get() );
|
||||||
|
}
|
||||||
|
|
||||||
public void testUndefinedOutputDirectory()
|
public void testUndefinedOutputDirectory()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue