You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by du...@hyperreal.org on 1999/11/01 05:54:28 UTC

cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs JavacOutputStream.java Javac.java

duncan      99/10/31 20:54:27

  Modified:    .        ant.jar
               ant      build.xml
               ant/src/main/org/apache/tools/ant Main.java
               ant/src/main/org/apache/tools/ant/taskdefs Javac.java
  Added:       ant/src/main/org/apache/tools/ant/taskdefs
                        JavacOutputStream.java
  Log:
  Updated to properly exit javac tasks when there is an error during compilation.
  
  Revision  Changes    Path
  1.12      +56 -57    jakarta-tools/ant.jar
  
  	<<Binary file>>
  
  
  1.2       +0 -4      jakarta-tools/ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/build.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- build.xml	1999/10/09 00:05:57	1.1
  +++ build.xml	1999/11/01 04:54:25	1.2
  @@ -21,10 +21,6 @@
        manifest="src/etc/manifest"/>
     </target>
   
  -  <target name="foo" depends="main">
  -    <jar jarfile="foo.jar" basedir="build" items="org/apache/tools/ant/taskdefs"/>
  -  </target>
  -  
     <target name="clean">
       <deltree dir="build"/>
     </target>
  
  
  
  1.4       +3 -3      jakarta-tools/ant/src/main/org/apache/tools/ant/Main.java
  
  Index: Main.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Main.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Main.java	1999/10/31 23:06:36	1.3
  +++ Main.java	1999/11/01 04:54:26	1.4
  @@ -116,9 +116,9 @@
   	try {
   	    ProjectHelper.configureProject(project, buildFile);
   	} catch (BuildException be) {
  -	    String msg = "STOP: ";
  +	    String msg = "BUILD CONFIG ERROR: ";
   	    System.out.println(msg + be.getMessage());
  -	    return;
  +	    System.exit(1);
   	}
   
           // cycle through command line defined properties after the
  @@ -143,7 +143,7 @@
   	try {
   	    project.executeTarget(target);
   	} catch (BuildException be) {
  -	    String msg = "STOP: ";
  +	    String msg = "BUILD FATAL ERROR: ";
   	    System.out.println(msg + be.getMessage());
   	    return;
   	}
  
  
  
  1.8       +135 -12   jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Javac.java	1999/10/22 19:54:46	1.7
  +++ Javac.java	1999/11/01 04:54:26	1.8
  @@ -11,8 +11,27 @@
   import java.util.Vector;
   
   /**
  + * Task to compile Java source files. This task can take the following
  + * arguments:
  + * <ul>
  + * <li>sourcedir
  + * <li>destdir
  + * <li>deprecation
  + * <li>classpath
  + * <li>bootclasspath
  + * <li>extdirs
  + * <li>optimize
  + * <li>debug
  + * <li>target
  + * </ul>
  + * Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
  + * <p>
  + * When this task executes, it will recursively scan the sourcedir and
  + * destdir looking for Java source files to compile. This task makes its
  + * compile decision based on timestamp. Any other file in the
  + * sourcedir will be copied to the destdir allowing support files to be
  + * located properly in the classpath.
    *
  - * 
    * @author duncan@x180.com
    */
   
  @@ -24,39 +43,110 @@
       private boolean debug = false;
       private boolean optimize = false;
       private boolean deprecation = true;
  -    private String target = "1.1";
  +    private String target;
       private String bootclasspath;
       private String extdirs;
   
       private Vector compileList = new Vector();
       private Hashtable filecopyList = new Hashtable();
   
  +    /**
  +     * Set the source dir to find the source Java files.
  +     */
  +    
       public void setSrcdir(String srcDirName) {
   	srcDir = project.resolveFile(srcDirName);
       }
   
  +    /**
  +     * Set the destination directory into which the Java source
  +     * files should be compiled.
  +     */
  +    
       public void setDestdir(String destDirName) {
   	destDir = project.resolveFile(destDirName);
       }
   
  +    /**
  +     * Set the classpath to be used for this compilation.
  +     */
  +    
       public void setClasspath(String classpath) {
  -	compileClasspath = classpath;
  +
  +        // XXX
  +        // need to translate ':' and '/' chars to native
  +        
  +        compileClasspath = classpath;
  +    }
  +
  +    /**
  +     * Sets the bootclasspath that will be used to compile the classes
  +     * against.
  +     */
  +    
  +    public void setBootclasspath(String bootclasspath) {
  +
  +        // XXX
  +        // need to translate ':' and '/' chars to native
  +        
  +        this.bootclasspath = bootclasspath;
       }
   
  +    /**
  +     * Sets the extension directories that will be used during the
  +     * compilation.
  +     */
  +    
  +    public void setExtdirs(String extdirs) {
  +
  +        // XXX
  +        // need to translate ':' and '/' chars to native
  +        
  +        this.extdirs = extdirs;
  +    }
  +
  +    
  +    /**
  +     * Set the deprecation flag. Valid strings are "on", "off", "true", and
  +     * "false".
  +     */
  +    
       public void setDeprecation(String deprecation) {
  -        if (deprecation.equalsIgnoreCase("on") || deprecation.equalsIgnoreCase("true"))
  +        if (deprecation.equalsIgnoreCase("on") ||
  +            deprecation.equalsIgnoreCase("true")) {
               this.deprecation = true;
  -        else if (deprecation.equalsIgnoreCase("off") || deprecation.equalsIgnoreCase("false"))
  +        } else {
               this.deprecation = false;
  +        }
       }
       
  -
  +    
  +    /**
  +     * Set the debug flag. Valid strings are "on", "off", "true", and "false".
  +     */
  +    
       public void setDebug(String debugString) {
  -	if (debugString.equalsIgnoreCase("on")) {
  +	if (debugString.equalsIgnoreCase("on") ||
  +            debugString.equalsIgnoreCase("true")) {
   	    debug = true;
  -	}
  +	} else {
  +            debug = false;
  +        }
       }
   
  +    /**
  +     * Sets the target VM that the classes will be compiled for. Valid
  +     * strings are "1.1", "1.2", and "1.3".
  +     */
  +    
  +    public void setTarget(String target) {
  +        this.target = target;
  +    }
  +
  +    /**
  +     * Executes the task.
  +     */
  +    
       public void execute() throws BuildException {
   
   	// first off, make sure that we've got a srcdir and destdir
  @@ -118,6 +208,11 @@
   	}
       }
   
  +    /**
  +     * Scans the directory looking for source files to be compiled and
  +     * support files to be copied.
  +     */
  +    
       private void scanDir(File srcDir, File destDir) {
   
   	String[] list = srcDir.list(new DesirableFilter());
  @@ -149,6 +244,13 @@
   	}
       }
   
  +    /**
  +     * Builds the compilation classpath.
  +     */
  +
  +    // XXX
  +    // we need a way to not use the current classpath.
  +    
       private String getCompileClasspath() {
   	StringBuffer classpath = new StringBuffer();
   
  @@ -178,6 +280,11 @@
   	return classpath.toString();
       }
       
  +
  +    /**
  +     * Peforms a copmile using the classic compiler that shipped with
  +     * JDK 1.1 and 1.2.
  +     */
       
       private void doClassicCompile() throws BuildException {
   	project.log("Using classic compiler", project.MSG_VERBOSE);
  @@ -198,8 +305,10 @@
   	    argList.addElement(classpath);
   	    argList.addElement("-sourcepath");
   	    argList.addElement(srcDir.getAbsolutePath());
  -	    argList.addElement("-target");
  -	    argList.addElement(target);
  +            if (target != null) {
  +                argList.addElement("-target");
  +                argList.addElement(target);
  +            }
   	}
   	if (debug) {
   	    argList.addElement("-g");
  @@ -244,16 +353,30 @@
   
   	// XXX
   	// provide the compiler a different message sink - namely our own
  -	
  +
  +        JavacOutputStream jos = new JavacOutputStream(project);
  +        
   	sun.tools.javac.Main compiler =
  -	    new sun.tools.javac.Main(System.out, "javac");
  +	    new sun.tools.javac.Main(jos, "javac");
   	compiler.compile(args);
  +        if (jos.getErrorFlag()) {
  +            String msg = "Compile failed, messages should have been provided.";
  +            throw new BuildException(msg);
  +        }
       } 
   
  +    /**
  +     * Performs a compile using the newer compiler that ships with JDK 1.3
  +     */
  +    
       private void doModernCompile() throws BuildException {
   	project.log("Performing a Modern Compile");
       }
   
  +    /**
  +     * Performs a compile using the Jikes compile.
  +     */
  +    
       private void doJikesCompile() throws BuildException {
   	project.log("Performing a Jikes COmpile");
       }
  
  
  
  1.1                  jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/JavacOutputStream.java
  
  Index: JavacOutputStream.java
  ===================================================================
  /*
   * $Id: JavacOutputStream.java,v 1.1 1999/11/01 04:54:27 duncan Exp $
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  package org.apache.tools.ant.taskdefs;
  
  import org.apache.tools.ant.*;
  import java.io.*;
  
  /**
   * Serves as an output stream to Javac. This let's us print messages
   * out to the project and detect whether or not Javac had an error
   * while compiling.
   *
   * @author James Duncan Davidson (duncan@x180.com)
   */
  
  class JavacOutputStream extends OutputStream {
  
      private Project project;
      private StringBuffer line;
      private boolean errorFlag = false;
  
      /**
       * Constructs a new JavacOutputStream with the given project
       * as the output source for messages.
       */
      
      JavacOutputStream(Project project) {
          this.project = project;
          line = new StringBuffer();
      }
  
      /**
       * Write a character to the output stream. This method looks
       * to make sure that there isn't an error being reported and
       * will flush each line of input out to the project's log stream.
       */
      
      public void write(int c) throws IOException {
          char cc = (char)c;
          if (cc == '\r' || cc == '\n') {
              // line feed
              if (line.length() > 0) {
                  processLine();
              }
          } else {
              line.append(cc);
          }
      }
  
      /**
       * Processes a line of input and determines if an error occured.
       */
      
      private void processLine() {
          String s = line.toString();
          if (s.indexOf("error") > -1) {
              errorFlag = true;
          }
          project.log(s);
          line = new StringBuffer();
      }
  
      /**
       * Returns the error status of the compile. If no errors occured,
       * this method will return false, else this method will return true.
       */
      
      boolean getErrorFlag() {
          return errorFlag;
      }
  }