Browse Source

Emulate extdirs feature with Jikes compiler.

Also fix two files to compile with the more strict Jikes compiler.

Submitted by: Sebastian Kanthak	<sebastian.kanthak@muehlheim.de>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267619 13f79535-47bb-0310-9956-ffa450edef68
master
Sam Ruby 25 years ago
parent
commit
f7ac20202d
3 changed files with 57 additions and 15 deletions
  1. +1
    -5
      src/main/org/apache/tools/ant/taskdefs/Available.java
  2. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  3. +52
    -6
      src/main/org/apache/tools/ant/taskdefs/Javac.java

+ 1
- 5
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -112,11 +112,7 @@ public class Available extends Task {
} }


private boolean checkResource(String resource) { private boolean checkResource(String resource) {
try { return (ClassLoader.getSystemResource(resource) != null);
return (ClassLoader.getSystemResource(resource) != null);
} catch (Exception e) {
return false;
}
} }


private boolean checkClass(String classname) { private boolean checkClass(String classname) {


+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/FixCRLF.java View File

@@ -281,13 +281,13 @@ public class FixCRLF extends MatchingTask {


for (int k=0; k<count; k++) { for (int k=0; k<count; k++) {
switch (indata[k]) { switch (indata[k]) {
case ' ': case (byte)' ':
// advance column // advance column
if (addtab == 0) outdata[o++]=(byte)' '; if (addtab == 0) outdata[o++]=(byte)' ';
col++; col++;
break; break;


case '\t': case (byte)'\t':
if (addtab == 0) { if (addtab == 0) {
// treat like any other character // treat like any other character
outdata[o++]=(byte)'\t'; outdata[o++]=(byte)'\t';
@@ -298,7 +298,7 @@ public class FixCRLF extends MatchingTask {
} }
break; break;


case '\r': case (byte)'\r':
if (addcr == 0) { if (addcr == 0) {
// treat like any other character // treat like any other character
outdata[o++]=(byte)'\r'; outdata[o++]=(byte)'\r';
@@ -306,7 +306,7 @@ public class FixCRLF extends MatchingTask {
} }
break; break;


case '\n': case (byte)'\n':
// start a new line (optional CR followed by LF) // start a new line (optional CR followed by LF)
if (addcr == +1) outdata[o++]=(byte)'\r'; if (addcr == +1) outdata[o++]=(byte)'\r';
outdata[o++]=(byte)'\n'; outdata[o++]=(byte)'\n';


+ 52
- 6
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -436,7 +436,19 @@ public class Javac extends MatchingTask {


private void doJikesCompile() throws BuildException { private void doJikesCompile() throws BuildException {
project.log("Using jikes compiler",project.MSG_VERBOSE); project.log("Using jikes compiler",project.MSG_VERBOSE);
String classpath = getCompileClasspath(); StringBuffer classpath = new StringBuffer();
classpath.append(getCompileClasspath());

// Jikes doesn't support an extension dir (-extdir)
// so we'll emulate it for compatibility and convenience.
addExtdirsToClasspath(classpath);

// Jikes has no option for source-path so we
// will add it to classpath.
classpath.append(File.pathSeparator);
classpath.append(srcDir.getAbsolutePath());

Vector argList = new Vector(); Vector argList = new Vector();


if (deprecation == true) if (deprecation == true)
@@ -449,11 +461,8 @@ public class Javac extends MatchingTask {
argList.addElement("-d"); argList.addElement("-d");
argList.addElement(destDir.getAbsolutePath()); argList.addElement(destDir.getAbsolutePath());
argList.addElement("-classpath"); argList.addElement("-classpath");
// Jikes has no option for source-path so we argList.addElement(classpath.toString());
// will add it to classpath.
// XXX is this correct?
argList.addElement(classpath+File.pathSeparator +
srcDir.getAbsolutePath());
if (debug) { if (debug) {
argList.addElement("-g"); argList.addElement("-g");
} }
@@ -542,4 +551,41 @@ public class Javac extends MatchingTask {
throw new BuildException(msg); throw new BuildException(msg);
} }
} }

class JarFilenameFilter implements FilenameFilter {
public boolean accept(File dir,String name) {
return name.endsWith(".jar");
}
}

/**
* Emulation of extdirs feature in java >= 1.2.
* This method adds all jar archives in the given
* directories (but not in sub-directories!) to the classpath,
* so that you don't have to specify them all one by one.
* @param classpath - stringbuffer to append jar files to
*/
private void addExtdirsToClasspath(StringBuffer classpath) {
// FIXME
// Should we scan files recursively? How does
// javac handle this?

if (extdirs != null) {
StringTokenizer tok = new StringTokenizer(extdirs,
File.pathSeparator,
false);
while (tok.hasMoreTokens()) {
File dir = project.resolveFile(tok.nextToken());
String[] files = dir.list(new JarFilenameFilter());
for (int i=0 ; i < files.length ; i++) {
File f = new File(dir,files[i]);
if (f.exists() && f.isFile()) {
classpath.append(File.pathSeparator);
classpath.append(f.getAbsolutePath());
}
}
}
}
}
} }


||||||
x
 
000:0
Loading…
Cancel
Save