implement lax parsing of repository metadata XML files

PR: MNG-1788


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@355404 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-12-09 07:58:04 +00:00
parent 4e955c058a
commit 65acc94926
19 changed files with 84 additions and 69 deletions

View File

@ -756,8 +756,7 @@ public class DefaultWagonManager
throw new IllegalArgumentException( "arguments can't be null" );
}
final XmlPlexusConfiguration xmlConf = ( configuration == null ) ? new XmlPlexusConfiguration( "configuration" )
: new XmlPlexusConfiguration( configuration );
final XmlPlexusConfiguration xmlConf = new XmlPlexusConfiguration( configuration );
serverConfigurationMap.put( repositoryId, xmlConf );
}

View File

@ -92,7 +92,7 @@ public abstract class AbstractRepositoryMetadata
{
reader = new FileReader( metadataFile );
metadata = mappingReader.read( reader );
metadata = mappingReader.read( reader, false );
}
finally
{

View File

@ -268,7 +268,7 @@ public class DefaultRepositoryMetadataManager
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
result = mappingReader.read( fileReader );
result = mappingReader.read( fileReader, false );
}
catch ( FileNotFoundException e )
{

View File

@ -117,7 +117,7 @@ public class ExpressionDocumenter
ParamdocXpp3Reader paramdocReader = new ParamdocXpp3Reader();
ExpressionDocumentation documentation = paramdocReader.read( reader );
ExpressionDocumentation documentation = paramdocReader.read( reader, true );
List expressions = documentation.getExpressions();

View File

@ -15,7 +15,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<goals>
@ -41,6 +41,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<id>v3</id>
@ -81,4 +82,4 @@
<artifactId>plexus-utils</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -14,7 +14,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<goals>
@ -47,4 +47,4 @@
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -284,7 +284,7 @@ public class PluginDescriptor
throw new FileNotFoundException( "Unable to find /META-INF/maven/lifecycle.xml in the plugin" );
}
r = new InputStreamReader( resourceAsStream );
config = reader.read( r );
config = reader.read( r, true );
}
finally
{

View File

@ -13,7 +13,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<id>base</id>
@ -49,4 +49,4 @@
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -30,19 +30,19 @@
<codeSegments>
<codeSegment>
<version>1.0.0</version>
<code><![CDATA[ private Map expressionsBySyntax;
<code><![CDATA[ private java.util.Map expressionsBySyntax;
public Map getExpressionsBySyntax()
public java.util.Map getExpressionsBySyntax()
{
if ( expressionsBySyntax == null )
{
expressionsBySyntax = new HashMap();
expressionsBySyntax = new java.util.HashMap();
List expressions = getExpressions();
java.util.List expressions = getExpressions();
if ( expressions != null && !expressions.isEmpty() )
{
for ( Iterator it = expressions.iterator(); it.hasNext(); )
for ( java.util.Iterator it = expressions.iterator(); it.hasNext(); )
{
Expression expr = (Expression) it.next();

View File

@ -14,7 +14,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<goals>
@ -41,4 +41,4 @@
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -63,7 +63,7 @@ public class Main
MavenXpp3Reader modelReader = new MavenXpp3Reader();
FileReader reader = new FileReader( pom );
Model model = modelReader.read( reader );
Model model = modelReader.read( reader, true );
// Not doing inheritence, except for groupId and version
if ( model.getGroupId() == null )

View File

@ -13,7 +13,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<goals>
@ -45,4 +45,4 @@
<artifactId>plexus-container-default</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -249,7 +249,7 @@ public class DefaultMavenProjectBuilder
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(),
d.getClassifier(), d.getScope(),
d.getClassifier(), d.getScope(),
d.isOptional() );
map.put( d.getManagementKey(), artifact );
}
@ -286,23 +286,24 @@ public class DefaultMavenProjectBuilder
ProfileManager profileManager, boolean checkDistributionManagementStatus )
throws ProjectBuildingException
{
Model model = readModel( "unknown", projectDescriptor );
Model model = readModel( "unknown", projectDescriptor, true );
// Always cache files in the source tree over those in the repository
MavenProject p = new MavenProject( model );
p.setFile( projectDescriptor );
String modelKey = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
if ( modelCache.containsKey( modelKey ) )
{
throw new ProjectBuildingException( model.getGroupId() + ":" + model.getArtifactId(),
"Duplicate project ID found in " + projectDescriptor.getAbsolutePath() );
throw new ProjectBuildingException( model.getGroupId() + ":" + model.getArtifactId(),
"Duplicate project ID found in " +
projectDescriptor.getAbsolutePath() );
}
modelCache.put( modelKey, p );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
buildArtifactRepositories( getSuperModel() ),
projectDescriptor.getAbsoluteFile().getParentFile(), profileManager );
projectDescriptor.getAbsoluteFile().getParentFile(), profileManager, true );
if ( checkDistributionManagementStatus )
{
@ -350,7 +351,8 @@ public class DefaultMavenProjectBuilder
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel );
return build( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null );
return build( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null,
false );
}
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
@ -385,7 +387,7 @@ public class DefaultMavenProjectBuilder
artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
File file = projectArtifact.getFile();
model = readModel( projectId, file );
model = readModel( projectId, file, false );
String downloadUrl = null;
ArtifactStatus status = ArtifactStatus.NONE;
@ -515,7 +517,8 @@ public class DefaultMavenProjectBuilder
}
private MavenProject build( String pomLocation, Model model, ArtifactRepository localRepository,
List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager )
List parentSearchRepositories, File projectDir, ProfileManager externalProfileManager,
boolean strict )
throws ProjectBuildingException
{
Model superModel = getSuperModel();
@ -589,7 +592,7 @@ public class DefaultMavenProjectBuilder
try
{
project = assembleLineage( model, lineage, localRepository, projectDir, parentSearchRepositories,
aggregatedRemoteWagonRepositories, externalProfileManager );
aggregatedRemoteWagonRepositories, externalProfileManager, strict );
}
catch ( InvalidRepositoryException e )
{
@ -626,7 +629,8 @@ public class DefaultMavenProjectBuilder
try
{
project = processProjectLogic( pomLocation, project, repositories, externalProfileManager, projectDir );
project =
processProjectLogic( pomLocation, project, repositories, externalProfileManager, projectDir, strict );
}
catch ( ModelInterpolationException e )
{
@ -684,7 +688,7 @@ public class DefaultMavenProjectBuilder
* and projects are not cached or reused
*/
private MavenProject processProjectLogic( String pomLocation, MavenProject project, List remoteRepositories,
ProfileManager profileMgr, File projectDir )
ProfileManager profileMgr, File projectDir, boolean strict )
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
{
Model model = project.getModel();
@ -718,7 +722,7 @@ public class DefaultMavenProjectBuilder
context.put( "basedir", projectDir.getAbsolutePath() );
}
model = modelInterpolator.interpolate( model, context );
model = modelInterpolator.interpolate( model, context, strict );
// interpolation is before injection, because interpolation is off-limits in the injected variables
modelDefaultsInjector.injectDefaults( model );
@ -796,7 +800,8 @@ public class DefaultMavenProjectBuilder
*/
private MavenProject assembleLineage( Model model, LinkedList lineage, ArtifactRepository localRepository,
File projectDir, List parentSearchRepositories,
Set aggregatedRemoteWagonRepositories, ProfileManager externalProfileManager )
Set aggregatedRemoteWagonRepositories, ProfileManager externalProfileManager,
boolean strict )
throws ProjectBuildingException, InvalidRepositoryException
{
if ( !model.getRepositories().isEmpty() )
@ -860,11 +865,11 @@ public class DefaultMavenProjectBuilder
{
throw new ProjectBuildingException( projectId, "Missing artifactId element from parent element" );
}
else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) )
else if ( parentModel.getGroupId().equals( model.getGroupId() ) &&
parentModel.getArtifactId().equals( model.getArtifactId() ) )
{
throw new ProjectBuildingException( projectId, "Parent element is a duplicate of " +
"the current project " );
throw new ProjectBuildingException( projectId,
"Parent element is a duplicate of " + "the current project " );
}
else if ( StringUtils.isEmpty( parentModel.getVersion() ) )
{
@ -898,16 +903,16 @@ public class DefaultMavenProjectBuilder
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Path specified in <relativePath/> (" + parentRelativePath
+ ") is a directory. Searching for 'pom.xml' within this directory." );
getLogger().debug( "Path specified in <relativePath/> (" + parentRelativePath +
") is a directory. Searching for 'pom.xml' within this directory." );
}
parentDescriptor = new File( parentDescriptor, "pom.xml" );
if ( !parentDescriptor.exists() )
{
throw new ProjectBuildingException( projectId, "missing parent project descriptor: " + parentDescriptor.getAbsolutePath() );
throw new ProjectBuildingException( projectId, "missing parent project descriptor: " +
parentDescriptor.getAbsolutePath() );
}
}
@ -924,7 +929,7 @@ public class DefaultMavenProjectBuilder
if ( parentDescriptor != null && parentDescriptor.exists() )
{
Model candidateParent = readModel( projectId, parentDescriptor );
Model candidateParent = readModel( projectId, parentDescriptor, strict );
String candidateParentGroupId = candidateParent.getGroupId();
if ( candidateParentGroupId == null && candidateParent.getParent() != null )
@ -985,9 +990,10 @@ public class DefaultMavenProjectBuilder
if ( model != null && !"pom".equals( model.getPackaging() ) )
{
throw new ProjectBuildingException( projectId, "Parent: " + model.getId() + " of project: " + projectId + " has wrong packaging: " + model.getPackaging() + ". Must be 'pom'." );
throw new ProjectBuildingException( projectId, "Parent: " + model.getId() + " of project: " +
projectId + " has wrong packaging: " + model.getPackaging() + ". Must be 'pom'." );
}
File parentProjectDir = null;
if ( parentDescriptor != null )
{
@ -995,7 +1001,7 @@ public class DefaultMavenProjectBuilder
}
MavenProject parent = assembleLineage( model, lineage, localRepository, parentProjectDir,
parentSearchRepositories, aggregatedRemoteWagonRepositories,
externalProfileManager );
externalProfileManager, strict );
parent.setFile( parentDescriptor );
project.setParent( parent );
@ -1080,14 +1086,14 @@ public class DefaultMavenProjectBuilder
}
}
private Model readModel( String projectId, File file )
private Model readModel( String projectId, File file, boolean strict )
throws ProjectBuildingException
{
Reader reader = null;
try
{
reader = new FileReader( file );
return readModel( projectId, file.getAbsolutePath(), reader );
return readModel( projectId, file.getAbsolutePath(), reader, strict );
}
catch ( FileNotFoundException e )
{
@ -1105,7 +1111,7 @@ public class DefaultMavenProjectBuilder
}
}
private Model readModel( String projectId, String pomLocation, Reader reader )
private Model readModel( String projectId, String pomLocation, Reader reader, boolean strict )
throws IOException, InvalidProjectModelException
{
StringWriter sw = new StringWriter();
@ -1123,22 +1129,23 @@ public class DefaultMavenProjectBuilder
try
{
return modelReader.read( sReader );
return modelReader.read( sReader, strict );
}
catch ( XmlPullParserException e )
{
throw new InvalidProjectModelException( projectId, pomLocation, "Parse error reading POM. Reason: " + e.getMessage(), e );
throw new InvalidProjectModelException( projectId, pomLocation,
"Parse error reading POM. Reason: " + e.getMessage(), e );
}
}
private Model readModel( String projectId, URL url )
private Model readModel( String projectId, URL url, boolean strict )
throws ProjectBuildingException
{
InputStreamReader reader = null;
try
{
reader = new InputStreamReader( url.openStream() );
return readModel( projectId, url.toExternalForm(), reader );
return readModel( projectId, url.toExternalForm(), reader, strict );
}
catch ( IOException e )
{
@ -1324,7 +1331,7 @@ public class DefaultMavenProjectBuilder
{
List remoteRepositories = buildArtifactRepositories( superModel );
project = processProjectLogic( "<Super-POM>", project, remoteRepositories, null, null );
project = processProjectLogic( "<Super-POM>", project, remoteRepositories, null, null, true );
project.setExecutionRoot( true );
@ -1351,7 +1358,7 @@ public class DefaultMavenProjectBuilder
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
return readModel( projectId, url );
return readModel( projectId, url, true );
}
public void contextualize( Context context )

View File

@ -97,7 +97,7 @@ public class ProjectArtifactMetadata
writer = new FileWriter( destination );
MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = modelReader.read( sReader );
Model model = modelReader.read( sReader, false );
model.setVersion( artifact.getVersion() );
DistributionManagement distributionManagement = model.getDistributionManagement();

View File

@ -32,4 +32,6 @@ public interface ModelInterpolator
Model interpolate( Model project, Map context )
throws ModelInterpolationException;
Model interpolate( Model model, Map context, boolean strict )
throws ModelInterpolationException;
}

View File

@ -42,6 +42,12 @@ public class RegexBasedModelInterpolator
extends AbstractLogEnabled
implements ModelInterpolator
{
public Model interpolate( Model project, Map context )
throws ModelInterpolationException
{
return interpolate( project, context, true );
}
/**
* Serialize the inbound Model instance to a StringWriter, perform the regex replacement to resolve
* POM expressions, then re-parse into the resolved Model instance.
@ -52,7 +58,7 @@ public class RegexBasedModelInterpolator
* @param context The other context map to be used during resolution
* @return The resolved instance of the inbound Model. This is a different instance!
*/
public Model interpolate( Model model, Map context )
public Model interpolate( Model model, Map context, boolean strict )
throws ModelInterpolationException
{
StringWriter sWriter = new StringWriter();
@ -68,13 +74,13 @@ public class RegexBasedModelInterpolator
}
String serializedModel = sWriter.toString();
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
interpolator.addValueSource( new MapBasedValueSource( context ) );
interpolator.addValueSource( new MapBasedValueSource( model.getProperties() ) );
interpolator.addValueSource( new ObjectBasedValueSource( model ) );
try
{
interpolator.addValueSource( new EnvarBasedValueSource() );
@ -84,7 +90,7 @@ public class RegexBasedModelInterpolator
getLogger().warn( "Cannot initialize environment variables resolver. Skipping environmental resolution." );
getLogger().debug( "Failed to initialize envar resolver. Skipping environmental resolution.", e );
}
serializedModel = interpolator.interpolate(serializedModel, "pom|project" );
StringReader sReader = new StringReader( serializedModel );
@ -92,7 +98,7 @@ public class RegexBasedModelInterpolator
MavenXpp3Reader modelReader = new MavenXpp3Reader();
try
{
model = modelReader.read( sReader );
model = modelReader.read( sReader, strict );
}
catch ( IOException e )
{

View File

@ -15,7 +15,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<executions>
<execution>
<goals>
@ -39,4 +39,4 @@
<artifactId>plexus-utils</artifactId>
</dependency>
</dependencies>
</project>
</project>

View File

@ -99,7 +99,7 @@
changed = true;
}
for ( Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
for ( java.util.Iterator i = versioning.getVersions().iterator(); i.hasNext(); )
{
String version = (String) i.next();
if ( !v.getVersions().contains( version ) )

View File

@ -13,7 +13,7 @@
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-6</version>
<version>1.0-alpha-7-SNAPSHOT</version>
<configuration>
<version>1.0.0</version>
<model>settings.mdo</model>