[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
This commit is contained in:
Carlos Sanchez Gonzalez 2008-02-15 02:39:02 +00:00
parent 17d401df6c
commit 53e9189566
1 changed files with 11 additions and 2 deletions

View File

@ -80,6 +80,7 @@ import java.util.Stack;
* </ol> * </ol>
*/ */
public class MavenProject public class MavenProject
implements Cloneable
{ {
public static final String EMPTY_PROJECT_GROUP_ID = "unknown"; 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 ) public MavenProject( MavenProject project )
{ {
deepCopy( project );
}
private final void deepCopy(MavenProject project){
// disown the parent // disown the parent
// copy fields // copy fields
@ -1825,11 +1830,15 @@ public class MavenProject
} }
/** /**
* @throws CloneNotSupportedException
* @since 2.0.9 * @since 2.0.9
*/ */
public Object clone() public Object clone()
throws CloneNotSupportedException
{ {
return new MavenProject( this ); MavenProject clone = (MavenProject) super.clone();
clone.deepCopy( this );
return clone;
} }
} }