From b310a40d6bd82ee97ecd9e7dc6401e48827403bf Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 30 Nov 2007 00:24:10 +0000 Subject: [PATCH] Fixing super-pom building to allow injection of external profiles (again). Also, removing use of pluginRepositories and improving error reporting just a tad. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@599658 13f79535-47bb-0310-9956-ffa450edef68 --- .../ProjectArtifactErrorReporterAspect.aj | 26 +++++----- .../injection/DefaultProfileInjector.java | 8 +-- .../project/DefaultMavenProjectBuilder.java | 51 ++++++++++++++----- .../apache/maven/project/MavenProject.java | 5 +- .../maven/project/MavenProjectBuilder.java | 3 ++ .../org/apache/maven/project/ModelUtils.java | 2 +- .../error/DefaultProjectErrorReporter.java | 8 +-- .../DefaultModelInheritanceAssembler.java | 20 +++++--- .../validation/DefaultModelValidator.java | 12 ++--- .../project/SuperPomProjectBuilderTest.java | 13 +---- .../validation/DefaultModelValidatorTest.java | 16 +++--- 11 files changed, 97 insertions(+), 67 deletions(-) diff --git a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectArtifactErrorReporterAspect.aj b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectArtifactErrorReporterAspect.aj index c0c83e3f49..89944193dc 100644 --- a/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectArtifactErrorReporterAspect.aj +++ b/maven-project/src/main/aspect/org/apache/maven/project/aspect/ProjectArtifactErrorReporterAspect.aj @@ -4,6 +4,7 @@ import org.apache.maven.project.build.model.DefaultModelLineageBuilder; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.model.Parent; import java.io.File; @@ -16,18 +17,21 @@ public privileged aspect ProjectArtifactErrorReporterAspect private pointcut mlbldr_resolveParentFromRepositories( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile ): execution( File DefaultModelLineageBuilder.resolveParentFromRepository( Parent, ArtifactRepository, List, String, File ) ) + && within( DefaultModelLineageBuilder ) && args( parentRef, localRepo, remoteRepos, childId, childPomFile ) && notWithinAspect(); - private pointcut anfe_handler( ArtifactNotFoundException cause ): - handler( ArtifactNotFoundException ) - && args( cause ) - && notWithinAspect(); + private pointcut mlbldr_parentArtifactNotFound( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ): + cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) ) + && !cflowbelow( mlbldr_resolveParentFromRepositories( Parent, ArtifactRepository, List, String, File ) ) + && call( ProjectBuildingException.new( .., ArtifactNotFoundException ) ) + && args( .., cause ); - private pointcut are_handler( ArtifactResolutionException cause ): - handler( ArtifactResolutionException ) - && args( cause ) - && notWithinAspect(); + private pointcut mlbldr_parentArtifactUnresolvable( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ): + cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) ) + && !cflowbelow( mlbldr_resolveParentFromRepositories( Parent, ArtifactRepository, List, String, File ) ) + && call( ProjectBuildingException.new( .., ArtifactResolutionException ) ) + && args( .., cause ); // ========================================================================= // Call Stack: @@ -40,8 +44,7 @@ public privileged aspect ProjectArtifactErrorReporterAspect // <---------- ProjectBuildingException // ========================================================================= before( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactNotFoundException cause ): - cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) ) - && anfe_handler( cause ) + mlbldr_parentArtifactNotFound( parentRef, localRepo, remoteRepos, childId, childPomFile, cause ) { getReporter().reportParentPomArtifactNotFound( parentRef, localRepo, remoteRepos, childId, childPomFile, cause ); } @@ -57,8 +60,7 @@ public privileged aspect ProjectArtifactErrorReporterAspect // <---------- ProjectBuildingException // ========================================================================= before( Parent parentRef, ArtifactRepository localRepo, List remoteRepos, String childId, File childPomFile, ArtifactResolutionException cause ): - cflow( mlbldr_resolveParentFromRepositories( parentRef, localRepo, remoteRepos, childId, childPomFile ) ) - && are_handler( cause ) + mlbldr_parentArtifactUnresolvable( parentRef, localRepo, remoteRepos, childId, childPomFile, cause ) { getReporter().reportParentPomArtifactUnresolvable( parentRef, localRepo, remoteRepos, childId, childPomFile, cause ); } diff --git a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java index 3d7b1db8b6..dd85ef35a9 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/injection/DefaultProfileInjector.java @@ -71,8 +71,8 @@ public class DefaultProfileInjector injectModules( profile, model ); model.setRepositories( ModelUtils.mergeRepositoryLists( profile.getRepositories(), model.getRepositories() ) ); - model.setPluginRepositories( ModelUtils.mergeRepositoryLists( profile.getPluginRepositories(), model - .getPluginRepositories() ) ); +// model.setPluginRepositories( ModelUtils.mergeRepositoryLists( profile.getPluginRepositories(), model +// .getPluginRepositories() ) ); injectReporting( profile, model ); @@ -291,7 +291,7 @@ public class DefaultProfileInjector } } - + /** * Merge two DOMs. Copy the dominant DOM so the original one is left unchanged. *

