mirror of https://github.com/apache/maven.git
Refactored out restorer class and related MavenProjectBuilder methods.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@694360 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
465ac54709
commit
45f10e7526
|
@ -41,6 +41,7 @@ import org.apache.maven.execution.RuntimeInformation;
|
|||
import org.apache.maven.lifecycle.statemgmt.StateManagementUtils;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.monitor.logging.DefaultLog;
|
||||
|
@ -56,6 +57,7 @@ import org.apache.maven.project.DuplicateArtifactAttachmentException;
|
|||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.project.ModelUtils;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.project.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
|
@ -89,6 +91,7 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -516,14 +519,16 @@ public class DefaultPluginManager
|
|||
|
||||
if ( !project.isConcrete() )
|
||||
{
|
||||
try
|
||||
{
|
||||
mavenProjectBuilder.calculateConcreteState( project, session.getProjectBuilderConfiguration() );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new PluginManagerException( mojoDescriptor, project, "Failed to calculate concrete state for project.", e );
|
||||
}
|
||||
Model model = ModelUtils.cloneModel( project.getModel() );
|
||||
|
||||
File basedir = project.getBasedir();
|
||||
|
||||
Model model2 = ModelUtils.cloneModel( model );
|
||||
pathTranslator.alignToBaseDirectory( model, basedir );
|
||||
project.preserveBuild( model2.getBuild() );
|
||||
|
||||
project.setBuild( model.getBuild() );
|
||||
project.setConcrete( true );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
||||
|
@ -734,14 +739,7 @@ public class DefaultPluginManager
|
|||
Thread.currentThread().setContextClassLoader( oldClassLoader );
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
mavenProjectBuilder.restoreDynamicState( project, session.getProjectBuilderConfiguration() );
|
||||
}
|
||||
catch ( ModelInterpolationException e )
|
||||
{
|
||||
throw new PluginManagerException( mojoDescriptor, project, "Failed to restore dynamic state for project.", e );
|
||||
}
|
||||
project.setConcrete( false );
|
||||
}
|
||||
|
||||
private Plugin createDummyPlugin( PluginDescriptor pluginDescriptor )
|
||||
|
|
|
@ -31,8 +31,6 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
|||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
|
@ -47,7 +45,6 @@ import org.apache.maven.project.builder.PomArtifactResolver;
|
|||
import org.apache.maven.project.builder.ProjectBuilder;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.apache.maven.project.validation.ModelValidationResult;
|
||||
import org.apache.maven.project.validation.ModelValidator;
|
||||
import org.apache.maven.project.workspace.ProjectWorkspace;
|
||||
|
@ -126,8 +123,6 @@ public class DefaultMavenProjectBuilder
|
|||
// TODO: make it a component
|
||||
private MavenXpp3Reader modelReader;
|
||||
|
||||
private PathTranslator pathTranslator;
|
||||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
private ProfileAdvisor profileAdvisor;
|
||||
|
@ -299,7 +294,7 @@ public class DefaultMavenProjectBuilder
|
|||
MavenProject project;
|
||||
try
|
||||
{
|
||||
project = new MavenProject( superModel, artifactFactory, mavenTools, repositoryHelper, this, config );
|
||||
project = new MavenProject( superModel, artifactFactory, mavenTools, this, config );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
@ -391,20 +386,6 @@ public class DefaultMavenProjectBuilder
|
|||
return new MavenProjectBuildingResult( project, result );
|
||||
}
|
||||
|
||||
public void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
new MavenProjectRestorer( pathTranslator, modelInterpolator, getLogger() ).calculateConcreteState( project,
|
||||
config );
|
||||
}
|
||||
|
||||
public void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
new MavenProjectRestorer( pathTranslator, modelInterpolator, getLogger() ).restoreDynamicState( project,
|
||||
config );
|
||||
}
|
||||
|
||||
public void enableLogging( Logger logger )
|
||||
{
|
||||
this.logger = logger;
|
||||
|
@ -482,7 +463,7 @@ public class DefaultMavenProjectBuilder
|
|||
model = modelInterpolator.interpolate( model, projectDir, config, getLogger().isDebugEnabled() );
|
||||
|
||||
// We will return a different project object using the new model (hence the need to return a project, not just modify the parameter)
|
||||
MavenProject project = new MavenProject( model, artifactFactory, mavenTools, repositoryHelper, this, config );
|
||||
MavenProject project = new MavenProject( model, artifactFactory, mavenTools, this, config );
|
||||
|
||||
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
|
||||
project.getVersion(), project.getPackaging() );
|
||||
|
@ -502,7 +483,7 @@ public class DefaultMavenProjectBuilder
|
|||
Model model = getSuperModel();
|
||||
try
|
||||
{
|
||||
superProject = new MavenProject( model, artifactFactory, mavenTools, repositoryHelper, this, config );
|
||||
superProject = new MavenProject( model, artifactFactory, mavenTools, this, config );
|
||||
}
|
||||
catch ( InvalidRepositoryException e )
|
||||
{
|
||||
|
|
|
@ -156,8 +156,6 @@ public class MavenProject
|
|||
|
||||
private Map projectReferences = new HashMap();
|
||||
|
||||
private Build buildOverlay;
|
||||
|
||||
private boolean executionRoot;
|
||||
|
||||
private Map moduleAdjustments;
|
||||
|
@ -166,10 +164,6 @@ public class MavenProject
|
|||
|
||||
private ArtifactFactory artifactFactory;
|
||||
|
||||
private MavenTools mavenTools;
|
||||
|
||||
private RepositoryHelper repositoryHelper;
|
||||
|
||||
private MavenProjectBuilder mavenProjectBuilder;
|
||||
|
||||
private ProjectBuilderConfiguration projectBuilderConfiguration;
|
||||
|
@ -202,15 +196,12 @@ public class MavenProject
|
|||
setModel( model );
|
||||
}
|
||||
|
||||
public MavenProject( Model model, ArtifactFactory artifactFactory, MavenTools mavenTools,
|
||||
RepositoryHelper repositoryHelper, MavenProjectBuilder mavenProjectBuilder,
|
||||
public MavenProject( Model model, ArtifactFactory artifactFactory, MavenTools mavenTools, MavenProjectBuilder mavenProjectBuilder,
|
||||
ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
setModel( model );
|
||||
this.artifactFactory = artifactFactory;
|
||||
this.mavenTools = mavenTools;
|
||||
this.repositoryHelper = repositoryHelper;
|
||||
this.mavenProjectBuilder = mavenProjectBuilder;
|
||||
this.projectBuilderConfiguration = projectBuilderConfiguration;
|
||||
originalModel = ModelUtils.cloneModel( model );
|
||||
|
@ -2048,27 +2039,6 @@ public class MavenProject
|
|||
Artifact attached = (Artifact) itr.next();
|
||||
if ( attached.getDependencyConflictId().equals( pluginArtifact.getDependencyConflictId() ) )
|
||||
{
|
||||
/* TODO: if I use the original, I get an exception below:
|
||||
java.lang.UnsupportedOperationException: Cannot change the download information for an attached artifact. It is derived from the main artifact.
|
||||
at org.apache.maven.project.artifact.AttachedArtifact.setDownloadUrl(AttachedArtifact.java:89)
|
||||
at org.apache.maven.project.artifact.MavenMetadataSource.retrieve(MavenMetadataSource.java:205)
|
||||
at org.apache.maven.artifact.resolver.DefaultArtifactCollector.recurse(DefaultArtifactCollector.java:275)
|
||||
at org.apache.maven.artifact.resolver.DefaultArtifactCollector.collect(DefaultArtifactCollector.java:67)
|
||||
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:223)
|
||||
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:211)
|
||||
at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolveTransitively(DefaultArtifactResolver.java:182)
|
||||
at org.apache.maven.plugin.DefaultPluginManager.resolveTransitiveDependencies(DefaultPluginManager.java:1117)
|
||||
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:366)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
|
||||
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
|
||||
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
|
||||
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
|
||||
at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
|
||||
*/
|
||||
Artifact resultArtifact = ArtifactUtils.copyArtifact( attached );
|
||||
resultArtifact.setScope( pluginArtifact.getScope() );
|
||||
return resultArtifact;
|
||||
|
|
|
@ -95,13 +95,4 @@ public interface MavenProjectBuilder
|
|||
MavenProject buildStandaloneSuperProject( ProjectBuilderConfiguration config )
|
||||
throws ProjectBuildingException;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// API BELOW IS USED TO PRESERVE DYNAMISM IN THE BUILD SECTION OF THE POM.
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException;
|
||||
|
||||
void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException;
|
||||
}
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
package org.apache.maven.project;
|
||||
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Resource;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolationException;
|
||||
import org.apache.maven.project.interpolation.ModelInterpolator;
|
||||
import org.apache.maven.project.path.PathTranslator;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
final class MavenProjectRestorer
|
||||
{
|
||||
|
||||
private ModelInterpolator modelInterpolator;
|
||||
|
||||
private PathTranslator pathTranslator;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
MavenProjectRestorer( PathTranslator pathTranslator, ModelInterpolator modelInterpolator, Logger logger )
|
||||
{
|
||||
this.pathTranslator = pathTranslator;
|
||||
this.modelInterpolator = modelInterpolator;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
Logger getLogger()
|
||||
{
|
||||
return logger;
|
||||
}
|
||||
|
||||
void restoreDynamicState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
if ( !project.isConcrete() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
/*
|
||||
restoreBuildRoots( project, config );
|
||||
if ( project.getBuild() != null )
|
||||
{
|
||||
restoreModelBuildSection( project, config );
|
||||
}
|
||||
restoreDynamicProjectReferences( project, config );
|
||||
|
||||
MavenProject executionProject = project.getExecutionProject();
|
||||
if ( executionProject != null && executionProject != project )
|
||||
{
|
||||
restoreDynamicState( executionProject, config );
|
||||
}
|
||||
*/
|
||||
project.setConcrete( false );
|
||||
}
|
||||
|
||||
void calculateConcreteState( MavenProject project, ProjectBuilderConfiguration config )
|
||||
throws ModelInterpolationException
|
||||
{
|
||||
if ( project.isConcrete() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Model model = ModelUtils.cloneModel( project.getModel() );
|
||||
|
||||
File basedir = project.getBasedir();
|
||||
|
||||
Model model2 = ModelUtils.cloneModel( model );
|
||||
pathTranslator.alignToBaseDirectory( model, basedir );
|
||||
project.preserveBuild( model2.getBuild() );
|
||||
|
||||
project.setBuild( model.getBuild() );
|
||||
|
||||
//
|
||||
/*
|
||||
MavenProject executionProject = project.getExecutionProject();
|
||||
if ( executionProject != null && executionProject != project )
|
||||
{
|
||||
calculateConcreteState( executionProject, config );
|
||||
}
|
||||
*/
|
||||
project.setConcrete( true );
|
||||
}
|
||||
}
|
|
@ -186,7 +186,7 @@ public final class DefaultProjectBuilder
|
|||
try
|
||||
{
|
||||
MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
|
||||
mavenTools, repositoryHelper, null,
|
||||
mavenTools, null,
|
||||
projectBuilderConfiguration );
|
||||
mavenProject.setParentFile( parentFile );
|
||||
return mavenProject;
|
||||
|
|
|
@ -124,9 +124,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
|
|
|
@ -44,8 +44,6 @@ public class DefaultMavenProjectBuilderTest
|
|||
|
||||
private File localRepoDir;
|
||||
|
||||
private DefaultMavenProjectBuilder projectBuilder;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
throws Exception
|
||||
|
@ -116,32 +114,6 @@ public class DefaultMavenProjectBuilderTest
|
|||
assertEquals( 2, ( (Plugin) project.getBuildPlugins().get( 0 ) ).getDependencies().size() );
|
||||
}
|
||||
|
||||
public void testBuildDirectoryExpressionInterpolatedWithTranslatedValue()
|
||||
throws Exception
|
||||
{
|
||||
File pom = getTestFile( "src/test/resources/projects/build-path-expression-pom.xml" );
|
||||
|
||||
MavenProject project = getProject( pom );
|
||||
|
||||
projectBuilder.calculateConcreteState( project, new DefaultProjectBuilderConfiguration() );
|
||||
|
||||
Build build = project.getBuild();
|
||||
assertNotNull( "Project should have a build section containing the test resource.", build );
|
||||
|
||||
String sourceDirectory = build.getSourceDirectory();
|
||||
assertNotNull( "Project build should contain a valid source directory.", sourceDirectory );
|
||||
|
||||
List resources = build.getResources();
|
||||
assertNotNull( "Project should contain a build resource.", resources );
|
||||
assertEquals( "Project should contain exactly one build resource.", 1, resources.size() );
|
||||
|
||||
Resource res = (Resource) resources.get( 0 );
|
||||
assertEquals( "Project resource should be the same directory as the source directory.",
|
||||
sourceDirectory,
|
||||
res.getDirectory() );
|
||||
|
||||
System.out.println( "Interpolated, translated resource directory is: " + res.getDirectory() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArtifactRepository getLocalRepository()
|
||||
|
|
|
@ -139,9 +139,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
|
|
|
@ -17,7 +17,7 @@ specific language governing permissions and limitations
|
|||
under the License.
|
||||
-->
|
||||
|
||||
<plexus>
|
||||
<plexus> svn ci-
|
||||
<components><!--Eliminate this component after Mercury Integration-->
|
||||
<component>
|
||||
<role>org.apache.maven.project.RepositoryHelper</role>
|
||||
|
@ -136,9 +136,6 @@ under the License.
|
|||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.path.PathTranslator</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
|
|
Loading…
Reference in New Issue