Browse Source

cosmetics on the <javac> family - I didn't really read the code for

the various adapters as reworking part of them is on my TODO list anyway.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272379 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
d95bfb6e60
11 changed files with 126 additions and 75 deletions
  1. +14
    -11
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  2. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java
  3. +24
    -13
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  4. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
  5. +20
    -9
      src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
  6. +7
    -3
      src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java
  7. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
  8. +13
    -7
      src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java
  9. +4
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java
  10. +30
    -24
      src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java
  11. +3
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java

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

@@ -105,6 +105,8 @@ import java.util.Vector;
* *
* @version $Revision$ * @version $Revision$
* *
* @since Ant 1.1
*
* @ant.task category="java" * @ant.task category="java"
*/ */


@@ -147,7 +149,7 @@ public class Javac extends MatchingTask {
* *
* <p>default is null</p> * <p>default is null</p>
* *
* @since 1.84, Ant 1.5
* @since Ant 1.5
*/ */
private String compiler = null; private String compiler = null;


@@ -615,8 +617,9 @@ public class Javac extends MatchingTask {
for (Enumeration enum = implementationSpecificArgs.elements(); for (Enumeration enum = implementationSpecificArgs.elements();
enum.hasMoreElements(); enum.hasMoreElements();
) { ) {
String[] curr =
((ImplementationSpecificArgument) enum.nextElement()).getParts();
ImplementationSpecificArgument arg =
((ImplementationSpecificArgument) enum.nextElement());
String[] curr = arg.getParts();
for (int i=0; i<curr.length; i++) { for (int i=0; i<curr.length; i++) {
args.addElement(curr[i]); args.addElement(curr[i]);
} }
@@ -631,11 +634,11 @@ public class Javac extends MatchingTask {
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
checkParameters(); checkParameters();
String[] list = src.list();
resetFileLists();


// scan source directories and dest directory to build up // scan source directories and dest directory to build up
// compile lists // compile lists
resetFileLists();
String[] list = src.list();
for (int i=0; i<list.length; i++) { for (int i=0; i<list.length; i++) {
File srcDir = project.resolveFile(list[i]); File srcDir = project.resolveFile(list[i]);
if (!srcDir.exists()) { if (!srcDir.exists()) {
@@ -703,7 +706,7 @@ public class Javac extends MatchingTask {
/** /**
* Choose the implementation for this particular task. * Choose the implementation for this particular task.
* *
* @since 1.84, Ant 1.5
* @since Ant 1.5
*/ */
public void setCompiler(String compiler) { public void setCompiler(String compiler) {
this.compiler = compiler; this.compiler = compiler;
@@ -715,7 +718,7 @@ public class Javac extends MatchingTask {
* <p>Defaults to the build.compiler property but can be overriden * <p>Defaults to the build.compiler property but can be overriden
* via the compiler and fork attributes.</p> * via the compiler and fork attributes.</p>
* *
* @since 1.84, Ant 1.5
* @since Ant 1.5
*/ */
public String getCompiler() { public String getCompiler() {
String compilerImpl = String compilerImpl =
@@ -740,8 +743,8 @@ public class Javac extends MatchingTask {
} }


if (compilerImpl == null) { if (compilerImpl == null) {
if (JavaEnvUtils.getJavaVersion() != Project.JAVA_1_1 &&
JavaEnvUtils.getJavaVersion() != Project.JAVA_1_2) {
if (JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_1 &&
JavaEnvUtils.getJavaVersion() != JavaEnvUtils.JAVA_1_2) {
compilerImpl = "modern"; compilerImpl = "modern";
} else { } else {
compilerImpl = "classic"; compilerImpl = "classic";
@@ -754,7 +757,7 @@ public class Javac extends MatchingTask {
* Check that all required attributes have been set and nothing * Check that all required attributes have been set and nothing
* silly has been entered. * silly has been entered.
* *
* @since 1.82, Ant 1.5
* @since Ant 1.5
*/ */
protected void checkParameters() throws BuildException { protected void checkParameters() throws BuildException {
if (src == null) { if (src == null) {
@@ -777,7 +780,7 @@ public class Javac extends MatchingTask {
/** /**
* Perform the compilation. * Perform the compilation.
* *
* @since 1.82, Ant 1.5
* @since Ant 1.5
*/ */
protected void compile() { protected void compile() {
String compilerImpl = getCompiler(); String compilerImpl = getCompiler();


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -68,6 +68,7 @@ import org.apache.tools.ant.taskdefs.Javac;
* reflection).</p> * reflection).</p>
* *
* @author Jay Dickon Glanville <a href="mailto:jayglanville@home.com">jayglanville@home.com</a> * @author Jay Dickon Glanville <a href="mailto:jayglanville@home.com">jayglanville@home.com</a>
* @since Ant 1.3
*/ */


public interface CompilerAdapter { public interface CompilerAdapter {


+ 24
- 13
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -78,6 +78,8 @@ import java.io.IOException;
* @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a> * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/ */
public abstract class DefaultCompilerAdapter implements CompilerAdapter { public abstract class DefaultCompilerAdapter implements CompilerAdapter {


@@ -162,9 +164,11 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
} }
} else { } else {
if ( includeAntRuntime ) { if ( includeAntRuntime ) {
classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
classpath.addExisting(compileClasspath
.concatSystemClasspath("last"));
} else { } else {
classpath.addExisting(compileClasspath.concatSystemClasspath("ignore"));
classpath.addExisting(compileClasspath
.concatSystemClasspath("ignore"));
} }
} }


@@ -202,19 +206,23 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
String memoryParameterPrefix = usingJava1_1 ? "-J-" : "-J-X"; String memoryParameterPrefix = usingJava1_1 ? "-J-" : "-J-X";
if (memoryInitialSize != null) { if (memoryInitialSize != null) {
if (!attributes.isForkedJavac()) { if (!attributes.isForkedJavac()) {
attributes.log("Since fork is false, ignoring memoryInitialSize setting.",
attributes.log("Since fork is false, ignoring "
+ "memoryInitialSize setting.",
Project.MSG_WARN); Project.MSG_WARN);
} else { } else {
cmd.createArgument().setValue(memoryParameterPrefix+"ms"+memoryInitialSize);
cmd.createArgument().setValue(memoryParameterPrefix
+ "ms" + memoryInitialSize);
} }
} }


if (memoryMaximumSize != null) { if (memoryMaximumSize != null) {
if (!attributes.isForkedJavac()) { if (!attributes.isForkedJavac()) {
attributes.log("Since fork is false, ignoring memoryMaximumSize setting.",
attributes.log("Since fork is false, ignoring "
+ "memoryMaximumSize setting.",
Project.MSG_WARN); Project.MSG_WARN);
} else { } else {
cmd.createArgument().setValue(memoryParameterPrefix+"mx"+memoryMaximumSize);
cmd.createArgument().setValue(memoryParameterPrefix
+ "mx" + memoryMaximumSize);
} }
} }


@@ -251,7 +259,8 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
cmd.createArgument().setPath(cp); cmd.createArgument().setPath(cp);
} else { } else {
cmd.createArgument().setPath(classpath); cmd.createArgument().setPath(classpath);
// If the buildfile specifies sourcepath="", then don't output any sourcepath.
// If the buildfile specifies sourcepath="", then don't
// output any sourcepath.
if (sourcepath.size() > 0) { if (sourcepath.size() > 0) {
cmd.createArgument().setValue("-sourcepath"); cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setPath(sourcepath); cmd.createArgument().setPath(sourcepath);
@@ -302,8 +311,8 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
} else if (Project.getJavaVersion().startsWith("1.2")) { } else if (Project.getJavaVersion().startsWith("1.2")) {
cmd.createArgument().setValue("-Xdepend"); cmd.createArgument().setValue("-Xdepend");
} else { } else {
attributes.log("depend attribute is not supported by the modern compiler",
Project.MSG_WARN);
attributes.log("depend attribute is not supported by the "
+ "modern compiler", Project.MSG_WARN);
} }
} }


@@ -413,7 +422,8 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
System.arraycopy(args, 0, commandArray, 0, firstFileName); System.arraycopy(args, 0, commandArray, 0, firstFileName);
commandArray[firstFileName] = "@" + tmpFile; commandArray[firstFileName] = "@" + tmpFile;
} catch (IOException e) { } catch (IOException e) {
throw new BuildException("Error creating temporary file", e, location);
throw new BuildException("Error creating temporary file",
e, location);
} finally { } finally {
if (out != null) { if (out != null) {
try {out.close();} catch (Throwable t) {} try {out.close();} catch (Throwable t) {}
@@ -424,9 +434,10 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
} }


try { try {
Execute exe = new Execute(new LogStreamHandler(attributes,
Project.MSG_INFO,
Project.MSG_WARN));
Execute exe = new Execute(
new LogStreamHandler(attributes,
Project.MSG_INFO,
Project.MSG_WARN));
exe.setAntRun(project); exe.setAntRun(project);
exe.setWorkingDirectory(project.getBaseDir()); exe.setWorkingDirectory(project.getBaseDir());
exe.setCommandline(commandArray); exe.setCommandline(commandArray);


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java View File

@@ -65,6 +65,7 @@ import org.apache.tools.ant.types.Path;
* This is primarily a cut-and-paste from the jikes. * This is primarily a cut-and-paste from the jikes.
* *
* @author <a href="mailto:tora@debian.org">Takashi Okamoto</a> * @author <a href="mailto:tora@debian.org">Takashi Okamoto</a>
* @since Ant 1.4
*/ */
public class Gcj extends DefaultCompilerAdapter { public class Gcj extends DefaultCompilerAdapter {


@@ -79,7 +80,8 @@ public class Gcj extends DefaultCompilerAdapter {
int firstFileName = cmd.size(); int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd); logAndAddFilesToCompile(cmd);


return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
return
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
} }


protected Commandline setupGCJCommand() { protected Commandline setupGCJCommand() {
@@ -113,7 +115,8 @@ public class Gcj extends DefaultCompilerAdapter {
cmd.createArgument().setFile(destDir); cmd.createArgument().setFile(destDir);
if(destDir.mkdirs()){ if(destDir.mkdirs()){
throw new BuildException("Can't make output directories. Maybe permission is wrong. ");
throw new BuildException("Can't make output directories. "
+ "Maybe permission is wrong. ");
}; };
} }


+ 20
- 9
src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -73,6 +73,8 @@ import java.lang.reflect.Method;
* @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a> * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/ */
public class Javac12 extends DefaultCompilerAdapter { public class Javac12 extends DefaultCompilerAdapter {


@@ -85,24 +87,33 @@ public class Javac12 extends DefaultCompilerAdapter {
// Create an instance of the compiler, redirecting output to // Create an instance of the compiler, redirecting output to
// the project log // the project log
Class c = Class.forName("sun.tools.javac.Main"); Class c = Class.forName("sun.tools.javac.Main");
Constructor cons = c.getConstructor(new Class[] { OutputStream.class, String.class });
Object compiler = cons.newInstance(new Object[] { logstr, "javac" });
Constructor cons =
c.getConstructor(new Class[] { OutputStream.class,
String.class });
Object compiler = cons.newInstance(new Object[] { logstr,
"javac" });


// Call the compile() method // Call the compile() method
Method compile = c.getMethod("compile", new Class [] { String[].class });
Boolean ok = (Boolean)compile.invoke(compiler, new Object[] {cmd.getArguments()});
Method compile = c.getMethod("compile",
new Class [] { String[].class });
Boolean ok =
(Boolean)compile.invoke(compiler,
new Object[] {cmd.getArguments()});
return ok.booleanValue(); return ok.booleanValue();
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
throw new BuildException("Cannot use classic compiler, as it is not available"+
" A common solution is to set the environment variable"+
" JAVA_HOME to your jdk directory.", location);
throw new BuildException("Cannot use classic compiler, as it is "
+ "not available. A common solution is "
+ "to set the environment variable"
+ " JAVA_HOME to your jdk directory.",
location);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex instanceof BuildException) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting classic compiler: ", ex, location);
throw new BuildException("Error starting classic compiler: ",
ex, location);
} }
} finally { } finally {
try { try {


+ 7
- 3
src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -71,6 +71,8 @@ import java.lang.reflect.Method;
* @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a> * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/ */
public class Javac13 extends DefaultCompilerAdapter { public class Javac13 extends DefaultCompilerAdapter {


@@ -90,13 +92,15 @@ public class Javac13 extends DefaultCompilerAdapter {
Method compile = c.getMethod ("compile", Method compile = c.getMethod ("compile",
new Class [] {(new String [] {}).getClass ()}); new Class [] {(new String [] {}).getClass ()});
int result = ((Integer) compile.invoke int result = ((Integer) compile.invoke
(compiler, new Object[] {cmd.getArguments()})) .intValue ();
(compiler, new Object[] {cmd.getArguments()}))
.intValue ();
return (result == MODERN_COMPILER_SUCCESS); return (result == MODERN_COMPILER_SUCCESS);
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof BuildException) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting modern compiler", ex, location);
throw new BuildException("Error starting modern compiler",
ex, location);
} }
} }
} }


+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -62,6 +62,7 @@ import org.apache.tools.ant.types.Commandline;
* Performs a compile using javac externally. * Performs a compile using javac externally.
* *
* @author Brian Deitte * @author Brian Deitte
* @since Ant 1.4
*/ */
public class JavacExternal extends DefaultCompilerAdapter { public class JavacExternal extends DefaultCompilerAdapter {


@@ -77,7 +78,8 @@ public class JavacExternal extends DefaultCompilerAdapter {
int firstFileName = cmd.size(); int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd); logAndAddFilesToCompile(cmd);


return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
return
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
} }


} }


+ 13
- 7
src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java View File

@@ -68,6 +68,7 @@ import org.apache.tools.ant.types.Commandline;
* @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a> * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @since Ant 1.3
*/ */
public class Jikes extends DefaultCompilerAdapter { public class Jikes extends DefaultCompilerAdapter {


@@ -172,10 +173,11 @@ public class Jikes extends DefaultCompilerAdapter {
* that don't exist. As this is often the case, these * that don't exist. As this is often the case, these
* warning can be pretty annoying. * warning can be pretty annoying.
*/ */
String warningsProperty = project.getProperty("build.compiler.warnings");
String warningsProperty =
project.getProperty("build.compiler.warnings");
if (warningsProperty != null) { if (warningsProperty != null) {
attributes.log("!! the build.compiler.warnings property is deprecated. !!",
Project.MSG_WARN);
attributes.log("!! the build.compiler.warnings property is "
+ "deprecated. !!", Project.MSG_WARN);
attributes.log("!! Use the nowarn attribute instead. !!", attributes.log("!! Use the nowarn attribute instead. !!",
Project.MSG_WARN); Project.MSG_WARN);
if (!Project.toBoolean(warningsProperty)) { if (!Project.toBoolean(warningsProperty)) {
@@ -194,7 +196,8 @@ public class Jikes extends DefaultCompilerAdapter {
/** /**
* Jikes can issue pedantic warnings. * Jikes can issue pedantic warnings.
*/ */
String pedanticProperty = project.getProperty("build.compiler.pedantic");
String pedanticProperty =
project.getProperty("build.compiler.pedantic");
if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) { if (pedanticProperty != null && Project.toBoolean(pedanticProperty)) {
cmd.createArgument().setValue("+P"); cmd.createArgument().setValue("+P");
} }
@@ -204,8 +207,10 @@ public class Jikes extends DefaultCompilerAdapter {
* checking", see the jikes documentation for differences * checking", see the jikes documentation for differences
* between -depend and +F. * between -depend and +F.
*/ */
String fullDependProperty = project.getProperty("build.compiler.fulldepend");
if (fullDependProperty != null && Project.toBoolean(fullDependProperty)) {
String fullDependProperty =
project.getProperty("build.compiler.fulldepend");
if (fullDependProperty != null
&& Project.toBoolean(fullDependProperty)) {
cmd.createArgument().setValue("+F"); cmd.createArgument().setValue("+F");
} }


@@ -219,7 +224,8 @@ public class Jikes extends DefaultCompilerAdapter {
int firstFileName = cmd.size(); int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd); logAndAddFilesToCompile(cmd);


return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
return
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
} }






+ 4
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -68,6 +68,7 @@ import org.apache.tools.ant.types.Commandline;
* @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a> * @author Robin Green <a href="mailto:greenrd@hotmail.com">greenrd@hotmail.com</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @since Ant 1.3
*/ */
public class Jvc extends DefaultCompilerAdapter { public class Jvc extends DefaultCompilerAdapter {


@@ -135,6 +136,7 @@ public class Jvc extends DefaultCompilerAdapter {
int firstFileName = cmd.size(); int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd); logAndAddFilesToCompile(cmd);


return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
return
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
} }
} }

+ 30
- 24
src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 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
@@ -69,7 +69,9 @@ import java.lang.reflect.Method;
* This is primarily a cut-and-paste from Jikes.java and * This is primarily a cut-and-paste from Jikes.java and
* DefaultCompilerAdapter. * DefaultCompilerAdapter.
* *
* @author <a href="mailto:tora@debian.org">Takashi Okamoto</a> + */
* @author <a href="mailto:tora@debian.org">Takashi Okamoto</a>
* @since Ant 1.4
*/
public class Kjc extends DefaultCompilerAdapter { public class Kjc extends DefaultCompilerAdapter {


public boolean execute() throws BuildException { public boolean execute() throws BuildException {
@@ -82,20 +84,24 @@ public class Kjc extends DefaultCompilerAdapter {
// Call the compile() method // Call the compile() method
Method compile = c.getMethod("compile", Method compile = c.getMethod("compile",
new Class [] { String [].class }); new Class [] { String [].class });
Boolean ok = (Boolean)compile.invoke(null,
new Object[] {cmd.getArguments()});
Boolean ok =
(Boolean)compile.invoke(null,
new Object[] {cmd.getArguments()});
return ok.booleanValue(); return ok.booleanValue();
} }
catch (ClassNotFoundException ex) { catch (ClassNotFoundException ex) {
throw new BuildException("Cannot use kjc compiler, as it is not available"+
" A common solution is to set the environment variable"+
" CLASSPATH to your kjc archive (kjc.jar).", location);
throw new BuildException("Cannot use kjc compiler, as it is not "
+ "available. A common solution is to "
+ "set the environment variable CLASSPATH "
+ "to your kjc archive (kjc.jar).",
location);
} }
catch (Exception ex) { catch (Exception ex) {
if (ex instanceof BuildException) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting kjc compiler: ", ex, location);
throw new BuildException("Error starting kjc compiler: ",
ex, location);
} }
} }
} }
@@ -121,33 +127,33 @@ public class Kjc extends DefaultCompilerAdapter {
// generate the clsspath // generate the clsspath
cmd.createArgument().setValue("-classpath"); cmd.createArgument().setValue("-classpath");


Path cp = new Path(project);
Path cp = new Path(project);


// kjc don't have bootclasspath option.
if (bootclasspath != null) {
// kjc don't have bootclasspath option.
if (bootclasspath != null) {
cp.append(bootclasspath); cp.append(bootclasspath);
}
if (extdirs != null) {
}
if (extdirs != null) {
cp.addExtdirs(extdirs); cp.addExtdirs(extdirs);
}
cp.append(classpath);
cp.append(src);
cmd.createArgument().setPath(cp);
// kjc-1.5A doesn't support -encoding option now.
}
cp.append(classpath);
cp.append(src);
cmd.createArgument().setPath(cp);
// kjc-1.5A doesn't support -encoding option now.
// but it will be supported near the feature. // but it will be supported near the feature.
if (encoding != null) { if (encoding != null) {
cmd.createArgument().setValue("-encoding"); cmd.createArgument().setValue("-encoding");
cmd.createArgument().setValue(encoding); cmd.createArgument().setValue(encoding);
} }
if (debug) { if (debug) {
cmd.createArgument().setValue("-g"); cmd.createArgument().setValue("-g");
} }
if (optimize) { if (optimize) {
cmd.createArgument().setValue("-O2"); cmd.createArgument().setValue("-O2");
} }


+ 3
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java View File

@@ -63,6 +63,7 @@ import org.apache.tools.ant.types.Commandline;
* Uses the defaults for DefaultCompilerAdapter * Uses the defaults for DefaultCompilerAdapter
* *
* @author <a href="mailto:don@bea.com">Don Ferguson</a> * @author <a href="mailto:don@bea.com">Don Ferguson</a>
* @since Ant 1.4
*/ */
public class Sj extends DefaultCompilerAdapter { public class Sj extends DefaultCompilerAdapter {


@@ -77,7 +78,8 @@ public class Sj extends DefaultCompilerAdapter {


int firstFileName = cmd.size() - compileList.length; int firstFileName = cmd.size() - compileList.length;


return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
return
executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
} }






Loading…
Cancel
Save