mirror of
https://github.com/apache/maven.git
synced 2025-02-07 10:38:47 +00:00
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
This commit is contained in:
parent
0d6bdba6d5
commit
b310a40d6b
@ -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 );
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ public void inject( Profile profile, Model model )
|
||||
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 @@ private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge two DOMs. Copy the dominant DOM so the original one is left unchanged.
|
||||
* <p>
|
||||
@ -299,7 +299,7 @@ private void injectPluginDefinition( Plugin profilePlugin, Plugin modelPlugin )
|
||||
* 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
|
||||
|
@ -201,18 +201,19 @@ public MavenProject buildFromRepository( Artifact artifact,
|
||||
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 MavenProject buildStandaloneSuperProject()
|
||||
|
||||
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 MavenProject buildStandaloneSuperProject()
|
||||
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 @@ private MavenProject processProjectLogic( MavenProject project,
|
||||
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 @@ protected Set createExtensionArtifacts( String projectId,
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
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 );
|
||||
|
@ -22,10 +22,10 @@
|
||||
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 ArtifactRepository getDistributionManagementArtifactRepository()
|
||||
|
||||
public List getPluginRepositories()
|
||||
{
|
||||
return model.getPluginRepositories();
|
||||
// return model.getPluginRepositories();
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
public void setActiveProfiles( List activeProfiles )
|
||||
|
@ -91,4 +91,7 @@ MavenProject buildFromRepository( Artifact artifact,
|
||||
*/
|
||||
MavenProject buildStandaloneSuperProject()
|
||||
throws ProjectBuildingException;
|
||||
|
||||
MavenProject buildStandaloneSuperProject( ProfileManager profileManager )
|
||||
throws ProjectBuildingException;
|
||||
}
|
||||
|
@ -573,7 +573,7 @@ private static List cloneProfiles( List profiles )
|
||||
newProfile.setModules( new ArrayList( modules ) );
|
||||
}
|
||||
|
||||
newProfile.setPluginRepositories( cloneProfileRepositories( profile.getPluginRepositories() ) );
|
||||
// newProfile.setPluginRepositories( cloneProfileRepositories( profile.getPluginRepositories() ) );
|
||||
|
||||
Properties props = profile.getProperties();
|
||||
|
||||
|
@ -654,11 +654,11 @@ public void reportErrorParsingProjectModel( String projectId,
|
||||
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 void reportErrorParsingParentProjectModel( ModelAndFile childInfo,
|
||||
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 );
|
||||
|
@ -170,8 +170,8 @@ private void assembleModelInheritance( Model child, Model parent, String childPa
|
||||
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 @@ private void assembleBuildInheritance( Model child, Model parent )
|
||||
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 @@ private void assembleBuildInheritance( Model child, Model parent )
|
||||
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 @@ protected String appendPath( String parentPath, String childPath, String pathAdj
|
||||
if ( appendPaths )
|
||||
{
|
||||
if ( pathAdjustment != null )
|
||||
{
|
||||
uncleanPath += "/" + pathAdjustment;
|
||||
}
|
||||
|
||||
if ( childPath != null )
|
||||
{
|
||||
uncleanPath += "/" + childPath;
|
||||
}
|
||||
}
|
||||
|
||||
String cleanedPath = "";
|
||||
@ -510,7 +514,9 @@ protected String appendPath( String parentPath, String childPath, String pathAdj
|
||||
}
|
||||
|
||||
if ( uncleanPath.startsWith( "/" ) )
|
||||
{
|
||||
cleanedPath += "/";
|
||||
}
|
||||
|
||||
return cleanedPath + resolvePath( uncleanPath );
|
||||
}
|
||||
@ -524,7 +530,7 @@ private static String resolvePath( String uncleanPath )
|
||||
|
||||
while ( tokenizer.hasMoreTokens() )
|
||||
{
|
||||
String token = (String) tokenizer.nextToken();
|
||||
String token = tokenizer.nextToken();
|
||||
|
||||
if ( token.equals( "" ) )
|
||||
{
|
||||
@ -556,7 +562,9 @@ else if ( token.equals( ".." ) )
|
||||
{
|
||||
cleanedPath.append( pathElements.removeFirst() );
|
||||
if ( !pathElements.isEmpty() )
|
||||
{
|
||||
cleanedPath.append( '/' );
|
||||
}
|
||||
}
|
||||
|
||||
return cleanedPath.toString();
|
||||
|
@ -59,17 +59,17 @@ public ModelValidationResult validate( Model model )
|
||||
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 ModelValidationResult validate( Model model )
|
||||
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 @@ else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
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 @@ else if ( StringUtils.isNotEmpty( d.getSystemPath() ) )
|
||||
|
||||
validateRepositories( result, model.getRepositories(), "repositories.repository" );
|
||||
|
||||
validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" );
|
||||
// validateRepositories( result, model.getPluginRepositories(), "pluginRepositories.pluginRepository" );
|
||||
|
||||
forcePluginExecutionIdCollision( model, result );
|
||||
|
||||
|
@ -19,15 +19,6 @@
|
||||
* 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 void testBuildFromMiddlePom() throws Exception
|
||||
MavenProject project = projectBuilder.buildStandaloneSuperProject();
|
||||
|
||||
assertNotNull( project.getRemoteArtifactRepositories() );
|
||||
|
||||
assertNotNull( project.getPluginArtifactRepositories() );
|
||||
//
|
||||
// assertNotNull( project.getPluginArtifactRepositories() );
|
||||
}
|
||||
}
|
@ -99,14 +99,14 @@ public void testMissingVersion()
|
||||
|
||||
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 void testMissingRepositoryId()
|
||||
{
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user