git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267596 13f79535-47bb-0310-9956-ffa450edef68master
@@ -131,7 +131,7 @@ import java.util.*; | |||||
* This will scan a directory called test for .class files, but excludes all | * This will scan a directory called test for .class files, but excludes all | ||||
* .class files in all directories under a directory called "modules" | * .class files in all directories under a directory called "modules" | ||||
* | * | ||||
* @author Arnout J. Kuiper <A HREF="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</A> | |||||
* @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a> | |||||
*/ | */ | ||||
public class DirectoryScanner { | public class DirectoryScanner { | ||||
@@ -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" | ||||
@@ -60,154 +60,53 @@ import java.io.*; | |||||
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
* Copies a directory. | |||||
* | * | ||||
* | |||||
* @author duncan@x180.com | |||||
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||||
*/ | */ | ||||
public class Copydir extends Task { | |||||
public class Copydir extends MatchingTask { | |||||
private File srcDir; | private File srcDir; | ||||
private File destDir; | private File destDir; | ||||
private String[] includes; | |||||
private String[] excludes; | |||||
private boolean useDefaultExcludes = true; | |||||
private Hashtable filecopyList = new Hashtable(); | private Hashtable filecopyList = new Hashtable(); | ||||
public void setSrc(String src) { | public void setSrc(String src) { | ||||
srcDir = project.resolveFile(src); | |||||
srcDir = project.resolveFile(src); | |||||
} | } | ||||
public void setDest(String dest) { | public void setDest(String dest) { | ||||
destDir = project.resolveFile(dest); | |||||
} | |||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
if (includes != null && includes.length() > 0) { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(includes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpIncludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.includes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
if (excludes != null && excludes.length() > 0) { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpExcludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.excludes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true" or "on" when default exclusions should | |||||
* be used, "false" or "off" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(String useDefaultExcludes) { | |||||
this.useDefaultExcludes = Project.toBoolean(useDefaultExcludes); | |||||
destDir = project.resolveFile(dest); | |||||
} | } | ||||
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 = new DirectoryScanner(); | |||||
ds.setBasedir(srcDir); | |||||
ds.setIncludes(includes); | |||||
ds.setExcludes(excludes); | |||||
if (useDefaultExcludes) { | |||||
ds.addDefaultExcludes(); | |||||
} | |||||
ds.scan(); | |||||
DirectoryScanner ds = super.getDirectoryScanner(srcDir); | |||||
String[] files = ds.getIncludedFiles(); | String[] files = ds.getIncludedFiles(); | ||||
scanDir(srcDir, destDir, files); | scanDir(srcDir, destDir, files); | ||||
if (filecopyList.size() > 0) { | |||||
project.log("Copying " + filecopyList.size() + " files to " | |||||
+ destDir.getAbsolutePath()); | |||||
Enumeration enum = filecopyList.keys(); | |||||
while (enum.hasMoreElements()) { | |||||
String fromFile = (String)enum.nextElement(); | |||||
String toFile = (String)filecopyList.get(fromFile); | |||||
try { | |||||
copyFile(fromFile, toFile); | |||||
} catch (IOException ioe) { | |||||
String msg = "Failed to copy " + fromFile + " to " + toFile | |||||
+ " due to " + ioe.getMessage(); | |||||
throw new BuildException(msg); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
List of filenames and directory names to not | |||||
include in the final .jar file. They should be either | |||||
, or " " (space) separated. | |||||
<p> | |||||
For example: | |||||
<p> | |||||
ignore="package.html, foo.class" | |||||
<p> | |||||
The ignored files will be logged. | |||||
@author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||||
*/ | |||||
public void setIgnore(String ignoreString) { | |||||
project.log("The ignore attribute is deprecated. "+ | |||||
"Please use the excludes attribute.", | |||||
Project.MSG_WARN); | |||||
if (ignoreString != null && ignoreString.length() > 0) { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(ignoreString, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
tmpExcludes.addElement("**/"+tok.nextToken().trim()+"/**"); | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
if (filecopyList.size() > 0) { | |||||
project.log("Copying " + filecopyList.size() + " files to " | |||||
+ destDir.getAbsolutePath()); | |||||
Enumeration enum = filecopyList.keys(); | |||||
while (enum.hasMoreElements()) { | |||||
String fromFile = (String)enum.nextElement(); | |||||
String toFile = (String)filecopyList.get(fromFile); | |||||
try { | |||||
copyFile(fromFile, toFile); | |||||
} catch (IOException ioe) { | |||||
String msg = "Failed to copy " + fromFile + " to " + toFile | |||||
+ " due to " + ioe.getMessage(); | |||||
throw new BuildException(msg); | |||||
} | |||||
} | } | ||||
} else { | |||||
this.excludes = null; | |||||
} | } | ||||
} | } | ||||
@@ -218,7 +117,7 @@ public class Copydir extends Task { | |||||
File destFile = new File(to, filename); | File destFile = new File(to, filename); | ||||
if (srcFile.lastModified() > destFile.lastModified()) { | if (srcFile.lastModified() > destFile.lastModified()) { | ||||
filecopyList.put(srcFile.getAbsolutePath(), | filecopyList.put(srcFile.getAbsolutePath(), | ||||
destFile.getAbsolutePath()); | |||||
destFile.getAbsolutePath()); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -57,23 +57,20 @@ package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
import java.io.*; | import java.io.*; | ||||
import java.util.Enumeration; | |||||
import java.util.StringTokenizer; | |||||
import java.util.Vector; | |||||
import java.util.zip.*; | import java.util.zip.*; | ||||
/** | /** | ||||
* Allows one to create a .gz file from another file such as a tar file. | |||||
* Compresses a file with the GZIP algorightm. Normally used to compress | |||||
* non-compressed archives such as TAR files. | |||||
* | * | ||||
* @author duncan@x180.com | |||||
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||||
* @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> | ||||
*/ | */ | ||||
public class GZip extends Task { | public class GZip extends Task { | ||||
private File zipFile; | private File zipFile; | ||||
private File source; | private File source; | ||||
private Vector items = new Vector(); | |||||
private Vector ignoreList = new Vector(); | |||||
public void setZipfile(String zipFilename) { | public void setZipfile(String zipFilename) { | ||||
zipFile = project.resolveFile(zipFilename); | zipFile = project.resolveFile(zipFilename); | ||||
@@ -60,9 +60,9 @@ import java.io.*; | |||||
import java.util.zip.*; | import java.util.zip.*; | ||||
/** | /** | ||||
* | |||||
* | |||||
* @author duncan@x180.com | |||||
* Creates a JAR archive. | |||||
* | |||||
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||||
*/ | */ | ||||
public class Jar extends Zip { | public class Jar extends Zip { | ||||
@@ -69,6 +69,7 @@ public class Java extends Exec { | |||||
private String classname = null; | private String classname = null; | ||||
private String args = null; | private String args = null; | ||||
private String jvmargs = null; | private String jvmargs = null; | ||||
private String classpath = null; | |||||
private boolean fork = false; | private boolean fork = false; | ||||
/** | /** | ||||
@@ -85,6 +86,11 @@ public class Java extends Exec { | |||||
if (fork) { | if (fork) { | ||||
StringBuffer b = new StringBuffer(); | StringBuffer b = new StringBuffer(); | ||||
b.append("java "); | b.append("java "); | ||||
if (classpath != null) { | |||||
b.append("-cp "); | |||||
b.append(classpath); | |||||
b.append(" "); | |||||
} | |||||
if (jvmargs != null) { | if (jvmargs != null) { | ||||
b.append(jvmargs); | b.append(jvmargs); | ||||
b.append(" "); | b.append(" "); | ||||
@@ -98,11 +104,18 @@ public class Java extends Exec { | |||||
run(b.toString()); | run(b.toString()); | ||||
} else { | } else { | ||||
Vector argList = tokenize(args); | Vector argList = tokenize(args); | ||||
if (jvmargs != null) project.log("JVM args ignored when same JVM is used.", "java", project.MSG_VERBOSE); | |||||
if (jvmargs != null) project.log("JVM args and classpath ignored when same JVM is used.", "java", project.MSG_VERBOSE); | |||||
project.log("Java args: " + argList.toString(), "java", project.MSG_VERBOSE); | project.log("Java args: " + argList.toString(), "java", project.MSG_VERBOSE); | ||||
run(classname, argList); | run(classname, argList); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Set the classpath to be used for this compilation. | |||||
*/ | |||||
public void setClasspath(String s) { | |||||
this.classpath = Project.translatePath(s); | |||||
} | |||||
/** | /** | ||||
* Set the source file. | * Set the source file. | ||||
@@ -57,10 +57,7 @@ package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.*; | import org.apache.tools.ant.*; | ||||
import java.io.*; | import java.io.*; | ||||
import java.util.Enumeration; | |||||
import java.util.Hashtable; | |||||
import java.util.StringTokenizer; | |||||
import java.util.Vector; | |||||
import java.util.*; | |||||
/** | /** | ||||
* Task to compile Java source files. This task can take the following | * Task to compile Java source files. This task can take the following | ||||
@@ -84,10 +81,10 @@ import java.util.Vector; | |||||
* sourcedir will be copied to the destdir allowing support files to be | * sourcedir will be copied to the destdir allowing support files to be | ||||
* located properly in the classpath. | * located properly in the classpath. | ||||
* | * | ||||
* @author duncan@x180.com | |||||
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | |||||
*/ | */ | ||||
public class Javac extends Task { | |||||
public class Javac extends MatchingTask { | |||||
private File srcDir; | private File srcDir; | ||||
private File destDir; | private File destDir; | ||||
@@ -98,9 +95,6 @@ public class Javac extends Task { | |||||
private String target; | private String target; | ||||
private String bootclasspath; | private String bootclasspath; | ||||
private String extdirs; | private String extdirs; | ||||
private String[] includes; | |||||
private String[] excludes; | |||||
private boolean useDefaultExcludes = true; | |||||
private Vector compileList = new Vector(); | private Vector compileList = new Vector(); | ||||
private Hashtable filecopyList = new Hashtable(); | private Hashtable filecopyList = new Hashtable(); | ||||
@@ -108,7 +102,6 @@ public class Javac extends Task { | |||||
/** | /** | ||||
* Set the source dir to find the source Java files. | * Set the source dir to find the source Java files. | ||||
*/ | */ | ||||
public void setSrcdir(String srcDirName) { | public void setSrcdir(String srcDirName) { | ||||
srcDir = project.resolveFile(srcDirName); | srcDir = project.resolveFile(srcDirName); | ||||
} | } | ||||
@@ -117,7 +110,6 @@ public class Javac extends Task { | |||||
* Set the destination directory into which the Java source | * Set the destination directory into which the Java source | ||||
* files should be compiled. | * files should be compiled. | ||||
*/ | */ | ||||
public void setDestdir(String destDirName) { | public void setDestdir(String destDirName) { | ||||
destDir = project.resolveFile(destDirName); | destDir = project.resolveFile(destDirName); | ||||
} | } | ||||
@@ -125,7 +117,6 @@ public class Javac extends Task { | |||||
/** | /** | ||||
* Set the classpath to be used for this compilation. | * Set the classpath to be used for this compilation. | ||||
*/ | */ | ||||
public void setClasspath(String classpath) { | public void setClasspath(String classpath) { | ||||
compileClasspath = Project.translatePath(classpath); | compileClasspath = Project.translatePath(classpath); | ||||
} | } | ||||
@@ -134,7 +125,6 @@ public class Javac extends Task { | |||||
* Sets the bootclasspath that will be used to compile the classes | * Sets the bootclasspath that will be used to compile the classes | ||||
* against. | * against. | ||||
*/ | */ | ||||
public void setBootclasspath(String bootclasspath) { | public void setBootclasspath(String bootclasspath) { | ||||
this.bootclasspath = Project.translatePath(bootclasspath); | this.bootclasspath = Project.translatePath(bootclasspath); | ||||
} | } | ||||
@@ -143,113 +133,39 @@ public class Javac extends Task { | |||||
* Sets the extension directories that will be used during the | * Sets the extension directories that will be used during the | ||||
* compilation. | * compilation. | ||||
*/ | */ | ||||
public void setExtdirs(String extdirs) { | public void setExtdirs(String extdirs) { | ||||
this.extdirs = Project.translatePath(extdirs); | this.extdirs = Project.translatePath(extdirs); | ||||
} | } | ||||
/** | /** | ||||
* Set the deprecation flag. Valid strings are "on", "off", "true", and | |||||
* "false". | |||||
* Set the deprecation flag. | |||||
*/ | */ | ||||
public void setDeprecation(String deprecation) { | |||||
this.deprecation = Project.toBoolean(deprecation); | |||||
public void setDeprecation(String deprecationString) { | |||||
this.deprecation = Project.toBoolean(deprecationString); | |||||
} | } | ||||
/** | /** | ||||
* Set the debug flag. Valid strings are "on", "off", "true", and "false". | |||||
* Set the debug flag. | |||||
*/ | */ | ||||
public void setDebug(String debugString) { | public void setDebug(String debugString) { | ||||
if (debugString.equalsIgnoreCase("on") || | |||||
debugString.equalsIgnoreCase("true")) { | |||||
debug = true; | |||||
} else { | |||||
debug = false; | |||||
} | |||||
this.debug = Project.toBoolean(debugString); | |||||
} | } | ||||
/** | /** | ||||
* Set the optimize flag. Valid strings are "on", "off", "true", and | |||||
* "false". | |||||
* Set the optimize flag. | |||||
*/ | */ | ||||
public void setOptimize(String optimizeString) { | public void setOptimize(String optimizeString) { | ||||
if (optimizeString.equalsIgnoreCase("on") || | |||||
optimizeString.equalsIgnoreCase("true")) { | |||||
optimize = true; | |||||
} else { | |||||
optimize = false; | |||||
} | |||||
this.optimize = Project.toBoolean(optimizeString); | |||||
} | } | ||||
/** | /** | ||||
* Sets the target VM that the classes will be compiled for. Valid | * Sets the target VM that the classes will be compiled for. Valid | ||||
* strings are "1.1", "1.2", and "1.3". | * strings are "1.1", "1.2", and "1.3". | ||||
*/ | */ | ||||
public void setTarget(String target) { | public void setTarget(String target) { | ||||
this.target = target; | this.target = target; | ||||
} | } | ||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
if (includes != null && includes.length() > 0) { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(includes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
tmpIncludes.addElement(tok.nextToken().trim()); | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.includes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
if (excludes != null && excludes.length() > 0) { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
tmpExcludes.addElement(tok.nextToken().trim()); | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.excludes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true" or "on" when default exclusions should | |||||
* be used, "false" or "off" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(String useDefaultExcludes) { | |||||
this.useDefaultExcludes = Project.toBoolean(useDefaultExcludes); | |||||
} | |||||
/** | /** | ||||
* Executes the task. | * Executes the task. | ||||
*/ | */ | ||||
@@ -269,14 +185,7 @@ public class Javac extends Task { | |||||
// scan source and dest dirs to build up both copy lists and | // scan source and dest dirs to build up both copy lists and | ||||
// compile lists | // compile lists | ||||
DirectoryScanner ds = new DirectoryScanner(); | |||||
ds.setBasedir(srcDir); | |||||
ds.setIncludes(includes); | |||||
ds.setExcludes(excludes); | |||||
if (useDefaultExcludes) { | |||||
ds.addDefaultExcludes(); | |||||
} | |||||
ds.scan(); | |||||
DirectoryScanner ds = super.getDirectoryScanner(srcDir); | |||||
String[] files = ds.getIncludedFiles(); | String[] files = ds.getIncludedFiles(); | ||||
@@ -412,7 +321,6 @@ public class Javac extends Task { | |||||
} | } | ||||
/** | /** | ||||
* Peforms a copmile using the classic compiler that shipped with | * Peforms a copmile using the classic compiler that shipped with | ||||
* JDK 1.1 and 1.2. | * JDK 1.1 and 1.2. | ||||
@@ -17,9 +17,9 @@ public class Jikes { | |||||
* @param command - name of jikes executeable | * @param command - name of jikes executeable | ||||
*/ | */ | ||||
protected Jikes(JikesOutputParser jop,String command) { | protected Jikes(JikesOutputParser jop,String command) { | ||||
super(); | |||||
this.jop = jop; | |||||
this.command = command; | |||||
super(); | |||||
this.jop = jop; | |||||
this.command = command; | |||||
} | } | ||||
/** | /** | ||||
@@ -27,21 +27,21 @@ public class Jikes { | |||||
* @param args - arguments to pass to process on command line | * @param args - arguments to pass to process on command line | ||||
*/ | */ | ||||
protected void compile(String[] args) { | protected void compile(String[] args) { | ||||
String[] commandArray = new String[args.length+1]; | |||||
commandArray[0] = command; | |||||
System.arraycopy(args,0,commandArray,1,args.length); | |||||
// We assume, that everything jikes writes goes to | |||||
// standard output, not to standard error. The option | |||||
// -Xstdout that is given to Jikes in Javac.doJikesCompile() | |||||
// should guarantee this. At least I hope so. :) | |||||
try { | |||||
Process jikes = Runtime.getRuntime().exec(commandArray); | |||||
BufferedReader reader = new BufferedReader(new InputStreamReader(jikes.getInputStream())); | |||||
jop.parseOutput(reader); | |||||
} catch (IOException e) { | |||||
// Where could we log this to? We don't have an instance | |||||
// of project. Perhaps we should add one to our constructor? | |||||
} | |||||
String[] commandArray = new String[args.length+1]; | |||||
commandArray[0] = command; | |||||
System.arraycopy(args,0,commandArray,1,args.length); | |||||
// We assume, that everything jikes writes goes to | |||||
// standard output, not to standard error. The option | |||||
// -Xstdout that is given to Jikes in Javac.doJikesCompile() | |||||
// should guarantee this. At least I hope so. :) | |||||
try { | |||||
Process jikes = Runtime.getRuntime().exec(commandArray); | |||||
BufferedReader reader = new BufferedReader(new InputStreamReader(jikes.getInputStream())); | |||||
jop.parseOutput(reader); | |||||
} catch (IOException e) { | |||||
// Where could we log this to? We don't have an instance | |||||
// of project. Perhaps we should add one to our constructor? | |||||
} | |||||
} | } | ||||
} | } |
@@ -0,0 +1,205 @@ | |||||
/* | |||||
* The Apache Software License, Version 1.1 | |||||
* | |||||
* Copyright (c) 1999 The Apache Software Foundation. All rights | |||||
* reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | |||||
* modification, are permitted provided that the following conditions | |||||
* are met: | |||||
* | |||||
* 1. Redistributions of source code must retain the above copyright | |||||
* 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 | |||||
* the documentation and/or other materials provided with the | |||||
* distribution. | |||||
* | |||||
* 3. The end-user documentation included with the redistribution, if | |||||
* 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 | |||||
* permission, please contact apache@apache.org. | |||||
* | |||||
* 5. Products derived from this software may not be called "Apache" | |||||
* nor may "Apache" appear in their names without prior written | |||||
* permission of the Apache Group. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||||
* SUCH DAMAGE. | |||||
* ==================================================================== | |||||
* | |||||
* This software consists of voluntary contributions made by many | |||||
* individuals on behalf of the Apache Software Foundation. For more | |||||
* information on the Apache Software Foundation, please see | |||||
* <http://www.apache.org/>. | |||||
*/ | |||||
package org.apache.tools.ant.taskdefs; | |||||
import org.apache.tools.ant.*; | |||||
import java.io.*; | |||||
import java.util.*; | |||||
/** | |||||
* This is an abstract task that should be used by all those tasks that | |||||
* require to include or exclude files based on pattern matching. | |||||
* | |||||
* @author Arnout J. Kuiper <a href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a> | |||||
* @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> | |||||
* @author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||||
*/ | |||||
public abstract class MatchingTask extends Task { | |||||
protected String[] includes; | |||||
protected String[] excludes; | |||||
protected boolean useDefaultExcludes = true; | |||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
if (includes != null && includes.length() > 0) { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(includes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpIncludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.includes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Set this to be the items in the base directory that you want to be | |||||
* included. You can also specify "*" for the items (ie: items="*") | |||||
* and it will include all the items in the base directory. | |||||
* | |||||
* @param itemString the string containing the files to include. | |||||
*/ | |||||
public void setItems(String itemString) { | |||||
project.log("The items attribute is deprecated. " + | |||||
"Please use the includes attribute.", | |||||
Project.MSG_WARN); | |||||
if (itemString == null || itemString.equals("*")) { | |||||
includes = new String[1]; | |||||
includes[0] = "**"; | |||||
} else { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(itemString, ", "); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpIncludes.addElement(pattern+"/**"); | |||||
} | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
if (excludes != null && excludes.length() > 0) { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpExcludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.excludes = null; | |||||
} | |||||
} | |||||
/** | |||||
* List of filenames and directory names to not include. They should be | |||||
* either , or " " (space) separated. The ignored files will be logged. | |||||
* | |||||
* @param ignoreString the string containing the files to ignore. | |||||
*/ | |||||
public void setIgnore(String ignoreString) { | |||||
project.log("The ignore attribute is deprecated." + | |||||
"Please use the excludes attribute.", | |||||
Project.MSG_WARN); | |||||
if (ignoreString != null && ignoreString.length() > 0) { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(ignoreString, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
tmpExcludes.addElement("**/"+tok.nextToken().trim()+"/**"); | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} else { | |||||
this.excludes = null; | |||||
} | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true"|"on"|"yes" when default exclusions | |||||
* should be used, "false"|"off"|"no" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(String useDefaultExcludes) { | |||||
this.useDefaultExcludes = Project.toBoolean(useDefaultExcludes); | |||||
} | |||||
/** | |||||
* Returns the directory scanner needed to access the files to process. | |||||
*/ | |||||
protected DirectoryScanner getDirectoryScanner(File baseDir) { | |||||
DirectoryScanner ds = new DirectoryScanner(); | |||||
ds.setBasedir(baseDir); | |||||
ds.setIncludes(includes); | |||||
ds.setExcludes(excludes); | |||||
if (useDefaultExcludes) ds.addDefaultExcludes(); | |||||
ds.scan(); | |||||
return ds; | |||||
} | |||||
} |
@@ -63,21 +63,16 @@ import java.util.Vector; | |||||
import java.util.zip.*; | import java.util.zip.*; | ||||
/** | /** | ||||
* Same as the Jar task, but creates .zip files without the MANIFEST | |||||
* stuff that .jar files have. | |||||
* Create a ZIP archive. | |||||
* | * | ||||
* @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a> | ||||
* @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> | ||||
*/ | */ | ||||
public class Zip extends Task { | |||||
public class Zip extends MatchingTask { | |||||
private File zipFile; | private File zipFile; | ||||
private File baseDir; | private File baseDir; | ||||
private String[] includes; | |||||
private String[] excludes; | |||||
private boolean useDefaultExcludes = true; | |||||
private File manifest; | |||||
protected String archiveType = "zip"; | protected String archiveType = "zip"; | ||||
/** | /** | ||||
@@ -95,136 +90,6 @@ public class Zip extends Task { | |||||
baseDir = project.resolveFile(baseDirname); | baseDir = project.resolveFile(baseDirname); | ||||
} | } | ||||
/** | |||||
Set this to be the items in the base directory | |||||
that you want to include in the zip archive. | |||||
(ie: items="foo, bar, ack.html, f.java"). | |||||
You can also specify "*" for the items (ie: items="*") | |||||
and it will include all the items in the base directory. | |||||
Do not try to have items="*, foo". Also note that | |||||
you can specify items to ignore with setIgnore and they | |||||
will still be ignored if you choose "*". Sometimes | |||||
ignore lists are easier than include lists. ;-) | |||||
*/ | |||||
public void setItems(String itemString) { | |||||
project.log("The items attribute is deprecated. "+ | |||||
"Please use the includes attribute.", | |||||
Project.MSG_WARN); | |||||
if (itemString == null || itemString.equals("*")) { | |||||
includes = new String[1]; | |||||
includes[0] = "**"; | |||||
} else { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(itemString, ", "); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpIncludes.addElement(pattern+"/**"); | |||||
} | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
List of filenames and directory names to not | |||||
include in the final .jar file. They should be either | |||||
, or " " (space) separated. | |||||
<p> | |||||
For example: | |||||
<p> | |||||
ignore="package.html, foo.class" | |||||
<p> | |||||
The ignored files will be logged. | |||||
@author Jon S. Stevens <a href="mailto:jon@clearink.com">jon@clearink.com</a> | |||||
*/ | |||||
public void setIgnore(String ignoreString) { | |||||
project.log("The ignore attribute is deprecated. "+ | |||||
"Please use the excludes attribute.", | |||||
Project.MSG_WARN); | |||||
if (ignoreString == null) { | |||||
this.excludes = null; | |||||
} else { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(ignoreString, ", "); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpExcludes.addElement("**/"+pattern+"/**"); | |||||
} | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Sets the set of include patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param includes the string containing the include patterns | |||||
*/ | |||||
public void setIncludes(String includes) { | |||||
if (includes == null) { | |||||
this.includes = null; | |||||
} else { | |||||
Vector tmpIncludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(includes, ", "); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpIncludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.includes = new String[tmpIncludes.size()]; | |||||
for (int i = 0; i < tmpIncludes.size(); i++) { | |||||
this.includes[i] = (String)tmpIncludes.elementAt(i); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Sets the set of exclude patterns. Patterns may be separated by a comma | |||||
* or a space. | |||||
* | |||||
* @param excludes the string containing the exclude patterns | |||||
*/ | |||||
public void setExcludes(String excludes) { | |||||
if (excludes == null) { | |||||
this.excludes = null; | |||||
} else { | |||||
Vector tmpExcludes = new Vector(); | |||||
StringTokenizer tok = new StringTokenizer(excludes, ", ", false); | |||||
while (tok.hasMoreTokens()) { | |||||
String pattern = tok.nextToken().trim(); | |||||
if (pattern.length() > 0) { | |||||
tmpExcludes.addElement(pattern); | |||||
} | |||||
} | |||||
this.excludes = new String[tmpExcludes.size()]; | |||||
for (int i = 0; i < tmpExcludes.size(); i++) { | |||||
this.excludes[i] = (String)tmpExcludes.elementAt(i); | |||||
} | |||||
} | |||||
} | |||||
/** | |||||
* Sets whether default exclusions should be used or not. | |||||
* | |||||
* @param useDefaultExcludes "true" or "on" when default exclusions should | |||||
* be used, "false" or "off" when they | |||||
* shouldn't be used. | |||||
*/ | |||||
public void setDefaultexcludes(String useDefaultExcludes) { | |||||
this.useDefaultExcludes = Project.toBoolean(useDefaultExcludes); | |||||
} | |||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
project.log("Building "+ archiveType +": "+ zipFile.getAbsolutePath()); | project.log("Building "+ archiveType +": "+ zipFile.getAbsolutePath()); | ||||
@@ -235,14 +100,7 @@ public class Zip extends Task { | |||||
throw new BuildException("basedir does not exist!"); | throw new BuildException("basedir does not exist!"); | ||||
} | } | ||||
DirectoryScanner ds = new DirectoryScanner(); | |||||
ds.setBasedir(baseDir); | |||||
ds.setIncludes(includes); | |||||
ds.setExcludes(excludes); | |||||
if (useDefaultExcludes) { | |||||
ds.addDefaultExcludes(); | |||||
} | |||||
ds.scan(); | |||||
DirectoryScanner ds = super.getDirectoryScanner(baseDir); | |||||
String[] files = ds.getIncludedFiles(); | String[] files = ds.getIncludedFiles(); | ||||
String[] dirs = ds.getIncludedDirectories(); | String[] dirs = ds.getIncludedDirectories(); | ||||