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$
*
* @since Ant 1.1
*
* @ant.task category="java"
*/

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

@@ -615,8 +617,9 @@ public class Javac extends MatchingTask {
for (Enumeration enum = implementationSpecificArgs.elements();
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++) {
args.addElement(curr[i]);
}
@@ -631,11 +634,11 @@ public class Javac extends MatchingTask {
*/
public void execute() throws BuildException {
checkParameters();
String[] list = src.list();
resetFileLists();

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

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";
} else {
compilerImpl = "classic";
@@ -754,7 +757,7 @@ public class Javac extends MatchingTask {
* Check that all required attributes have been set and nothing
* silly has been entered.
*
* @since 1.82, Ant 1.5
* @since Ant 1.5
*/
protected void checkParameters() throws BuildException {
if (src == null) {
@@ -777,7 +780,7 @@ public class Javac extends MatchingTask {
/**
* Perform the compilation.
*
* @since 1.82, Ant 1.5
* @since Ant 1.5
*/
protected void compile() {
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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,7 @@ import org.apache.tools.ant.taskdefs.Javac;
* reflection).</p>
*
* @author Jay Dickon Glanville <a href="mailto:jayglanville@home.com">jayglanville@home.com</a>
* @since Ant 1.3
*/

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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/
public abstract class DefaultCompilerAdapter implements CompilerAdapter {

@@ -162,9 +164,11 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
}
} else {
if ( includeAntRuntime ) {
classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
classpath.addExisting(compileClasspath
.concatSystemClasspath("last"));
} 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";
if (memoryInitialSize != null) {
if (!attributes.isForkedJavac()) {
attributes.log("Since fork is false, ignoring memoryInitialSize setting.",
attributes.log("Since fork is false, ignoring "
+ "memoryInitialSize setting.",
Project.MSG_WARN);
} else {
cmd.createArgument().setValue(memoryParameterPrefix+"ms"+memoryInitialSize);
cmd.createArgument().setValue(memoryParameterPrefix
+ "ms" + memoryInitialSize);
}
}

if (memoryMaximumSize != null) {
if (!attributes.isForkedJavac()) {
attributes.log("Since fork is false, ignoring memoryMaximumSize setting.",
attributes.log("Since fork is false, ignoring "
+ "memoryMaximumSize setting.",
Project.MSG_WARN);
} 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);
} else {
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) {
cmd.createArgument().setValue("-sourcepath");
cmd.createArgument().setPath(sourcepath);
@@ -302,8 +311,8 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
} else if (Project.getJavaVersion().startsWith("1.2")) {
cmd.createArgument().setValue("-Xdepend");
} 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);
commandArray[firstFileName] = "@" + tmpFile;
} catch (IOException e) {
throw new BuildException("Error creating temporary file", e, location);
throw new BuildException("Error creating temporary file",
e, location);
} finally {
if (out != null) {
try {out.close();} catch (Throwable t) {}
@@ -424,9 +434,10 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
}

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.setWorkingDirectory(project.getBaseDir());
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.
*
* @author <a href="mailto:tora@debian.org">Takashi Okamoto</a>
* @since Ant 1.4
*/
public class Gcj extends DefaultCompilerAdapter {

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

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

protected Commandline setupGCJCommand() {
@@ -113,7 +115,8 @@ public class Gcj extends DefaultCompilerAdapter {
cmd.createArgument().setFile(destDir);
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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* 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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/
public class Javac12 extends DefaultCompilerAdapter {

@@ -85,24 +87,33 @@ public class Javac12 extends DefaultCompilerAdapter {
// Create an instance of the compiler, redirecting output to
// the project log
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
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();
}
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) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
} else {
throw new BuildException("Error starting classic compiler: ", ex, location);
throw new BuildException("Error starting classic compiler: ",
ex, location);
}
} finally {
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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* 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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
*
* @since Ant 1.3
*/
public class Javac13 extends DefaultCompilerAdapter {

@@ -90,13 +92,15 @@ public class Javac13 extends DefaultCompilerAdapter {
Method compile = c.getMethod ("compile",
new Class [] {(new String [] {}).getClass ()});
int result = ((Integer) compile.invoke
(compiler, new Object[] {cmd.getArguments()})) .intValue ();
(compiler, new Object[] {cmd.getArguments()}))
.intValue ();
return (result == MODERN_COMPILER_SUCCESS);
} catch (Exception ex) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
} 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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* 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.
*
* @author Brian Deitte
* @since Ant 1.4
*/
public class JavacExternal extends DefaultCompilerAdapter {

@@ -77,7 +78,8 @@ public class JavacExternal extends DefaultCompilerAdapter {
int firstFileName = cmd.size();
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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @since Ant 1.3
*/
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
* warning can be pretty annoying.
*/
String warningsProperty = project.getProperty("build.compiler.warnings");
String warningsProperty =
project.getProperty("build.compiler.warnings");
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. !!",
Project.MSG_WARN);
if (!Project.toBoolean(warningsProperty)) {
@@ -194,7 +196,8 @@ public class Jikes extends DefaultCompilerAdapter {
/**
* 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)) {
cmd.createArgument().setValue("+P");
}
@@ -204,8 +207,10 @@ public class Jikes extends DefaultCompilerAdapter {
* checking", see the jikes documentation for differences
* 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");
}

@@ -219,7 +224,8 @@ public class Jikes extends DefaultCompilerAdapter {
int firstFileName = cmd.size();
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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* 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 <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @since Ant 1.3
*/
public class Jvc extends DefaultCompilerAdapter {

@@ -135,6 +136,7 @@ public class Jvc extends DefaultCompilerAdapter {
int firstFileName = cmd.size();
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
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* 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
* 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 boolean execute() throws BuildException {
@@ -82,20 +84,24 @@ public class Kjc extends DefaultCompilerAdapter {
// Call the compile() method
Method compile = c.getMethod("compile",
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();
}
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) {
if (ex instanceof BuildException) {
throw (BuildException) ex;
} 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
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);
}
if (extdirs != null) {
}
if (extdirs != null) {
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.
if (encoding != null) {
cmd.createArgument().setValue("-encoding");
cmd.createArgument().setValue(encoding);
}
if (debug) {
cmd.createArgument().setValue("-g");
}
if (optimize) {
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
*
* @author <a href="mailto:don@bea.com">Don Ferguson</a>
* @since Ant 1.4
*/
public class Sj extends DefaultCompilerAdapter {

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

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

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




Loading…
Cancel
Save