bodewig 2005/02/04 00:08:59 Modified: . build.xml src/etc/testcases/taskdefs sync.xml src/main/org/apache/tools/ant/taskdefs Sync.java src/main/org/apache/tools/ant/types AbstractFileSet.java CommandlineJava.java src/main/org/apache/tools/ant/types/selectors NotSelector.java src/main/org/apache/tools/ant/util LeadPipeInputStream.java src/testcases/org/apache/tools/ant ProjectTest.java src/testcases/org/apache/tools/ant/taskdefs SyncTest.java Log: Turn <deleteFromTarget> into <preserveInTarget> in <sync> Revision Changes Path 1.453 +1 -10 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.452 retrieving revision 1.453 diff -u -r1.452 -r1.453 --- build.xml 1 Feb 2005 07:50:21 -0000 1.452 +++ build.xml 4 Feb 2005 08:08:58 -0000 1.453 @@ -158,14 +158,6 @@ </or> </selector> - <!-- classes that should be present in Sun based JVMs, but not in - Kaffe for example --> - <selector id="needs.sun.tools"> - <or> - <filename name="${optional.package}/Javah*"/> - </or> - </selector> - <selector id="needs.sun.uue"> <filename name="${ant.package}/taskdefs/email/UUMailer*"/> </selector> @@ -647,7 +639,6 @@ <selector refid="needs.jdk1.3+" unless="jdk1.3+"/> <selector refid="needs.jdk1.4+" unless="jdk1.4+"/> <selector refid="needs.jdk1.5+" unless="jdk1.5+"/> - <selector refid="needs.sun.tools" unless="sun.tools.present"/> <selector refid="needs.sun.uue" unless="sunuue.present"/> <selector refid="needs.sun.b64" unless="base64.present"/> @@ -1670,4 +1661,4 @@ description="--> creates a minimum distribution in ./dist" depends="dist-lite"/> -</project> +</project> \ No newline at end of file 1.3 +27 -3 ant/src/etc/testcases/taskdefs/sync.xml Index: sync.xml =================================================================== RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/sync.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- sync.xml 20 Jan 2005 13:50:56 -0000 1.2 +++ sync.xml 4 Feb 2005 08:08:59 -0000 1.3 @@ -35,6 +35,17 @@ </sync> </target> + <target name="copyandremove-emptypreserve" depends="setup"> + <mkdir dir="${src}/a/b/c"/> + <touch file="${src}/a/b/c/d"/> + <mkdir dir="${dest}/e"/> + <touch file="${dest}/e/f"/> + <sync todir="${dest}"> + <fileset dir="${src}"/> + <preserveintarget/> + </sync> + </target> + <target name="emptycopy" depends="setup"> <mkdir dir="${src}/a/b/c"/> <touch file="${src}/a/b/c/d"/> @@ -69,9 +80,22 @@ <touch file="${dest}/e/f"/> <sync todir="${dest}"> <fileset dir="${src}"/> - <deletefromtarget> - <exclude name="e/f"/> - </deletefromtarget> + <preserveintarget> + <include name="e/f"/> + </preserveintarget> + </sync> + </target> + + <target name="copynoremove-selectors" depends="setup"> + <mkdir dir="${src}/a/b/c"/> + <touch file="${src}/a/b/c/d"/> + <mkdir dir="${dest}/e"/> + <touch file="${dest}/e/f"/> + <sync todir="${dest}"> + <fileset dir="${src}"/> + <preserveintarget> + <filename name="e/f"/> + </preserveintarget> </sync> </target> 1.21 +37 -14 ant/src/main/org/apache/tools/ant/taskdefs/Sync.java Index: Sync.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Sync.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- Sync.java 20 Jan 2005 14:30:07 -0000 1.20 +++ Sync.java 4 Feb 2005 08:08:59 -0000 1.21 @@ -34,6 +34,9 @@ import org.apache.tools.ant.Task; import org.apache.tools.ant.types.AbstractFileSet; import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.PatternSet; +import org.apache.tools.ant.types.selectors.FileSelector; +import org.apache.tools.ant.types.selectors.NoneSelector; /** * Synchronize a local target directory from the files defined @@ -163,8 +166,33 @@ DirectoryScanner ds = null; if (syncTarget != null) { - syncTarget.setTargetDir(toDir); - ds = syncTarget.getDirectoryScanner(getProject()); + FileSet fs = new FileSet(); + fs.setDir(toDir); + fs.setCaseSensitive(syncTarget.isCaseSensitive()); + fs.setFollowSymlinks(syncTarget.isFollowSymlinks()); + + // preserveInTarget would find all files we want to keep, + // but we need to find all that we want to delete - so the + // meaning of all patterns and selectors must be inverted + PatternSet ps = syncTarget.mergePatterns(getProject()); + String[] excludes = ps.getExcludePatterns(getProject()); + fs.appendExcludes(ps.getIncludePatterns(getProject())); + fs.appendIncludes(ps.getExcludePatterns(getProject())); + fs.setDefaultexcludes(!syncTarget.getDefaultexcludes()); + + // selectors are implicitly ANDed in DirectoryScanner. To + // revert their logic we wrap them into a <none> selector + // instead. + FileSelector[] s = syncTarget.getSelectors(getProject()); + if (s.length > 0) { + NoneSelector ns = new NoneSelector(); + for (int i = 0; i < s.length; i++) { + ns.appendSelector(s[i]); + } + fs.appendSelector(ns); + } + + ds = fs.getDirectoryScanner(getProject()); } else { ds = new DirectoryScanner(); ds.setBasedir(toDir); @@ -180,7 +208,7 @@ ++removedCount[1]; } String[] dirs = ds.getIncludedDirectories(); - // ds returns the directories as it has visited them. + // ds returns the directories in lexicographic order. // iterating through the array backwards means we are deleting // leaves before their parent nodes - thus making sure (well, // more likely) that the directories are empty when we try to @@ -306,13 +334,13 @@ * are not present in any source directory. * * <p>You must not invoke this method more than once.</p> - * @param s a deletefromtarget nested element + * @param s a preserveintarget nested element * @since Ant 1.7 */ - public void addDeleteFromTarget(SyncTarget s) { + public void addPreserveInTarget(SyncTarget s) { if (syncTarget != null) { throw new BuildException("you must not specify multiple " - + "deletefromtaget elements."); + + "preserveintarget elements."); } syncTarget = s; } @@ -381,24 +409,19 @@ */ public SyncTarget() { super(); - setDefaultexcludes(false); } /** * Override AbstractFileSet#setDir(File) to disallow - * setting the directory. This is now set by #setTargetDir(File). + * setting the directory. * @param dir ignored * @throws BuildException always */ public void setDir(File dir) throws BuildException { - throw new BuildException("synctarget doesn't support the dir " + throw new BuildException("preserveintarget doesn't support the dir " + "attribute"); } - private void setTargetDir(File dir) throws BuildException { - super.setDir(dir); - } - } /** 1.37 +108 -14 ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java Index: AbstractFileSet.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/AbstractFileSet.java,v retrieving revision 1.36 retrieving revision 1.37 diff -u -r1.36 -r1.37 --- AbstractFileSet.java 10 Dec 2004 21:49:32 -0000 1.36 +++ AbstractFileSet.java 4 Feb 2005 08:08:59 -0000 1.37 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 The Apache Software Foundation + * Copyright 2002-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -63,7 +63,7 @@ private File dir; private boolean useDefaultExcludes = true; - private boolean isCaseSensitive = true; + private boolean caseSensitive = true; private boolean followSymlinks = true; /** @@ -84,7 +84,7 @@ this.additionalPatterns = fileset.additionalPatterns; this.selectors = fileset.selectors; this.useDefaultExcludes = fileset.useDefaultExcludes; - this.isCaseSensitive = fileset.isCaseSensitive; + this.caseSensitive = fileset.caseSensitive; this.followSymlinks = fileset.followSymlinks; setProject(fileset.getProject()); } @@ -216,6 +216,24 @@ } /** + * Appends <code>includes</code> to the current list of include + * patterns. + * + * @param includes array containing the include patterns. + * @since Ant 1.7 + */ + public void appendIncludes(String[] includes) { + if (isReference()) { + throw tooManyAttributes(); + } + if (includes != null) { + for (int i = 0; i < includes.length; i++) { + defaultPatterns.createInclude().setName(includes[i]); + } + } + } + + /** * Appends <code>excludes</code> to the current list of exclude * patterns. * @@ -231,6 +249,24 @@ } /** + * Appends <code>excludes</code> to the current list of include + * patterns. + * + * @param excludes array containing the exclude patterns. + * @since Ant 1.7 + */ + public void appendExcludes(String[] excludes) { + if (isReference()) { + throw tooManyAttributes(); + } + if (excludes != null) { + for (int i = 0; i < excludes.length; i++) { + defaultPatterns.createExclude().setName(excludes[i]); + } + } + } + + /** * Sets the <code>File</code> containing the includes patterns. * * @param incl <code>File</code> instance. @@ -267,15 +303,37 @@ } /** + * Whether default exclusions should be used or not. + * @since Ant 1.7 + */ + public boolean getDefaultexcludes() { + return (isReference()) + ? getRef(getProject()).getDefaultexcludes() : useDefaultExcludes; + } + + /** * Sets case sensitivity of the file system. * * @param isCaseSensitive <code>boolean</code>. */ - public void setCaseSensitive(boolean isCaseSensitive) { + public void setCaseSensitive(boolean caseSensitive) { if (isReference()) { throw tooManyAttributes(); } - this.isCaseSensitive = isCaseSensitive; + this.caseSensitive = caseSensitive; + } + + /** + * Find out if the fileset is case sensitive. + * + * @return <code>boolean</code> indicating whether the fileset is + * case sensitive. + * + * @since Ant 1.7 + */ + public boolean isCaseSensitive() { + return (isReference()) + ? getRef(getProject()).isCaseSensitive() : caseSensitive; } /** @@ -365,16 +423,12 @@ } ds.setBasedir(dir); - final int count = additionalPatterns.size(); - for (int i = 0; i < count; i++) { - Object o = additionalPatterns.elementAt(i); - defaultPatterns.append((PatternSet) o, p); - } + PatternSet ps = mergePatterns(p); p.log(getDataTypeName() + ": Setup scanner in dir " + dir - + " with " + defaultPatterns, Project.MSG_DEBUG); + + " with " + ps, Project.MSG_DEBUG); - ds.setIncludes(defaultPatterns.getIncludePatterns(p)); - ds.setExcludes(defaultPatterns.getExcludePatterns(p)); + ds.setIncludes(ps.getIncludePatterns(p)); + ds.setExcludes(ps.getExcludePatterns(p)); if (ds instanceof SelectorScanner) { SelectorScanner ss = (SelectorScanner) ds; ss.setSelectors(getSelectors(p)); @@ -382,7 +436,7 @@ if (useDefaultExcludes) { ds.addDefaultExcludes(); } - ds.setCaseSensitive(isCaseSensitive); + ds.setCaseSensitive(caseSensitive); } /** @@ -683,4 +737,44 @@ } } + /** + * @return the include patterns of the default pattern set and all + * nested patternsets. + * + * @since Ant 1.7 + */ + public String[] mergeIncludes(Project p) { + return mergePatterns(p).getIncludePatterns(p); + } + + /** + * @return the exclude patterns of the default pattern set and all + * nested patternsets. + * + * @since Ant 1.7 + */ + public String[] mergeExcludes(Project p) { + return mergePatterns(p).getExcludePatterns(p); + } + + /** + * @return the default patternset merged with the additional sets + * in a new PatternSet instance. + * + * @since Ant 1.7 + */ + public PatternSet mergePatterns(Project p) { + if (isReference()) { + return getRef(p).mergePatterns(p); + } + PatternSet ps = new PatternSet(); + ps.append(defaultPatterns, p); + final int count = additionalPatterns.size(); + for (int i = 0; i < count; i++) { + Object o = additionalPatterns.elementAt(i); + ps.append((PatternSet) o, p); + } + return ps; + } + } 1.67 +1 -1 ant/src/main/org/apache/tools/ant/types/CommandlineJava.java Index: CommandlineJava.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/CommandlineJava.java,v retrieving revision 1.66 retrieving revision 1.67 diff -u -r1.66 -r1.67 --- CommandlineJava.java 2 Feb 2005 12:52:49 -0000 1.66 +++ CommandlineJava.java 4 Feb 2005 08:08:59 -0000 1.67 @@ -74,7 +74,7 @@ * Specialized Environment class for System properties */ public static class SysProperties extends Environment implements Cloneable { - private Properties sys = null; + Properties sys = null; private Vector propertySets = new Vector(); /** 1.10 +11 -1 ant/src/main/org/apache/tools/ant/types/selectors/NotSelector.java Index: NotSelector.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/types/selectors/NotSelector.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- NotSelector.java 9 Mar 2004 16:48:47 -0000 1.9 +++ NotSelector.java 4 Feb 2005 08:08:59 -0000 1.10 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2004 The Apache Software Foundation + * Copyright 2002-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,16 @@ } /** + * Constructor that inverts the meaning of its argument. + * @param other the selector to invert + * @since Ant 1.7 + */ + public NotSelector(FileSelector other) { + this(); + appendSelector(other); + } + + /** * @return a string representation of the selector */ public String toString() { 1.4 +45 -0 ant/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java Index: LeadPipeInputStream.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/LeadPipeInputStream.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LeadPipeInputStream.java 2 Feb 2005 12:52:50 -0000 1.3 +++ LeadPipeInputStream.java 4 Feb 2005 08:08:59 -0000 1.4 @@ -28,6 +28,7 @@ /** * Special <CODE>PipedInputStream</CODE> that will not die * when the writing <CODE>Thread</CODE> is no longer alive. + * @since Ant 1.6.2 */ public class LeadPipeInputStream extends PipedInputStream { private ProjectComponent managingPc; @@ -40,6 +41,16 @@ } /** + * Construct a new <CODE>LeadPipeInputStream</CODE> + * with the specified buffer size. + * @param size the size of the circular buffer. + */ + public LeadPipeInputStream(int size) { + super(); + setBufferSize(size); + } + + /** * Construct a new <CODE>LeadPipeInputStream</CODE> to pull * from the specified <CODE>PipedOutputStream</CODE>. * @param src the <CODE>PipedOutputStream</CODE> source. @@ -49,6 +60,18 @@ super(src); } + /** + * Construct a new <CODE>LeadPipeInputStream</CODE> to pull + * from the specified <CODE>PipedOutputStream</CODE>, using a + * circular buffer of the specified size. + * @param src the <CODE>PipedOutputStream</CODE> source. + * @param size the size of the circular buffer. + */ + public LeadPipeInputStream(PipedOutputStream src, int size) throws IOException { + super(src); + setBufferSize(size); + } + //inherit doc public synchronized int read() throws IOException { int result = -1; @@ -69,6 +92,28 @@ } /** + * Set the size of the buffer. + * @param size the new buffer size. Ignored if <= current size. + */ + public synchronized void setBufferSize(int size) { + if (size > buffer.length) { + byte[] newBuffer = new byte[size]; + if (in >= 0) { + if (in > out) { + System.arraycopy(buffer, out, newBuffer, out, in - out); + } else { + int outlen = buffer.length - out; + System.arraycopy(buffer, out, newBuffer, 0, outlen); + System.arraycopy(buffer, 0, newBuffer, outlen, in); + in+= outlen; + out = 0; + } + } + buffer = newBuffer; + } + } + + /** * Set a managing <CODE>Task</CODE> for * this <CODE>LeadPipeInputStream</CODE>. * @param task the managing <CODE>Task</CODE>. 1.28 +1 -1 ant/src/testcases/org/apache/tools/ant/ProjectTest.java Index: ProjectTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/ProjectTest.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- ProjectTest.java 7 Jan 2005 15:04:09 -0000 1.27 +++ ProjectTest.java 4 Feb 2005 08:08:59 -0000 1.28 @@ -34,7 +34,7 @@ /** * Very limited test class for Project. Waiting to be extended. * -*/ + */ public class ProjectTest extends TestCase { private Project p; 1.4 +20 -0 ant/src/testcases/org/apache/tools/ant/taskdefs/SyncTest.java Index: SyncTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/SyncTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SyncTest.java 20 Jan 2005 13:50:57 -0000 1.3 +++ SyncTest.java 4 Feb 2005 08:08:59 -0000 1.4 @@ -70,6 +70,17 @@ assertDebuglogContaining("Removed 1 dangling directory from"); } + public void testCopyAndRemoveEmptyPreserve() { + executeTarget("copyandremove-emptypreserve"); + String d = getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(getFullLog().indexOf("Removing orphan file:") > -1); + assertDebuglogContaining("Removed 1 dangling file from"); + assertDebuglogContaining("Removed 1 dangling directory from"); + } + public void testEmptyDirCopyAndRemove() { executeTarget("emptydircopyandremove"); String d = getProject().getProperty("dest") + "/a/b/c/d"; @@ -92,6 +103,15 @@ assertTrue(getFullLog().indexOf("Removing orphan file:") == -1); } + public void testCopyNoRemoveSelectors() { + executeTarget("copynoremove-selectors"); + String d = getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = getProject().getProperty("dest") + "/e/f"; + assertFileIsPresent(f); + assertTrue(getFullLog().indexOf("Removing orphan file:") == -1); + } + public void assertFileIsPresent(String f) { assertTrue("Expected file " + f, getProject().resolveFile(f).exists());
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]