From d95bfb6e605b1eefc16889b9dfdf081072c82e51 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 11 Apr 2002 15:20:33 +0000 Subject: [PATCH] cosmetics on the 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 --- .../org/apache/tools/ant/taskdefs/Javac.java | 25 +++++---- .../taskdefs/compilers/CompilerAdapter.java | 3 +- .../compilers/DefaultCompilerAdapter.java | 37 ++++++++----- .../tools/ant/taskdefs/compilers/Gcj.java | 7 ++- .../tools/ant/taskdefs/compilers/Javac12.java | 29 ++++++---- .../tools/ant/taskdefs/compilers/Javac13.java | 10 ++-- .../ant/taskdefs/compilers/JavacExternal.java | 6 ++- .../tools/ant/taskdefs/compilers/Jikes.java | 20 ++++--- .../tools/ant/taskdefs/compilers/Jvc.java | 6 ++- .../tools/ant/taskdefs/compilers/Kjc.java | 54 ++++++++++--------- .../tools/ant/taskdefs/compilers/Sj.java | 4 +- 11 files changed, 126 insertions(+), 75 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 79a089fba..1f07794fd 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -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 { * *

default is null

* - * @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; iDefaults to the build.compiler property but can be overriden * via the compiler and fork attributes.

* - * @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(); diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java index 8e6d8e0c5..4f1466580 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/CompilerAdapter.java @@ -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).

* * @author Jay Dickon Glanville jayglanville@home.com + * @since Ant 1.3 */ public interface CompilerAdapter { diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index d9e83f318..99ece8899 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -78,6 +78,8 @@ import java.io.IOException; * @author Robin Green greenrd@hotmail.com * @author Stefan Bodewig * @author J D Glanville + * + * @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); diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java index d188b2435..4a8040cf9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java @@ -65,6 +65,7 @@ import org.apache.tools.ant.types.Path; * This is primarily a cut-and-paste from the jikes. * * @author Takashi Okamoto + * @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. "); }; } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java index b99bbd216..218ba6652 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java @@ -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 greenrd@hotmail.com * @author Stefan Bodewig * @author J D Glanville + * + * @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 { diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java index 6fab1e5bc..965c9b115 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac13.java @@ -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 greenrd@hotmail.com * @author Stefan Bodewig * @author J D Glanville + * + * @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); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java index 49d8a5c36..66cc65194 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java @@ -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; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java index e8d1df1c3..1786e0847 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java @@ -68,6 +68,7 @@ import org.apache.tools.ant.types.Commandline; * @author Robin Green greenrd@hotmail.com * @author Stefan Bodewig * @author J D Glanville + * @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; } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java index 667a668ef..6c4824bc6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java @@ -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 greenrd@hotmail.com * @author Stefan Bodewig * @author J D Glanville + * @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; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java index 8a9fb535c..c3ef6db11 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java @@ -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 Takashi Okamoto + */ + * @author Takashi Okamoto + * @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"); } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java index fa53fde09..76cb4b39b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Sj.java @@ -63,6 +63,7 @@ import org.apache.tools.ant.types.Commandline; * Uses the defaults for DefaultCompilerAdapter * * @author Don Ferguson + * @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; }