o cleaning up the project builder, deprecating maven 1.x repository support, it will be 3 years by the time this is actually released

so tough noogies for people still trying to use Maven 1.x repositories with Maven 2.x.

  The next series of refactoring I will be doing with GIT.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@580609 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2007-09-29 17:25:19 +00:00
parent 0c84fd3f65
commit e6a6476ad7
11 changed files with 113 additions and 269 deletions

View File

@ -252,6 +252,7 @@ private void initializeBuildContext( MavenExecutionRequest request )
true ); true );
systemContext.setSystemProperties( request.getProperties() ); systemContext.setSystemProperties( request.getProperties() );
systemContext.store( buildContextManager ); systemContext.store( buildContextManager );
} }
@ -276,45 +277,29 @@ private List getProjects( MavenExecutionRequest request )
// instances just-in-time. // instances just-in-time.
try try
{ {
buildExtensionScanner.scanForBuildExtensions( buildExtensionScanner.scanForBuildExtensions( files, request.getLocalRepository(), request.getProfileManager() );
files,
request.getLocalRepository(),
request.getProfileManager() );
} }
catch ( ExtensionScanningException e ) catch ( ExtensionScanningException e )
{ {
throw new MavenExecutionException( throw new MavenExecutionException( "Error scanning for extensions: " + e.getMessage(), e );
"Error scanning for extensions: " + e.getMessage(),
e );
} }
try try
{ {
projects = collectProjects( projects = collectProjects( files, request.getLocalRepository(), request.isRecursive(), request.getProfileManager(), !request.useReactor() );
files,
request.getLocalRepository(),
request.isRecursive(),
request.getProfileManager(),
!request.useReactor() );
} }
catch ( ArtifactResolutionException e ) catch ( ArtifactResolutionException e )
{ {
throw new MavenExecutionException( throw new MavenExecutionException( e.getMessage(), e );
e.getMessage(),
e );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
throw new MavenExecutionException( throw new MavenExecutionException( e.getMessage(), e );
e.getMessage(),
e );
} }
catch ( ProfileActivationException e ) catch ( ProfileActivationException e )
{ {
throw new MavenExecutionException( throw new MavenExecutionException( e.getMessage(), e );
e.getMessage(),
e );
} }
return projects; return projects;
} }
@ -342,10 +327,7 @@ private List collectProjects( List files,
usingReleasePom = true; usingReleasePom = true;
} }
MavenProject project = projectBuilder.build( MavenProject project = projectBuilder.build( file, localRepository, globalProfileManager );
file,
localRepository,
globalProfileManager );
if ( isRoot ) if ( isRoot )
{ {
@ -355,6 +337,7 @@ private List collectProjects( List files,
if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null ) if ( project.getPrerequisites() != null && project.getPrerequisites().getMaven() != null )
{ {
DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() ); DefaultArtifactVersion version = new DefaultArtifactVersion( project.getPrerequisites().getMaven() );
if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 ) if ( runtimeInformation.getApplicationVersion().compareTo( version ) < 0 )
{ {
throw new BuildFailureException( throw new BuildFailureException(
@ -372,14 +355,14 @@ private List collectProjects( List files,
// Initial ordering is as declared in the modules section // Initial ordering is as declared in the modules section
List moduleFiles = new ArrayList( project.getModules().size() ); List moduleFiles = new ArrayList( project.getModules().size() );
for ( Iterator i = project.getModules().iterator(); i.hasNext(); ) for ( Iterator i = project.getModules().iterator(); i.hasNext(); )
{ {
String name = (String) i.next(); String name = (String) i.next();
if ( StringUtils.isEmpty( StringUtils.trim( name ) ) ) if ( StringUtils.isEmpty( StringUtils.trim( name ) ) )
{ {
getLogger().warn( getLogger().warn( "Empty module detected. Please check you don't have any empty module definitions in your POM." );
"Empty module detected. Please check you don't have any empty module definitions in your POM." );
continue; continue;
} }
@ -388,15 +371,11 @@ private List collectProjects( List files,
if ( usingReleasePom ) if ( usingReleasePom )
{ {
moduleFile = new File( moduleFile = new File( basedir, name + "/" + Maven.RELEASE_POMv4 );
basedir,
name + "/" + Maven.RELEASE_POMv4 );
} }
else else
{ {
moduleFile = new File( moduleFile = new File( basedir, name + "/" + Maven.POMv4 );
basedir,
name + "/" + Maven.POMv4 );
} }
if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
@ -409,9 +388,7 @@ private List collectProjects( List files,
} }
catch ( IOException e ) catch ( IOException e )
{ {
throw new MavenExecutionException( throw new MavenExecutionException( "Unable to canonicalize file name " + moduleFile, e );
"Unable to canonicalize file name " + moduleFile,
e );
} }
} }
@ -478,17 +455,11 @@ private List getProjectFiles( MavenExecutionRequest request )
if ( request.useReactor() ) if ( request.useReactor() )
{ {
String includes = System.getProperty( String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 + ",**/" + RELEASE_POMv4 );
"maven.reactor.includes",
"**/" + POMv4 + ",**/" + RELEASE_POMv4 );
String excludes = System.getProperty(
"maven.reactor.excludes",
POMv4 + "," + RELEASE_POMv4 );
files = FileUtils.getFiles( String excludes = System.getProperty( "maven.reactor.excludes", POMv4 + "," + RELEASE_POMv4 );
userDir,
includes, files = FileUtils.getFiles( userDir, includes, excludes );
excludes );
filterOneProjectFilePerDirectory( files ); filterOneProjectFilePerDirectory( files );
@ -506,15 +477,11 @@ else if ( request.getPomFile() != null )
} }
else else
{ {
File projectFile = new File( File projectFile = new File( userDir, RELEASE_POMv4 );
userDir,
RELEASE_POMv4 );
if ( !projectFile.exists() ) if ( !projectFile.exists() )
{ {
projectFile = new File( projectFile = new File( userDir, POMv4 );
userDir,
POMv4 );
} }
if ( projectFile.exists() ) if ( projectFile.exists() )

View File

@ -92,6 +92,7 @@ public void addExtension( Extension extension,
Parent originatingParent = originatingModel.getParent(); Parent originatingParent = originatingModel.getParent();
String groupId = originatingModel.getGroupId(); String groupId = originatingModel.getGroupId();
if ( ( groupId == null ) && ( originatingParent != null ) ) if ( ( groupId == null ) && ( originatingParent != null ) )
{ {
groupId = originatingParent.getGroupId(); groupId = originatingParent.getGroupId();
@ -100,6 +101,7 @@ public void addExtension( Extension extension,
String artifactId = originatingModel.getArtifactId(); String artifactId = originatingModel.getArtifactId();
String version = originatingModel.getVersion(); String version = originatingModel.getVersion();
if ( ( version == null ) && ( originatingParent != null ) ) if ( ( version == null ) && ( originatingParent != null ) )
{ {
version = originatingParent.getVersion(); version = originatingParent.getVersion();

View File

@ -291,7 +291,7 @@ private void checkRequiredMavenVersion( Plugin plugin,
plugin.getVersion() ); plugin.getVersion() );
MavenProject project = mavenProjectBuilder.buildFromRepository( artifact, MavenProject project = mavenProjectBuilder.buildFromRepository( artifact,
remoteRepositories, remoteRepositories,
localRepository, false ); localRepository );
// if we don't have the required Maven version, then ignore an update // if we don't have the required Maven version, then ignore an update
if ( ( project.getPrerequisites() != null ) if ( ( project.getPrerequisites() != null )
&& ( project.getPrerequisites().getMaven() != null ) ) && ( project.getPrerequisites().getMaven() != null ) )

View File

@ -215,9 +215,8 @@ private String resolveMetaVersion( String groupId,
try try
{ {
artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion ); artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion );
pluginProject = mavenProjectBuilder.buildFromRepository( artifact,
project.getPluginArtifactRepositories(), pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getPluginArtifactRepositories(), localRepository );
localRepository, false );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {

View File

@ -387,7 +387,7 @@ private Map findArtifactTypeHandlers( MavenProject project )
public MavenProject readProject( File mavenProject ) public MavenProject readProject( File mavenProject )
throws ProjectBuildingException throws ProjectBuildingException
{ {
return mavenProjectBuilder.build( mavenProject, request.getLocalRepository(), request.getProfileManager(), false ); return mavenProjectBuilder.build( mavenProject, request.getLocalRepository(), request.getProfileManager() );
} }
/** /**
@ -442,8 +442,7 @@ public MavenExecutionResult readProjectWithDependencies( MavenExecutionRequest r
projectBuildingResult = mavenProjectBuilder.buildWithDependencies( projectBuildingResult = mavenProjectBuilder.buildWithDependencies(
new File( request.getPomFile() ), new File( request.getPomFile() ),
request.getLocalRepository(), request.getLocalRepository(),
request.getProfileManager(), request.getProfileManager() );
request.getTransferListener() );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {

View File

@ -134,15 +134,11 @@ private void pom( MavenExecutionRequest request, Configuration configuration )
else if ( request.getBaseDirectory() != null ) else if ( request.getBaseDirectory() != null )
{ {
// Look for a release POM // Look for a release POM
File pom = new File( File pom = new File( request.getBaseDirectory(), Maven.RELEASE_POMv4 );
request.getBaseDirectory(),
Maven.RELEASE_POMv4 );
if ( !pom.exists() ) if ( !pom.exists() )
{ {
pom = new File( pom = new File( request.getBaseDirectory(), Maven.POMv4 );
request.getBaseDirectory(),
Maven.POMv4 );
} }
request.setPomFile( pom.getAbsolutePath() ); request.setPomFile( pom.getAbsolutePath() );

View File

@ -62,12 +62,10 @@ public class DefaultProfileAdvisor
private PlexusContainer container; private PlexusContainer container;
public List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds, public List applyActivatedProfiles( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
List explicitlyInactiveIds )
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, explicitlyInactiveIds );
explicitlyInactiveIds );
return applyActivatedProfiles( model, projectDir, profileManager ); return applyActivatedProfiles( model, projectDir, profileManager );
} }
@ -123,13 +121,13 @@ private List applyActivatedProfiles( Model model, File projectDir, ProfileManage
return activeProfiles; return activeProfiles;
} }
private ProfileManager buildProfileManager( Model model, File projectDir, List explicitlyActiveIds, private ProfileManager buildProfileManager( Model model, File projectDir, List explicitlyActiveIds, List explicitlyInactiveIds )
List explicitlyInactiveIds )
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProfileManager profileManager = new DefaultProfileManager( container ); ProfileManager profileManager = new DefaultProfileManager( container );
profileManager.explicitlyActivate( explicitlyActiveIds ); profileManager.explicitlyActivate( explicitlyActiveIds );
profileManager.explicitlyDeactivate( explicitlyInactiveIds ); profileManager.explicitlyDeactivate( explicitlyInactiveIds );
profileManager.addProfiles( model.getProfiles() ); profileManager.addProfiles( model.getProfiles() );
@ -146,8 +144,7 @@ public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, Fil
List explicitlyActiveIds, List explicitlyInactiveIds ) List explicitlyActiveIds, List explicitlyInactiveIds )
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, ProfileManager profileManager = buildProfileManager( model, projectDir, explicitlyActiveIds, explicitlyInactiveIds );
explicitlyInactiveIds );
List activeExternalProfiles; List activeExternalProfiles;
{ {
@ -171,7 +168,7 @@ public LinkedHashSet getArtifactRepositoriesFromActiveProfiles( Model model, Fil
{ {
Repository mavenRepo = (Repository) repoIterator.next(); Repository mavenRepo = (Repository) repoIterator.next();
ArtifactRepository artifactRepo = null; ArtifactRepository artifactRepo;
try try
{ {
artifactRepo = mavenTools.buildArtifactRepository( mavenRepo ); artifactRepo = mavenTools.buildArtifactRepository( mavenRepo );

View File

@ -25,7 +25,6 @@
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@ -52,6 +51,7 @@
import org.apache.maven.profiles.MavenProfilesBuilder; import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.build.ProfileAdvisor;
import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.build.ProjectBuildCache; import org.apache.maven.project.build.ProjectBuildCache;
import org.apache.maven.project.build.ProjectBuildContext; import org.apache.maven.project.build.ProjectBuildContext;
@ -59,7 +59,6 @@
import org.apache.maven.project.build.model.ModelLineage; import org.apache.maven.project.build.model.ModelLineage;
import org.apache.maven.project.build.model.ModelLineageBuilder; import org.apache.maven.project.build.model.ModelLineageBuilder;
import org.apache.maven.project.build.model.ModelLineageIterator; import org.apache.maven.project.build.model.ModelLineageIterator;
import org.apache.maven.profiles.build.ProfileAdvisor;
import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.inheritance.ModelInheritanceAssembler;
import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.interpolation.ModelInterpolationException;
@ -67,7 +66,6 @@
import org.apache.maven.project.path.PathTranslator; import org.apache.maven.project.path.PathTranslator;
import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator; import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.wagon.events.TransferListener;
import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
@ -141,7 +139,9 @@
*/ */
public class DefaultMavenProjectBuilder public class DefaultMavenProjectBuilder
extends AbstractLogEnabled extends AbstractLogEnabled
implements MavenProjectBuilder, Initializable, Contextualizable implements MavenProjectBuilder,
Initializable,
Contextualizable
{ {
protected PlexusContainer container; protected PlexusContainer container;
@ -174,16 +174,6 @@ public class DefaultMavenProjectBuilder
private MavenTools mavenTools; private MavenTools mavenTools;
// ----------------------------------------------------------------------
// I am making this available for use with a new method that takes a
// a monitor wagon monitor as a parameter so that tools can use the
// methods here and receive callbacks. MNG-1015
//
// Probably no longer relevant with wagonManager/wagonManager change - joakime
// ----------------------------------------------------------------------
private WagonManager wagonManager;
public static final String MAVEN_MODEL_VERSION = "4.0.0"; public static final String MAVEN_MODEL_VERSION = "4.0.0";
public void initialize() public void initialize()
@ -200,28 +190,24 @@ public MavenProject build( File projectDescriptor,
ProfileManager profileManager ) ProfileManager profileManager )
throws ProjectBuildingException throws ProjectBuildingException
{ {
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager, true ); return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager );
} }
public MavenProject build( File projectDescriptor, /** @deprecated */
ArtifactRepository localRepository,
ProfileManager profileManager,
boolean checkDistributionManagementStatus )
throws ProjectBuildingException
{
return buildFromSourceFileInternal( projectDescriptor, localRepository, profileManager, checkDistributionManagementStatus );
}
// jvz:note
// When asked for something from the repository are we getting it from the reactor? Yes, when using this call
// we are assuming that the reactor has been run and we have collected the projects required to satisfy it0042
// which means the projects in the reactor are required for finding classes in <project>/target/classes. Not
// sure this is ideal. I remove all caching from the builder and all reactor related ITs which assume
// access to simbling project resources failed.
public MavenProject buildFromRepository( Artifact artifact, public MavenProject buildFromRepository( Artifact artifact,
List remoteArtifactRepositories, List remoteArtifactRepositories,
ArtifactRepository localRepository, ArtifactRepository localRepository,
boolean allowStubModel ) boolean allowStub )
throws ProjectBuildingException
{
return buildFromRepository( artifact, remoteArtifactRepositories, localRepository );
}
public MavenProject buildFromRepository( Artifact artifact,
List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException throws ProjectBuildingException
{ {
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
@ -233,19 +219,11 @@ public MavenProject buildFromRepository( Artifact artifact,
return project; return project;
} }
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository, allowStubModel ); Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
return buildInternal( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null, false ); return buildInternal( "Artifact [" + artifact + "]", model, localRepository, remoteArtifactRepositories, null, null, false );
} }
public MavenProject buildFromRepository( Artifact artifact,
List remoteArtifactRepositories,
ArtifactRepository localRepository )
throws ProjectBuildingException
{
return buildFromRepository( artifact, remoteArtifactRepositories, localRepository, true );
}
private MavenProject superProject; private MavenProject superProject;
public MavenProject buildStandaloneSuperProject() public MavenProject buildStandaloneSuperProject()
@ -289,19 +267,7 @@ public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
ProfileManager profileManager ) ProfileManager profileManager )
throws ProjectBuildingException throws ProjectBuildingException
{ {
return buildWithDependencies( projectDescriptor, localRepository, profileManager, null ); MavenProject project = build( projectDescriptor, localRepository, profileManager );
}
// note:jvz This was added for the embedder.
/** @todo move to metadatasource itself? */
public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
ArtifactRepository localRepository,
ProfileManager profileManager,
TransferListener transferListener )
throws ProjectBuildingException
{
MavenProject project = build( projectDescriptor, localRepository, profileManager, false );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Typically when the project builder is being used from maven proper // Typically when the project builder is being used from maven proper
@ -335,11 +301,6 @@ public MavenProjectBuildingResult buildWithDependencies( File projectDescriptor,
e.getMessage(), e ); e.getMessage(), e );
} }
if ( transferListener != null )
{
wagonManager.setDownloadMonitor( transferListener );
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest() ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( projectArtifact ) .setArtifact( projectArtifact )
.setArtifactDependencies( project.getDependencyArtifacts() ) .setArtifactDependencies( project.getDependencyArtifacts() )
@ -377,8 +338,7 @@ private void ensureMetadataSourceIsInitialized()
} }
private Map createManagedVersionMap( String projectId, private Map createManagedVersionMap( String projectId,
DependencyManagement dependencyManagement, DependencyManagement dependencyManagement )
MavenProject parent )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Map map = null; Map map = null;
@ -399,10 +359,10 @@ private Map createManagedVersionMap( String projectId,
try try
{ {
VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
versionRange, d.getType(), Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(),
d.getClassifier(), d.getScope(), d.getClassifier(), d.getScope(), d.isOptional() );
d.isOptional() );
if ( getLogger().isDebugEnabled() ) if ( getLogger().isDebugEnabled() )
{ {
getLogger().debug( " " + artifact ); getLogger().debug( " " + artifact );
@ -411,22 +371,27 @@ private Map createManagedVersionMap( String projectId,
// If the dependencyManagement section listed exclusions, // If the dependencyManagement section listed exclusions,
// add them to the managed artifacts here so that transitive // add them to the managed artifacts here so that transitive
// dependencies will be excluded if necessary. // dependencies will be excluded if necessary.
if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() ) if ( ( null != d.getExclusions() ) && !d.getExclusions().isEmpty() )
{ {
List exclusions = new ArrayList(); List exclusions = new ArrayList();
Iterator exclItr = d.getExclusions().iterator();
while ( exclItr.hasNext() ) for ( Iterator j = d.getExclusions().iterator(); j.hasNext(); )
{ {
Exclusion e = (Exclusion) exclItr.next(); Exclusion e = (Exclusion) j.next();
exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); exclusions.add( e.getGroupId() + ":" + e.getArtifactId() );
} }
ExcludesArtifactFilter eaf = new ExcludesArtifactFilter( exclusions ); ExcludesArtifactFilter eaf = new ExcludesArtifactFilter( exclusions );
artifact.setDependencyFilter( eaf ); artifact.setDependencyFilter( eaf );
} }
else else
{ {
artifact.setDependencyFilter( null ); artifact.setDependencyFilter( null );
} }
map.put( d.getManagementKey(), artifact ); map.put( d.getManagementKey(), artifact );
} }
catch ( InvalidVersionSpecificationException e ) catch ( InvalidVersionSpecificationException e )
@ -445,15 +410,16 @@ else if ( map == null )
private MavenProject buildFromSourceFileInternal( File projectDescriptor, private MavenProject buildFromSourceFileInternal( File projectDescriptor,
ArtifactRepository localRepository, ArtifactRepository localRepository,
ProfileManager profileManager, ProfileManager profileManager )
boolean checkDistributionManagementStatus )
throws ProjectBuildingException throws ProjectBuildingException
{ {
/*
// TODO: Remove this once we have build-context stuff working... // TODO: Remove this once we have build-context stuff working...
if ( !container.getContext().contains( "SystemProperties" ) ) if ( !container.getContext().contains( "SystemProperties" ) )
{ {
container.addContextValue( "SystemProperties", System.getProperties() ); container.addContextValue( "SystemProperties", System.getProperties() );
} }
*/
Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING ); Model model = readModel( "unknown", projectDescriptor, STRICT_MODEL_PARSING );
@ -465,29 +431,12 @@ private MavenProject buildFromSourceFileInternal( File projectDescriptor,
profileManager, profileManager,
STRICT_MODEL_PARSING ); STRICT_MODEL_PARSING );
/*
MNG-3178: What is this actually for as we're not deploying this anymore.
if ( checkDistributionManagementStatus )
{
if ( ( project.getDistributionManagement() != null ) && ( project.getDistributionManagement().getStatus() != null ) )
{
String projectId = safeVersionlessKey( project.getGroupId(), project.getArtifactId() );
throw new ProjectBuildingException( projectId,
"Invalid project file: distribution status must not be specified for a project outside of the repository" );
}
}
*/
return project; return project;
} }
private Model findModelFromRepository( Artifact artifact, private Model findModelFromRepository( Artifact artifact,
List remoteArtifactRepositories, List remoteArtifactRepositories,
ArtifactRepository localRepository, ArtifactRepository localRepository )
boolean allowStubModel )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Artifact projectArtifact; Artifact projectArtifact;
@ -552,18 +501,9 @@ private Model findModelFromRepository( Artifact artifact,
throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e ); throw new ProjectBuildingException( projectId, "Error getting POM for '" + projectId + "' from the repository: " + e.getMessage(), e );
} }
catch ( ArtifactNotFoundException e ) catch ( ArtifactNotFoundException e )
{
if ( allowStubModel )
{
getLogger().debug( "Artifact not found - using stub model: " + e.getMessage() );
model = createStubModel( projectArtifact );
}
else
{ {
throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e ); throw new ProjectBuildingException( projectId, "POM '" + projectId + "' not found in repository: " + e.getMessage(), e );
} }
}
return model; return model;
} }
@ -608,33 +548,6 @@ private void checkStatusAndUpdate( Artifact projectArtifact,
} }
} }
// jvz:note
// This is used when requested artifacts do not have an associated POM. This is for the case where we are
// using an m1 repo where the only thing required to be present are the JAR files.
private Model createStubModel( Artifact projectArtifact )
{
getLogger().debug( "Using defaults for missing POM " + projectArtifact );
Model model = new Model();
model.setModelVersion( "4.0.0" );
model.setArtifactId( projectArtifact.getArtifactId() );
model.setGroupId( projectArtifact.getGroupId() );
model.setVersion( projectArtifact.getVersion() );
// TODO: not correct in some instances
model.setPackaging( projectArtifact.getType() );
model.setDistributionManagement( new DistributionManagement() );
model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
return model;
}
// jvz:note // jvz:note
// We've got a mixture of things going in the USD and from the repository, sometimes the descriptor // We've got a mixture of things going in the USD and from the repository, sometimes the descriptor
// is a real file and sometimes null which makes things confusing. // is a real file and sometimes null which makes things confusing.
@ -661,6 +574,7 @@ private MavenProject buildInternal( String pomLocation,
String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() );
List explicitlyActive; List explicitlyActive;
List explicitlyInactive; List explicitlyInactive;
if ( externalProfileManager != null ) if ( externalProfileManager != null )
@ -676,11 +590,13 @@ private MavenProject buildInternal( String pomLocation,
} }
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds(); explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds(); explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
} }
else else
{ {
explicitlyActive = Collections.EMPTY_LIST; explicitlyActive = Collections.EMPTY_LIST;
explicitlyInactive = Collections.EMPTY_LIST; explicitlyInactive = Collections.EMPTY_LIST;
} }
@ -696,17 +612,11 @@ private MavenProject buildInternal( String pomLocation,
Model originalModel = ModelUtils.cloneModel( model ); Model originalModel = ModelUtils.cloneModel( model );
MavenProject project = null; MavenProject project;
try try
{ {
project = assembleLineage( model, project = assembleLineage( model, lineage, localRepository, projectDir, aggregatedRemoteWagonRepositories, externalProfileManager, strict );
lineage,
localRepository,
projectDir,
parentSearchRepositories,
aggregatedRemoteWagonRepositories,
externalProfileManager,
strict );
} }
catch ( InvalidRepositoryException e ) catch ( InvalidRepositoryException e )
{ {
@ -734,7 +644,9 @@ private MavenProject buildInternal( String pomLocation,
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().debug( "Cannot determine whether " + currentProject.getId() + " is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(), e ); getLogger().debug(
"Cannot determine whether " + currentProject.getId() + " is a module of " + previousProject.getId() + ". Reason: " + e.getMessage(),
e );
} }
modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment ); modelInheritanceAssembler.assembleModelInheritance( current, previous, pathAdjustment );
@ -760,7 +672,7 @@ private MavenProject buildInternal( String pomLocation,
try try
{ {
project = processProjectLogic( pomLocation, project, externalProfileManager, projectDir, strict ); project = processProjectLogic( pomLocation, project, projectDir, strict );
} }
catch ( ModelInterpolationException e ) catch ( ModelInterpolationException e )
{ {
@ -772,14 +684,13 @@ private MavenProject buildInternal( String pomLocation,
} }
ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager ); ProjectBuildCache projectBuildCache = ProjectBuildCache.read( buildContextManager );
projectBuildCache.cacheProject( project ); projectBuildCache.cacheProject( project );
projectBuildCache.store( buildContextManager ); projectBuildCache.store( buildContextManager );
// jvz:note
// this only happens if we are building from a source file
if ( projectDescriptor != null ) if ( projectDescriptor != null )
{ {
// Only translate the base directory for files in the source tree
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() ); pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor.getParentFile() );
Build build = project.getBuild(); Build build = project.getBuild();
@ -807,8 +718,7 @@ private MavenProject buildInternal( String pomLocation,
} }
} }
project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement(), project.setManagedVersionMap( createManagedVersionMap( projectId, project.getDependencyManagement() ) );
project.getParent() ) );
return project; return project;
} }
@ -851,9 +761,7 @@ private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
List explicitlyInactive ) List explicitlyInactive )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir, Set reposFromProfiles = profileAdvisor.getArtifactRepositoriesFromActiveProfiles( model, projectDir, explicitlyActive, explicitlyInactive );
explicitlyActive,
explicitlyInactive );
if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() ) if ( ( reposFromProfiles != null ) && !reposFromProfiles.isEmpty() )
{ {
@ -861,6 +769,7 @@ private void collectInitialRepositoriesFromModel( LinkedHashSet collected,
} }
List modelRepos = model.getRepositories(); List modelRepos = model.getRepositories();
if ( ( modelRepos != null ) && !modelRepos.isEmpty() ) if ( ( modelRepos != null ) && !modelRepos.isEmpty() )
{ {
try try
@ -920,7 +829,6 @@ private List buildArtifactRepositories( Model model )
*/ */
private MavenProject processProjectLogic( String pomLocation, private MavenProject processProjectLogic( String pomLocation,
MavenProject project, MavenProject project,
ProfileManager profileMgr,
File projectDir, File projectDir,
boolean strict ) boolean strict )
throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException throws ProjectBuildingException, ModelInterpolationException, InvalidRepositoryException
@ -1029,29 +937,31 @@ private MavenProject assembleLineage( Model model,
LinkedList lineage, LinkedList lineage,
ArtifactRepository localRepository, ArtifactRepository localRepository,
File projectDir, File projectDir,
List parentSearchRepositories,
Set aggregatedRemoteWagonRepositories, Set aggregatedRemoteWagonRepositories,
ProfileManager externalProfileManager, ProfileManager externalProfileManager,
boolean strict ) boolean strict )
throws ProjectBuildingException, InvalidRepositoryException throws ProjectBuildingException, InvalidRepositoryException
{ {
ModelLineage modelLineage = new DefaultModelLineage(); ModelLineage modelLineage = new DefaultModelLineage();
modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) ); modelLineage.setOrigin( model, new File( projectDir, "pom.xml" ), new ArrayList( aggregatedRemoteWagonRepositories ) );
// strict means "no stubs", so we invert it here for the allowStubs parameter.
modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict ); modelLineageBuilder.resumeBuildingModelLineage( modelLineage, localRepository, externalProfileManager, !strict );
ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true ); ProjectBuildContext projectContext = ProjectBuildContext.getProjectBuildContext( buildContextManager, true );
projectContext.setModelLineage( modelLineage ); projectContext.setModelLineage( modelLineage );
projectContext.store( buildContextManager ); projectContext.store( buildContextManager );
List explicitlyActive; List explicitlyActive;
List explicitlyInactive; List explicitlyInactive;
if ( externalProfileManager != null ) if ( externalProfileManager != null )
{ {
explicitlyActive = externalProfileManager.getExplicitlyActivatedIds(); explicitlyActive = externalProfileManager.getExplicitlyActivatedIds();
explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds(); explicitlyInactive = externalProfileManager.getExplicitlyDeactivatedIds();
} }
else else

