Browse Source

improved filtering granularity... now all tasks that use copyfile can turn filtering on and off on a task granularity level, useful to avoid binary corruption by filtering

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267607 13f79535-47bb-0310-9956-ffa450edef68
master
Stefano Mazzocchi 25 years ago
parent
commit
764d1e985b
5 changed files with 87 additions and 46 deletions
  1. +24
    -6
      src/main/org/apache/tools/ant/Project.java
  2. +8
    -3
      src/main/org/apache/tools/ant/taskdefs/Copydir.java
  3. +8
    -3
      src/main/org/apache/tools/ant/taskdefs/Copyfile.java
  4. +11
    -3
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  5. +36
    -31
      src/main/org/apache/tools/ant/taskdefs/Rmic.java

+ 24
- 6
src/main/org/apache/tools/ant/Project.java View File

@@ -102,7 +102,6 @@ public class Project {
private Hashtable taskClassDefinitions = new Hashtable(); private Hashtable taskClassDefinitions = new Hashtable();
private Hashtable targets = new Hashtable(); private Hashtable targets = new Hashtable();
private Hashtable filters = new Hashtable(); private Hashtable filters = new Hashtable();
private boolean filtering = false;
private File baseDir; private File baseDir;


public Project(PrintStream out, int msgOutputLevel) { public Project(PrintStream out, int msgOutputLevel) {
@@ -223,7 +222,6 @@ public class Project {
log("Setting token to filter: " + token + " -> " log("Setting token to filter: " + token + " -> "
+ value, MSG_VERBOSE); + value, MSG_VERBOSE);
this.filters.put(token, value); this.filters.put(token, value);
this.filtering = true;
} }


public Hashtable getFilters() { public Hashtable getFilters() {
@@ -504,16 +502,36 @@ public class Project {
return(bs.toString()); 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 * Convienence method to copy a file from a source to a destination
* using token filtering.
* specifying if token filtering must be used.
* *
* @throws IOException * @throws IOException
*/ */
public void copyFile(String sourceFile, String destFile)
public void copyFile(String sourceFile, String destFile, boolean filtering)
throws IOException 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 * @throws IOException
*/ */
public void copyFile(File sourceFile, File destFile)
public void copyFile(File sourceFile, File destFile, boolean filtering)
throws IOException throws IOException
{ {




+ 8
- 3
src/main/org/apache/tools/ant/taskdefs/Copydir.java View File

@@ -69,6 +69,7 @@ public class Copydir extends MatchingTask {


private File srcDir; private File srcDir;
private File destDir; private File destDir;
private boolean filtering = false;
private Hashtable filecopyList = new Hashtable(); private Hashtable filecopyList = new Hashtable();


public void setSrc(String src) { public void setSrc(String src) {
@@ -79,15 +80,19 @@ public class Copydir extends MatchingTask {
destDir = project.resolveFile(dest); destDir = project.resolveFile(dest);
} }


public void setFiltering(String filter) {
filtering = Project.toBoolean(filter);
}

public void execute() throws BuildException { public void execute() throws BuildException {
if (srcDir == null) { if (srcDir == null) {
throw new BuildException("srcdir attribute must be set!"); throw new BuildException("srcdir attribute must be set!");
} }
if (!srcDir.exists()) { if (!srcDir.exists()) {
throw new BuildException("srcdir does not exist!"); throw new BuildException("srcdir does not exist!");
} }
DirectoryScanner ds = super.getDirectoryScanner(srcDir); DirectoryScanner ds = super.getDirectoryScanner(srcDir);


String[] files = ds.getIncludedFiles(); String[] files = ds.getIncludedFiles();
@@ -100,7 +105,7 @@ public class Copydir extends MatchingTask {
String fromFile = (String) enum.nextElement(); String fromFile = (String) enum.nextElement();
String toFile = (String) filecopyList.get(fromFile); String toFile = (String) filecopyList.get(fromFile);
try { try {
project.copyFile(fromFile, toFile);
project.copyFile(fromFile, toFile, filtering);
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + ioe.getMessage(); + " due to " + ioe.getMessage();


+ 8
- 3
src/main/org/apache/tools/ant/taskdefs/Copyfile.java View File

@@ -67,8 +67,9 @@ import java.util.*;


public class Copyfile extends Task { 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) { public void setSrc(String src) {
srcFile = project.resolveFile(src); srcFile = project.resolveFile(src);
@@ -78,10 +79,14 @@ public class Copyfile extends Task {
destFile = project.resolveFile(dest); destFile = project.resolveFile(dest);
} }


public void setFiltering(String filter) {
filtering = Project.toBoolean(filter);
}

public void execute() throws BuildException { public void execute() throws BuildException {
if (srcFile.lastModified() > destFile.lastModified()) { if (srcFile.lastModified() > destFile.lastModified()) {
try { try {
project.copyFile(srcFile, destFile);
project.copyFile(srcFile, destFile, filtering);
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Error copying file: " + srcFile.getAbsolutePath() String msg = "Error copying file: " + srcFile.getAbsolutePath()
+ " due to " + ioe.getMessage(); + " due to " + ioe.getMessage();


+ 11
- 3
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -92,6 +92,7 @@ public class Javac extends MatchingTask {
private boolean debug = false; private boolean debug = false;
private boolean optimize = false; private boolean optimize = false;
private boolean deprecation = false; private boolean deprecation = false;
private boolean filtering = false;
private String target; private String target;
private String bootclasspath; private String bootclasspath;
private String extdirs; private String extdirs;
@@ -166,6 +167,13 @@ public class Javac extends MatchingTask {
this.target = target; this.target = target;
} }


/**
* Set the filtering flag.
*/
public void setFiltering(String filter) {
filtering = Project.toBoolean(filter);
}

/** /**
* Executes the task. * Executes the task.
*/ */
@@ -225,10 +233,10 @@ public class Javac extends MatchingTask {
" support files to " + destDir.getAbsolutePath()); " support files to " + destDir.getAbsolutePath());
Enumeration enum = filecopyList.keys(); Enumeration enum = filecopyList.keys();
while (enum.hasMoreElements()) { 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 { try {
project.copyFile(fromFile, toFile);
project.copyFile(fromFile, toFile, filtering);
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Failed to copy " + fromFile + " to " + toFile String msg = "Failed to copy " + fromFile + " to " + toFile
+ " due to " + ioe.getMessage(); + " due to " + ioe.getMessage();


+ 36
- 31
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met: * are met:
* *
* 1. Redistributions of source code must retain the above copyright * 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 * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in * notice, this list of conditions and the following disclaimer in
@@ -17,15 +17,15 @@
* distribution. * distribution.
* *
* 3. The end-user documentation included with the redistribution, if * 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/)." * Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * if and wherever such third-party acknowlegements normally appear.
* *
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived * 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. * permission, please contact apache@apache.org.
* *
* 5. Products derived from this software may not be called "Apache" * 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 * individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/
*/


package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;


@@ -82,21 +82,26 @@ public class Rmic extends Task {
private String sourceBase; private String sourceBase;
private String stubVersion; private String stubVersion;
private String compileClasspath; private String compileClasspath;
private boolean filtering = false;


public void setBase(String base) { public void setBase(String base) {
this.base = base;
this.base = base;
} }


public void setClass(String classname) { public void setClass(String classname) {
this.classname = classname;
this.classname = classname;
} }


public void setSourceBase(String sourceBase) { public void setSourceBase(String sourceBase) {
this.sourceBase = sourceBase;
this.sourceBase = sourceBase;
} }


public void setStubVersion(String stubVersion) { 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 { public void execute() throws BuildException {
File baseFile = project.resolveFile(base);
File baseFile = project.resolveFile(base);
File sourceBaseFile = null; File sourceBaseFile = null;
if (null != sourceBase) if (null != sourceBase)
sourceBaseFile = project.resolveFile(sourceBase); sourceBaseFile = project.resolveFile(sourceBase);
String classpath = getCompileClasspath(baseFile); 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; int i = 0;
if (null != stubVersion) argCount++; if (null != stubVersion) argCount++;
if (null != sourceBase) argCount++; if (null != sourceBase) argCount++;
@@ -140,14 +145,14 @@ public class Rmic extends Task {


// Move the generated source file to the base directory // Move the generated source file to the base directory
if (null != sourceBase) { if (null != sourceBase) {
String stubFileName = classname.replace('.', '/') + "_Stub.java";
String stubFileName = classname.replace('.', '/') + "_Stub.java";
File oldStubFile = new File(baseFile, stubFileName); File oldStubFile = new File(baseFile, stubFileName);
File newStubFile = new File(sourceBaseFile, stubFileName); File newStubFile = new File(sourceBaseFile, stubFileName);
try { try {
project.copyFile(oldStubFile, newStubFile);
project.copyFile(oldStubFile, newStubFile, filtering);
oldStubFile.delete(); oldStubFile.delete();
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Failed to copy " + oldStubFile + " to " +
String msg = "Failed to copy " + oldStubFile + " to " +
newStubFile + " due to " + ioe.getMessage(); newStubFile + " due to " + ioe.getMessage();
throw new BuildException(msg); throw new BuildException(msg);
} }
@@ -156,10 +161,10 @@ public class Rmic extends Task {
File oldSkelFile = new File(baseFile, skelFileName); File oldSkelFile = new File(baseFile, skelFileName);
File newSkelFile = new File(sourceBaseFile, skelFileName); File newSkelFile = new File(sourceBaseFile, skelFileName);
try { try {
project.copyFile(oldSkelFile, newSkelFile);
oldSkelFile.delete();
project.copyFile(oldSkelFile, newSkelFile, filtering);
oldSkelFile.delete();
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Failed to copy " + oldSkelFile + " to " +
String msg = "Failed to copy " + oldSkelFile + " to " +
newSkelFile + " due to " + ioe.getMessage(); newSkelFile + " due to " + ioe.getMessage();
throw new BuildException(msg); throw new BuildException(msg);
} }
@@ -175,19 +180,19 @@ public class Rmic extends Task {
// we need a way to not use the current classpath. // we need a way to not use the current classpath.


private String getCompileClasspath(File baseFile) { 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); addExistingToClasspath(classpath,compileClasspath);
}
}


// add the system classpath
// add the system classpath


addExistingToClasspath(classpath,System.getProperty("java.class.path")); addExistingToClasspath(classpath,System.getProperty("java.class.path"));
// in jdk 1.2, the system classes are not on the visible classpath. // 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")) { if (Project.getJavaVersion().startsWith("1.2")) {
String bootcp = System.getProperty("sun.boot.class.path"); String bootcp = System.getProperty("sun.boot.class.path");
if (bootcp != null) { if (bootcp != null) {
addExistingToClasspath(classpath, bootcp);
addExistingToClasspath(classpath, bootcp);
} }
} }
return classpath.toString();
return classpath.toString();
} }


/** /**


Loading…
Cancel
Save