mirror of https://github.com/apache/maven.git
o Decoupled calculation of child path adjustment from filesystem which would make the effective model depend on the user's environment and breaks with our goal of reproducible builds
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@773047 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d36a4ab8eb
commit
4116ac3f0b
|
@ -242,7 +242,7 @@ public class ProcessorContext
|
||||||
Model previousModel = null;
|
Model previousModel = null;
|
||||||
for ( Model currentModel : models )
|
for ( Model currentModel : models )
|
||||||
{
|
{
|
||||||
inheritanceAssembler.assembleModelInheritance( currentModel, previousModel, "" );
|
inheritanceAssembler.assembleModelInheritance( currentModel, previousModel );
|
||||||
previousModel = currentModel;
|
previousModel = currentModel;
|
||||||
}
|
}
|
||||||
if ( true )
|
if ( true )
|
||||||
|
|
|
@ -38,11 +38,62 @@ public class DefaultInheritanceAssembler
|
||||||
|
|
||||||
private MavenModelMerger merger = new MavenModelMerger();
|
private MavenModelMerger merger = new MavenModelMerger();
|
||||||
|
|
||||||
public void assembleModelInheritance( Model child, Model parent, String childPathAdjustment )
|
public void assembleModelInheritance( Model child, Model parent )
|
||||||
{
|
{
|
||||||
Map<Object, Object> hints = new HashMap<Object, Object>();
|
Map<Object, Object> hints = new HashMap<Object, Object>();
|
||||||
hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, childPathAdjustment );
|
hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT, getChildPathAdjustment( child, parent ) );
|
||||||
merger.merge( child, parent, false, hints );
|
merger.merge( child, parent, false, hints );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the relative path from the base directory of the parent to the parent directory of the base directory
|
||||||
|
* of the child. The general idea is to adjust inherited URLs to match the project layout (in SCM). This calculation
|
||||||
|
* is only a heuristic based on our conventions. In detail, the algo relies on the following assumptions. The parent
|
||||||
|
* uses aggregation and refers to the child via the modules section. The module path to the child is considered to
|
||||||
|
* point at the POM rather than its base directory if the path ends with ".xml" (ignoring case). The name of the
|
||||||
|
* child's base directory matches the artifact id of the child. Note that for the sake of independence from the user
|
||||||
|
* environment, the filesystem is intentionally not used for the calculation.
|
||||||
|
*
|
||||||
|
* @param child The child model, must not be <code>null</code>.
|
||||||
|
* @param parent The parent model, may be <code>null</code>.
|
||||||
|
* @return The path adjustment, can be empty but never <code>null</code>.
|
||||||
|
*/
|
||||||
|
private String getChildPathAdjustment( Model child, Model parent )
|
||||||
|
{
|
||||||
|
String adjustment = "";
|
||||||
|
|
||||||
|
if ( parent != null )
|
||||||
|
{
|
||||||
|
String childArtifactId = child.getArtifactId();
|
||||||
|
|
||||||
|
for ( String module : parent.getModules() )
|
||||||
|
{
|
||||||
|
module = module.replace( '\\', '/' );
|
||||||
|
|
||||||
|
if ( module.regionMatches( true, module.length() - 4, ".xml", 0, 4 ) )
|
||||||
|
{
|
||||||
|
module = module.substring( 0, module.lastIndexOf( '/' ) + 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
String moduleName = module;
|
||||||
|
if ( moduleName.endsWith( "/" ) )
|
||||||
|
{
|
||||||
|
moduleName = moduleName.substring( 0, moduleName.length() - 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int lastSlash = moduleName.lastIndexOf( '/' );
|
||||||
|
|
||||||
|
moduleName = moduleName.substring( lastSlash + 1 );
|
||||||
|
|
||||||
|
if ( moduleName.equals( childArtifactId ) && lastSlash >= 0 )
|
||||||
|
{
|
||||||
|
adjustment = module.substring( 0, lastSlash );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return adjustment;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,7 @@ public interface InheritanceAssembler
|
||||||
* @param child The child model into which to merge the values inherited from the parent, must not be
|
* @param child The child model into which to merge the values inherited from the parent, must not be
|
||||||
* <code>null</code>.
|
* <code>null</code>.
|
||||||
* @param parent The (read-only) parent model from which to inherit the values, may be <code>null</code>.
|
* @param parent The (read-only) parent model from which to inherit the values, may be <code>null</code>.
|
||||||
* @param childPathAdjustment The relative path adjustment required to navigate from the parent's base directory to
|
|
||||||
* the parent directory of the child's base directory, must not be <code>null</code>.
|
|
||||||
*/
|
*/
|
||||||
void assembleModelInheritance( Model child, Model parent, String childPathAdjustment );
|
void assembleModelInheritance( Model child, Model parent );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -568,7 +568,7 @@ public class MavenModelMerger
|
||||||
{
|
{
|
||||||
String uncleanPath = parentPath;
|
String uncleanPath = parentPath;
|
||||||
|
|
||||||
if ( pathAdjustment != null )
|
if ( pathAdjustment != null && pathAdjustment.length() > 0 )
|
||||||
{
|
{
|
||||||
uncleanPath += "/" + pathAdjustment;
|
uncleanPath += "/" + pathAdjustment;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue