MNG-3905 First pass at collecting all the repository related code and started to decouple from maven-artifact

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@726383 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2008-12-14 06:24:01 +00:00
parent 4074068126
commit ea43792cf2
8 changed files with 202 additions and 228 deletions

View File

@ -558,17 +558,21 @@ public class DefaultPluginManager
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
Xpp3Dom dom = mojoExecution.getConfiguration(); Xpp3Dom dom = mojoExecution.getConfiguration();
if ( dom != null ) if ( dom != null )
{ {
try try
{ {
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>(); List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getExecutionProperties(),
PomInterpolatorTag.SYSTEM_PROPERTIES.name())); PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name())); PomInterpolatorTag.USER_PROPERTIES.name()));
String interpolatedDom =
Interpolator.interpolateXmlString( String.valueOf( dom ), interpolatorProperties ); String interpolatedDom = Interpolator.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) ); dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
} }
catch ( XmlPullParserException e ) catch ( XmlPullParserException e )

View File

@ -26,11 +26,10 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.apache.maven.Maven; import org.apache.maven.Maven;
import org.apache.maven.MavenTools;
import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.embedder.Configuration; import org.apache.maven.embedder.Configuration;
import org.apache.maven.embedder.MavenEmbedder; import org.apache.maven.embedder.MavenEmbedder;
import org.apache.maven.embedder.MavenEmbedderException; import org.apache.maven.embedder.MavenEmbedderException;
@ -53,15 +52,11 @@ import org.apache.maven.settings.Settings;
import org.apache.maven.settings.SettingsConfigurationException; import org.apache.maven.settings.SettingsConfigurationException;
import org.apache.maven.settings.SettingsUtils; import org.apache.maven.settings.SettingsUtils;
import org.apache.maven.wagon.repository.RepositoryPermissions; import org.apache.maven.wagon.repository.RepositoryPermissions;
import org.codehaus.plexus.MutablePlexusContainer;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.Xpp3Dom;
@ -85,12 +80,6 @@ public class DefaultMavenExecutionRequestPopulator
extends AbstractLogEnabled extends AbstractLogEnabled
implements MavenExecutionRequestPopulator implements MavenExecutionRequestPopulator
{ {
@Requirement
private ArtifactRepositoryFactory artifactRepositoryFactory;
@Requirement
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
@Requirement @Requirement
private PlexusContainer container; private PlexusContainer container;
@ -100,6 +89,9 @@ public class DefaultMavenExecutionRequestPopulator
@Requirement @Requirement
private MavenSettingsBuilder settingsBuilder; private MavenSettingsBuilder settingsBuilder;
@Requirement
private MavenTools mavenTools;
public MavenExecutionRequest populateDefaults( MavenExecutionRequest request, public MavenExecutionRequest populateDefaults( MavenExecutionRequest request,
Configuration configuration ) Configuration configuration )
throws MavenEmbedderException throws MavenEmbedderException
@ -259,8 +251,7 @@ public class DefaultMavenExecutionRequestPopulator
snapshots.setUpdatePolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); snapshots.setUpdatePolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
} }
ArtifactRepository ar = artifactRepositoryFactory.createArtifactRepository( r.getId(), r.getUrl(), ArtifactRepository ar = mavenTools.createRepository( r.getId(), r.getUrl(), snapshots, releases );
defaultArtifactRepositoryLayout, snapshots, releases );
request.addRemoteRepository( ar ); request.addRemoteRepository( ar );
} }
@ -347,10 +338,6 @@ public class DefaultMavenExecutionRequestPopulator
} }
} }
// ------------------------------------------------------------------------
// Local Repository
// ------------------------------------------------------------------------
private void localRepository( MavenExecutionRequest request, private void localRepository( MavenExecutionRequest request,
Configuration configuration ) Configuration configuration )
throws MavenEmbedderException throws MavenEmbedderException
@ -368,119 +355,7 @@ public class DefaultMavenExecutionRequestPopulator
request.setLocalRepository( createLocalRepository( request, request.getSettings(), configuration ) ); request.setLocalRepository( createLocalRepository( request, request.getSettings(), configuration ) );
} }
} }
public ArtifactRepository createLocalRepository( MavenExecutionRequest request,
Settings settings,
Configuration configuration )
throws MavenEmbedderException
{
String localRepositoryPath = null;
if ( request.getLocalRepositoryPath() != null )
{
localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath();
}
if ( StringUtils.isEmpty( localRepositoryPath ) && ( configuration.getLocalRepository() != null ) )
{
localRepositoryPath = configuration.getLocalRepository().getAbsolutePath();
}
if ( StringUtils.isEmpty( localRepositoryPath ) )
{
localRepositoryPath = settings.getLocalRepository();
}
if ( StringUtils.isEmpty( localRepositoryPath ) )
{
localRepositoryPath = MavenEmbedder.defaultUserLocalRepository.getAbsolutePath();
}
return createLocalRepository(
localRepositoryPath,
MavenEmbedder.DEFAULT_LOCAL_REPO_ID );
}
public ArtifactRepository createLocalRepository( String url,
String repositoryId )
throws MavenEmbedderException
{
try
{
return createRepository(
canonicalFileUrl( url ),
repositoryId );
}
catch ( IOException e )
{
throw new MavenEmbedderException(
"Unable to resolve canonical path for local repository " + url,
e );
}
}
private String canonicalFileUrl( String url )
throws IOException
{
if ( !url.startsWith( "file:" ) )
{
url = "file://" + url;
}
else if ( url.startsWith( "file:" ) && !url.startsWith( "file://" ) )
{
url = "file://" + url.substring( "file:".length() );
}
// So now we have an url of the form file://<path>
// We want to eliminate any relative path nonsense and lock down the path so we
// need to fully resolve it before any sub-modules use the path. This can happen
// when you are using a custom settings.xml that contains a relative path entry
// for the local repository setting.
File localRepository = new File( url.substring( "file://".length() ) );
if ( !localRepository.isAbsolute() )
{
url = "file://" + localRepository.getCanonicalPath();
}
return url;
}
public ArtifactRepository createRepository( String url,
String repositoryId )
{
// snapshots vs releases
// offline = to turning the update policy off
//TODO: we'll need to allow finer grained creation of repositories but this will do for now
String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
ArtifactRepositoryPolicy snapshotsPolicy =
new ArtifactRepositoryPolicy(
true,
updatePolicyFlag,
checksumPolicyFlag );
ArtifactRepositoryPolicy releasesPolicy =
new ArtifactRepositoryPolicy(
true,
updatePolicyFlag,
checksumPolicyFlag );
return artifactRepositoryFactory.createArtifactRepository(
repositoryId,
url,
defaultArtifactRepositoryLayout,
snapshotsPolicy,
releasesPolicy );
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Snapshot Policy // Snapshot Policy
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -505,12 +380,12 @@ public class DefaultMavenExecutionRequestPopulator
{ {
if ( request.isUpdateSnapshots() ) if ( request.isUpdateSnapshots() )
{ {
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); mavenTools.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
} }
else if ( request.isNoSnapshotUpdates() ) else if ( request.isNoSnapshotUpdates() )
{ {
getLogger().info( "+ Supressing SNAPSHOT updates." ); getLogger().info( "+ Supressing SNAPSHOT updates." );
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER ); mavenTools.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
} }
} }
} }
@ -528,7 +403,7 @@ public class DefaultMavenExecutionRequestPopulator
// We take the checksum passed in via the request. // We take the checksum passed in via the request.
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
artifactRepositoryFactory.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() ); mavenTools.setGlobalChecksumPolicy( request.getGlobalChecksumPolicy() );
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -626,7 +501,7 @@ public class DefaultMavenExecutionRequestPopulator
} }
RepositoryPermissions defaultPermissions = new RepositoryPermissions(); RepositoryPermissions defaultPermissions = new RepositoryPermissions();
defaultPermissions.setDirectoryMode( "775" ); defaultPermissions.setDirectoryMode( "775" );
defaultPermissions.setFileMode( "664" ); defaultPermissions.setFileMode( "664" );
@ -649,6 +524,43 @@ public class DefaultMavenExecutionRequestPopulator
} }
} }
public ArtifactRepository createLocalRepository( MavenExecutionRequest request,
Settings settings,
Configuration configuration )
throws MavenEmbedderException
{
String localRepositoryPath = null;
if ( request.getLocalRepositoryPath() != null )
{
localRepositoryPath = request.getLocalRepositoryPath().getAbsolutePath();
}
if ( StringUtils.isEmpty( localRepositoryPath ) && ( configuration.getLocalRepository() != null ) )
{
localRepositoryPath = configuration.getLocalRepository().getAbsolutePath();
}
if ( StringUtils.isEmpty( localRepositoryPath ) )
{
localRepositoryPath = settings.getLocalRepository();
}
if ( StringUtils.isEmpty( localRepositoryPath ) )
{
localRepositoryPath = MavenEmbedder.defaultUserLocalRepository.getAbsolutePath();
}
try
{
return mavenTools.createLocalRepository( localRepositoryPath, MavenEmbedder.DEFAULT_LOCAL_REPO_ID );
}
catch ( IOException e )
{
throw new MavenEmbedderException( "Cannot create local repository.", e );
}
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Eventing // Eventing
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
@ -689,15 +601,12 @@ public class DefaultMavenExecutionRequestPopulator
{ {
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Profile Manager // Profile Manager
//
//
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
ProfileActivationContext activationContext = request.getProfileActivationContext(); ProfileActivationContext activationContext = request.getProfileActivationContext();
if ( activationContext == null ) if ( activationContext == null )
{ {
activationContext = new DefaultProfileActivationContext( activationContext = new DefaultProfileActivationContext( request.getProperties(), false );
request.getProperties(), false );
} }
activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() ); activationContext.setExplicitlyActiveProfileIds( request.getActiveProfiles() );

View File

@ -169,13 +169,16 @@ public class PomTransformer
} }
} }
List<ModelProperty> pList = new ArrayList<ModelProperty>(); List<ModelProperty> pList;
if ( !hasExecutionsTag ) if ( !hasExecutionsTag )
{ {
pList = managementContainer.getProperties(); pList = managementContainer.getProperties();
} }
else else
{ {
pList = new ArrayList<ModelProperty>();
for ( ModelProperty mp : managementContainer.getProperties() ) for ( ModelProperty mp : managementContainer.getProperties() )
{ {
if ( !mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) ) if ( !mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) )
@ -191,8 +194,8 @@ public class PomTransformer
if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) ) if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) )
{ {
ModelDataSource dependencyDatasource = new DefaultModelDataSource(); ModelDataSource pluginDatasource = new DefaultModelDataSource();
dependencyDatasource.init( pluginContainer.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(), pluginDatasource.init( pluginContainer.getProperties(), Arrays.asList( new ArtifactModelContainerFactory(),
new IdModelContainerFactory() ) ); new IdModelContainerFactory() ) );
ModelDataSource managementDatasource = new DefaultModelDataSource(); ModelDataSource managementDatasource = new DefaultModelDataSource();
@ -208,12 +211,12 @@ public class PomTransformer
source.join( pluginContainer, new ArtifactModelContainerFactory().create(managementPropertiesWithoutExecutions) ); source.join( pluginContainer, new ArtifactModelContainerFactory().create(managementPropertiesWithoutExecutions) );
List<ModelContainer> dependencyExecutionContainers = dependencyDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); List<ModelContainer> pluginExecutionContainers = pluginDatasource.queryFor(ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri);
List<ModelContainer> joinedExecutionContainers = new ArrayList<ModelContainer>(); List<ModelContainer> joinedExecutionContainers = new ArrayList<ModelContainer>();
for(ModelContainer a : managementExecutionContainers) for(ModelContainer a : managementExecutionContainers)
{ {
for(ModelContainer b : dependencyExecutionContainers) for(ModelContainer b : pluginExecutionContainers)
{ {
if(b.containerAction(a).equals(ModelContainerAction.JOIN)) if(b.containerAction(a).equals(ModelContainerAction.JOIN))
{ {
@ -269,8 +272,8 @@ public class PomTransformer
ModelDataSource executionSource = new DefaultModelDataSource(); ModelDataSource executionSource = new DefaultModelDataSource();
executionSource.init( pluginContainer.getProperties(), executionSource.init( pluginContainer.getProperties(),
Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) ); Arrays.asList( new ArtifactModelContainerFactory(), new PluginExecutionIdModelContainerFactory() ) );
List<ModelContainer> executionContainers = List<ModelContainer> executionContainers = executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri );
executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri );
if ( executionContainers.size() < 2 ) if ( executionContainers.size() < 2 )
{ {
continue; continue;

View File

@ -19,6 +19,8 @@ package org.apache.maven;
* under the License. * under the License.
*/ */
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -27,6 +29,7 @@ import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import org.apache.maven.model.RepositoryPolicy; import org.apache.maven.model.RepositoryPolicy;
@ -44,6 +47,9 @@ public class DefaultMavenTools
@Requirement @Requirement
private ArtifactRepositoryFactory artifactRepositoryFactory; private ArtifactRepositoryFactory artifactRepositoryFactory;
@Requirement
private ArtifactRepositoryLayout defaultArtifactRepositoryLayout;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Code snagged from ProjectUtils: this will have to be moved somewhere else // Code snagged from ProjectUtils: this will have to be moved somewhere else
// but just trying to collect it all in one place right now. // but just trying to collect it all in one place right now.
@ -140,4 +146,78 @@ public class DefaultMavenTools
return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy );
} }
// From MavenExecutionRequestPopulator
public ArtifactRepository createLocalRepository( String url, String repositoryId )
throws IOException
{
return createRepository( canonicalFileUrl( url ), repositoryId );
}
private String canonicalFileUrl( String url )
throws IOException
{
if ( !url.startsWith( "file:" ) )
{
url = "file://" + url;
}
else if ( url.startsWith( "file:" ) && !url.startsWith( "file://" ) )
{
url = "file://" + url.substring( "file:".length() );
}
// So now we have an url of the form file://<path>
// We want to eliminate any relative path nonsense and lock down the path so we
// need to fully resolve it before any sub-modules use the path. This can happen
// when you are using a custom settings.xml that contains a relative path entry
// for the local repository setting.
File localRepository = new File( url.substring( "file://".length() ) );
if ( !localRepository.isAbsolute() )
{
url = "file://" + localRepository.getCanonicalPath();
}
return url;
}
public ArtifactRepository createRepository( String url,
String repositoryId )
{
// snapshots vs releases
// offline = to turning the update policy off
//TODO: we'll need to allow finer grained creation of repositories but this will do for now
String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS;
String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN;
ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag );
ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag );
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy );
}
public ArtifactRepository createRepository( String url,
String repositoryId,
ArtifactRepositoryPolicy snapshotsPolicy,
ArtifactRepositoryPolicy releasesPolicy )
{
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy );
}
public void setGlobalUpdatePolicy( String policy )
{
artifactRepositoryFactory.setGlobalUpdatePolicy( policy );
}
public void setGlobalChecksumPolicy( String policy )
{
artifactRepositoryFactory.setGlobalChecksumPolicy( policy );
}
} }

