From 3e615520363e28a3f45c9620b398152f81414dc5 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 27 May 2003 09:30:17 +0000 Subject: [PATCH] fix the completely broken clone() implementations. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274622 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/types/AbstractFileSet.java | 13 +++++++++ .../apache/tools/ant/types/Commandline.java | 11 +++++--- .../tools/ant/types/CommandlineJava.java | 27 ++++++++++--------- .../org/apache/tools/ant/types/DirSet.java | 6 ++--- .../org/apache/tools/ant/types/FileSet.java | 6 ++--- .../org/apache/tools/ant/types/FilterSet.java | 11 ++++++-- src/main/org/apache/tools/ant/types/Path.java | 10 ++++--- .../apache/tools/ant/types/ZipFileSet.java | 4 +-- 8 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/main/org/apache/tools/ant/types/AbstractFileSet.java b/src/main/org/apache/tools/ant/types/AbstractFileSet.java index 274fb2470..56fccb58c 100644 --- a/src/main/org/apache/tools/ant/types/AbstractFileSet.java +++ b/src/main/org/apache/tools/ant/types/AbstractFileSet.java @@ -668,4 +668,17 @@ public abstract class AbstractFileSet extends DataType implements Cloneable, return sb.toString(); } + /** + * @since Ant 1.6 + */ + public Object clone() { + try { + AbstractFileSet fs = (AbstractFileSet) super.clone(); + fs.setProject(getProject()); + return fs; + } catch (CloneNotSupportedException e) { + throw new BuildException(e); + } + } + } diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java index 13eb19db6..96e00615e 100644 --- a/src/main/org/apache/tools/ant/types/Commandline.java +++ b/src/main/org/apache/tools/ant/types/Commandline.java @@ -427,10 +427,13 @@ public class Commandline implements Cloneable { } public Object clone() { - Commandline c = new Commandline(); - c.setExecutable(executable); - c.addArguments(getArguments()); - return c; + try { + Commandline c = (Commandline) super.clone(); + c.arguments = (Vector) arguments.clone(); + return c; + } catch (CloneNotSupportedException e) { + throw new BuildException(e); + } } /** diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 2b9569326..02928ca3e 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -440,20 +440,21 @@ public class CommandlineJava implements Cloneable { * @return a CommandlineJava object */ public Object clone() { - CommandlineJava c = new CommandlineJava(); - c.vmCommand = (Commandline) vmCommand.clone(); - c.javaCommand = (Commandline) javaCommand.clone(); - c.sysProperties = (SysProperties) sysProperties.clone(); - c.maxMemory = maxMemory; - if (classpath != null) { - c.classpath = (Path) classpath.clone(); - } - if (bootclasspath != null) { - c.bootclasspath = (Path) bootclasspath.clone(); + try { + CommandlineJava c = (CommandlineJava) super.clone(); + c.vmCommand = (Commandline) vmCommand.clone(); + c.javaCommand = (Commandline) javaCommand.clone(); + c.sysProperties = (SysProperties) sysProperties.clone(); + if (classpath != null) { + c.classpath = (Path) classpath.clone(); + } + if (bootclasspath != null) { + c.bootclasspath = (Path) bootclasspath.clone(); + } + return c; + } catch (CloneNotSupportedException e) { + throw new BuildException(e); } - c.vmVersion = vmVersion; - c.executeJar = executeJar; - return c; } /** diff --git a/src/main/org/apache/tools/ant/types/DirSet.java b/src/main/org/apache/tools/ant/types/DirSet.java index 61b4b7ed6..d3d8e5834 100644 --- a/src/main/org/apache/tools/ant/types/DirSet.java +++ b/src/main/org/apache/tools/ant/types/DirSet.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2002 The Apache Software Foundation. All rights + * Copyright (c) 2002-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -76,9 +76,9 @@ public class DirSet extends AbstractFileSet { */ public Object clone() { if (isReference()) { - return new DirSet((DirSet) getRef(getProject())); + return ((DirSet) getRef(getProject())).clone(); } else { - return new DirSet(this); + return super.clone(); } } diff --git a/src/main/org/apache/tools/ant/types/FileSet.java b/src/main/org/apache/tools/ant/types/FileSet.java index 64140f2f9..99b7b1b00 100644 --- a/src/main/org/apache/tools/ant/types/FileSet.java +++ b/src/main/org/apache/tools/ant/types/FileSet.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -81,9 +81,9 @@ public class FileSet extends AbstractFileSet { */ public Object clone() { if (isReference()) { - return new FileSet((FileSet) getRef(getProject())); + return ((FileSet) getRef(getProject())).clone(); } else { - return new FileSet(this); + return super.clone(); } } diff --git a/src/main/org/apache/tools/ant/types/FilterSet.java b/src/main/org/apache/tools/ant/types/FilterSet.java index 181e647c7..64cefa549 100644 --- a/src/main/org/apache/tools/ant/types/FilterSet.java +++ b/src/main/org/apache/tools/ant/types/FilterSet.java @@ -487,9 +487,16 @@ public class FilterSet extends DataType implements Cloneable { public Object clone() throws BuildException { if (isReference()) { - return new FilterSet(getRef()); + return ((FilterSet) getRef()).clone(); } else { - return new FilterSet(this); + try { + FilterSet fs = (FilterSet) super.clone(); + fs.filters = (Vector) getFilters().clone(); + fs.setProject(getProject()); + return fs; + } catch (CloneNotSupportedException e) { + throw new BuildException(e); + } } } diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index 68953aa46..6b7e6dccd 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -457,9 +457,13 @@ public class Path extends DataType implements Cloneable { * Return a Path that holds the same elements as this instance. */ public Object clone() { - Path p = new Path(getProject()); - p.append(this); - return p; + try { + Path p = (Path) super.clone(); + p.elements = (Vector) elements.clone(); + return p; + } catch (CloneNotSupportedException e) { + throw new BuildException(e); + } } /** diff --git a/src/main/org/apache/tools/ant/types/ZipFileSet.java b/src/main/org/apache/tools/ant/types/ZipFileSet.java index ca96cd9a5..f89abcf26 100644 --- a/src/main/org/apache/tools/ant/types/ZipFileSet.java +++ b/src/main/org/apache/tools/ant/types/ZipFileSet.java @@ -310,9 +310,9 @@ public class ZipFileSet extends FileSet { */ public Object clone() { if (isReference()) { - return new ZipFileSet((ZipFileSet) getRef(getProject())); + return ((ZipFileSet) getRef(getProject())).clone(); } else { - return new ZipFileSet(this); + return super.clone(); } } }