View File

@ -58,56 +58,34 @@ public interface MavenProjectBuilder
boolean STRICT_MODEL_PARSING = true; boolean STRICT_MODEL_PARSING = true;
MavenProject build( File project, ArtifactRepository localRepository, ProfileManager globalProfileManager ) MavenProject build( File project,
throws ProjectBuildingException; ArtifactRepository localRepository,
MavenProject build( File project, ArtifactRepository localRepository, ProfileManager globalProfileManager,
boolean checkDistributionManagementStatus )
throws ProjectBuildingException;
// ----------------------------------------------------------------------
// These methods are used by the MavenEmbedder
// ----------------------------------------------------------------------
MavenProjectBuildingResult buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager, TransferListener transferListener )
throws ProjectBuildingException;
MavenProjectBuildingResult buildWithDependencies( File project, ArtifactRepository localRepository,
ProfileManager globalProfileManager ) ProfileManager globalProfileManager )
throws ProjectBuildingException; throws ProjectBuildingException;
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
/** MavenProjectBuildingResult buildWithDependencies( File project,
* Build the artifact from the local repository, resolving it if necessary. ArtifactRepository localRepository,
* ProfileManager globalProfileManager )
* @param artifact the artifact description throws ProjectBuildingException;
* @param localRepository the local repository
* @param remoteArtifactRepositories the remote repository list MavenProject buildFromRepository( Artifact artifact,
* @return the built project List remoteArtifactRepositories,
* @throws ProjectBuildingException
*/
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ProjectBuildingException; throws ProjectBuildingException;
/** /** @deprecated We do not want to allow projects to not have POMs. Maven 1.x repositories be damned. */
* Build the artifact from the local repository, resolving it if necessary. MavenProject buildFromRepository( Artifact artifact,
* List remoteArtifactRepositories,
* @param artifact the artifact description ArtifactRepository localRepository,
* @param localRepository the local repository boolean allowStub )
* @param remoteArtifactRepositories the remote repository list
* @param allowStubModel return a stub if the POM is not found
* @return the built project
* @throws ProjectBuildingException
*/
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository, boolean allowStubModel )
throws ProjectBuildingException; throws ProjectBuildingException;
/**
*
* @return
* @throws ProjectBuildingException
*/
MavenProject buildStandaloneSuperProject() MavenProject buildStandaloneSuperProject()
throws ProjectBuildingException; throws ProjectBuildingException;
} }

View File

@ -112,8 +112,7 @@ public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepo
{ {
try try
{ {
project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository, project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
true );
} }
catch ( InvalidProjectModelException e ) catch ( InvalidProjectModelException e )
{ {

View File

@ -184,9 +184,6 @@ under the License.
<role>org.apache.maven.context.BuildContextManager</role> <role>org.apache.maven.context.BuildContextManager</role>
<role-hint>default</role-hint> <role-hint>default</role-hint>
</requirement> </requirement>
<requirement>
<role>org.apache.maven.artifact.manager.WagonManager</role>
</requirement>
<requirement> <requirement>
<role>org.apache.maven.MavenTools</role> <role>org.apache.maven.MavenTools</role>
</requirement> </requirement>