From 53e918956626b05987baa63e9e99bf9a6775f507 Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Gonzalez Date: Fri, 15 Feb 2008 02:39:02 +0000 Subject: [PATCH] [MNG-3400] Implement clone properly following Effective Java' book considerations git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@627932 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/maven/project/MavenProject.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index cb7a781d22..7675f88196 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -80,6 +80,7 @@ import java.util.Stack; * */ public class MavenProject + implements Cloneable { public static final String EMPTY_PROJECT_GROUP_ID = "unknown"; @@ -169,10 +170,14 @@ public class MavenProject } /** - * @deprecated use {@link #clone()} + * @deprecated use {@link #clone()} so subclasses can provide a copy of the same class */ public MavenProject( MavenProject project ) { + deepCopy( project ); + } + + private final void deepCopy(MavenProject project){ // disown the parent // copy fields @@ -1825,11 +1830,15 @@ public class MavenProject } /** + * @throws CloneNotSupportedException * @since 2.0.9 */ public Object clone() + throws CloneNotSupportedException { - return new MavenProject( this ); + MavenProject clone = (MavenProject) super.clone(); + clone.deepCopy( this ); + return clone; } }