diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java b/maven-project/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java new file mode 100644 index 0000000000..d354893f0a --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/processor/ContributorsProcessor.java @@ -0,0 +1,70 @@ +package org.apache.maven.project.processor; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.model.Contributor; +import org.apache.maven.model.Model; + +public class ContributorsProcessor + extends BaseProcessor +{ + + public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) + { + super.process( parent, child, target, isChildMostSpecialized ); + + Model p = (Model) parent; + Model c = (Model) child; + Model t = (Model) target; + + if ( !c.getContributors().isEmpty() ) + { + copyContributors( c.getContributors(), t ); + } + else if ( p != null && !p.getContributors().isEmpty() ) + { + copyContributors( p.getContributors(), t ); + } + } + + private static void copyContributors( List contributors, Model target ) + { + for ( Contributor contributor : contributors ) + { + Contributor copy = new Contributor(); + copy.setName( contributor.getName() ); + copy.setEmail( contributor.getEmail() ); + copy.setUrl( contributor.getUrl() ); + copy.setOrganization( contributor.getOrganization() ); + copy.setOrganizationUrl( contributor.getOrganizationUrl() ); + copy.setTimezone( contributor.getTimezone() ); + copy.setRoles( new ArrayList( contributor.getRoles() ) ); + Properties props = new Properties(); + props.putAll( contributor.getProperties() ); + copy.setProperties( props ); + target.addContributor( copy ); + } + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java b/maven-project/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java new file mode 100644 index 0000000000..b84c8abfbd --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/processor/DevelopersProcessor.java @@ -0,0 +1,71 @@ +package org.apache.maven.project.processor; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.model.Developer; +import org.apache.maven.model.Model; + +public class DevelopersProcessor + extends BaseProcessor +{ + + public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) + { + super.process( parent, child, target, isChildMostSpecialized ); + + Model p = (Model) parent; + Model c = (Model) child; + Model t = (Model) target; + + if ( !c.getDevelopers().isEmpty() ) + { + copyDevelopers( c.getDevelopers(), t ); + } + else if ( p != null && !p.getDevelopers().isEmpty() ) + { + copyDevelopers( p.getDevelopers(), t ); + } + } + + private static void copyDevelopers( List developers, Model target ) + { + for ( Developer developer : developers ) + { + Developer copy = new Developer(); + copy.setId( developer.getId() ); + copy.setName( developer.getName() ); + copy.setEmail( developer.getEmail() ); + copy.setUrl( developer.getUrl() ); + copy.setOrganization( developer.getOrganization() ); + copy.setOrganizationUrl( developer.getOrganizationUrl() ); + copy.setTimezone( developer.getTimezone() ); + copy.setRoles( new ArrayList( developer.getRoles() ) ); + Properties props = new Properties(); + props.putAll( developer.getProperties() ); + copy.setProperties( props ); + target.addDeveloper( copy ); + } + } + +} diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/ProcessorContext.java b/maven-project/src/main/java/org/apache/maven/project/processor/ProcessorContext.java index fd8d362329..99a7646241 100644 --- a/maven-project/src/main/java/org/apache/maven/project/processor/ProcessorContext.java +++ b/maven-project/src/main/java/org/apache/maven/project/processor/ProcessorContext.java @@ -176,7 +176,8 @@ public class ProcessorContext new MailingListProcessor(), new IssueManagementProcessor(), new CiManagementProcessor(), new ReportingProcessor(), new RepositoriesProcessor(), new DistributionManagementProcessor(), - new LicensesProcessor(), new ScmProcessor(), new PrerequisitesProcessor() ); + new LicensesProcessor(), new ScmProcessor(), new PrerequisitesProcessor(), + new ContributorsProcessor(), new DevelopersProcessor() ); Model target = processModelsForInheritance( convertDomainModelsToMavenModels( domainModels ), processors, true ); PomClassicDomainModel model = convertToDomainModel( target, false ); diff --git a/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java index 0f39882f43..bcdd728342 100644 --- a/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -983,11 +983,28 @@ public class PomConstructionTest assertEquals( "repo", pom.getValue( "licenses[1]/distribution" ) ); assertEquals( "free", pom.getValue( "licenses[1]/comments" ) ); - /* FIXME - assertEquals( 1, ((List)pom.getValue( "developers" )).size() ); + assertEquals( 1, ( (List) pom.getValue( "developers" ) ).size() ); + assertEquals( "dev", pom.getValue( "developers[1]/id" ) ); + assertEquals( "project-developer", pom.getValue( "developers[1]/name" ) ); + assertEquals( "developer@", pom.getValue( "developers[1]/email" ) ); + assertEquals( "http://developer", pom.getValue( "developers[1]/url" ) ); + assertEquals( "developer", pom.getValue( "developers[1]/organization" ) ); + assertEquals( "http://devel.org", pom.getValue( "developers[1]/organizationUrl" ) ); + assertEquals( "-1", pom.getValue( "developers[1]/timezone" ) ); + assertEquals( "yes", pom.getValue( "developers[1]/properties/developer" ) ); + assertEquals( 1, ( (List) pom.getValue( "developers[1]/roles" ) ).size() ); + assertEquals( "devel", pom.getValue( "developers[1]/roles[1]" ) ); - assertEquals( 1, ((List)pom.getValue( "contributors" )).size() ); - //*/ + assertEquals( 1, ( (List) pom.getValue( "contributors" ) ).size() ); + assertEquals( "project-contributor", pom.getValue( "contributors[1]/name" ) ); + assertEquals( "contributor@", pom.getValue( "contributors[1]/email" ) ); + assertEquals( "http://contributor", pom.getValue( "contributors[1]/url" ) ); + assertEquals( "contributor", pom.getValue( "contributors[1]/organization" ) ); + assertEquals( "http://contrib.org", pom.getValue( "contributors[1]/organizationUrl" ) ); + assertEquals( "+1", pom.getValue( "contributors[1]/timezone" ) ); + assertEquals( "yes", pom.getValue( "contributors[1]/properties/contributor" ) ); + assertEquals( 1, ( (List) pom.getValue( "contributors[1]/roles" ) ).size() ); + assertEquals( "contrib", pom.getValue( "contributors[1]/roles[1]" ) ); assertEquals( 1, ( (List) pom.getValue( "mailingLists" ) ).size() ); assertEquals( "project-mailing-list", pom.getValue( "mailingLists[1]/name" ) );