diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index 5f446093d..3d5cf1966 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -102,7 +102,6 @@ public class Project { private Hashtable taskClassDefinitions = new Hashtable(); private Hashtable targets = new Hashtable(); private Hashtable filters = new Hashtable(); - private boolean filtering = false; private File baseDir; public Project(PrintStream out, int msgOutputLevel) { @@ -223,7 +222,6 @@ public class Project { log("Setting token to filter: " + token + " -> " + value, MSG_VERBOSE); this.filters.put(token, value); - this.filtering = true; } public Hashtable getFilters() { @@ -504,16 +502,36 @@ public class Project { return(bs.toString()); } + /** + * Convienence method to copy a file from a source to a destination. + * No filtering is performed. + * + * @throws IOException + */ + public void copyFile(String sourceFile, String destFile) throws IOException { + copyFile(new File(sourceFile), new File(destFile), false); + } + /** * Convienence method to copy a file from a source to a destination - * using token filtering. + * specifying if token filtering must be used. * * @throws IOException */ - public void copyFile(String sourceFile, String destFile) + public void copyFile(String sourceFile, String destFile, boolean filtering) throws IOException { - copyFile(new File(sourceFile), new File(destFile)); + copyFile(new File(sourceFile), new File(destFile), filtering); + } + + /** + * Convienence method to copy a file from a source to a destination. + * No filtering is performed. + * + * @throws IOException + */ + public void copyFile(File sourceFile, File destFile) throws IOException { + copyFile(sourceFile, destFile, false); } /** @@ -522,7 +540,7 @@ public class Project { * * @throws IOException */ - public void copyFile(File sourceFile, File destFile) + public void copyFile(File sourceFile, File destFile, boolean filtering) throws IOException { diff --git a/src/main/org/apache/tools/ant/taskdefs/Copydir.java b/src/main/org/apache/tools/ant/taskdefs/Copydir.java index f5fdf8834..afac0b8a3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copydir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copydir.java @@ -69,6 +69,7 @@ public class Copydir extends MatchingTask { private File srcDir; private File destDir; + private boolean filtering = false; private Hashtable filecopyList = new Hashtable(); public void setSrc(String src) { @@ -79,15 +80,19 @@ public class Copydir extends MatchingTask { destDir = project.resolveFile(dest); } + public void setFiltering(String filter) { + filtering = Project.toBoolean(filter); + } + public void execute() throws BuildException { if (srcDir == null) { throw new BuildException("srcdir attribute must be set!"); } - + if (!srcDir.exists()) { throw new BuildException("srcdir does not exist!"); } - + DirectoryScanner ds = super.getDirectoryScanner(srcDir); String[] files = ds.getIncludedFiles(); @@ -100,7 +105,7 @@ public class Copydir extends MatchingTask { String fromFile = (String) enum.nextElement(); String toFile = (String) filecopyList.get(fromFile); try { - project.copyFile(fromFile, toFile); + project.copyFile(fromFile, toFile, filtering); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + ioe.getMessage(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java index bfa93070b..0a8efc783 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copyfile.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copyfile.java @@ -67,8 +67,9 @@ import java.util.*; public class Copyfile extends Task { - public File srcFile; - public File destFile; + private File srcFile; + private File destFile; + private boolean filtering = false; public void setSrc(String src) { srcFile = project.resolveFile(src); @@ -78,10 +79,14 @@ public class Copyfile extends Task { destFile = project.resolveFile(dest); } + public void setFiltering(String filter) { + filtering = Project.toBoolean(filter); + } + public void execute() throws BuildException { if (srcFile.lastModified() > destFile.lastModified()) { try { - project.copyFile(srcFile, destFile); + project.copyFile(srcFile, destFile, filtering); } catch (IOException ioe) { String msg = "Error copying file: " + srcFile.getAbsolutePath() + " due to " + ioe.getMessage(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 9e5038e30..2226d8492 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -92,6 +92,7 @@ public class Javac extends MatchingTask { private boolean debug = false; private boolean optimize = false; private boolean deprecation = false; + private boolean filtering = false; private String target; private String bootclasspath; private String extdirs; @@ -166,6 +167,13 @@ public class Javac extends MatchingTask { this.target = target; } + /** + * Set the filtering flag. + */ + public void setFiltering(String filter) { + filtering = Project.toBoolean(filter); + } + /** * Executes the task. */ @@ -225,10 +233,10 @@ public class Javac extends MatchingTask { " support files to " + destDir.getAbsolutePath()); Enumeration enum = filecopyList.keys(); while (enum.hasMoreElements()) { - String fromFile = (String)enum.nextElement(); - String toFile = (String)filecopyList.get(fromFile); + String fromFile = (String) enum.nextElement(); + String toFile = (String) filecopyList.get(fromFile); try { - project.copyFile(fromFile, toFile); + project.copyFile(fromFile, toFile, filtering); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + ioe.getMessage(); diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index a9558dcdb..6215d1956 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -9,7 +9,7 @@ * are met: * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in @@ -17,15 +17,15 @@ * distribution. * * 3. The end-user documentation included with the redistribution, if - * any, must include the following acknowlegement: - * "This product includes software developed by the + * any, must include the following acknowlegement: + * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived - * from this software without prior written permission. For written + * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" @@ -50,7 +50,7 @@ * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . - */ + */ package org.apache.tools.ant.taskdefs; @@ -82,21 +82,26 @@ public class Rmic extends Task { private String sourceBase; private String stubVersion; private String compileClasspath; + private boolean filtering = false; public void setBase(String base) { - this.base = base; + this.base = base; } public void setClass(String classname) { - this.classname = classname; + this.classname = classname; } public void setSourceBase(String sourceBase) { - this.sourceBase = sourceBase; + this.sourceBase = sourceBase; } public void setStubVersion(String stubVersion) { - this.stubVersion = stubVersion; + this.stubVersion = stubVersion; + } + + public void setFiltering(String filter) { + filtering = Project.toBoolean(filter); } /** @@ -107,16 +112,16 @@ public class Rmic extends Task { } public void execute() throws BuildException { - File baseFile = project.resolveFile(base); + File baseFile = project.resolveFile(base); File sourceBaseFile = null; if (null != sourceBase) sourceBaseFile = project.resolveFile(sourceBase); String classpath = getCompileClasspath(baseFile); - // XXX - // need to provide an input stream that we read in from! + // XXX + // need to provide an input stream that we read in from! - sun.rmi.rmic.Main compiler = new sun.rmi.rmic.Main(System.out, "rmic"); - int argCount = 5; + sun.rmi.rmic.Main compiler = new sun.rmi.rmic.Main(System.out, "rmic"); + int argCount = 5; int i = 0; if (null != stubVersion) argCount++; if (null != sourceBase) argCount++; @@ -140,14 +145,14 @@ public class Rmic extends Task { // Move the generated source file to the base directory if (null != sourceBase) { - String stubFileName = classname.replace('.', '/') + "_Stub.java"; + String stubFileName = classname.replace('.', '/') + "_Stub.java"; File oldStubFile = new File(baseFile, stubFileName); File newStubFile = new File(sourceBaseFile, stubFileName); try { - project.copyFile(oldStubFile, newStubFile); + project.copyFile(oldStubFile, newStubFile, filtering); oldStubFile.delete(); } catch (IOException ioe) { - String msg = "Failed to copy " + oldStubFile + " to " + + String msg = "Failed to copy " + oldStubFile + " to " + newStubFile + " due to " + ioe.getMessage(); throw new BuildException(msg); } @@ -156,10 +161,10 @@ public class Rmic extends Task { File oldSkelFile = new File(baseFile, skelFileName); File newSkelFile = new File(sourceBaseFile, skelFileName); try { - project.copyFile(oldSkelFile, newSkelFile); - oldSkelFile.delete(); + project.copyFile(oldSkelFile, newSkelFile, filtering); + oldSkelFile.delete(); } catch (IOException ioe) { - String msg = "Failed to copy " + oldSkelFile + " to " + + String msg = "Failed to copy " + oldSkelFile + " to " + newSkelFile + " due to " + ioe.getMessage(); throw new BuildException(msg); } @@ -175,19 +180,19 @@ public class Rmic extends Task { // we need a way to not use the current classpath. private String getCompileClasspath(File baseFile) { - StringBuffer classpath = new StringBuffer(); + StringBuffer classpath = new StringBuffer(); - // add dest dir to classpath so that previously compiled and - // untouched classes are on classpath - classpath.append(baseFile.getAbsolutePath()); + // add dest dir to classpath so that previously compiled and + // untouched classes are on classpath + classpath.append(baseFile.getAbsolutePath()); - // add our classpath to the mix + // add our classpath to the mix - if (compileClasspath != null) { + if (compileClasspath != null) { addExistingToClasspath(classpath,compileClasspath); - } + } - // add the system classpath + // add the system classpath addExistingToClasspath(classpath,System.getProperty("java.class.path")); // in jdk 1.2, the system classes are not on the visible classpath. @@ -195,10 +200,10 @@ public class Rmic extends Task { if (Project.getJavaVersion().startsWith("1.2")) { String bootcp = System.getProperty("sun.boot.class.path"); if (bootcp != null) { - addExistingToClasspath(classpath, bootcp); + addExistingToClasspath(classpath, bootcp); } } - return classpath.toString(); + return classpath.toString(); } /**