diff --git a/maven-model/src/main/mdo/maven.mdo b/maven-model/src/main/mdo/maven.mdo
index 296d56465d..0458e4002e 100644
--- a/maven-model/src/main/mdo/maven.mdo
+++ b/maven-model/src/main/mdo/maven.mdo
@@ -2121,12 +2121,36 @@
boolean
false
+
+ mergeId
+ 4.0.0+
+
+
+
+ String
+
4.0.0
resources )
+ {
+ if ( resources != null )
+ {
+ for ( Resource resource : resources )
+ {
+ resource.initMergeId();
+ }
+ }
+ }
+
private void calculateConcreteProjectReferences( MavenProject project,
ProjectBuilderConfiguration config )
throws ModelInterpolationException
@@ -1506,9 +1524,10 @@ public class DefaultMavenProjectBuilder
return result;
}
- private List restoreResources( List originalResources,
- List originalInterpolatedResources,
- List changedResources,
+ // TODO: Convert this to use the mergeId on each resource...
+ private List restoreResources( List originalResources,
+ List originalInterpolatedResources,
+ List changedResources,
MavenProject project,
ProjectBuilderConfiguration config )
throws ModelInterpolationException
@@ -1518,60 +1537,88 @@ public class DefaultMavenProjectBuilder
return originalResources;
}
- List result = new ArrayList();
+ List result = new ArrayList();
- Map orig = new HashMap();
+ Map originalResourcesByMergeId = new HashMap();
for ( int idx = 0; idx < originalResources.size(); idx++ )
{
Resource[] permutations = new Resource[2];
- permutations[0] = (Resource) originalInterpolatedResources.get( idx );
- permutations[1] = (Resource) originalResources.get( idx );
+ permutations[0] = originalInterpolatedResources.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 rDir = modelInterpolator.interpolate( resource.getDirectory(), project.getModel(), project.getBasedir(), config, getLogger().isDebugEnabled() );
-
- 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 )
+ String mergeId = resource.getMergeId();
+ if ( mergeId == null || !originalResourcesByMergeId.containsKey( mergeId ) )
{
result.add( resource );
}
else
{
- // TODO: Synchronize all non-directory fields, such as targetPath, includes, and excludes.
-// String target = interpolator.interpolate( resource.getTargetPath(), model, context );
-// String oTarget = interpolator.interpolate( originalResource.getTargetPath(), model, context );
+ Resource originalInterpolatedResource = originalResourcesByMergeId.get( mergeId )[0];
+ Resource originalResource = originalResourcesByMergeId.get( mergeId )[1];
- 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;
}
+ private List collectRestoredListOfPatterns( List patterns,
+ List originalPatterns,
+ List originalInterpolatedPatterns )
+ {
+ LinkedHashSet collectedPatterns = new LinkedHashSet();
+
+ collectedPatterns.addAll( originalPatterns );
+
+ for ( String pattern : patterns )
+ {
+ if ( !originalInterpolatedPatterns.contains( pattern ) )
+ {
+ collectedPatterns.add( pattern );
+ }
+ }
+
+ return (List) ( collectedPatterns.isEmpty() ? Collections.emptyList()
+ : new ArrayList( collectedPatterns ) );
+ }
+
private void validateModel( Model model,
File pomFile )
throws InvalidProjectModelException