You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/11/05 14:13:39 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers JavacExternal.java

bodewig     01/11/05 05:13:39

  Modified:    docs/manual/CoreTasks javac.html
               src/main/org/apache/tools/ant/taskdefs Javac.java
               src/main/org/apache/tools/ant/taskdefs/compilers
                        JavacExternal.java
  Log:
  Make name of the javac executable configurable in fork mode.
  
  PR: 4119
  
  Revision  Changes    Path
  1.15      +25 -2     jakarta-ant/docs/manual/CoreTasks/javac.html
  
  Index: javac.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/javac.html,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- javac.html	2001/10/30 10:05:34	1.14
  +++ javac.html	2001/11/05 13:13:39	1.15
  @@ -191,8 +191,11 @@
     </tr>
     <tr>
       <td valign="top">fork</td> 
  -    <td valign="top">whether to execute Javac using the JDK compiler externally;
  -    defaults to <code>no</code>.</td>
  +    <td valign="top">whether to execute Javac using the JDK compiler
  +      externally; defaults to <code>no</code>.  You can also give a
  +      complete path to the javac executable to use instead of
  +      <code>yes</code>, which would run the compiler of the Java
  +      vesrion that is currently running Ant.</td>
       <td align="center" valign="top">No</td>
     </tr>  
     <tr>
  @@ -251,6 +254,26 @@
   directory, and stores
   the <code>.class</code> files in the <code>${build}</code> directory.
   The classpath used contains <code>xyz.jar</code>, and debug information is on.</p>
  +
  +<pre>  &lt;javac srcdir=&quot;${src}&quot;
  +         destdir=&quot;${build}&quot;
  +         fork=&quot;true&quot;
  +  /&gt;</pre>
  +<p>compiles all <code>.java</code> files under the <code>${src}</code>
  +directory, and stores the <code>.class</code> files in the
  +<code>${build}</code> directory.  This will fork off the javac
  +compiler using the default javac executable.</p>
  +
  +<pre>  &lt;javac srcdir=&quot;${src}&quot;
  +         destdir=&quot;${build}&quot;
  +         fork=&quot;java$$javac.exe&quot;
  +  /&gt;</pre>
  +<p>compiles all <code>.java</code> files under the <code>${src}</code>
  +directory, and stores the <code>.class</code> files in the
  +<code>${build}</code> directory.  This will fork off the javac
  +compiler using the executable named <code>java$javac.exe</code>.  Note
  +that the <code>$</code> sign needs to be escaped by a second one.</p>
  +
   <pre>  &lt;javac srcdir=&quot;${src}&quot;
            destdir=&quot;${build}&quot;
            includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  
  
  
  1.72      +48 -6     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.71
  retrieving revision 1.72
  diff -u -r1.71 -r1.72
  --- Javac.java	2001/10/28 21:26:29	1.71
  +++ Javac.java	2001/11/05 13:13:39	1.72
  @@ -63,6 +63,7 @@
   import org.apache.tools.ant.util.SourceFileScanner;
   import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter;
   import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory;
  +import org.apache.tools.ant.taskdefs.condition.Os;
   
   import java.io.File;
   
  @@ -118,7 +119,8 @@
       private Path extdirs;
       private boolean includeAntRuntime = true;
       private boolean includeJavaRuntime = false;
  -    private boolean fork = false;
  +    private String fork = "false";
  +    private String forkedExecutable = null;
       private boolean nowarn = false;
       private String memoryInitialSize;
       private String memoryMaximumSize;
  @@ -452,20 +454,40 @@
   
       /**
        * Sets whether to fork the javac compiler.
  +     *
  +     * @param f "true|false|on|off|yes|no" or the name of the javac
  +     * executable.
        */
  -    public void setFork(boolean fork)
  -    {
  -        this.fork = fork;
  +    public void setFork(String f) {
  +        if (f.equalsIgnoreCase("on")
  +            || f.equalsIgnoreCase("true")
  +            || f.equalsIgnoreCase("yes")) {
  +            fork = "true";
  +            forkedExecutable = getSystemJavac();
  +        } else if (f.equalsIgnoreCase("off")
  +                   || f.equalsIgnoreCase("false")
  +                   || f.equalsIgnoreCase("no")) {
  +            fork = "false";
  +        } else {
  +            fork = "true";
  +            forkedExecutable = f;
  +        }
       }
   
       /**
        * Is this a forked invocation of JDK's javac?
        */
       public boolean isForkedJavac() {
  -        return fork || 
  +        return !"false".equals(fork) || 
               "extJavac".equals(project.getProperty("build.compiler"));
       }
   
  +    /**
  +     * The name of the javac executable to use in fork-mode.
  +     */
  +    public String getJavacExecutable() {
  +        return forkedExecutable;
  +    }
   
       /**
        * Sets whether the -nowarn option should be used.
  @@ -519,7 +541,7 @@
   
           String compiler = project.getProperty("build.compiler");
   
  -        if (fork) {
  +        if (!"false".equals(fork)) {
               if (compiler != null) {
                   if (isJdkCompiler(compiler)) {
                       log("Since fork is true, ignoring build.compiler setting.",
  @@ -611,4 +633,24 @@
               "javac1.4".equals(compiler);
       }
   
  +    protected String getSystemJavac() {
  +	// This is the most common extension case - exe for windows and OS/2, 
  +        // nothing for *nix.
  +	String extension =  Os.isFamily("dos") ? ".exe" : "";
  +
  +	// Look for java in the java.home/../bin directory.  Unfortunately
  +	// on Windows java.home doesn't always refer to the correct location, 
  +	// so we need to fall back to assuming java is somewhere on the
  +	// PATH.
  +	java.io.File jExecutable = 
  +            new java.io.File(System.getProperty("java.home") +
  +                             "/../bin/javac" + extension );
  +
  +	if (jExecutable.exists() && !Os.isFamily("netware")) {
  +	    return jExecutable.getAbsolutePath();
  +	} else {
  +	    return "javac";
  +	}
  +    }
  +    
   }
  
  
  
  1.5       +1 -22     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java
  
  Index: JavacExternal.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/JavacExternal.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- JavacExternal.java	2001/11/02 15:18:47	1.4
  +++ JavacExternal.java	2001/11/05 13:13:39	1.5
  @@ -56,7 +56,6 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
  -import org.apache.tools.ant.taskdefs.condition.Os;
   import org.apache.tools.ant.types.Commandline;
   
   /**
  @@ -73,7 +72,7 @@
           attributes.log("Using external javac compiler", Project.MSG_VERBOSE);
   
           Commandline cmd = new Commandline();
  -        cmd.setExecutable(getJavacExecutableName());
  +        cmd.setExecutable(getJavac().getJavacExecutable());
           setupModernJavacCommandlineSwitches(cmd);
           int firstFileName = cmd.size();
           logAndAddFilesToCompile(cmd);
  @@ -81,25 +80,5 @@
           return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0;
       }
   
  -    private String getJavacExecutableName() {
  -	// This is the most common extension case - exe for windows and OS/2, 
  -        // nothing for *nix.
  -	String extension =  Os.isFamily("dos") ? ".exe" : "";
  -
  -	// Look for java in the java.home/../bin directory.  Unfortunately
  -	// on Windows java.home doesn't always refer to the correct location, 
  -	// so we need to fall back to assuming java is somewhere on the
  -	// PATH.
  -	java.io.File jExecutable = 
  -            new java.io.File(System.getProperty("java.home") +
  -                             "/../bin/javac" + extension );
  -
  -	if (jExecutable.exists() && !Os.isFamily("netware")) {
  -	    return jExecutable.getAbsolutePath();
  -	} else {
  -	    return "javac";
  -	}
  -    }
  -    
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>