Browse Source

Create a deep (well, deeper) clone in AbstractFileSet#clone

PR: 23090

Make PatternSet Clonable.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275248 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
469dcdf7a4
2 changed files with 44 additions and 9 deletions
  1. +22
    -7
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  2. +22
    -2
      src/main/org/apache/tools/ant/types/PatternSet.java

+ 22
- 7
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -719,16 +719,31 @@ public abstract class AbstractFileSet extends DataType implements Cloneable,
} }


/** /**
* Creates a deep clone of this instance, except for the nested
* selectors (the list of selectors is a shallow clone of this
* instance's list).
*
* @since Ant 1.6 * @since Ant 1.6
*/ */
public Object clone() { public Object clone() {
try {
AbstractFileSet fs = (AbstractFileSet) super.clone();
fs.setProject(getProject());
return fs;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
if (isReference()) {
return (getRef(getProject())).clone();
} else {
try {
AbstractFileSet fs = (AbstractFileSet) super.clone();
fs.defaultPatterns = (PatternSet) defaultPatterns.clone();
fs.additionalPatterns = new Vector(additionalPatterns.size());
Enumeration e = additionalPatterns.elements();
while (e.hasMoreElements()) {
fs.additionalPatterns
.addElement(((PatternSet) e.nextElement()).clone());
}
fs.selectors = (Vector) fs.selectors.clone();
return fs;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
}
} }
} }


}
}

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

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -77,7 +77,7 @@ import org.apache.tools.ant.Project;
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> * @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a>
* @author Stefan Bodewig * @author Stefan Bodewig
*/ */
public class PatternSet extends DataType {
public class PatternSet extends DataType implements Cloneable {
private Vector includeList = new Vector(); private Vector includeList = new Vector();
private Vector excludeList = new Vector(); private Vector excludeList = new Vector();
private Vector includesFileList = new Vector(); private Vector includesFileList = new Vector();
@@ -477,4 +477,24 @@ public class PatternSet extends DataType {
+ " excludes: " + excludeList + " }"; + " excludes: " + excludeList + " }";
} }


/**
* @since Ant 1.6
*/
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
} else {
try {
PatternSet ps = (PatternSet) super.clone();
ps.includeList = (Vector) includeList.clone();
ps.excludeList = (Vector) excludeList.clone();
ps.includesFileList = (Vector) includesFileList.clone();
ps.excludesFileList = (Vector) excludesFileList.clone();
return ps;
} catch (CloneNotSupportedException e) {
throw new BuildException(e);
}
}
}

} }

Loading…
Cancel
Save