mirror of https://github.com/apache/maven.git
[MNG-3642] Adding internal-only unique id 'mergeId' to build resources, to allow back-propagation of changed resource information from plugin executions to the dynamic version of the POM build section. Also, modified the project-builder's dynamism methods (calculate*, restore*) to use mergeId.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@673417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
116105ef35
commit
3d6b63bc11
|
@ -2121,12 +2121,36 @@
|
||||||
<type>boolean</type>
|
<type>boolean</type>
|
||||||
<defaultValue>false</defaultValue>
|
<defaultValue>false</defaultValue>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>mergeId</name>
|
||||||
|
<version>4.0.0+</version>
|
||||||
|
<description>
|
||||||
|
<![CDATA[
|
||||||
|
FOR INTERNAL USE ONLY. This is a unique identifier assigned to each
|
||||||
|
resource to allow Maven to merge changes to this resource that take
|
||||||
|
place during the execution of a plugin. This field must be managed
|
||||||
|
by the generated parser and formatter classes in order to allow it
|
||||||
|
to survive model interpolation.
|
||||||
|
]]>
|
||||||
|
</description>
|
||||||
|
<type>String</type>
|
||||||
|
</field>
|
||||||
</fields>
|
</fields>
|
||||||
<codeSegments>
|
<codeSegments>
|
||||||
<codeSegment>
|
<codeSegment>
|
||||||
<version>4.0.0</version>
|
<version>4.0.0</version>
|
||||||
<code>
|
<code>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
private static int mergeIdCounter = 0;
|
||||||
|
|
||||||
|
public void initMergeId()
|
||||||
|
{
|
||||||
|
if ( getMergeId() == null )
|
||||||
|
{
|
||||||
|
setMergeId( "resource-" + (mergeIdCounter++) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1126,6 +1126,13 @@ public class DefaultMavenProjectBuilder
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Build build = project.getBuild();
|
||||||
|
if ( build != null )
|
||||||
|
{
|
||||||
|
initResourceMergeIds( build.getResources() );
|
||||||
|
initResourceMergeIds( build.getTestResources() );
|
||||||
|
}
|
||||||
|
|
||||||
Model model = ModelUtils.cloneModel( project.getModel() );
|
Model model = ModelUtils.cloneModel( project.getModel() );
|
||||||
|
|
||||||
File basedir = project.getBasedir();
|
File basedir = project.getBasedir();
|
||||||
|
@ -1178,6 +1185,17 @@ public class DefaultMavenProjectBuilder
|
||||||
project.setConcrete( true );
|
project.setConcrete( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initResourceMergeIds( List<Resource> resources )
|
||||||
|
{
|
||||||
|
if ( resources != null )
|
||||||
|
{
|
||||||
|
for ( Resource resource : resources )
|
||||||
|
{
|
||||||
|
resource.initMergeId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void calculateConcreteProjectReferences( MavenProject project,
|
private void calculateConcreteProjectReferences( MavenProject project,
|
||||||
ProjectBuilderConfiguration config )
|
ProjectBuilderConfiguration config )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
|
@ -1506,9 +1524,10 @@ public class DefaultMavenProjectBuilder
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List restoreResources( List originalResources,
|
// TODO: Convert this to use the mergeId on each resource...
|
||||||
List originalInterpolatedResources,
|
private List restoreResources( List<Resource> originalResources,
|
||||||
List changedResources,
|
List<Resource> originalInterpolatedResources,
|
||||||
|
List<Resource> changedResources,
|
||||||
MavenProject project,
|
MavenProject project,
|
||||||
ProjectBuilderConfiguration config )
|
ProjectBuilderConfiguration config )
|
||||||
throws ModelInterpolationException
|
throws ModelInterpolationException
|
||||||
|
@ -1518,60 +1537,88 @@ public class DefaultMavenProjectBuilder
|
||||||
return originalResources;
|
return originalResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
List result = new ArrayList();
|
List<Resource> result = new ArrayList<Resource>();
|
||||||
|
|
||||||
Map orig = new HashMap();
|
Map<String, Resource[]> originalResourcesByMergeId = new HashMap<String, Resource[]>();
|
||||||
for ( int idx = 0; idx < originalResources.size(); idx++ )
|
for ( int idx = 0; idx < originalResources.size(); idx++ )
|
||||||
{
|
{
|
||||||
Resource[] permutations = new Resource[2];
|
Resource[] permutations = new Resource[2];
|
||||||
|
|
||||||
permutations[0] = (Resource) originalInterpolatedResources.get( idx );
|
permutations[0] = originalInterpolatedResources.get( idx );
|
||||||
permutations[1] = (Resource) originalResources.get( idx );
|
permutations[1] = originalResources.get( idx );
|
||||||
|
|
||||||
orig.put( permutations[0].getDirectory(), permutations );
|
originalResourcesByMergeId.put( permutations[0].getMergeId(), permutations );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Iterator it = changedResources.iterator(); it.hasNext(); )
|
for ( Resource resource : changedResources )
|
||||||
{
|
{
|
||||||
Resource resource = (Resource) it.next();
|
String mergeId = resource.getMergeId();
|
||||||
String rDir = modelInterpolator.interpolate( resource.getDirectory(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
|
if ( mergeId == null || !originalResourcesByMergeId.containsKey( mergeId ) )
|
||||||
|
|
||||||
String relativeDir;
|
|
||||||
if ( project.getBasedir() != null )
|
|
||||||
{
|
|
||||||
relativeDir = pathTranslator.unalignFromBaseDirectory( resource.getDirectory(),
|
|
||||||
project.getBasedir() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
relativeDir = resource.getDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
String relativeRDir = modelInterpolator.interpolate( relativeDir, project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
|
|
||||||
|
|
||||||
Resource[] original = (Resource[]) orig.get( rDir );
|
|
||||||
if ( original == null )
|
|
||||||
{
|
|
||||||
original = (Resource[]) orig.get( relativeRDir );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( original == null )
|
|
||||||
{
|
{
|
||||||
result.add( resource );
|
result.add( resource );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Synchronize all non-directory fields, such as targetPath, includes, and excludes.
|
Resource originalInterpolatedResource = originalResourcesByMergeId.get( mergeId )[0];
|
||||||
// String target = interpolator.interpolate( resource.getTargetPath(), model, context );
|
Resource originalResource = originalResourcesByMergeId.get( mergeId )[1];
|
||||||
// String oTarget = interpolator.interpolate( originalResource.getTargetPath(), model, context );
|
|
||||||
|
|
||||||
result.add( original[1] );
|
String dir = modelInterpolator.interpolate( resource.getDirectory(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
|
||||||
|
String oDir = originalInterpolatedResource.getDirectory();
|
||||||
|
|
||||||
|
if ( !dir.equals( oDir ) )
|
||||||
|
{
|
||||||
|
originalResource.setDirectory( pathTranslator.unalignFromBaseDirectory( dir, project.getBasedir() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( resource.getTargetPath() != null )
|
||||||
|
{
|
||||||
|
String target = modelInterpolator.interpolate( resource.getTargetPath(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
|
||||||
|
|
||||||
|
String oTarget = originalInterpolatedResource.getTargetPath();
|
||||||
|
|
||||||
|
if ( !target.equals( oTarget ) )
|
||||||
|
{
|
||||||
|
originalResource.setTargetPath( pathTranslator.unalignFromBaseDirectory( target, project.getBasedir() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
originalResource.setFiltering( resource.isFiltering() );
|
||||||
|
|
||||||
|
originalResource.setExcludes( collectRestoredListOfPatterns( resource.getExcludes(),
|
||||||
|
originalResource.getExcludes(),
|
||||||
|
originalInterpolatedResource.getExcludes() ) );
|
||||||
|
|
||||||
|
originalResource.setIncludes( collectRestoredListOfPatterns( resource.getIncludes(),
|
||||||
|
originalResource.getIncludes(),
|
||||||
|
originalInterpolatedResource.getIncludes() ) );
|
||||||
|
|
||||||
|
result.add( originalResource );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<String> collectRestoredListOfPatterns( List<String> patterns,
|
||||||
|
List<String> originalPatterns,
|
||||||
|
List<String> originalInterpolatedPatterns )
|
||||||
|
{
|
||||||
|
LinkedHashSet<String> collectedPatterns = new LinkedHashSet<String>();
|
||||||
|
|
||||||
|
collectedPatterns.addAll( originalPatterns );
|
||||||
|
|
||||||
|
for ( String pattern : patterns )
|
||||||
|
{
|
||||||
|
if ( !originalInterpolatedPatterns.contains( pattern ) )
|
||||||
|
{
|
||||||
|
collectedPatterns.add( pattern );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (List<String>) ( collectedPatterns.isEmpty() ? Collections.emptyList()
|
||||||
|
: new ArrayList<String>( collectedPatterns ) );
|
||||||
|
}
|
||||||
|
|
||||||
private void validateModel( Model model,
|
private void validateModel( Model model,
|
||||||
File pomFile )
|
File pomFile )
|
||||||
throws InvalidProjectModelException
|
throws InvalidProjectModelException
|
||||||
|
|
Loading…
Reference in New Issue