o Fixed handling of missing project artifact id

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@934440 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-04-15 15:09:40 +00:00
parent 7e5e5eb1da
commit 41eb59fdd1
4 changed files with 115 additions and 17 deletions

View File

@ -1089,14 +1089,15 @@ public void testPropertiesNoDuplication()
assertEquals(1, ( (Properties) pom.getValue( "properties" ) ).size());
assertEquals("child", pom.getValue( "properties/pomProfile" ) );
}
public void testPomInheritance()
throws Exception
{
PomTestWrapper pom = buildPom( "pom-inheritance/sub" );
assertEquals("parent-description", pom.getValue("description"));
}
throws Exception
{
PomTestWrapper pom = buildPom( "pom-inheritance/sub" );
assertEquals( "parent-description", pom.getValue( "description" ) );
assertEquals( "jar", pom.getValue( "packaging" ) );
}
public void testCompleteModelWithoutParent()
throws Exception
{
@ -1756,6 +1757,20 @@ public void testPluginOrderAfterMergingWithInjectedPlugins()
assertEquals( actual, expected );
}
public void testProjectArtifactIdIsNotInheritedButMandatory()
throws Exception
{
try
{
buildPom( "artifact-id-inheritance/child" );
fail( "Missing artifactId did not cause validation error" );
}
catch ( ProjectBuildingException e )
{
// expected
}
}
private void assertPathSuffixEquals( String expected, Object actual )
{
String a = actual.toString();

View File

@ -0,0 +1,32 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>
<!-- while groupId and version are inherited, artifactId is not and must be specified -->
</project>

View File

@ -0,0 +1,35 @@
<?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>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<!--
NOTE: This extends the test to check an edge case of URL adjustment which must not error out during inheritance
if the child misses the artifactId (as to be reported by validation).
-->
<url>http://maven.apache.org/</url>
</project>

View File

@ -101,8 +101,7 @@ protected void mergeModel_Url( Model target, Model source, boolean sourceDominan
}
else if ( target.getUrl() == null )
{
target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(),
context.get( CHILD_PATH_ADJUSTMENT ).toString() ) );
target.setUrl( appendPath( src, context ) );
}
}
}
@ -168,6 +167,12 @@ protected void mergeModel_ModelVersion( Model target, Model source, boolean sour
// neither inherited nor injected
}
@Override
protected void mergeModel_ArtifactId( Model target, Model source, boolean sourceDominant, Map<Object, Object> context )
{
// neither inherited nor injected
}
@Override
protected void mergeModel_Profiles( Model target, Model source, boolean sourceDominant, Map<Object, Object> context )
{
@ -396,8 +401,7 @@ protected void mergeSite_Url( Site target, Site source, boolean sourceDominant,
}
else if ( target.getUrl() == null )
{
target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(),
context.get( CHILD_PATH_ADJUSTMENT ).toString() ) );
target.setUrl( appendPath( src, context ) );
}
}
}
@ -414,8 +418,7 @@ protected void mergeScm_Url( Scm target, Scm source, boolean sourceDominant, Map
}
else if ( target.getUrl() == null )
{
target.setUrl( appendPath( src, context.get( ARTIFACT_ID ).toString(),
context.get( CHILD_PATH_ADJUSTMENT ).toString() ) );
target.setUrl( appendPath( src, context ) );
}
}
}
@ -432,8 +435,7 @@ protected void mergeScm_Connection( Scm target, Scm source, boolean sourceDomina
}
else if ( target.getConnection() == null )
{
target.setConnection( appendPath( src, context.get( ARTIFACT_ID ).toString(),
context.get( CHILD_PATH_ADJUSTMENT ).toString() ) );
target.setConnection( appendPath( src, context ) );
}
}
}
@ -451,8 +453,7 @@ protected void mergeScm_DeveloperConnection( Scm target, Scm source, boolean sou
}
else if ( target.getDeveloperConnection() == null )
{
target.setDeveloperConnection( appendPath( src, context.get( ARTIFACT_ID ).toString(),
context.get( CHILD_PATH_ADJUSTMENT ).toString() ) );
target.setDeveloperConnection( appendPath( src, context ) );
}
}
}
@ -556,6 +557,21 @@ protected Object getExtensionKey( Extension object )
return object.getGroupId() + ':' + object.getArtifactId();
}
private String appendPath( String parentPath, Map<Object, Object> context )
{
Object artifactId = context.get( ARTIFACT_ID );
Object childPathAdjustment = context.get( CHILD_PATH_ADJUSTMENT );
if ( artifactId != null && childPathAdjustment != null )
{
return appendPath( parentPath, artifactId.toString(), childPathAdjustment.toString() );
}
else
{
return parentPath;
}
}
private String appendPath( String parentPath, String childPath, String pathAdjustment )
{
String path = parentPath;