bodewig     02/02/08 07:02:17

  Modified:    src/main/org/apache/tools/ant/taskdefs Javac.java
  Log:
  split execute in <javac> to make it easier to extend.
  
  Sugested by:  Misha Dmitriev <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.82      +61 -41    
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.81
  retrieving revision 1.82
  diff -u -r1.81 -r1.82
  --- Javac.java        26 Jan 2002 19:16:06 -0000      1.81
  +++ Javac.java        8 Feb 2002 15:02:17 -0000       1.82
  @@ -574,19 +574,8 @@
        * 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 @@
           for (int i=0; i<list.length; i++) {
               File srcDir = project.resolveFile(list[i]);
               if (!srcDir.exists()) {
  -                throw new BuildException("srcdir \"" + srcDir.getPath() + 
"\" does not exist!", location);
  +                throw new BuildException("srcdir \"" 
  +                                         + srcDir.getPath() 
  +                                         + "\" does not exist!", location);
               }
   
               DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  -
               String[] files = ds.getIncludedFiles();
   
               scanDir(srcDir, destDir != null ? destDir : srcDir, files);
           }
   
  -        // compile the source files
  -
  -        String compiler = determineCompiler();
  -
  -        if (compileList.length > 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();
       }
   
       /**
  @@ -734,6 +699,61 @@
               }
           }
           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);
  +                }
  +            }
  +        }
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to