View File

@ -21,9 +21,12 @@ package org.apache.maven;
import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.InvalidRepositoryException;
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.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.DeploymentRepository;
import org.apache.maven.model.Repository; import org.apache.maven.model.Repository;
import java.io.IOException;
import java.util.List; import java.util.List;
/** /**
@ -45,4 +48,15 @@ public interface MavenTools
ArtifactRepository buildArtifactRepository( Repository repo ) ArtifactRepository buildArtifactRepository( Repository repo )
throws InvalidRepositoryException; throws InvalidRepositoryException;
ArtifactRepository createLocalRepository( String url, String repositoryId )
throws IOException;
ArtifactRepository createRepository( String url, String repositoryId );
ArtifactRepository createRepository( String url, String repositoryId, ArtifactRepositoryPolicy snapshotsPolicy, ArtifactRepositoryPolicy releasesPolicy );
void setGlobalUpdatePolicy( String policy );
void setGlobalChecksumPolicy( String policy );
} }

View File

@ -74,15 +74,6 @@ public class DefaultMavenProjectBuilder
@Requirement @Requirement
protected MavenProfilesBuilder profilesBuilder; protected MavenProfilesBuilder profilesBuilder;
@Requirement
protected ArtifactResolver artifactResolver;
@Requirement
protected ArtifactMetadataSource artifactMetadataSource;
@Requirement
private ArtifactFactory artifactFactory;
@Requirement @Requirement
private ModelValidator validator; private ModelValidator validator;
@ -101,6 +92,15 @@ public class DefaultMavenProjectBuilder
private MavenXpp3Reader modelReader; private MavenXpp3Reader modelReader;
private Logger logger; private Logger logger;
@Requirement
protected ArtifactResolver artifactResolver;
@Requirement
protected ArtifactMetadataSource artifactMetadataSource;
@Requirement
private ArtifactFactory artifactFactory;
//DO NOT USE, it is here only for backward compatibility reasons. The existing //DO NOT USE, it is here only for backward compatibility reasons. The existing
// maven-assembly-plugin (2.2-beta-1) is accessing it via reflection. // maven-assembly-plugin (2.2-beta-1) is accessing it via reflection.
@ -135,22 +135,21 @@ public class DefaultMavenProjectBuilder
public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config ) public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config )
throws ProjectBuildingException throws ProjectBuildingException
{ {
MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( config.getLocalRepository(), repositoryHelper
config.getLocalRepository(), repositoryHelper.buildArtifactRepositories( .buildArtifactRepositories( getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config );
getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config );
project.setFile( projectDescriptor ); project.setFile( projectDescriptor );
project = buildWithProfiles( project.getModel(), config, projectDescriptor, project.getParentFile(), true ); project = buildWithProfiles( project.getModel(), config, projectDescriptor, project.getParentFile(), true );
Build build = project.getBuild(); Build build = project.getBuild();
// NOTE: setting this script-source root before path translation, because // NOTE: setting this script-source root before path translation, because
// the plugin tools compose basedir and scriptSourceRoot into a single file. // the plugin tools compose basedir and scriptSourceRoot into a single file.
project.addScriptSourceRoot( build.getScriptSourceDirectory() ); project.addScriptSourceRoot( build.getScriptSourceDirectory() );
project.addCompileSourceRoot( build.getSourceDirectory() ); project.addCompileSourceRoot( build.getSourceDirectory() );
project.addTestCompileSourceRoot( build.getTestSourceDirectory() ); project.addTestCompileSourceRoot( build.getTestSourceDirectory() );
project.setFile( projectDescriptor ); project.setFile( projectDescriptor );
setBuildOutputDirectoryOnParent( project ); setBuildOutputDirectoryOnParent( project );
return project; return project;
} }
@ -189,8 +188,7 @@ public class DefaultMavenProjectBuilder
return project; return project;
} }
File f = (artifact.getFile() != null) ? artifact.getFile() : File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );
new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) );;
repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ); ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
@ -200,7 +198,6 @@ public class DefaultMavenProjectBuilder
project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config );
project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile(), false ); project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile(), false );
// project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config );
artifact.setFile( f ); artifact.setFile( f );
project.setVersion( artifact.getVersion() ); project.setVersion( artifact.getVersion() );
@ -242,8 +239,10 @@ public class DefaultMavenProjectBuilder
} }
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>(); List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(),
PomInterpolatorTag.SYSTEM_PROPERTIES.name())); PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name())); PomInterpolatorTag.USER_PROPERTIES.name()));
@ -482,6 +481,7 @@ public class DefaultMavenProjectBuilder
} }
URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" ); URL url = DefaultMavenProjectBuilder.class.getResource( "pom-" + MAVEN_MODEL_VERSION + ".xml" );
String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID ); String projectId = safeVersionlessKey( STANDALONE_SUPERPOM_GROUPID, STANDALONE_SUPERPOM_ARTIFACTID );
Reader reader = null; Reader reader = null;
@ -492,13 +492,13 @@ public class DefaultMavenProjectBuilder
if ( modelSource.indexOf( "<modelVersion>" + MAVEN_MODEL_VERSION ) < 0 ) if ( modelSource.indexOf( "<modelVersion>" + MAVEN_MODEL_VERSION ) < 0 )
{ {
throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.", throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION + " POM.", new File( "." ) );
new File( "." ) );
} }
StringReader sReader = new StringReader( modelSource ); StringReader sReader = new StringReader( modelSource );
superModel = modelReader.read( sReader, STRICT_MODEL_PARSING ); superModel = modelReader.read( sReader, STRICT_MODEL_PARSING );
return superModel; return superModel;
} }
catch ( XmlPullParserException e ) catch ( XmlPullParserException e )
@ -526,14 +526,11 @@ public class DefaultMavenProjectBuilder
throw new IllegalArgumentException( "projectDescriptor: null, Project Id =" + projectId ); throw new IllegalArgumentException( "projectDescriptor: null, Project Id =" + projectId );
} }
if ( projectBuilder == null )
{
throw new IllegalArgumentException( "projectBuilder: not initialized" );
}
List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>(); List<InterpolatorProperty> interpolatorProperties = new ArrayList<InterpolatorProperty>();
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(),
PomInterpolatorTag.SYSTEM_PROPERTIES.name())); PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(), interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name())); PomInterpolatorTag.USER_PROPERTIES.name()));
@ -545,13 +542,19 @@ public class DefaultMavenProjectBuilder
} }
interpolatorProperties.add(new InterpolatorProperty("${mavenVersion}", MavenProjectBuilder.STANDALONE_SUPERPOM_VERSION, PomInterpolatorTag.SYSTEM_PROPERTIES.name())); interpolatorProperties.add(new InterpolatorProperty("${mavenVersion}", MavenProjectBuilder.STANDALONE_SUPERPOM_VERSION, PomInterpolatorTag.SYSTEM_PROPERTIES.name()));
MavenProject mavenProject; MavenProject mavenProject;
try try
{ {
mavenProject = projectBuilder.buildFromLocalPath( new FileInputStream( projectDescriptor ), Arrays.asList( mavenProject = projectBuilder.buildFromLocalPath( new FileInputStream( projectDescriptor ),
getSuperProject( config, projectDescriptor, true ).getModel() ), null, interpolatorProperties, resolver, Arrays.asList(
projectDescriptor.getParentFile(), getSuperProject( config, projectDescriptor, true ).getModel() ),
config ); null,
interpolatorProperties,
resolver,
projectDescriptor.getParentFile(),
config );
} }
catch ( IOException e ) catch ( IOException e )
{ {

View File

@ -37,21 +37,20 @@ public interface MavenProjectBuilder
// site // site
MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager ) MavenProject build( File project, ArtifactRepository localRepository, ProfileManager profileManager )
throws ProjectBuildingException; throws ProjectBuildingException;
// remote resources plugin // remote resources plugin
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository, boolean allowStub ) MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository, boolean allowStub )
throws ProjectBuildingException; throws ProjectBuildingException;
//
MavenProject build( File project, ProjectBuilderConfiguration configuration ) MavenProject build( File project, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException; throws ProjectBuildingException;
MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuilderConfiguration config ) MavenProjectBuildingResult buildProjectWithDependencies( File project, ProjectBuilderConfiguration configuration )
throws ProjectBuildingException; throws ProjectBuildingException;
MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException; throws ProjectBuildingException;
MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config ) MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration configuration )
throws ProjectBuildingException; throws ProjectBuildingException;
} }

40
pom.xml
View File

@ -46,44 +46,6 @@ under the License.
<system>jira</system> <system>jira</system>
<url>http://jira.codehaus.org/browse/MNG</url> <url>http://jira.codehaus.org/browse/MNG</url>
</issueManagement> </issueManagement>
<!-- TODO: TAKE THIS OUT BEFORE WE RELEASE! -->
<repositories>
<repository>
<id>sonatype.snapshots</id>
<url>http://repository.sonatype.org/service/local/repositories/snapshots/content/</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>sonatype.releases</id>
<url>http://repository.sonatype.org/service/local/repositories/releases/content/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>apache.snapshots</id>
<url>http://people.apache.org/repo/m2-snapshot-repository/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>codehaus.snapshots</id>
<url>http://snapshots.repository.codehaus.org/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<mailingLists> <mailingLists>
<mailingList> <mailingList>
<name>Maven Developer List</name> <name>Maven Developer List</name>
@ -297,7 +259,7 @@ under the License.
<plexusUtilsVersion>1.5.5</plexusUtilsVersion> <plexusUtilsVersion>1.5.5</plexusUtilsVersion>
<wagonVersion>1.0-beta-4</wagonVersion> <wagonVersion>1.0-beta-4</wagonVersion>
<mavenSharedModel>1.0-SNAPSHOT</mavenSharedModel> <mavenSharedModel>1.0-SNAPSHOT</mavenSharedModel>
<mercuryVersion>1.0.0-alpha-2-SNAPSHOT</mercuryVersion> <mercuryVersion>1.0.0-alpha-2</mercuryVersion>
<woodstoxVersion>3.2.6</woodstoxVersion> <woodstoxVersion>3.2.6</woodstoxVersion>
<modelloVersion>1.0-alpha-22</modelloVersion> <modelloVersion>1.0-alpha-22</modelloVersion>
</properties> </properties>