Index: src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
===================================================================
--- src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java (revision 896602)
+++ src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java (working copy)
@@ -102,7 +102,14 @@
{
if ( parent.getUrl() != null )
{
- child.setUrl( appendPath( parent.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ if ( endsWithMavenVariable( parent.getUrl() ) )
+ {
+ child.setUrl( parent.getUrl() );
+ }
+ else
+ {
+ child.setUrl( appendPath( parent.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ }
}
else
{
@@ -353,37 +360,68 @@
private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
{
- if ( parent.getScm() != null )
+ Scm parentScm = parent.getScm();
+
+ if ( parentScm == null )
{
- Scm parentScm = parent.getScm();
+ return;
+ }
- Scm childScm = child.getScm();
+ Scm childScm = child.getScm();
- if ( childScm == null )
- {
- childScm = new Scm();
+ if ( childScm == null )
+ {
+ childScm = new Scm();
+ child.setScm( childScm );
+ }
- child.setScm( childScm );
- }
+ String parentScmConn = parentScm.getConnection();
+ String parentDevConn = parentScm.getDeveloperConnection();
+ String parentUrl = parentScm.getUrl();
- if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty( parentScm.getConnection() ) )
+ String childScmConn = childScm.getConnection();
+ String childDevConn = childScm.getDeveloperConnection();
+ String childUrl = childScm.getUrl();
+
+ String childArtifactId = child.getArtifactId();
+
+ if ( StringUtils.isEmpty( childScmConn ) && !StringUtils.isEmpty( parentScmConn ) )
+ {
+ if ( endsWithMavenVariable( parentScmConn ) )
{
+ childScm.setConnection( parentScmConn );
+ }
+ else
+ {
childScm.setConnection(
- appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ appendPath( parentScmConn, childArtifactId, childPathAdjustment, appendPaths ) );
}
+ }
- if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
- !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
+ if ( StringUtils.isEmpty( childDevConn ) && !StringUtils.isEmpty( parentDevConn ) )
+ {
+ if ( endsWithMavenVariable( parentDevConn ) )
{
+ childScm.setDeveloperConnection( parentDevConn );
+ }
+ else
+ {
childScm
- .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
+ .setDeveloperConnection( appendPath( parentDevConn, childArtifactId,
childPathAdjustment, appendPaths ) );
}
+ }
- if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) )
+ if ( StringUtils.isEmpty( childUrl ) && !StringUtils.isEmpty( parentUrl ) )
+ {
+ if ( endsWithMavenVariable( parentUrl ) )
{
+ childScm.setUrl( parentUrl );
+ }
+ else
+ {
childScm.setUrl(
- appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ appendPath( parentUrl, childArtifactId, childPathAdjustment, appendPaths ) );
}
}
}
@@ -415,12 +453,16 @@
site.setName( parentDistMgmt.getSite().getName() );
- site.setUrl( parentDistMgmt.getSite().getUrl() );
+ String parentSiteUrl = parentDistMgmt.getSite().getUrl();
- if ( site.getUrl() != null )
+ if ( endsWithMavenVariable( parentSiteUrl ) )
{
+ site.setUrl( parentSiteUrl );
+ }
+ else if ( parentSiteUrl != null )
+ {
site.setUrl(
- appendPath( site.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ appendPath( parentSiteUrl, child.getArtifactId(), childPathAdjustment, appendPaths ) );
}
}
}
@@ -561,4 +603,16 @@
return cleanedPath.toString();
}
+ boolean endsWithMavenVariable( String str )
+ {
+ String firstCharExp =
+ "([a-zA-Z]|:|_|[\\u00C0-\\u00D6]|[\\u00D8-\\u00F6]|[\\u00F8-\\u02FF]|[\\u0370-\\u037D]|[\\u037F-\\u1FFF]|[\\u200C-\\u200D]|[\\u2070-\\u218F]|[\\u2C00-\\u2FEF]|[\\u3001-\\uD7FF]|[\\uF900-\\uFDCF]|[\\uFDF0-\\uFFFD]|[\\u10000-\\uEFFFF])";
+ String charExp =
+ "(" + firstCharExp
+ + "|\\-|\\.|\\d|\\u00B7|[\\u0300-\\u036F]|[\\u203F-\\u2040])";
+ String mavenVarExp = "\\$\\{" + charExp + "+" + "\\}";
+ String endsWithMavenVarExp = ".*" + mavenVarExp + "$";
+
+ return str != null && str.matches( endsWithMavenVarExp );
+ }
}
Index: src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java
===================================================================
--- src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java (revision 896602)
+++ src/test/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssemblerTest.java (working copy)
@@ -1177,4 +1177,28 @@
}
}
+ public void testEndsWithMavenVariable()
+ {
+ String goodStr = "http://www.foo.com/${project.artifactId}";
+ String badStr = null;
+ DefaultModelInheritanceAssembler assmblr = new DefaultModelInheritanceAssembler();
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ assertTrue ( assmblr.endsWithMavenVariable( goodStr ) );
+ badStr = "";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ badStr = "http://www.foo.com/${project.artifactId}/";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ badStr = "http://www.foo.com/${project.artifactId";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ badStr = "http://www.foo.com/{project.artifactId}";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ badStr = "http://www.foo.com/$project.artifactId}/";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ goodStr = "${project.artifactId}";
+ assertTrue ( assmblr.endsWithMavenVariable( goodStr ) );
+ badStr = "${}";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ badStr = "${!}";
+ assertFalse( assmblr.endsWithMavenVariable( badStr ) );
+ }
}
Index: src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java
===================================================================
--- src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java (revision 896602)
+++ src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java (working copy)
@@ -27,8 +27,11 @@
import java.util.Map;
import org.apache.maven.model.Build;
+import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Plugin;
+import org.apache.maven.model.Scm;
+import org.apache.maven.model.Site;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
@@ -74,6 +77,8 @@
File pom3 = new File( pom2.getParentFile(), "p3/pom.xml" );
File pom4 = new File( pom3.getParentFile(), "p4/pom.xml" );
File pom5 = new File( pom4.getParentFile(), "p5/pom.xml" );
+ File pom6 = new File( pom5.getParentFile(), "p6/pom.xml" );
+ File pom7 = new File( pom6.getParentFile(), "p7/pom.xml" );
System.out.println( "Location of project-4's POM: " + pom4.getPath() );
@@ -84,6 +89,8 @@
MavenProject project3 = getProject( pom3 );
MavenProject project4 = getProject( pom4 );
MavenProject project5 = getProject( pom5 );
+ MavenProject project6 = getProject( pom6 );
+ MavenProject project7 = getProject( pom7 );
assertEquals( "p4", project4.getName() );
@@ -116,6 +123,51 @@
// ----------------------------------------------------------------------
assertEquals( "4.0.0", project4.getModelVersion() );
+
+ // ----------------------------------------------------------------------
+ // p6 url, scm and distro mgmt site url are all valued and thus override
+ // any parent properties. each ends in a maven expression.
+ // this is in reference to:
+ // http://jira.codehaus.org/browse/MNG-3244
+ // and related issues (see issue links)
+ // ----------------------------------------------------------------------
+ assertNotNull("p6 url was null", project6.getUrl());
+ assertTrue("p6 url does not end in a Maven expression", project6.getUrl().matches(".*\\$\\{[^\\}]+\\}$"));
+ Scm p6Scm = project6.getScm();
+ assertNotNull("p6 scm was null", p6Scm);
+ assertNotNull("p6 scm.connection was null", p6Scm.getConnection());
+ assertTrue("p6 scm.connection does not end in a Maven expression", p6Scm.getConnection().matches(".*\\$\\{[^\\}]+\\}$"));
+ assertNotNull("p6 scm.developerConnection was null", p6Scm.getDeveloperConnection());
+ assertTrue("p6 scm.developerConnection does not end in a Maven expression", p6Scm.getDeveloperConnection().matches(".*\\$\\{[^\\}]+\\}$"));
+ assertNotNull("p6 scm.url was null", p6Scm.getUrl());
+ assertTrue("p6 scm.url does not end in a Maven expression", p6Scm.getUrl().matches(".*\\$\\{[^\\}]+\\}$"));
+ DistributionManagement p6distroMgmt = project6.getDistributionManagement();
+ assertNotNull("p6 distributionManagement was null", p6distroMgmt);
+ Site p6site = p6distroMgmt.getSite();
+ assertNotNull("p6 distributionManagement.site was null", p6site);
+ assertNotNull("p6 distributionManagement.site.url was null", p6site.getUrl());
+ assertTrue("p6 distributionManagement.site.url does not end in a Maven expression", p6site.getUrl().matches(".*\\$\\{[^\\}]+\\}$"));
+
+ // ----------------------------------------------------------------------
+ // p7 url, scm and distro mgmt site url were all null and should inherit
+ // from parent (p6) but since parent's values end in a maven expression
+ // there should be no "append child path" logic applied to the values.
+ // in other words, parent and child values should be equal.
+ // this is in reference to:
+ // http://jira.codehaus.org/browse/MNG-3244
+ // and related issues (see issue links)
+ // ----------------------------------------------------------------------
+ assertEquals("p6 and p7 urls were not equal", project6.getUrl(), project7.getUrl());
+ Scm p7Scm = project7.getScm();
+ assertNotNull("p7 scm was null", p7Scm);
+ assertEquals("p6 and p7 scm.connections were not equal", p6Scm.getConnection(), p7Scm.getConnection());
+ assertEquals("p6 and p7 scm.developerConnections were not equal", p6Scm.getDeveloperConnection(), p7Scm.getDeveloperConnection());
+ assertEquals("p6 and p7 scm.urls were not equal", p6Scm.getUrl(), p7Scm.getUrl());
+ DistributionManagement p7distroMgmt = project7.getDistributionManagement();
+ assertNotNull("p7 distributionManagement was null", p7distroMgmt);
+ Site p7site = p7distroMgmt.getSite();
+ assertNotNull("p7 distributionManagement.site was null", p7site);
+ assertEquals("p6 and p7 distributionManagement.site.urls were not equal", p6site.getUrl(), p7site.getUrl());
Build build = project4.getBuild();
List plugins = build.getPlugins();
Index: src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/pom.xml
===================================================================
--- src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/pom.xml (revision 0)
+++ src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/pom.xml (revision 0)
@@ -0,0 +1,44 @@
+
+
+
+ p3
+ maven
+ 1.0
+
+ 4.0.0
+ maven
+ p6
+ pom
+ p6
+ 1.0
+ http://maven.apache.org/${website}
+
+ http://maven.apache.org/${scm.conn}
+ http://maven.apache.org/${scm.dev.conn}
+ http://maven.apache.org/${browse.url}
+
+
+
+ foo
+ foo
+ dav:${mvn.site}
+
+
+
Index: src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/p7/pom.xml
===================================================================
--- src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/p7/pom.xml (revision 0)
+++ src/test/resources/inheritance-repo/t02/p0/p1/p2/p3/p4/p5/p6/p7/pom.xml (revision 0)
@@ -0,0 +1,31 @@
+
+
+
+ p6
+ maven
+ 1.0
+
+ 4.0.0
+ maven
+ p7
+ jar
+ p7
+ 1.0
+