@@ -299,7 +299,7 @@ public class DefaultProfileInjector * Profiles are dominant, thus they are merge targets, but they may be merged in several times * (e.g. if they are inherited). So with the second merge, you don't get the profile's original * DOM, but an already merged one. - * + * * @param dominant Dominant DOM * @param recessive Recessive DOM * @return Merged DOM diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 56d0085ac1..32263568a5 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -201,18 +201,19 @@ public class DefaultMavenProjectBuilder false, false, false ); } - private MavenProject superProject; - private Logger logger; + // what is using this externally? jvz. public MavenProject buildStandaloneSuperProject() throws ProjectBuildingException { - if ( superProject != null ) - { - return superProject; - } + //TODO mkleint - use the (Container, Properties) constructor to make system properties embeddable + return buildStandaloneSuperProject( null ); + } + public MavenProject buildStandaloneSuperProject( ProfileManager profileManager ) + throws ProjectBuildingException + { Model superModel = getSuperModel(); superModel.setGroupId( STANDALONE_SUPERPOM_GROUPID ); @@ -221,13 +222,30 @@ public class DefaultMavenProjectBuilder superModel.setVersion( STANDALONE_SUPERPOM_VERSION ); - superProject = new MavenProject( superModel ); + List activeProfiles; + if ( profileManager != null ) + { + activeProfiles = profileAdvisor.applyActivatedExternalProfiles( superModel, null, profileManager ); + } + else + { + activeProfiles = Collections.EMPTY_LIST; + } + + MavenProject project = new MavenProject( superModel ); + + String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); + + project.setManagedVersionMap( + createManagedVersionMap( projectId, superModel.getDependencyManagement(), null ) ); + + project.setActiveProfiles( activeProfiles ); try { - superProject.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); + project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); - superProject.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); + project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); } catch ( InvalidRepositoryException e ) { @@ -239,11 +257,11 @@ public class DefaultMavenProjectBuilder e ); } - superProject.setOriginalModel( superModel ); + project.setOriginalModel( superModel ); - superProject.setExecutionRoot( true ); + project.setExecutionRoot( true ); - return superProject; + return project; } /** @since 2.0.x */ @@ -840,7 +858,7 @@ public class DefaultMavenProjectBuilder project.getVersion(), project.getPackaging() ); project.setArtifact( projectArtifact ); - project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( model.getPluginRepositories() ) ); +// project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( model.getPluginRepositories() ) ); DistributionManagement dm = model.getDistributionManagement(); @@ -1227,9 +1245,16 @@ public class DefaultMavenProjectBuilder // // ---------------------------------------------------------------------- + private Model superModel; + private Model getSuperModel() throws ProjectBuildingException { + if ( superModel != null ) + { + return superModel; + } + URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" ); String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index f45d04e08a..5226c568b1 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -22,10 +22,10 @@ package org.apache.maven.project; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; -import org.apache.maven.artifact.versioning.ManagedVersionMap; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ManagedVersionMap; import org.apache.maven.model.Build; import org.apache.maven.model.CiManagement; import org.apache.maven.model.Contributor; @@ -1329,7 +1329,8 @@ public class MavenProject public List getPluginRepositories() { - return model.getPluginRepositories(); +// return model.getPluginRepositories(); + return Collections.EMPTY_LIST; } public void setActiveProfiles( List activeProfiles ) diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index b0fa41ad85..e8ec427176 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -91,4 +91,7 @@ public interface MavenProjectBuilder */ MavenProject buildStandaloneSuperProject() throws ProjectBuildingException; + + MavenProject buildStandaloneSuperProject( ProfileManager profileManager ) + throws ProjectBuildingException; } diff --git a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java index e3b4d615bf..cdbe3e9edf 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java +++ b/maven-project/src/main/java/org/apache/maven/project/ModelUtils.java @@ -573,7 +573,7 @@ public final class ModelUtils newProfile.setModules( new ArrayList( modules ) ); } - newProfile.setPluginRepositories( cloneProfileRepositories( profile.getPluginRepositories() ) ); +// newProfile.setPluginRepositories( cloneProfileRepositories( profile.getPluginRepositories() ) ); Properties props = profile.getProperties(); diff --git a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java b/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java index f61ef9382c..adfe585018 100644 --- a/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java +++ b/maven-project/src/main/java/org/apache/maven/project/error/DefaultProjectErrorReporter.java @@ -654,11 +654,11 @@ public class DefaultProjectErrorReporter writer.write( NEWLINE ); if ( pomFile == null ) { - writer.write( "Error parsing built-in super POM!" ); + writer.write( "Error reading built-in super POM!" ); } else { - writer.write( "Error parsing POM." ); + writer.write( "Error reading POM." ); } writer.write( NEWLINE ); @@ -682,11 +682,11 @@ public class DefaultProjectErrorReporter writer.write( NEWLINE ); if ( parentPomFile == null ) { - writer.write( "Error parsing built-in super POM!" ); + writer.write( "Error reading built-in super POM!" ); } else { - writer.write( "Error parsing parent-POM." ); + writer.write( "Error reading parent-POM." ); } writer.write( NEWLINE ); diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index 684570d329..b3c7f20f5e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -170,8 +170,8 @@ public class DefaultModelInheritanceAssembler assembleDependencyInheritance( child, parent ); child.setRepositories( ModelUtils.mergeRepositoryLists( child.getRepositories(), parent.getRepositories() ) ); - child.setPluginRepositories( - ModelUtils.mergeRepositoryLists( child.getPluginRepositories(), parent.getPluginRepositories() ) ); +// child.setPluginRepositories( +// ModelUtils.mergeRepositoryLists( child.getPluginRepositories(), parent.getPluginRepositories() ) ); assembleReportingInheritance( child, parent ); @@ -335,13 +335,13 @@ public class DefaultModelInheritanceAssembler ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() ); List resources = childBuild.getResources(); - if ( resources == null || resources.isEmpty() ) + if ( ( resources == null ) || resources.isEmpty() ) { childBuild.setResources( parentBuild.getResources() ); } resources = childBuild.getTestResources(); - if ( resources == null || resources.isEmpty() ) + if ( ( resources == null ) || resources.isEmpty() ) { childBuild.setTestResources( parentBuild.getTestResources() ); } @@ -353,7 +353,7 @@ public class DefaultModelInheritanceAssembler PluginManagement dominantPM = childBuild.getPluginManagement(); PluginManagement recessivePM = parentBuild.getPluginManagement(); - if ( dominantPM == null && recessivePM != null ) + if ( ( dominantPM == null ) && ( recessivePM != null ) ) { childBuild.setPluginManagement( recessivePM ); } @@ -493,10 +493,14 @@ public class DefaultModelInheritanceAssembler if ( appendPaths ) { if ( pathAdjustment != null ) + { uncleanPath += "/" + pathAdjustment; + } if ( childPath != null ) + { uncleanPath += "/" + childPath; + } } String cleanedPath = ""; @@ -510,7 +514,9 @@ public class DefaultModelInheritanceAssembler } if ( uncleanPath.startsWith( "/" ) ) + { cleanedPath += "/"; + } return cleanedPath + resolvePath( uncleanPath ); } @@ -524,7 +530,7 @@ public class DefaultModelInheritanceAssembler while ( tokenizer.hasMoreTokens() ) { - String token = (String) tokenizer.nextToken(); + String token = tokenizer.nextToken(); if ( token.equals( "" ) ) { @@ -556,7 +562,9 @@ public class DefaultModelInheritanceAssembler { cleanedPath.append( pathElements.removeFirst() ); if ( !pathElements.isEmpty() ) + { cleanedPath.append( '/' ); + } } return cleanedPath.toString(); diff --git a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index a2891d83fc..6c69aadc1c 100644 --- a/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-project/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -59,17 +59,17 @@ public class DefaultModelValidator validateId( "artifactId", result, model.getArtifactId() ); validateStringNotEmpty( "packaging", result, model.getPackaging() ); - + if ( !model.getModules().isEmpty() && !"pom".equals( model.getPackaging() ) ) { result.addMessage( "Packaging '" + model.getPackaging() + "' is invalid. Aggregator projects " + "require 'pom' as packaging." ); } - + Parent parent = model.getParent(); if ( parent != null ) { - if ( parent.getGroupId().equals( model.getGroupId() ) && + if ( parent.getGroupId().equals( model.getGroupId() ) && parent.getArtifactId().equals( model.getArtifactId() ) ) { result.addMessage( "The parent element cannot have the same ID as the project." ); @@ -93,7 +93,7 @@ public class DefaultModelValidator if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) { String systemPath = d.getSystemPath(); - + if ( StringUtils.isEmpty( systemPath ) ) { result.addMessage( "For dependency " + d + ": system-scoped dependency must specify systemPath." ); @@ -130,7 +130,7 @@ public class DefaultModelValidator if ( Artifact.SCOPE_SYSTEM.equals( d.getScope() ) ) { String systemPath = d.getSystemPath(); - + if ( StringUtils.isEmpty( systemPath ) ) { result.addMessage( "For managed dependency " + d + ": system-scoped dependency must specify systemPath." ); @@ -194,7 +194,7 @@ public class DefaultModelValidator validateRepositories( result, model.getRepositories(), "repositories.repository" ); - validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" ); +// validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" ); forcePluginExecutionIdCollision( model, result ); diff --git a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java index ce05b85cc6..7c20b5c03c 100644 --- a/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/SuperPomProjectBuilderTest.java @@ -19,15 +19,6 @@ package org.apache.maven.project; * under the License. */ -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.codehaus.plexus.util.FileUtils; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; public class SuperPomProjectBuilderTest extends AbstractMavenProjectTestCase @@ -45,7 +36,7 @@ public class SuperPomProjectBuilderTest MavenProject project = projectBuilder.buildStandaloneSuperProject(); assertNotNull( project.getRemoteArtifactRepositories() ); - - assertNotNull( project.getPluginArtifactRepositories() ); +// +// assertNotNull( project.getPluginArtifactRepositories() ); } } \ No newline at end of file diff --git a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index 0b0cab64f1..18857bea16 100644 --- a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -99,14 +99,14 @@ public class DefaultModelValidatorTest assertEquals( "'version' is missing.", result.getMessage( 0 ) ); } - + public void testInvalidAggregatorPackaging() throws Exception { ModelValidationResult result = validate( "invalid-aggregator-packaging-pom.xml" ); - + assertEquals( 1, result.getMessageCount() ); - + assertTrue( result.getMessage( 0 ).indexOf( "Aggregator projects require 'pom' as packaging." ) > -1 ); } @@ -193,15 +193,15 @@ public class DefaultModelValidatorTest { ModelValidationResult result = validate( "missing-repository-id-pom.xml" ); - assertEquals( 4, result.getMessageCount() ); + assertEquals( 2, result.getMessageCount() ); assertEquals( "'repositories.repository.id' is missing.", result.getMessage( 0 ) ); assertEquals( "'repositories.repository.url' is missing.", result.getMessage( 1 ) ); - - assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getMessage( 2 ) ); - - assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) ); +// +// assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getMessage( 2 ) ); +// +// assertEquals( "'pluginRepositories.pluginRepository.url' is missing.", result.getMessage( 3 ) ); } public void testMissingResourceDirectory()