From 2fc16b00db8c09cd8afe70416a7cc5f13139e535 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Mon, 9 Mar 2009 19:49:19 +0000 Subject: [PATCH] Processors: IssueManagement, Prerequisites git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@751810 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/processor/BuildProcessor.java | 1 - .../processor/IssueManagementProcessor.java | 34 +++++++++++++ .../processor/PrerequisitesProcessor.java | 25 ++++++++++ .../IssueManagementProcessorTest.java | 27 ++++++++++ .../processor/PrerequisitesProcessorTest.java | 49 +++++++++++++++++++ 5 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 maven-project/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java create mode 100644 maven-project/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java create mode 100644 maven-project/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java create mode 100644 maven-project/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java b/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java index 81842531c4..fb50ffcb30 100644 --- a/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java +++ b/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java @@ -13,6 +13,5 @@ public class BuildProcessor public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) { super.process( parent, child, target, isChildMostSpecialized ); - } } diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java b/maven-project/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java new file mode 100644 index 0000000000..6c0353dd23 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/processor/IssueManagementProcessor.java @@ -0,0 +1,34 @@ +package org.apache.maven.project.processor; + +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.Model; + +public class IssueManagementProcessor extends BaseProcessor +{ + public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) + { + super.process( parent, child, target, isChildMostSpecialized ); + Model t = (Model) target; + Model c = (Model) child; + Model p = (Model) parent; + + if( c.getIssueManagement() != null) + { + IssueManagement childMng = c.getIssueManagement(); + IssueManagement mng = new IssueManagement(); + + mng.setSystem( childMng.getSystem() ); + mng.setUrl( childMng.getUrl() ); + t.setIssueManagement( mng ); + } + else if(p != null && p.getIssueManagement() != null) + { + IssueManagement parentMng = p.getIssueManagement(); + IssueManagement mng = new IssueManagement(); + + mng.setSystem( parentMng .getSystem() ); + mng.setUrl( parentMng .getUrl() ); + t.setIssueManagement( mng ); + } + } +} diff --git a/maven-project/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java b/maven-project/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java new file mode 100644 index 0000000000..a13cc32156 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/project/processor/PrerequisitesProcessor.java @@ -0,0 +1,25 @@ +package org.apache.maven.project.processor; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Prerequisites; + +public class PrerequisitesProcessor extends BaseProcessor +{ + public void process( Object parent, Object child, Object target, boolean isChildMostSpecialized ) + { + super.process( parent, child, target, isChildMostSpecialized ); + + if ( isChildMostSpecialized ) + { + Model t = (Model) target; + Model c = (Model) child; + if(c.getPrerequisites() == null) + { + return; + } + Prerequisites prerequisites = new Prerequisites(); + prerequisites.setMaven( c.getPrerequisites().getMaven()); + t.setPrerequisites( prerequisites ); + } + } +} diff --git a/maven-project/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java b/maven-project/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java new file mode 100644 index 0000000000..db29bfaccb --- /dev/null +++ b/maven-project/src/test/java/org/apache/maven/project/processor/IssueManagementProcessorTest.java @@ -0,0 +1,27 @@ +package org.apache.maven.project.processor; + +import org.apache.maven.model.IssueManagement; +import org.apache.maven.model.Model; + +import junit.framework.TestCase; + +public class IssueManagementProcessorTest extends TestCase +{ + public void testChildCopy() + { + IssueManagement mng = new IssueManagement(); + mng.setSystem( "system" ); + mng.setUrl( "http://url" ); + + Model child = new Model(); + child.setIssueManagement( mng ); + + Model target = new Model(); + + IssueManagementProcessor proc = new IssueManagementProcessor(); + proc.process( null, child, target, false ); + + assertEquals("system", target.getIssueManagement().getSystem()); + assertEquals("http://url", target.getIssueManagement().getUrl()); + } +} diff --git a/maven-project/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java b/maven-project/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java new file mode 100644 index 0000000000..46a4cfb5a2 --- /dev/null +++ b/maven-project/src/test/java/org/apache/maven/project/processor/PrerequisitesProcessorTest.java @@ -0,0 +1,49 @@ +package org.apache.maven.project.processor; + +import org.apache.maven.model.Model; +import org.apache.maven.model.Prerequisites; + +import junit.framework.TestCase; + +public class PrerequisitesProcessorTest extends TestCase +{ + + public void testMaven() + { + Prerequisites prerequisites = new Prerequisites(); + prerequisites.setMaven( "2.1" ); + + Model child = new Model(); + child.setPrerequisites( prerequisites ); + + Model target = new Model(); + + PrerequisitesProcessor proc = new PrerequisitesProcessor(); + proc.process( null, child, target, true ); + + assertEquals("2.1", target.getPrerequisites().getMaven()); + + //Immutable + prerequisites.setMaven( "2.2" ); + assertEquals("2.1", target.getPrerequisites().getMaven()); + + } + + public void testMavenParent() + { + Prerequisites prerequisites = new Prerequisites(); + prerequisites.setMaven( "2.1" ); + + Model parent = new Model(); + parent.setPrerequisites( prerequisites ); + + Model target = new Model(); + + PrerequisitesProcessor proc = new PrerequisitesProcessor(); + proc.process( parent, new Model(), target, false ); + + assertEquals(null, target.getPrerequisites()); + + } + +}