Author: bentmann Date: Thu Apr 15 15:09:40 2010 New Revision: 934440 URL: http://svn.apache.org/viewvc?rev=934440&view=rev Log: o Fixed handling of missing project artifact id
Added: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/ (with props) maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/ (with props) maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml (with props) maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml (with props) Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=934440&r1=934439&r2=934440&view=diff ============================================================================== --- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java (original) +++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/project/PomConstructionTest.java Thu Apr 15 15:09:40 2010 @@ -1089,14 +1089,15 @@ public class PomConstructionTest 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 class PomConstructionTest 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(); Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/ ------------------------------------------------------------------------------ bugtraq:label = Enter issue ID: Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/ ------------------------------------------------------------------------------ bugtraq:message = Issue id: %BUGID% Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/ ------------------------------------------------------------------------------ bugtraq:number = false Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/ ------------------------------------------------------------------------------ bugtraq:url = http://jira.codehaus.org/browse/%BUGID% Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/ ------------------------------------------------------------------------------ bugtraq:label = Enter issue ID: Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/ ------------------------------------------------------------------------------ bugtraq:message = Issue id: %BUGID% Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/ ------------------------------------------------------------------------------ bugtraq:number = false Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/ ------------------------------------------------------------------------------ bugtraq:url = http://jira.codehaus.org/browse/%BUGID% Added: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml?rev=934440&view=auto ============================================================================== --- maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml (added) +++ maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml Thu Apr 15 15:09:40 2010 @@ -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> Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/child/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml?rev=934440&view=auto ============================================================================== --- maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml (added) +++ maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml Thu Apr 15 15:09:40 2010 @@ -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> Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/maven-3/trunk/maven-core/src/test/resources-project-builder/artifact-id-inheritance/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java?rev=934440&r1=934439&r2=934440&view=diff ============================================================================== --- maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java (original) +++ maven/maven-3/trunk/maven-model-builder/src/main/java/org/apache/maven/model/merge/MavenModelMerger.java Thu Apr 15 15:09:40 2010 @@ -101,8 +101,7 @@ public class MavenModelMerger } 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 ) ); } } } @@ -169,6 +168,12 @@ public class MavenModelMerger } @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 ) { // neither inherited nor injected @@ -396,8 +401,7 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger } 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 @@ public class MavenModelMerger 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;