mirror of https://github.com/apache/maven.git
decouple project stuff from maven-core
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@164205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a803fc26b4
commit
9774d3d1cb
|
@ -17,8 +17,8 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
|
@ -109,20 +109,40 @@ public class DefaultMavenProjectBuilder
|
|||
// MavenProjectBuilder Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
public MavenProject buildWithDependencies( File projectDescriptor, ArtifactRepository localRepository,
|
||||
ArtifactMetadataSource artifactMetadataSource )
|
||||
throws ProjectBuildingException, ArtifactResolutionException
|
||||
{
|
||||
return buildFromSourceFile( projectDescriptor, localRepository, true );
|
||||
MavenProject project = buildFromSourceFile( projectDescriptor, localRepository );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Typically when the project builder is being used from maven proper
|
||||
// the transitive dependencies will not be resolved here because this
|
||||
// requires a lot of work when we may only be interested in running
|
||||
// something simple like 'm2 clean'. So the artifact collector is used
|
||||
// in the dependency resolution phase if it is required by any of the
|
||||
// goals being executed. But when used as a component in another piece
|
||||
// of code people may just want to build maven projects and have the
|
||||
// dependencies resolved for whatever reason: this is why we keep
|
||||
// this snippet of code here.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||
project.getRemoteArtifactRepositories(),
|
||||
localRepository,
|
||||
artifactMetadataSource );
|
||||
|
||||
project.addArtifacts( result.getArtifacts().values(), artifactFactory );
|
||||
return project;
|
||||
}
|
||||
|
||||
public MavenProject build( File projectDescriptor, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
return buildFromSourceFile( projectDescriptor, localRepository, false );
|
||||
return buildFromSourceFile( projectDescriptor, localRepository );
|
||||
}
|
||||
|
||||
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository,
|
||||
boolean resolveDependencies )
|
||||
private MavenProject buildFromSourceFile( File projectDescriptor, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model model = readModel( projectDescriptor );
|
||||
|
@ -130,7 +150,7 @@ public class DefaultMavenProjectBuilder
|
|||
// Always cache files in the source tree over those in the repository
|
||||
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model );
|
||||
|
||||
MavenProject project = build( model, localRepository, resolveDependencies );
|
||||
MavenProject project = build( model, localRepository );
|
||||
|
||||
// Only translate the base directory for files in the source tree
|
||||
pathTranslator.alignToBaseDirectory( project.getModel(), projectDescriptor );
|
||||
|
@ -153,7 +173,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
Model model = findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
|
||||
|
||||
return build( model, localRepository, false );
|
||||
return build( model, localRepository );
|
||||
}
|
||||
|
||||
private Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
|
||||
|
@ -176,7 +196,7 @@ public class DefaultMavenProjectBuilder
|
|||
return model;
|
||||
}
|
||||
|
||||
private MavenProject build( Model model, ArtifactRepository localRepository, boolean resolveDependencies )
|
||||
private MavenProject build( Model model, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model superModel = getSuperModel();
|
||||
|
@ -200,18 +220,12 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
try
|
||||
{
|
||||
project = processProjectLogic( project, localRepository, aggregatedRemoteWagonRepositories,
|
||||
resolveDependencies );
|
||||
project = processProjectLogic( project, aggregatedRemoteWagonRepositories );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Error building project: " + model.getId(), e );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Error building project: " + model.getId(), e );
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -222,9 +236,8 @@ public class DefaultMavenProjectBuilder
|
|||
* the resolved source roots, etc for the parent - that occurs for the parent when it is constructed independently
|
||||
* and projects are not cached or reused
|
||||
*/
|
||||
private MavenProject processProjectLogic( MavenProject project, ArtifactRepository localRepository,
|
||||
List remoteRepositories, boolean resolveDependencies )
|
||||
throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException
|
||||
private MavenProject processProjectLogic( MavenProject project, List remoteRepositories )
|
||||
throws ProjectBuildingException, ModelInterpolationException
|
||||
{
|
||||
Model model = project.getModel();
|
||||
String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
|
||||
|
@ -255,30 +268,6 @@ public class DefaultMavenProjectBuilder
|
|||
project.setRemoteArtifactRepositories( remoteRepositories );
|
||||
project.setArtifacts( createArtifacts( project.getDependencies() ) );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Typically when the project builder is being used from maven proper
|
||||
// the transitive dependencies will not be resolved here because this
|
||||
// requires a lot of work when we may only be interested in running
|
||||
// something simple like 'm2 clean'. So the artifact collector is used
|
||||
// in the dependency resolution phase if it is required by any of the
|
||||
// goals being executed. But when used as a component in another piece
|
||||
// of code people may just want to build maven projects and have the
|
||||
// dependencies resolved for whatever reason: this is why we keep
|
||||
// this snippet of code here.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
if ( resolveDependencies )
|
||||
{
|
||||
// TODO: comes from Maven CORE
|
||||
MavenMetadataSource sourceReader = new MavenMetadataSource( artifactResolver, this );
|
||||
|
||||
ArtifactResolutionResult result = artifactResolver.resolveTransitively( project.getArtifacts(),
|
||||
remoteRepositories,
|
||||
localRepository, sourceReader );
|
||||
|
||||
project.addArtifacts( result.getArtifacts().values(), artifactFactory );
|
||||
}
|
||||
|
||||
ModelValidationResult validationResult = validator.validate( model );
|
||||
|
||||
if ( validationResult.getMessageCount() > 0 )
|
||||
|
@ -495,7 +484,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
List remoteRepositories = buildArtifactRepositories( superModel.getRepositories() );
|
||||
|
||||
project = processProjectLogic( project, localRepository, remoteRepositories, false );
|
||||
project = processProjectLogic( project, remoteRepositories );
|
||||
|
||||
return project;
|
||||
}
|
||||
|
@ -503,10 +492,15 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( "Error building super-project", e );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ProjectBuildingException( "Error building super-project", e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @todo remove
|
||||
*/
|
||||
public ArtifactResolver getArtifactResolver()
|
||||
{
|
||||
return artifactResolver;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -18,6 +18,10 @@ package org.apache.maven.project;
|
|||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.settings.Settings;
|
||||
|
||||
|
@ -37,8 +41,9 @@ public interface MavenProjectBuilder
|
|||
MavenProject build( File project, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
MavenProject buildWithDependencies( File project, ArtifactRepository localRepository,
|
||||
ArtifactMetadataSource artifactMetadataSource )
|
||||
throws ProjectBuildingException, ArtifactResolutionException;
|
||||
|
||||
/**
|
||||
* Build the artifact from the local repository, resolving it if necessary.
|
||||
|
@ -55,4 +60,6 @@ public interface MavenProjectBuilder
|
|||
|
||||
MavenProject buildStandaloneSuperProject( ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
ArtifactResolver getArtifactResolver();
|
||||
}
|
||||
|
|
|
@ -16,12 +16,12 @@ package org.apache.maven;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.settings.MavenSettingsBuilder;
|
||||
import org.codehaus.plexus.ArtifactEnabledPlexusTestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -54,8 +54,8 @@ public abstract class MavenTestCase
|
|||
|
||||
protected File getLocalRepositoryPath()
|
||||
{
|
||||
File markerFile = getFileForClasspathResource( "local-repo/marker.txt" );
|
||||
|
||||
File markerFile = getFileForClasspathResource( "local-repo/marker.txt" );
|
||||
|
||||
return markerFile.getAbsoluteFile().getParentFile();
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,9 @@ public abstract class MavenTestCase
|
|||
protected MavenProject getProjectWithDependencies( File pom )
|
||||
throws Exception
|
||||
{
|
||||
return projectBuilder.buildWithDependencies( pom, getLocalRepository() );
|
||||
return projectBuilder.buildWithDependencies( pom, getLocalRepository(),
|
||||
new MavenMetadataSource( projectBuilder.getArtifactResolver(),
|
||||
projectBuilder ) );
|
||||
}
|
||||
|
||||
protected MavenProject getProject( File pom )
|
||||
|
|
Loading…
Reference in New Issue