mirror of https://github.com/apache/maven.git
Resolving: MNG-666
If a v3 POM is encountered (or any POM where modelVersion is != '4.0.0'), an InvalidModelException is thrown. This exception extends ProjectBuildingException, to enable piggybacking on the same catch() clause. When the MavenMetadataSource catches InvalidModelException, it returns a ResolutionGroup with the pomArtifact and empty collections for the pom dependency artifacts and the repository list with which to resolve the empty artifacts set. Also, added it0059 to test builds where a dependency POM is a v3 pom (missing <modelVersion/>). git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
224af053c7
commit
da3aa1090f
|
@ -164,6 +164,9 @@ it0057: Verify that scope == 'provided' dependencies are available to tests.
|
|||
it0058: Verify that profiles from settings.xml do not pollute module lists
|
||||
across projects in a reactorized build.
|
||||
|
||||
it0059: Verify that maven-1 POMs will be ignored but not stop the resolution
|
||||
process.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
- generated sources
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
it0059
|
||||
it0058
|
||||
it0057
|
||||
it0056
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
target/maven-core-it0059-1.0.jar
|
|
@ -0,0 +1 @@
|
|||
package
|
|
@ -0,0 +1,22 @@
|
|||
<project>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.maven.it</groupId>
|
||||
<artifactId>maven-core-it0059</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>test</id>
|
||||
<url>file:test-repo</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>test</groupId>
|
||||
<artifactId>test</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0001;
|
||||
|
||||
public class Person
|
||||
{
|
||||
private String name;
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
name = jason
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.maven.it0001;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class PersonTest
|
||||
extends TestCase
|
||||
{
|
||||
public void testPerson()
|
||||
{
|
||||
Person person = new Person();
|
||||
|
||||
person.setName( "foo" );
|
||||
|
||||
assertEquals( "foo", person.getName() );
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,5 @@
|
|||
<project>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
</project>
|
|
@ -0,0 +1 @@
|
|||
failOnErrorOutput=false
|
|
@ -72,6 +72,9 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -854,11 +857,11 @@ public class DefaultMavenProjectBuilder
|
|||
private Model readModel( File file )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
FileReader reader = null;
|
||||
Reader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( file );
|
||||
return modelReader.read( reader );
|
||||
return readModel( reader );
|
||||
}
|
||||
catch ( FileNotFoundException e )
|
||||
{
|
||||
|
@ -879,6 +882,24 @@ public class DefaultMavenProjectBuilder
|
|||
IOUtil.close( reader );
|
||||
}
|
||||
}
|
||||
|
||||
private Model readModel( Reader reader ) throws IOException, XmlPullParserException, InvalidModelException
|
||||
{
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
IOUtil.copy( reader, sw );
|
||||
|
||||
String modelSource = sw.toString();
|
||||
|
||||
if ( modelSource.indexOf( "<modelVersion>4.0.0" ) < 0 )
|
||||
{
|
||||
throw new InvalidModelException( "Invalid POM (not v4.0.0 modelVersion)" );
|
||||
}
|
||||
|
||||
StringReader sReader = new StringReader( modelSource );
|
||||
|
||||
return modelReader.read( sReader );
|
||||
}
|
||||
|
||||
private Model readModel( URL url )
|
||||
throws ProjectBuildingException
|
||||
|
@ -887,7 +908,7 @@ public class DefaultMavenProjectBuilder
|
|||
try
|
||||
{
|
||||
reader = new InputStreamReader( url.openStream() );
|
||||
return modelReader.read( reader );
|
||||
return readModel( reader );
|
||||
}
|
||||
catch ( IOException e )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
public class InvalidModelException
|
||||
extends ProjectBuildingException
|
||||
{
|
||||
|
||||
public InvalidModelException( String message, Throwable cause )
|
||||
{
|
||||
super( message, cause );
|
||||
}
|
||||
|
||||
public InvalidModelException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
|
||||
}
|
|
@ -31,12 +31,14 @@ import org.apache.maven.model.Dependency;
|
|||
import org.apache.maven.model.DistributionManagement;
|
||||
import org.apache.maven.model.Exclusion;
|
||||
import org.apache.maven.model.Relocation;
|
||||
import org.apache.maven.project.InvalidModelException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -83,42 +85,56 @@ public class MavenMetadataSource
|
|||
{
|
||||
project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
|
||||
}
|
||||
catch ( InvalidModelException e )
|
||||
{
|
||||
getLogger().warn( "POM for: \'" + pomArtifact.getId() + "\' does not appear to be valid. Its will be ignored for artifact resolution." );
|
||||
|
||||
project = null;
|
||||
}
|
||||
catch ( ProjectBuildingException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e );
|
||||
}
|
||||
|
||||
Relocation relocation = null;
|
||||
|
||||
DistributionManagement distMgmt = project.getDistributionManagement();
|
||||
if ( distMgmt != null )
|
||||
if ( project != null )
|
||||
{
|
||||
relocation = distMgmt.getRelocation();
|
||||
}
|
||||
if ( relocation != null )
|
||||
{
|
||||
if ( relocation.getGroupId() != null )
|
||||
Relocation relocation = null;
|
||||
|
||||
DistributionManagement distMgmt = project.getDistributionManagement();
|
||||
if ( distMgmt != null )
|
||||
{
|
||||
artifact.setGroupId( relocation.getGroupId() );
|
||||
}
|
||||
if ( relocation.getArtifactId() != null )
|
||||
{
|
||||
artifact.setArtifactId( relocation.getArtifactId() );
|
||||
}
|
||||
if ( relocation.getVersion() != null )
|
||||
{
|
||||
artifact.setVersion( relocation.getVersion() );
|
||||
relocation = distMgmt.getRelocation();
|
||||
}
|
||||
|
||||
String message = "\n This artifact has been relocated to " + artifact.getGroupId() + ":" +
|
||||
artifact.getArtifactId() + ":" + artifact.getVersion() + ".\n";
|
||||
|
||||
if ( relocation.getMessage() != null )
|
||||
if ( relocation != null )
|
||||
{
|
||||
message += " " + relocation.getMessage() + "\n";
|
||||
}
|
||||
if ( relocation.getGroupId() != null )
|
||||
{
|
||||
artifact.setGroupId( relocation.getGroupId() );
|
||||
}
|
||||
if ( relocation.getArtifactId() != null )
|
||||
{
|
||||
artifact.setArtifactId( relocation.getArtifactId() );
|
||||
}
|
||||
if ( relocation.getVersion() != null )
|
||||
{
|
||||
artifact.setVersion( relocation.getVersion() );
|
||||
}
|
||||
|
||||
getLogger().warn( message + "\n" );
|
||||
String message = "\n This artifact has been relocated to " + artifact.getGroupId() + ":"
|
||||
+ artifact.getArtifactId() + ":" + artifact.getVersion() + ".\n";
|
||||
|
||||
if ( relocation.getMessage() != null )
|
||||
{
|
||||
message += " " + relocation.getMessage() + "\n";
|
||||
}
|
||||
|
||||
getLogger().warn( message + "\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -132,15 +148,27 @@ public class MavenMetadataSource
|
|||
|
||||
try
|
||||
{
|
||||
// TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered
|
||||
// or used the inherited scope (should that be passed to the buildFromRepository method above?)
|
||||
Set artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
|
||||
ResolutionGroup result;
|
||||
|
||||
if ( project == null )
|
||||
{
|
||||
// if the project is null, we encountered an invalid model (read: m1 POM)
|
||||
// we'll just return an empty resolution group.
|
||||
result = new ResolutionGroup( pomArtifact, Collections.EMPTY_SET, Collections.EMPTY_LIST );
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: we could possibly use p.getDependencyArtifacts instead of this call, but they haven't been filtered
|
||||
// or used the inherited scope (should that be passed to the buildFromRepository method above?)
|
||||
Set artifacts = project.createArtifacts( artifactFactory, artifact.getScope(),
|
||||
artifact.getDependencyFilter() );
|
||||
|
||||
|
||||
List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
|
||||
|
||||
result = new ResolutionGroup( pomArtifact, artifacts, repositories );
|
||||
}
|
||||
|
||||
List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() );
|
||||
|
||||
return new ResolutionGroup( pomArtifact, artifacts, repositories );
|
||||
return result;
|
||||
}
|
||||
catch ( InvalidVersionSpecificationException e )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue