Browse Source

fix the completely broken clone() implementations.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274622 13f79535-47bb-0310-9956-ffa450edef68
remotes/1764451979815917619/tmp_3d8e3a89d4098dca994cd5590e78794be11894e8
Stefan Bodewig 22 years ago
parent
commit
3e61552036
8 changed files with 58 additions and 30 deletions
  1. +13
    -0
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  2. +7
    -4
      src/main/org/apache/tools/ant/types/Commandline.java
  3. +14
    -13
      src/main/org/apache/tools/ant/types/CommandlineJava.java
  4. +3
    -3
      src/main/org/apache/tools/ant/types/DirSet.java
  5. +3
    -3
      src/main/org/apache/tools/ant/types/FileSet.java
  6. +9
    -2
      src/main/org/apache/tools/ant/types/FilterSet.java
  7. +7
    -3
      src/main/org/apache/tools/ant/types/Path.java
  8. +2
    -2
      src/main/org/apache/tools/ant/types/ZipFileSet.java

+ 13
- 0
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -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);
}
}

}

+ 7
- 4
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -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);
}
}

/**


+ 14
- 13
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -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;
}

/**


+ 3
- 3
src/main/org/apache/tools/ant/types/DirSet.java View File

@@ -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();
}
}



+ 3
- 3
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -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();
}
}



+ 9
- 2
src/main/org/apache/tools/ant/types/FilterSet.java View File

@@ -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);
}
}
}



+ 7
- 3
src/main/org/apache/tools/ant/types/Path.java View File

@@ -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);
}
}

/**


+ 2
- 2
src/main/org/apache/tools/ant/types/ZipFileSet.java View File

@@ -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();
}
}
}

Loading…
Cancel
Save