Browse Source

Style and remove one stray debug

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274848 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 22 years ago
parent
commit
60f4887526
6 changed files with 303 additions and 182 deletions
  1. +0
    -1
      src/main/org/apache/tools/ant/DemuxOutputStream.java
  2. +10
    -11
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  3. +75
    -25
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  4. +53
    -20
      src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
  5. +81
    -73
      src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.java
  6. +84
    -52
      src/main/org/apache/tools/ant/types/FilterSet.java

+ 0
- 1
src/main/org/apache/tools/ant/DemuxOutputStream.java View File

@@ -257,7 +257,6 @@ public class DemuxOutputStream extends OutputStream {
// either end of buffer or a line separator char // either end of buffer or a line separator char
int blockLength = offset - blockStartOffset; int blockLength = offset - blockStartOffset;
if (blockLength > 0) { if (blockLength > 0) {
project.log("Sending " + blockLength);
bufferInfo.buffer.write(b, blockStartOffset, blockLength); bufferInfo.buffer.write(b, blockStartOffset, blockLength);
} }
while(remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) { while(remaining > 0 && (b[offset] == 0x0a || b[offset] == 0x0d)) {


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

@@ -735,8 +735,8 @@ public class Javac extends MatchingTask {
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m); File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);


if (newFiles.length > 0) { if (newFiles.length > 0) {
File[] newCompileList = new File[compileList.length +
newFiles.length];
File[] newCompileList
= new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0, System.arraycopy(compileList, 0, newCompileList, 0,
compileList.length); compileList.length);
System.arraycopy(newFiles, 0, newCompileList, System.arraycopy(newFiles, 0, newCompileList,
@@ -751,12 +751,12 @@ public class Javac extends MatchingTask {
} }


protected boolean isJdkCompiler(String compilerImpl) { protected boolean isJdkCompiler(String compilerImpl) {
return "modern".equals(compilerImpl) ||
"classic".equals(compilerImpl) ||
"javac1.1".equals(compilerImpl) ||
"javac1.2".equals(compilerImpl) ||
"javac1.3".equals(compilerImpl) ||
"javac1.4".equals(compilerImpl);
return "modern".equals(compilerImpl)
|| "classic".equals(compilerImpl)
|| "javac1.1".equals(compilerImpl)
|| "javac1.2".equals(compilerImpl)
|| "javac1.3".equals(compilerImpl)
|| "javac1.4".equals(compilerImpl);
} }


protected String getSystemJavac() { protected String getSystemJavac() {
@@ -854,13 +854,12 @@ public class Javac extends MatchingTask {
String compilerImpl = getCompiler(); String compilerImpl = getCompiler();


if (compileList.length > 0) { if (compileList.length > 0) {
log("Compiling " + compileList.length +
" source file"
log("Compiling " + compileList.length + " source file"
+ (compileList.length == 1 ? "" : "s") + (compileList.length == 1 ? "" : "s")
+ (destDir != null ? " to " + destDir : "")); + (destDir != null ? " to " + destDir : ""));


if (listFiles) { if (listFiles) {
for (int i = 0 ; i < compileList.length ; i++) {
for (int i = 0; i < compileList.length; i++) {
String filename = compileList[i].getAbsolutePath(); String filename = compileList[i].getAbsolutePath();
log(filename) ; log(filename) ;
} }


+ 75
- 25
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -313,7 +313,17 @@ public class Javadoc extends Task {
/** The source file */ /** The source file */
private File file; private File file;


public SourceFile() {}
/**
* Default constructor
*/
public SourceFile() {
}

/**
* Constructor specifying the source file directly
*
* @param file the source file
*/
public SourceFile(File file) { public SourceFile(File file) {
this.file = file; this.file = file;
} }
@@ -390,9 +400,9 @@ public class Javadoc extends Task {


/** Flag which indicates if javadoc from JDK 1.4 is available */ /** Flag which indicates if javadoc from JDK 1.4 is available */
private static boolean javadoc4 = private static boolean javadoc4 =
(!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) &&
!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2) &&
!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3));
!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)
&& !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)
&& !JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3);


/** /**
* Utility method to add an argument to the command line conditionally * Utility method to add an argument to the command line conditionally
@@ -446,7 +456,7 @@ public class Javadoc extends Task {
private Path sourcePath = null; private Path sourcePath = null;
private File destDir = null; private File destDir = null;
private Vector sourceFiles = new Vector(); private Vector sourceFiles = new Vector();
private Vector packageNames = new Vector(5);
private Vector packageNames = new Vector();
private Vector excludePackageNames = new Vector(1); private Vector excludePackageNames = new Vector(1);
private boolean author = true; private boolean author = true;
private boolean version = true; private boolean version = true;
@@ -455,9 +465,9 @@ public class Javadoc extends Task {
private Path bootclasspath = null; private Path bootclasspath = null;
private String group = null; private String group = null;
private String packageList = null; private String packageList = null;
private Vector links = new Vector(2);
private Vector groups = new Vector(2);
private Vector tags = new Vector(5);
private Vector links = new Vector();
private Vector groups = new Vector();
private Vector tags = new Vector();
private boolean useDefaultExcludes = true; private boolean useDefaultExcludes = true;
private Html doctitle = null; private Html doctitle = null;
private Html header = null; private Html header = null;
@@ -1063,6 +1073,8 @@ public class Javadoc extends Task {
/** /**
* Link to docs at "url" using package list at "url2" * Link to docs at "url" using package list at "url2"
* - separate the URLs by using a space character. * - separate the URLs by using a space character.
*
* @param src the offline link specification (url and package list)
*/ */
public void setLinkoffline(String src) { public void setLinkoffline(String src) {
if (!javadoc1) { if (!javadoc1) {
@@ -1086,6 +1098,10 @@ public class Javadoc extends Task {


/** /**
* Group specified packages together in overview page. * Group specified packages together in overview page.
*
* @param src the group packages - a command separated list of group specs,
* each one being a group name and package specification separated
* by a space.
*/ */
public void setGroup(String src) { public void setGroup(String src) {
group = src; group = src;
@@ -1101,49 +1117,63 @@ public class Javadoc extends Task {
} }


/** /**
* If true, do not include @deprecated information.
* Control deprecation infromation
*
* @param b If true, do not include deprecated information.
*/ */
public void setNodeprecated(boolean b) { public void setNodeprecated(boolean b) {
addArgIf(b, "-nodeprecated"); addArgIf(b, "-nodeprecated");
} }


/** /**
* If true, do not generate deprecated list.
* Control deprecated list generation
*
* @param b if true, do not generate deprecated list.
*/ */
public void setNodeprecatedlist(boolean b) { public void setNodeprecatedlist(boolean b) {
add12ArgIf(b, "-nodeprecatedlist"); add12ArgIf(b, "-nodeprecatedlist");
} }


/** /**
* If true, do not generate class hierarchy.
* Control class tree generation.
*
* @param b if true, do not generate class hierarchy.
*/ */
public void setNotree(boolean b) { public void setNotree(boolean b) {
addArgIf(b, "-notree"); addArgIf(b, "-notree");
} }


/** /**
* If true, do not generate index.
* Control generation of index.
*
* @param b if true, do not generate index.
*/ */
public void setNoindex(boolean b) { public void setNoindex(boolean b) {
addArgIf(b, "-noindex"); addArgIf(b, "-noindex");
} }


/** /**
* If true, do not generate help link
* Control generation of help link.
*
* @param b if true, do not generate help link
*/ */
public void setNohelp(boolean b) { public void setNohelp(boolean b) {
add12ArgIf(b, "-nohelp"); add12ArgIf(b, "-nohelp");
} }


/** /**
* If true, do not generate navigation bar.
* Control generation of the navigation bar.
*
* @param b if true, do not generate navigation bar.
*/ */
public void setNonavbar(boolean b) { public void setNonavbar(boolean b) {
add12ArgIf(b, "-nonavbar"); add12ArgIf(b, "-nonavbar");
} }


/** /**
* If true, generate warning about @serial tag.
* Control warnings about serial tag.
*
* @param b if true, generate warning aboutthe serial tag.
*/ */
public void setSerialwarn(boolean b) { public void setSerialwarn(boolean b) {
add12ArgIf(b, "-serialwarn"); add12ArgIf(b, "-serialwarn");
@@ -1151,6 +1181,8 @@ public class Javadoc extends Task {


/** /**
* Specifies the CSS stylesheet file to use. * Specifies the CSS stylesheet file to use.
*
* @param f the file with the CSS to use.
*/ */
public void setStylesheetfile(File f) { public void setStylesheetfile(File f) {
if (!javadoc1) { if (!javadoc1) {
@@ -1161,6 +1193,8 @@ public class Javadoc extends Task {


/** /**
* Specifies the HTML help file to use. * Specifies the HTML help file to use.
*
* @param f the file containing help content.
*/ */
public void setHelpfile(File f) { public void setHelpfile(File f) {
if (!javadoc1) { if (!javadoc1) {
@@ -1171,6 +1205,8 @@ public class Javadoc extends Task {


/** /**
* Output file encoding name. * Output file encoding name.
*
* @param enc name of the encoding to use.
*/ */
public void setDocencoding(String enc) { public void setDocencoding(String enc) {
cmd.createArgument().setValue("-docencoding"); cmd.createArgument().setValue("-docencoding");
@@ -1179,6 +1215,8 @@ public class Javadoc extends Task {


/** /**
* The name of a file containing the packages to process. * The name of a file containing the packages to process.
*
* @param src the file containing the package list.
*/ */
public void setPackageList(String src) { public void setPackageList(String src) {
if (!javadoc1) { if (!javadoc1) {
@@ -1188,6 +1226,8 @@ public class Javadoc extends Task {


/** /**
* Create link to javadoc output at the given URL. * Create link to javadoc output at the given URL.
*
* @param link argument to configure
*/ */
public LinkArgument createLink() { public LinkArgument createLink() {
LinkArgument la = new LinkArgument(); LinkArgument la = new LinkArgument();
@@ -1195,6 +1235,10 @@ public class Javadoc extends Task {
return la; return la;
} }


/**
* Represents a link triplet (href, whether link is offline, location of the
* package list if off line)
*/
public class LinkArgument { public class LinkArgument {
private String href; private String href;
private boolean offline = false; private boolean offline = false;
@@ -1334,8 +1378,9 @@ public class Javadoc extends Task {
} else { } else {
int i; int i;
for (i = 0; i < SCOPE_ELEMENTS.length; i++) { for (i = 0; i < SCOPE_ELEMENTS.length; i++) {
if (next.equals (SCOPE_ELEMENTS[i]))
if (next.equals (SCOPE_ELEMENTS[i])) {
break; break;
}
} }
if (i == SCOPE_ELEMENTS.length) { if (i == SCOPE_ELEMENTS.length) {
throw new BuildException ("Unrecognised scope element: " throw new BuildException ("Unrecognised scope element: "
@@ -1412,7 +1457,7 @@ public class Javadoc extends Task {


public class GroupArgument { public class GroupArgument {
private Html title; private Html title;
private Vector packages = new Vector(3);
private Vector packages = new Vector();


public GroupArgument() { public GroupArgument() {
} }
@@ -1765,7 +1810,7 @@ public class Javadoc extends Task {
while (tok.hasMoreTokens()) { while (tok.hasMoreTokens()) {
String grp = tok.nextToken().trim(); String grp = tok.nextToken().trim();
int space = grp.indexOf(" "); int space = grp.indexOf(" ");
if (space > 0){
if (space > 0) {
String name = grp.substring(0, space); String name = grp.substring(0, space);
String pkgList = grp.substring(space + 1); String pkgList = grp.substring(space + 1);
toExecute.createArgument().setValue("-group"); toExecute.createArgument().setValue("-group");
@@ -1799,7 +1844,7 @@ public class Javadoc extends Task {
if (element instanceof TagArgument) { if (element instanceof TagArgument) {
TagArgument ta = (TagArgument) element; TagArgument ta = (TagArgument) element;
File tagDir = ta.getDir(getProject()); File tagDir = ta.getDir(getProject());
if (tagDir == null ) {
if (tagDir == null) {
// The tag element is not used as a fileset, // The tag element is not used as a fileset,
// but specifies the tag directly. // but specifies the tag directly.
toExecute.createArgument().setValue ("-tag"); toExecute.createArgument().setValue ("-tag");
@@ -1810,17 +1855,20 @@ public class Javadoc extends Task {
DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject()); DirectoryScanner tagDefScanner = ta.getDirectoryScanner(getProject());
String[] files = tagDefScanner.getIncludedFiles(); String[] files = tagDefScanner.getIncludedFiles();
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
File tagDefFile = new File( tagDir, files[i] );
File tagDefFile = new File(tagDir, files[i]);
try { try {
BufferedReader in = new BufferedReader( new FileReader(tagDefFile) );
BufferedReader in
= new BufferedReader(new FileReader(tagDefFile));
String line = null; String line = null;
while( (line = in.readLine()) != null ) {
while ((line = in.readLine()) != null) {
toExecute.createArgument().setValue ("-tag"); toExecute.createArgument().setValue ("-tag");
toExecute.createArgument().setValue (line); toExecute.createArgument().setValue (line);
} }
in.close(); in.close();
} catch( IOException ioe ) {
throw new BuildException( "Couldn't read tag file from " + tagDefFile.getAbsolutePath(), ioe );
} catch (IOException ioe) {
throw new BuildException("Couldn't read "
+ " tag file from "
+ tagDefFile.getAbsolutePath(), ioe );
} }
} }
} }
@@ -1952,7 +2000,9 @@ public class Javadoc extends Task {
try { try {
out.close(); out.close();
err.close(); err.close();
} catch (IOException e) {}
} catch (IOException e) {
// ignore
}
} }
} }




+ 53
- 20
src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java View File

@@ -96,117 +96,150 @@ public abstract class ConditionBase extends ProjectComponent {
* *
* @since 1.1 * @since 1.1
*/ */
public void addAvailable(Available a) {conditions.addElement(a);}
public void addAvailable(Available a) {
conditions.addElement(a);
}


/** /**
* Add an &lt;checksum&gt; condition. * Add an &lt;checksum&gt; condition.
* *
* @since 1.4, Ant 1.5 * @since 1.4, Ant 1.5
*/ */
public void addChecksum(Checksum c) {conditions.addElement(c);}
public void addChecksum(Checksum c) {
conditions.addElement(c);
}


/** /**
* Add an &lt;uptodate&gt; condition. * Add an &lt;uptodate&gt; condition.
* *
* @since 1.1 * @since 1.1
*/ */
public void addUptodate(UpToDate u) {conditions.addElement(u);}
public void addUptodate(UpToDate u) {
conditions.addElement(u);
}


/** /**
* Add an &lt;not&gt; condition "container". * Add an &lt;not&gt; condition "container".
* *
* @since 1.1 * @since 1.1
*/ */
public void addNot(Not n) {conditions.addElement(n);}
public void addNot(Not n) {
conditions.addElement(n);
}


/** /**
* Add an &lt;and&gt; condition "container". * Add an &lt;and&gt; condition "container".
* *
* @since 1.1 * @since 1.1
*/ */
public void addAnd(And a) {conditions.addElement(a);}
public void addAnd(And a) {
conditions.addElement(a);
}


/** /**
* Add an &lt;or&gt; condition "container". * Add an &lt;or&gt; condition "container".
* *
* @since 1.1 * @since 1.1
*/ */
public void addOr(Or o) {conditions.addElement(o);}
public void addOr(Or o) {
conditions.addElement(o);
}


/** /**
* Add an &lt;equals&gt; condition. * Add an &lt;equals&gt; condition.
* *
* @since 1.1 * @since 1.1
*/ */
public void addEquals(Equals e) {conditions.addElement(e);}
public void addEquals(Equals e) {
conditions.addElement(e);
}


/** /**
* Add an &lt;os&gt; condition. * Add an &lt;os&gt; condition.
* *
* @since 1.1 * @since 1.1
*/ */
public void addOs(Os o) {conditions.addElement(o);}
public void addOs(Os o) {
conditions.addElement(o);
}


/** /**
* Add an &lt;isset&gt; condition. * Add an &lt;isset&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addIsSet(IsSet i) {conditions.addElement(i);}
public void addIsSet(IsSet i) {
conditions.addElement(i);
}


/** /**
* Add an &lt;http&gt; condition. * Add an &lt;http&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addHttp(Http h) {conditions.addElement(h);}
public void addHttp(Http h) {
conditions.addElement(h);
}


/** /**
* Add a &lt;socket&gt; condition. * Add a &lt;socket&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addSocket(Socket s) {conditions.addElement(s);}
public void addSocket(Socket s) {
conditions.addElement(s);
}


/** /**
* Add a &lt;filesmatch&gt; condition. * Add a &lt;filesmatch&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addFilesMatch(FilesMatch test) {conditions.addElement(test);}
public void addFilesMatch(FilesMatch test) {
conditions.addElement(test);
}

/** /**
* Add a &lt;contains&gt; condition. * Add a &lt;contains&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addContains(Contains test) {conditions.addElement(test);}
public void addContains(Contains test) {
conditions.addElement(test);
}


/** /**
* Add a &lt;istrue&gt; condition. * Add a &lt;istrue&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addIsTrue(IsTrue test) {conditions.addElement(test);}
public void addIsTrue(IsTrue test) {
conditions.addElement(test);
}


/** /**
* Add a &lt;isfalse&gt; condition. * Add a &lt;isfalse&gt; condition.
* *
* @since Ant 1.5 * @since Ant 1.5
*/ */
public void addIsFalse(IsFalse test) {conditions.addElement(test);}
public void addIsFalse(IsFalse test) {
conditions.addElement(test);
}

/** /**
* Add an &lt;isreference&gt; condition. * Add an &lt;isreference&gt; condition.
* *
* @since Ant 1.6 * @since Ant 1.6
*/ */
public void addIsReference(IsReference i) {conditions.addElement(i);}
public void addIsReference(IsReference i) {
conditions.addElement(i);
}


/** /**
* Add an arbitary condition * Add an arbitary condition
* @since Ant 1.6 * @since Ant 1.6
*/ */
public void add(Condition c) {conditions.addElement(c);}
public void add(Condition c) {
conditions.addElement(c);
}
} }

+ 81
- 73
src/main/org/apache/tools/ant/taskdefs/optional/jsp/WLJspc.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-2003 The Apache Software Foundation. All rights
* Copyright (c) 2000,2002-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
@@ -67,34 +67,34 @@ import org.apache.tools.ant.types.Path;


/** /**
* Precompiles JSP's using WebLogic's JSP compiler (weblogic.jspc). * Precompiles JSP's using WebLogic's JSP compiler (weblogic.jspc).
*
*
* @author <a href="mailto:avik@aviksengupta.com">Avik Sengupta</a> http://www.webteksoftware.com * @author <a href="mailto:avik@aviksengupta.com">Avik Sengupta</a> http://www.webteksoftware.com
*
*
* Tested only on Weblogic 4.5.1 - NT4.0 and Solaris 5.7 * Tested only on Weblogic 4.5.1 - NT4.0 and Solaris 5.7
*
*
* required attributes * required attributes
* src : root of source tree for JSP, ie, the document root for your weblogic server * src : root of source tree for JSP, ie, the document root for your weblogic server
* dest : root of destination directory, what you have set as WorkingDir in the weblogic properties * dest : root of destination directory, what you have set as WorkingDir in the weblogic properties
* package : start package name under which your JSP's would be compiled * package : start package name under which your JSP's would be compiled
*
*
* other attributes * other attributes
* classpath * classpath
*
*
* A classpath should be set which contains the weblogic classes as well as all application classes * A classpath should be set which contains the weblogic classes as well as all application classes
* referenced by the JSP. The system classpath is also appended when the jspc is called, so you may
* referenced by the JSP. The system classpath is also appended when the jspc is called, so you may
* choose to put everything in the classpath while calling Ant. However, since presumably the JSP's will reference * choose to put everything in the classpath while calling Ant. However, since presumably the JSP's will reference
* classes being build by Ant, it would be better to explicitly add the classpath in the task * classes being build by Ant, it would be better to explicitly add the classpath in the task
*
*
* The task checks timestamps on the JSP's and the generated classes, and compiles * The task checks timestamps on the JSP's and the generated classes, and compiles
* only those files that have changed.
*
* It follows the weblogic naming convention of putting classes in
* only those files that have changed.
*
* It follows the weblogic naming convention of putting classes in
* <b> _dirName/_fileName.class for dirname/fileName.jsp </b> * <b> _dirName/_fileName.class for dirname/fileName.jsp </b>
*
* Limitation: It compiles the files thru the Classic compiler only.
*
* Limitation: It compiles the files thru the Classic compiler only.
* Limitation: Since it is my experience that weblogic jspc throws out of memory error on being given too * Limitation: Since it is my experience that weblogic jspc throws out of memory error on being given too
* many files at one go, it is called multiple times with one jsp file each.
*
* many files at one go, it is called multiple times with one jsp file each.
*
* <pre> * <pre>
* example * example
* &lt;target name="jspcompile" depends="compile"&gt; * &lt;target name="jspcompile" depends="compile"&gt;
@@ -103,43 +103,52 @@ import org.apache.tools.ant.types.Path;
* &lt;pathelement location="${weblogic.classpath}" /&gt; * &lt;pathelement location="${weblogic.classpath}" /&gt;
* &lt;pathelement path="${compile.dest}" /&gt; * &lt;pathelement path="${compile.dest}" /&gt;
* &lt;/classpath&gt; * &lt;/classpath&gt;
*
*
* &lt;/wljspc&gt; * &lt;/wljspc&gt;
* &lt;/target&gt; * &lt;/target&gt;
* </pre> * </pre>
*
*
*/ */


public class WLJspc extends MatchingTask { public class WLJspc extends MatchingTask {
//TODO Test on other versions of weblogic //TODO Test on other versions of weblogic
//TODO add more attributes to the task, to take care of all jspc options //TODO add more attributes to the task, to take care of all jspc options
//TODO Test on Unix //TODO Test on Unix
private File destinationDirectory; //root of compiled files tree
private File sourceDirectory; // root of source files tree
private String destinationPackage; //package under which resultant classes will reside
private Path compileClasspath; //classpath used to compile the jsp files.

/** root of compiled files tree */
private File destinationDirectory;

/** root of source files tree */
private File sourceDirectory;

/** package under which resultant classes will reside */
private String destinationPackage;

/** classpath used to compile the jsp files. */
private Path compileClasspath;

//private String compilerPath; //fully qualified name for the compiler executable //private String compilerPath; //fully qualified name for the compiler executable
private String pathToPackage = ""; private String pathToPackage = "";
private Vector filesToDo = new Vector(); private Vector filesToDo = new Vector();
public void execute() throws BuildException { public void execute() throws BuildException {
if (!destinationDirectory.isDirectory()) { if (!destinationDirectory.isDirectory()) {
throw new BuildException("destination directory " + destinationDirectory.getPath() +
" is not valid");
throw new BuildException("destination directory "
+ destinationDirectory.getPath() + " is not valid");
} }
if (!sourceDirectory.isDirectory()) { if (!sourceDirectory.isDirectory()) {
throw new BuildException("src directory " + sourceDirectory.getPath() +
" is not valid");
throw new BuildException("src directory "
+ sourceDirectory.getPath() + " is not valid");
} }


if (destinationPackage == null) { if (destinationPackage == null) {
throw new BuildException("package attribute must be present.", getLocation());
throw new BuildException("package attribute must be present.",
getLocation());
} }
pathToPackage pathToPackage
= this.destinationPackage.replace('.', File.separatorChar); = this.destinationPackage.replace('.', File.separatorChar);
// get all the files in the sourceDirectory // get all the files in the sourceDirectory
@@ -149,30 +158,30 @@ public class WLJspc extends MatchingTask {
if (compileClasspath == null) { if (compileClasspath == null) {
compileClasspath = new Path(getProject()); compileClasspath = new Path(getProject());
} }
compileClasspath = compileClasspath.concatSystemClasspath(); compileClasspath = compileClasspath.concatSystemClasspath();
String[] files = ds.getIncludedFiles(); String[] files = ds.getIncludedFiles();
//Weblogic.jspc calls System.exit() ... have to fork //Weblogic.jspc calls System.exit() ... have to fork
// Therefore, takes loads of time
// Can pass directories at a time (*.jsp) but easily runs out of memory on hefty dirs
// (even on a Sun)
// Therefore, takes loads of time
// Can pass directories at a time (*.jsp) but easily runs out of
// memory on hefty dirs (even on a Sun)
Java helperTask = (Java) getProject().createTask("java"); Java helperTask = (Java) getProject().createTask("java");
helperTask.setFork(true); helperTask.setFork(true);
helperTask.setClassname("weblogic.jspc"); helperTask.setClassname("weblogic.jspc");
helperTask.setTaskName(getTaskName()); helperTask.setTaskName(getTaskName());
String[] args = new String[12]; String[] args = new String[12];
File jspFile = null; File jspFile = null;
String parents = ""; String parents = "";
int j = 0; int j = 0;
//XXX this array stuff is a remnant of prev trials.. gotta remove.
//XXX this array stuff is a remnant of prev trials.. gotta remove.
args[j++] = "-d"; args[j++] = "-d";
args[j++] = destinationDirectory.getAbsolutePath().trim();
args[j++] = destinationDirectory.getAbsolutePath().trim();
args[j++] = "-docroot"; args[j++] = "-docroot";
args[j++] = sourceDirectory.getAbsolutePath().trim(); args[j++] = sourceDirectory.getAbsolutePath().trim();
args[j++] = "-keepgenerated"; //TODO: Parameterise ?? args[j++] = "-keepgenerated"; //TODO: Parameterise ??
//Call compiler as class... dont want to fork again
//Call compiler as class... dont want to fork again
//Use classic compiler -- can be parameterised? //Use classic compiler -- can be parameterised?
args[j++] = "-compilerclass"; args[j++] = "-compilerclass";
args[j++] = "sun.tools.javac.Main"; args[j++] = "sun.tools.javac.Main";
@@ -181,14 +190,14 @@ public class WLJspc extends MatchingTask {
// Am i missing something about the Java task?? // Am i missing something about the Java task??
args[j++] = "-classpath"; args[j++] = "-classpath";
args[j++] = compileClasspath.toString(); args[j++] = compileClasspath.toString();
this.scanDir(files); this.scanDir(files);
log("Compiling " + filesToDo.size() + " JSP files"); log("Compiling " + filesToDo.size() + " JSP files");
for (int i = 0; i < filesToDo.size(); i++) { for (int i = 0; i < filesToDo.size(); i++) {
//XXX //XXX
// All this to get package according to weblogic standards // All this to get package according to weblogic standards
// Can be written better... this is too hacky!
// Can be written better... this is too hacky!
// Careful.. similar code in scanDir , but slightly different!! // Careful.. similar code in scanDir , but slightly different!!
String filename = (String) filesToDo.elementAt(i); String filename = (String) filesToDo.elementAt(i);
jspFile = new File(filename); jspFile = new File(filename);
@@ -200,27 +209,27 @@ public class WLJspc extends MatchingTask {
} else { } else {
args[j + 1] = destinationPackage; args[j + 1] = destinationPackage;
} }
args[j + 2] = sourceDirectory + File.separator + filename; args[j + 2] = sourceDirectory + File.separator + filename;
helperTask.clearArgs(); helperTask.clearArgs();
for (int x = 0; x < j + 3; x++) { for (int x = 0; x < j + 3; x++) {
helperTask.createArg().setValue(args[x]); helperTask.createArg().setValue(args[x]);
} }
helperTask.setClasspath(compileClasspath); helperTask.setClasspath(compileClasspath);
if (helperTask.executeJava() != 0) {
if (helperTask.executeJava() != 0) {
log(filename + " failed to compile", Project.MSG_WARN); log(filename + " failed to compile", Project.MSG_WARN);
} }
} }
} }


/** /**
* Set the classpath to be used for this compilation. * Set the classpath to be used for this compilation.
*
*
*/ */
public void setClasspath(Path classpath) { public void setClasspath(Path classpath) {
if (compileClasspath == null) { if (compileClasspath == null) {
@@ -242,38 +251,38 @@ public class WLJspc extends MatchingTask {


/** /**
* Set the directory containing the source jsp's * Set the directory containing the source jsp's
*
*
* *
* @param dirName the directory containg the source jsp's * @param dirName the directory containg the source jsp's
*/ */
public void setSrc(File dirName) { public void setSrc(File dirName) {
sourceDirectory = dirName; sourceDirectory = dirName;
} }
/** /**
* Set the directory containing the source jsp's * Set the directory containing the source jsp's
*
*
* *
* @param dirName the directory containg the source jsp's * @param dirName the directory containg the source jsp's
*/ */
public void setDest(File dirName) { public void setDest(File dirName) {
destinationDirectory = dirName; destinationDirectory = dirName;
} }
/** /**
* Set the package under which the compiled classes go * Set the package under which the compiled classes go
*
*
* @param packageName the package name for the clases * @param packageName the package name for the clases
*/ */
public void setPackage(String packageName) { public void setPackage(String packageName) {
destinationPackage = packageName;
destinationPackage = packageName;
} }
protected void scanDir(String files[]) { protected void scanDir(String files[]) {


long now = (new Date()).getTime(); long now = (new Date()).getTime();
@@ -283,8 +292,8 @@ public class WLJspc extends MatchingTask {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
File srcFile = new File(this.sourceDirectory, files[i]); File srcFile = new File(this.sourceDirectory, files[i]);
//XXX //XXX
// All this to convert source to destination directory according to weblogic standards
// Can be written better... this is too hacky!
// All this to convert source to destination directory according
// to weblogic standards Can be written better... this is too hacky!
jspFile = new File(files[i]); jspFile = new File(files[i]);
parents = jspFile.getParent(); parents = jspFile.getParent();


@@ -294,17 +303,17 @@ public class WLJspc extends MatchingTask {
} else { } else {
pack = pathToPackage; pack = pathToPackage;
} }
String filePath = pack + File.separator + "_"; String filePath = pack + File.separator + "_";
int startingIndex
int startingIndex
= files[i].lastIndexOf(File.separator) != -1 ? files[i].lastIndexOf(File.separator) + 1 : 0; = files[i].lastIndexOf(File.separator) != -1 ? files[i].lastIndexOf(File.separator) + 1 : 0;
int endingIndex = files[i].indexOf(".jsp"); int endingIndex = files[i].indexOf(".jsp");
if (endingIndex == -1) { if (endingIndex == -1) {
log("Skipping " + files[i] + ". Not a JSP",
log("Skipping " + files[i] + ". Not a JSP",
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
continue; continue;
} }
filePath += files[i].substring(startingIndex, endingIndex); filePath += files[i].substring(startingIndex, endingIndex);
filePath += ".class"; filePath += ".class";
File classFile = new File(this.destinationDirectory, filePath); File classFile = new File(this.destinationDirectory, filePath);
@@ -314,14 +323,13 @@ public class WLJspc extends MatchingTask {
files[i], Project.MSG_WARN); files[i], Project.MSG_WARN);
} }
if (srcFile.lastModified() > classFile.lastModified()) { if (srcFile.lastModified() > classFile.lastModified()) {
//log("Files are" + srcFile.getAbsolutePath()+" " +classFile.getAbsolutePath());
filesToDo.addElement(files[i]); filesToDo.addElement(files[i]);
log("Recompiling File " + files[i], Project.MSG_VERBOSE); log("Recompiling File " + files[i], Project.MSG_VERBOSE);
} }
} }
} }
protected String replaceString(String inpString, String escapeChars, protected String replaceString(String inpString, String escapeChars,
String replaceChars) { String replaceChars) {
String localString = ""; String localString = "";


+ 84
- 52
src/main/org/apache/tools/ant/types/FilterSet.java View File

@@ -74,7 +74,7 @@ import org.apache.tools.ant.Project;
* @author <A href="mailto:martin@mvdb.net"> Martin van den Bemt </A> * @author <A href="mailto:martin@mvdb.net"> Martin van den Bemt </A>
*/ */
public class FilterSet extends DataType implements Cloneable { public class FilterSet extends DataType implements Cloneable {
/** /**
* Individual filter component of filterset * Individual filter component of filterset
* *
@@ -83,10 +83,10 @@ public class FilterSet extends DataType implements Cloneable {
public static class Filter { public static class Filter {
/** Token which will be replaced in the filter operation */ /** Token which will be replaced in the filter operation */
String token; String token;
/** The value which will replace the token in the filtering operation */ /** The value which will replace the token in the filtering operation */
String value; String value;
/** /**
* Constructor for the Filter object * Constructor for the Filter object
* *
@@ -97,13 +97,13 @@ public class FilterSet extends DataType implements Cloneable {
this.token = token; this.token = token;
this.value = value; this.value = value;
} }
/** /**
* No argument conmstructor * No argument conmstructor
*/ */
public Filter() { public Filter() {
} }
/** /**
* Sets the Token attribute of the Filter object * Sets the Token attribute of the Filter object
* *
@@ -112,7 +112,7 @@ public class FilterSet extends DataType implements Cloneable {
public void setToken(String token) { public void setToken(String token) {
this.token = token; this.token = token;
} }
/** /**
* Sets the Value attribute of the Filter object * Sets the Value attribute of the Filter object
* *
@@ -121,7 +121,7 @@ public class FilterSet extends DataType implements Cloneable {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
/** /**
* Gets the Token attribute of the Filter object * Gets the Token attribute of the Filter object
* *
@@ -130,7 +130,7 @@ public class FilterSet extends DataType implements Cloneable {
public String getToken() { public String getToken() {
return token; return token;
} }
/** /**
* Gets the Value attribute of the Filter object * Gets the Value attribute of the Filter object
* *
@@ -140,20 +140,20 @@ public class FilterSet extends DataType implements Cloneable {
return value; return value;
} }
} }
/** /**
* The filtersfile nested element. * The filtersfile nested element.
* *
* @author Michael McCallum * @author Michael McCallum
*/ */
public class FiltersFile { public class FiltersFile {
/** /**
* Constructor for the Filter object * Constructor for the Filter object
*/ */
public FiltersFile() { public FiltersFile() {
} }
/** /**
* Sets the file from which filters will be read. * Sets the file from which filters will be read.
* *
@@ -163,24 +163,27 @@ public class FilterSet extends DataType implements Cloneable {
readFiltersFromFile(file); readFiltersFromFile(file);
} }
} }
/** The default token start string */ /** The default token start string */
public static final String DEFAULT_TOKEN_START = "@"; public static final String DEFAULT_TOKEN_START = "@";
/** The default token end string */ /** The default token end string */
public static final String DEFAULT_TOKEN_END = "@"; public static final String DEFAULT_TOKEN_END = "@";
private String startOfToken = DEFAULT_TOKEN_START; private String startOfToken = DEFAULT_TOKEN_START;
private String endOfToken = DEFAULT_TOKEN_END; private String endOfToken = DEFAULT_TOKEN_END;
/** /**
* List of ordered filters and filter files. * List of ordered filters and filter files.
*/ */
private Vector filters = new Vector(); private Vector filters = new Vector();

/**
* Default constructor
*/
public FilterSet() { public FilterSet() {
} }
/** /**
* Create a Filterset from another filterset * Create a Filterset from another filterset
* *
@@ -191,6 +194,11 @@ public class FilterSet extends DataType implements Cloneable {
this.filters = (Vector) filterset.getFilters().clone(); this.filters = (Vector) filterset.getFilters().clone();
} }


/**
* Get the filters in the filter set
*
* @return a Vector of Filter instances
*/
protected Vector getFilters() { protected Vector getFilters() {
if (isReference()) { if (isReference()) {
return getRef().getFilters(); return getRef().getFilters();
@@ -198,10 +206,15 @@ public class FilterSet extends DataType implements Cloneable {
return filters; return filters;
} }


/**
* Get the referred filter set
*
* @return the filterset from the reference.
*/
protected FilterSet getRef() { protected FilterSet getRef() {
return (FilterSet) getCheckedRef(FilterSet.class, "filterset"); return (FilterSet) getCheckedRef(FilterSet.class, "filterset");
} }
/** /**
* Gets the filter hash of the FilterSet. * Gets the filter hash of the FilterSet.
* *
@@ -216,7 +229,7 @@ public class FilterSet extends DataType implements Cloneable {
} }
return filterHash; return filterHash;
} }
/** /**
* set the file containing the filters for this filterset. * set the file containing the filters for this filterset.
* *
@@ -229,7 +242,7 @@ public class FilterSet extends DataType implements Cloneable {
} }
readFiltersFromFile(filtersFile); readFiltersFromFile(filtersFile);
} }
/** /**
* The string used to id the beginning of a token. * The string used to id the beginning of a token.
* *
@@ -245,14 +258,19 @@ public class FilterSet extends DataType implements Cloneable {
this.startOfToken = startOfToken; this.startOfToken = startOfToken;
} }


/**
* Get the begin token for this filterset
*
* @return the filter set's begin token for filtering
*/
public String getBeginToken() { public String getBeginToken() {
if (isReference()) { if (isReference()) {
return getRef().getBeginToken(); return getRef().getBeginToken();
} }
return startOfToken; return startOfToken;
} }
/** /**
* The string used to id the end of a token. * The string used to id the end of a token.
* *
@@ -268,14 +286,19 @@ public class FilterSet extends DataType implements Cloneable {
this.endOfToken = endOfToken; this.endOfToken = endOfToken;
} }


/**
* Get the end token for this filterset
*
* @return the filter set's end token for replacement delimiting
*/
public String getEndToken() { public String getEndToken() {
if (isReference()) { if (isReference()) {
return getRef().getEndToken(); return getRef().getEndToken();
} }
return endOfToken; return endOfToken;
} }
/** /**
* Read the filters from the given file. * Read the filters from the given file.
* *
@@ -289,7 +312,7 @@ public class FilterSet extends DataType implements Cloneable {
} }


if (!filtersFile.exists()) { if (!filtersFile.exists()) {
throw new BuildException("Could not read filters from file "
throw new BuildException("Could not read filters from file "
+ filtersFile + " as it doesn't exist."); + filtersFile + " as it doesn't exist.");
} }


@@ -300,7 +323,7 @@ public class FilterSet extends DataType implements Cloneable {
Properties props = new Properties(); Properties props = new Properties();
in = new FileInputStream(filtersFile); in = new FileInputStream(filtersFile);
props.load(in); props.load(in);
Enumeration enum = props.propertyNames(); Enumeration enum = props.propertyNames();
Vector filters = getFilters(); Vector filters = getFilters();
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
@@ -309,22 +332,23 @@ public class FilterSet extends DataType implements Cloneable {
filters.addElement(new Filter(strPropName, strValue)); filters.addElement(new Filter(strPropName, strValue));
} }
} catch (Exception e) { } catch (Exception e) {
throw new BuildException("Could not read filters from file: "
throw new BuildException("Could not read filters from file: "
+ filtersFile); + filtersFile);
} finally { } finally {
if (in != null) { if (in != null) {
try { try {
in.close(); in.close();
} catch (IOException ioex) { } catch (IOException ioex) {
// ignore
} }
} }
} }
} else { } else {
throw new BuildException("Must specify a file not a directory in "
throw new BuildException("Must specify a file not a directory in "
+ "the filtersfile attribute:" + filtersFile); + "the filtersfile attribute:" + filtersFile);
} }
} }
/** /**
* Does replacement on the given string with token matching. * Does replacement on the given string with token matching.
* This uses the defined begintoken and endtoken values which default to @ for both. * This uses the defined begintoken and endtoken values which default to @ for both.
@@ -336,7 +360,7 @@ public class FilterSet extends DataType implements Cloneable {
String beginToken = getBeginToken(); String beginToken = getBeginToken();
String endToken = getEndToken(); String endToken = getEndToken();
int index = line.indexOf(beginToken); int index = line.indexOf(beginToken);
if (index > -1) { if (index > -1) {
Hashtable tokens = getFilterHash(); Hashtable tokens = getFilterHash();
try { try {
@@ -344,14 +368,14 @@ public class FilterSet extends DataType implements Cloneable {
int i = 0; int i = 0;
String token = null; String token = null;
String value = null; String value = null;
do { do {
int endIndex = line.indexOf(endToken,
int endIndex = line.indexOf(endToken,
index + beginToken.length() + 1); index + beginToken.length() + 1);
if (endIndex == -1) { if (endIndex == -1) {
break; break;
} }
token
token
= line.substring(index + beginToken.length(), endIndex); = line.substring(index + beginToken.length(), endIndex);
b.append(line.substring(i, index)); b.append(line.substring(i, index));
if (tokens.containsKey(token)) { if (tokens.containsKey(token)) {
@@ -360,10 +384,10 @@ public class FilterSet extends DataType implements Cloneable {
// we have another token, let's parse it. // we have another token, let's parse it.
value = replaceTokens(value, token); value = replaceTokens(value, token);
} }
log("Replacing: " + beginToken + token + endToken
log("Replacing: " + beginToken + token + endToken
+ " -> " + value, Project.MSG_VERBOSE); + " -> " + value, Project.MSG_VERBOSE);
b.append(value); b.append(value);
i = index + beginToken.length() + token.length()
i = index + beginToken.length() + token.length()
+ endToken.length(); + endToken.length();
} else { } else {
// just append beginToken and search further // just append beginToken and search further
@@ -371,7 +395,7 @@ public class FilterSet extends DataType implements Cloneable {
i = index + beginToken.length(); i = index + beginToken.length();
} }
} while ((index = line.indexOf(beginToken, i)) > -1); } while ((index = line.indexOf(beginToken, i)) > -1);
b.append(line.substring(i)); b.append(line.substring(i));
return b.toString(); return b.toString();
} catch (StringIndexOutOfBoundsException e) { } catch (StringIndexOutOfBoundsException e) {
@@ -381,12 +405,12 @@ public class FilterSet extends DataType implements Cloneable {
return line; return line;
} }
} }
/** Contains a list of parsed tokens */ /** Contains a list of parsed tokens */
private Vector passedTokens; private Vector passedTokens;
/** if a ducplicate token is found, this is set to true */ /** if a ducplicate token is found, this is set to true */
private boolean duplicateToken = false; private boolean duplicateToken = false;
/** /**
* This parses tokens which point to tokens. * This parses tokens which point to tokens.
* It also maintains a list of currently used tokens, so we cannot * It also maintains a list of currently used tokens, so we cannot
@@ -395,8 +419,7 @@ public class FilterSet extends DataType implements Cloneable {
* @param parent the parant token (= the token it was parsed from) * @param parent the parant token (= the token it was parsed from)
*/ */
private String replaceTokens(String line, String parent) private String replaceTokens(String line, String parent)
throws BuildException
{
throws BuildException {
if (passedTokens == null) { if (passedTokens == null) {
passedTokens = new Vector(); passedTokens = new Vector();
} }
@@ -405,8 +428,10 @@ public class FilterSet extends DataType implements Cloneable {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("Inifinite loop in tokens. Currently known tokens : "); sb.append("Inifinite loop in tokens. Currently known tokens : ");
sb.append(passedTokens); sb.append(passedTokens);
sb.append("\nProblem token : "+getBeginToken()+parent+getEndToken());
sb.append(" called from "+getBeginToken()+passedTokens.lastElement());
sb.append("\nProblem token : " + getBeginToken() + parent
+ getEndToken());
sb.append(" called from " + getBeginToken()
+ passedTokens.lastElement());
sb.append(getEndToken()); sb.append(getEndToken());
System.out.println(sb.toString()); System.out.println(sb.toString());
return parent; return parent;
@@ -416,24 +441,24 @@ public class FilterSet extends DataType implements Cloneable {
if (value.indexOf(getBeginToken()) == -1 && !duplicateToken) { if (value.indexOf(getBeginToken()) == -1 && !duplicateToken) {
duplicateToken = false; duplicateToken = false;
passedTokens = null; passedTokens = null;
} else if(duplicateToken) {
} else if (duplicateToken) {
// should always be the case... // should always be the case...
if (passedTokens.size() > 0) { if (passedTokens.size() > 0) {
value = (String) passedTokens.lastElement(); value = (String) passedTokens.lastElement();
passedTokens.removeElementAt(passedTokens.size()-1);
passedTokens.removeElementAt(passedTokens.size() - 1);
if (passedTokens.size() == 0) { if (passedTokens.size() == 0) {
value = getBeginToken()+value+getEndToken();
value = getBeginToken() + value + getEndToken();
duplicateToken = false; duplicateToken = false;
} }
} }
} }
return value; return value;
} }
/** /**
* Create a new filter * Create a new filter
* *
* @param the filter to be added
* @param filter the filter to be added
*/ */
public void addFilter(Filter filter) { public void addFilter(Filter filter) {
if (isReference()) { if (isReference()) {
@@ -441,7 +466,7 @@ public class FilterSet extends DataType implements Cloneable {
} }
filters.addElement(filter); filters.addElement(filter);
} }
/** /**
* Create a new FiltersFile * Create a new FiltersFile
* *
@@ -453,7 +478,7 @@ public class FilterSet extends DataType implements Cloneable {
} }
return new FiltersFile(); return new FiltersFile();
} }
/** /**
* Add a new filter made from the given token and value. * Add a new filter made from the given token and value.
* *
@@ -466,7 +491,7 @@ public class FilterSet extends DataType implements Cloneable {
} }
filters.addElement(new Filter(token, value)); filters.addElement(new Filter(token, value));
} }
/** /**
* Add a Filterset to this filter set * Add a Filterset to this filter set
* *
@@ -480,7 +505,7 @@ public class FilterSet extends DataType implements Cloneable {
filters.addElement(e.nextElement()); filters.addElement(e.nextElement());
} }
} }
/** /**
* Test to see if this filter set it empty. * Test to see if this filter set it empty.
* *
@@ -490,6 +515,13 @@ public class FilterSet extends DataType implements Cloneable {
return getFilters().size() > 0; return getFilters().size() > 0;
} }


/**
* clone the filterset
*
* @return a deep clone of this filterset
*
* @throws BuildException if the clone cannot be performed.
*/
public Object clone() throws BuildException { public Object clone() throws BuildException {
if (isReference()) { if (isReference()) {
return ((FilterSet) getRef()).clone(); return ((FilterSet) getRef()).clone();
@@ -506,6 +538,6 @@ public class FilterSet extends DataType implements Cloneable {
} }


} }





Loading…
Cancel
Save