From d8169cab92f4ce5ecf09286db0c57c752fcc5874 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 8 Feb 2002 15:02:17 +0000 Subject: [PATCH] split execute in to make it easier to extend. Sugested by: Misha Dmitriev git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271223 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Javac.java | 102 +++++++++++------- 1 file changed, 61 insertions(+), 41 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 9e4026266..cfeba0f4f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -574,19 +574,8 @@ public class Javac extends MatchingTask { * Executes the task. */ public void execute() throws BuildException { - // first off, make sure that we've got a srcdir - - if (src == null) { - throw new BuildException("srcdir attribute must be set!", location); - } - String [] list = src.list(); - if (list.length == 0) { - throw new BuildException("srcdir attribute must be set!", location); - } - - if (destDir != null && !destDir.isDirectory()) { - throw new BuildException("destination directory \"" + destDir + "\" does not exist or is not a directory", location); - } + checkParameters(); + String[] list = src.list(); // scan source directories and dest directory to build up // compile lists @@ -594,42 +583,18 @@ public class Javac extends MatchingTask { for (int i=0; i 0) { - - CompilerAdapter adapter = CompilerAdapterFactory.getCompiler( - compiler, this ); - log("Compiling " + compileList.length + - " source file" - + (compileList.length == 1 ? "" : "s") - + (destDir != null ? " to " + destDir : "")); - - // now we need to populate the compiler adapter - adapter.setJavac( this ); - - // finally, lets execute the compiler!! - if (!adapter.execute()) { - if (failOnError) { - throw new BuildException(FAIL_MSG, location); - } - else { - log(FAIL_MSG, Project.MSG_ERR); - } - } - } + compile(); } /** @@ -736,6 +701,61 @@ public class Javac extends MatchingTask { return compiler; } + /** + * Check that all required attributes have been set and nothing + * silly has been entered. + * + * @since 1.82, Ant 1.5 + */ + protected void checkParameters() throws BuildException { + if (src == null) { + throw new BuildException("srcdir attribute must be set!", + location); + } + if (src.size() == 0) { + throw new BuildException("srcdir attribute must be set!", + location); + } + + if (destDir != null && !destDir.isDirectory()) { + throw new BuildException("destination directory \"" + + destDir + + "\" does not exist " + + "or is not a directory", location); + } + } + + /** + * Perform the compilation. + * + * @since 1.82, Ant 1.5 + */ + protected void compile() { + String compiler = determineCompiler(); + + if (compileList.length > 0) { + log("Compiling " + compileList.length + + " source file" + + (compileList.length == 1 ? "" : "s") + + (destDir != null ? " to " + destDir : "")); + + CompilerAdapter adapter = + CompilerAdapterFactory.getCompiler(compiler, this); + + // now we need to populate the compiler adapter + adapter.setJavac(this); + + // finally, lets execute the compiler!! + if (!adapter.execute()) { + if (failOnError) { + throw new BuildException(FAIL_MSG, location); + } else { + log(FAIL_MSG, Project.MSG_ERR); + } + } + } + } + /** * Adds an "implementation" attribute to Commandline$Attribute * used to filter command line attributes based on the current