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) {
try {
return (ClassLoader.getSystemResource(resource) != null);
} catch (Exception e) {
return false;
}
return (ClassLoader.getSystemResource(resource) != null);
}

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++) {
switch (indata[k]) {
case ' ':
case (byte)' ':
// advance column
if (addtab == 0) outdata[o++]=(byte)' ';
col++;
break;

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

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

case '\n':
case (byte)'\n':
// start a new line (optional CR followed by LF)
if (addcr == +1) outdata[o++]=(byte)'\r';
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 {
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();

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

if (debug) {
argList.addElement("-g");
}
@@ -542,4 +551,41 @@ public class Javac extends MatchingTask {
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());
}
}
}
}
}
}


Loading…
Cancel
Save