I think I have found a way to support module directory in SCM & site that is 
not artifactId
AFAIK, it's a long awaited feature that was until now feared to wreck havock

please review and tell what you think about it

Regards,

Hervé

Le mercredi 26 août 2015 20:26:37 [email protected] a écrit :
> Repository: maven
> Updated Branches:
>   refs/heads/MNG-5878 [created] 812e1e9d5
> 
> 
> MNG-5878 added project.directory property to configure module directory
> when not equals to artifactId
> 
> Project: http://git-wip-us.apache.org/repos/asf/maven/repo
> Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/812e1e9d
> Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/812e1e9d
> Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/812e1e9d
> 
> Branch: refs/heads/MNG-5878
> Commit: 812e1e9d5b7d15a3b206371fc18110193f83cc1f
> Parents: 6b6e9bf
> Author: Hervé Boutemy <[email protected]>
> Authored: Wed Aug 26 22:26:17 2015 +0200
> Committer: Hervé Boutemy <[email protected]>
> Committed: Wed Aug 26 22:26:17 2015 +0200
> 
> ----------------------------------------------------------------------
>  .../DefaultInheritanceAssembler.java            | 60 ++++++++++++++++----
>  maven-model-builder/src/site/apt/index.apt      |  2 +-
>  .../DefaultInheritanceAssemblerTest.java        | 27 ++++++++-
>  .../module-path-not-artifactId-child.xml        | 43 ++++++++++++++
>  .../module-path-not-artifactId-expected.xml     | 44 ++++++++++++++
>  .../module-path-not-artifactId-parent.xml       | 37 ++++++++++++
>  6 files changed, 199 insertions(+), 14 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/main/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemb
> ler.java
> ---------------------------------------------------------------------- diff
> --git
> a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssembler.java
> b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssembler.java index 48fdad5..7c2a3b4 100644
> ---
> a/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssembler.java +++
> b/maven-model-builder/src/main/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssembler.java @@ -19,14 +19,16 @@ package
> org.apache.maven.model.inheritance;
>   * under the License.
>   */
> 
> -import java.io.File;
>  import java.util.ArrayList;
>  import java.util.HashMap;
>  import java.util.LinkedHashMap;
>  import java.util.List;
>  import java.util.Map;
> +import java.util.Properties;
> 
> +import org.apache.maven.model.InputLocation;
>  import org.apache.maven.model.Model;
> +import org.apache.maven.model.ModelBase;
>  import org.apache.maven.model.Plugin;
>  import org.apache.maven.model.PluginContainer;
>  import org.apache.maven.model.ReportPlugin;
> @@ -48,12 +50,18 @@ public class DefaultInheritanceAssembler
> 
>      private InheritanceModelMerger merger = new InheritanceModelMerger();
> 
> +    private final static String CHILD_DIRECTORY = "child-directory";
> +
> +    private final static String CHILD_DIRECTORY_PROPERTY =
> "project.directory"; +
>      @Override
>      public void assembleModelInheritance( Model child, Model parent,
> ModelBuildingRequest request, ModelProblemCollector problems ) {
>          Map<Object, Object> hints = new HashMap<>();
> -        hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT,
> getChildPathAdjustment( child, parent ) ); +        String childPath =
> child.getProperties().getProperty( CHILD_DIRECTORY_PROPERTY,
> child.getArtifactId() ); +        hints.put( CHILD_DIRECTORY, childPath );
> +        hints.put( MavenModelMerger.CHILD_PATH_ADJUSTMENT,
> getChildPathAdjustment( child, parent, childPath ) ); merger.merge( child,
> parent, false, hints );
>      }
> 
> @@ -75,7 +83,7 @@ public class DefaultInheritanceAssembler
>       * @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 )
> +    private String getChildPathAdjustment( Model child, Model parent,
> String childDirectory ) {
>          String adjustment = "";
> 
> @@ -90,10 +98,9 @@ public class DefaultInheritanceAssembler
>               * repository. In other words, modules where artifactId !=
> moduleDirName will see different effective URLs * depending on how the
> model was constructed (from filesystem or from repository). */
> -            File childDirectory = child.getProjectDirectory();
> -            if ( childDirectory != null )
> +            if ( child.getProjectDirectory() != null )
>              {
> -                childName = childDirectory.getName();
> +                childName = child.getProjectDirectory().getName();
>              }
> 
>              for ( String module : parent.getModules() )
> @@ -115,7 +122,7 @@ public class DefaultInheritanceAssembler
> 
>                  moduleName = moduleName.substring( lastSlash + 1 );
> 
> -                if ( moduleName.equals( childName ) && lastSlash >= 0 )
> +                if ( ( moduleName.equals( childName ) || (
> moduleName.equals( childDirectory ) ) ) && lastSlash >= 0 ) {
>                      adjustment = module.substring( 0, lastSlash );
>                      break;
> @@ -133,13 +140,13 @@ public class DefaultInheritanceAssembler
>          @Override
>          protected String extrapolateChildUrl( String parentUrl, Map<Object,
> Object> context ) {
> -            Object artifactId = context.get( ARTIFACT_ID );
> +            Object childDirectory = context.get( CHILD_DIRECTORY );
>              Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT
> );
> 
> -            if ( artifactId != null && childPathAdjustment != null )
> +            if ( childDirectory != null && childPathAdjustment != null )
>              {
> -                // append childPathAdjustment and artifactId to parent url
> -                return appendPath( parentUrl, artifactId.toString(),
> childPathAdjustment.toString() ); +                // append
> childPathAdjustment and childDirectory to parent url +               
> return appendPath( parentUrl, childDirectory.toString(),
> childPathAdjustment.toString() ); }
>              else
>              {
> @@ -185,6 +192,37 @@ public class DefaultInheritanceAssembler
>          }
> 
>          @Override
> +        protected void mergeModelBase_Properties( ModelBase target,
> ModelBase source, boolean sourceDominant, +                                
>                  Map<Object, Object> context ) +        {
> +            Properties merged = new Properties();
> +            if ( sourceDominant )
> +            {
> +                merged.putAll( target.getProperties() );
> +                putAll( merged, source.getProperties(),
> CHILD_DIRECTORY_PROPERTY ); +            }
> +            else
> +            {
> +                merged.putAll( source.getProperties() );
> +                putAll( merged, target.getProperties(),
> CHILD_DIRECTORY_PROPERTY ); +            }
> +            target.setProperties( merged );
> +            target.setLocation( "properties", InputLocation.merge(
> target.getLocation( "properties" ), +                                      
>                             source.getLocation( "properties" ),
> sourceDominant ) ); +        }
> +
> +        private void putAll( Map<Object, Object> s, Map<Object, Object> t,
> Object excludeKey ) +        {
> +            for ( Map.Entry<Object, Object> e : t.entrySet() )
> +            {
> +                if ( !e.getKey().equals( excludeKey ) )
> +                {
> +                    s.put( e.getKey(), e.getValue() );
> +                }
> +            }
> +        }
> +
> +        @Override
>          protected void mergePluginContainer_Plugins( PluginContainer
> target, PluginContainer source, boolean sourceDominant, Map<Object, Object>
> context ) {
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/site/apt/index.apt
> ---------------------------------------------------------------------- diff
> --git a/maven-model-builder/src/site/apt/index.apt
> b/maven-model-builder/src/site/apt/index.apt index 9a645f4..764f8c6 100644
> --- a/maven-model-builder/src/site/apt/index.apt
> +++ b/maven-model-builder/src/site/apt/index.apt
> @@ -62,7 +62,7 @@ Maven Model Builder
>    
> ({{{./xref/org/apache/maven/model/inheritance/DefaultInheritanceAssembler.h
> tml}source}}). Notice that <<<project.url>>>, <<<project.scm.connection>>>,
> <<<project.scm.developerConnection>>>, <<<project.scm.url>>> and
> <<<project.distributionManagement.site.url>>> have a special treatment: if
> not overridden in child, the default value is parent's one -   with child
> artifact id appended
> +   with child artifact id appended, or <<<project.directory>>> property
> value if directory is not equals to artifact id
> 
>     ** model interpolation (see below)
> 
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemb
> lerTest.java
> ---------------------------------------------------------------------- diff
> --git
> a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssemblerTest.java
> b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssemblerTest.java index f9e95ec..e3a2d50 100644
> ---
> a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssemblerTest.java +++
> b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/Defa
> ultInheritanceAssemblerTest.java @@ -88,12 +88,35 @@ public class
> DefaultInheritanceAssemblerTest
>          try ( Reader control = new InputStreamReader( new FileInputStream(
> expected ), "UTF-8" ); Reader test = new InputStreamReader( new
> FileInputStream( actual ), "UTF-8" ) ) {
> -
>              XMLUnit.setIgnoreComments( true );
>              XMLUnit.setIgnoreWhitespace( true );
>              XMLAssert.assertXMLEqual( control, test );
>          }
> -
>      }
> 
> +    public void testModulePathNotArtifactId()
> +        throws Exception
> +    {
> +        Model parent = getModel( "module-path-not-artifactId-parent" );
> +
> +        Model child = getModel( "module-path-not-artifactId-child" );
> +
> +        SimpleProblemCollector problems = new SimpleProblemCollector();
> +
> +        assembler.assembleModelInheritance( child, parent, null, problems
> ); +
> +        File actual = getTestFile(
> "target/test-classes/poms/inheritance/module-path-not-artifactId-actual.xml
> " ); +
> +        writer.write( actual, null, child );
> +
> +        // check with getPom( "module-path-not-artifactId-effective" )
> +        File expected = getPom( "module-path-not-artifactId-expected" );
> +        try ( Reader control = new InputStreamReader( new FileInputStream(
> expected ), "UTF-8" ); +              Reader test = new InputStreamReader(
> new FileInputStream( actual ), "UTF-8" ) ) +        {
> +            XMLUnit.setIgnoreComments( true );
> +            XMLUnit.setIgnoreWhitespace( true );
> +            XMLAssert.assertXMLEqual( control, test );
> +        }
> +    }
>  }
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/test/resources/poms/inheritance/module-path-not-artifactId-child.xml
> ---------------------------------------------------------------------- diff
> --git
> a/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-child.xml
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-child.xml new file mode 100644
> index 0000000..7031f44
> --- /dev/null
> +++
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-child.xml @@ -0,0 +1,43 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +
> +<!--
> +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.
> +-->
> +
> +<project xmlns="http://maven.apache.org/POM/4.0.0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; + 
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd";> + 
> <modelVersion>4.0.0</modelVersion>
> +
> +  <parent>
> +    <groupId>inheritance</groupId>
> +    <artifactId>parent</artifactId>
> +    <version>11-SNAPSHOT</version>
> +  </parent>
> +
> +  <artifactId>child-artifact-id</artifactId>
> +  <name>Model inheritance test parent: module directory !=
> artifactId</name> +  <description>
> +    artifactId == "child-artifact-id"
> +    but expect path on SCM and site == "child"
> +    feature: support "project.directory" property, ressembling future model
> addition of "directory" element along "artifactId" +  </description>
> +
> +  <properties>
> +    <project.directory>child</project.directory>
> +  </properties>
> +</project>
> \ No newline at end of file
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/test/resources/poms/inheritance/module-path-not-artifactId-expected.x
> ml ----------------------------------------------------------------------
> diff --git
> a/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-expected.xml
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-expected.xml new file mode 100644
> index 0000000..38d9406
> --- /dev/null
> +++
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-expected.xml @@ -0,0 +1,44 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +
> +<!--
> +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.
> +-->
> +
> +<project xmlns="http://maven.apache.org/POM/4.0.0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; + 
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd";> + 
> <modelVersion>4.0.0</modelVersion>
> +
> +  <parent>
> +    <groupId>inheritance</groupId>
> +    <artifactId>parent</artifactId>
> +    <version>11-SNAPSHOT</version>
> +  </parent>
> +
> +  <groupId>inheritance</groupId>
> +  <artifactId>child-artifact-id</artifactId>
> +  <version>11-SNAPSHOT</version>
> +  <name>Model inheritance test parent: module directory !=
> artifactId</name> +  <description>
> +    artifactId == "child-artifact-id"
> +    but expect path on SCM and site == "child"
> +    feature: support "project.directory" property, ressembling future model
> addition of "directory" element along "artifactId" +  </description>
> +
> +  <url>http://www.apache.org/child/</url>
> +
> +</project>
> 
> http://git-wip-us.apache.org/repos/asf/maven/blob/812e1e9d/maven-model-build
> er/src/test/resources/poms/inheritance/module-path-not-artifactId-parent.xml
> ---------------------------------------------------------------------- diff
> --git
> a/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-parent.xml
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-parent.xml new file mode 100644
> index 0000000..d29d78c
> --- /dev/null
> +++
> b/maven-model-builder/src/test/resources/poms/inheritance/module-path-not-a
> rtifactId-parent.xml @@ -0,0 +1,37 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +
> +<!--
> +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.
> +-->
> +
> +<project xmlns="http://maven.apache.org/POM/4.0.0";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; + 
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd";> + 
> <modelVersion>4.0.0</modelVersion>
> +
> +  <groupId>inheritance</groupId>
> +  <artifactId>parent</artifactId>
> +  <version>11-SNAPSHOT</version>
> +
> +  <name>Model inheritance test parent: module path != artifactId</name>
> +  <url>http://www.apache.org/</url>
> +
> +  <modules>
> +    <module>child</module>
> +  </modules>
> +
> +</project>
> \ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to