From: Takashi Okamoto <[email protected]>
To: [email protected]
Subject: [PATCH] for multiple rmic compilers (RE: [PATCH] Rmic.java for Kaffe)
In-Reply-To: In your message of "Thu, 8 Mar 2001 14:27:37 +1100"
	<[email protected]>
References: <87wva17y5v.wl@piccolo>
	<[email protected]>
User-Agent: Wanderlust/2.2.15 (More Than Words) EMIKO/1.13.9 (Euglena tripteris) FLIM/1.13.2 (Kasanui) APEL/10.2 Emacs/20.7 (i386-debian-linux-gnu) MULE/4.1 (AOI)
MIME-Version: 1.0 (generated by EMIKO 1.13.9 - "Euglena tripteris")
Content-Type: text/plain; charset=US-ASCII

At Thu, 8 Mar 2001 14:27:37 +1100,
Conor MacNeill <[email protected]> wrote:
> Perhaps rather than just trying every rmic that you can currently think of,
> you should look at the approach of javac where compilers can be plugged in.
> That way, someone could add the weblogic rmic in the future. I suggest that
> rather than using a magic property such as ${build.compiler}, you might make
> it an attribute of the <rmic> task.

I looked for above topic. I modified following:

- modify src/main/org/apache/tools/ant/taskdef/Rmic.java
- make rmic subdirectory.
- add following new file:
    src/main/org/apache/tools/ant/taskdef/rmic/DefaultRmicAdapter.java
    src/main/org/apache/tools/ant/taskdef/rmic/RmicAdapterFactory.java
    src/main/org/apache/tools/ant/taskdef/rmic/RmicAdapter.java
    src/main/org/apache/tools/ant/taskdef/rmic/KaffeRmic.java 
    src/main/org/apache/tools/ant/taskdef/rmic/SunRmic.java

    We can specify rmi compiler by 'build.rmic' property. For example:
    <property name="build.rmic" value="kaffe"/>	     for Kaffe's rmic
    <property name="build.rmic" value="sun"/>	     for SUN's rmic

- add KAFFE for Java Version at orig/src/main/org/apache/tools/ant/Project.java 
I copied and pasted from taskdef/Rmic.java and
taskdef/compiler/*.java. I confirmed that my patch is working but I
didn't review code so much. Maybe it is included useless code.

This patch is written for ant-1.4alpha. But it work with ant-1.3. 
I tested and confirmed.

regards.
--------------------
Takashi Okamoto


diff -urN orig/src/main/org/apache/tools/ant/Project.java src/main/org/apache/tools/ant/Project.java
--- orig/src/main/org/apache/tools/ant/Project.java	Sat Mar 10 23:52:56 2001
+++ src/main/org/apache/tools/ant/Project.java	Sat Mar 10 23:54:35 2001
@@ -89,6 +89,7 @@
     public static final String JAVA_1_1 = "1.1";
     public static final String JAVA_1_2 = "1.2";
     public static final String JAVA_1_3 = "1.3";
+    public static final String KAFFE    = "kaffe";
 
     public static final String TOKEN_START = "@";
     public static final String TOKEN_END = "@";
@@ -130,6 +131,9 @@
             // swallow as we've hit the max class version that
             // we have
         }
+	if(System.getProperty("java.vm.name").equals("Kaffe")){
+            javaVersion = KAFFE;
+	}
     }
 
     public Project() {
diff -urN orig/src/main/org/apache/tools/ant/taskdefs/Rmic.java src/main/org/apache/tools/ant/taskdefs/Rmic.java
--- orig/src/main/org/apache/tools/ant/taskdefs/Rmic.java	Sat Mar 10 23:52:56 2001
+++ src/main/org/apache/tools/ant/taskdefs/Rmic.java	Sat Mar 10 23:56:27 2001
@@ -62,6 +62,7 @@
 import org.apache.tools.ant.types.Path;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.*;
+import org.apache.tools.ant.taskdefs.rmic.*;
 
 import java.io.*;
 import java.util.StringTokenizer;
@@ -81,6 +82,8 @@
  * <li>iiopopts: Include IIOP options 
  * <li>idl: Generate IDL output 
  * <li>idlopts: Include IDL options 
+ * <li>includeantruntime
+ * <li>includejavaruntime
  * </ul>
  * Of these arguments, <b>base</b> is required.
  * <p>
@@ -92,10 +95,14 @@
  * @author [email protected]
  * @author David Maclean <a href="mailto:[email protected]";>[email protected]</a>
  * @author <a href="mailto:[email protected]";>Stefan Bodewig</a> 
- */
+ * @author Takashi Okamoto [email protected]
+*/
 
 public class Rmic extends MatchingTask {
 
+    private static final String FAIL_MSG 
+        = "Rmic failed, messages should have been provided.";
+
     private File baseDir;
     private String classname;
     private File sourceBase;
@@ -109,35 +116,72 @@
     private boolean idl  = false;
     private String  idlopts;
     private boolean debug  = false;
+    private boolean includeAntRuntime = true;
+    private boolean includeJavaRuntime = false;
 
     private Vector compileList = new Vector();
 
     private ClassLoader loader = null;
 
+    /** Sets the base directory to output generated class. */
     public void setBase(File base) {
         this.baseDir = base;
     }
 
+    /** Gets the base directory to output generated class. */
+    public File getBase() {
+      return this.baseDir;
+    }
+
+    /** Sets the class name to compile. */
     public void setClassname(String classname) {
         this.classname = classname;
     }
 
+    /** Gets the class name to compile. */
+    public String getClassname() {
+      return classname;
+    }
+
+    /** Sets the source dirs to find the source java files. */
     public void setSourceBase(File sourceBase) {
         this.sourceBase = sourceBase;
     }
 
+    /** Gets the source dirs to find the source java files. */
+    public File getSourceBase() {
+      return sourceBase;
+    }
+
+    /** Sets the stub version. */
     public void setStubVersion(String stubVersion) {
         this.stubVersion = stubVersion;
     }
 
+    /** Gets the stub version. */
+    public String getStubVersion() {
+      return stubVersion;
+    }
+
+    /** Gets the stub version. */
     public void setFiltering(boolean filter) {
         filtering = filter;
     }
 
+    public boolean getFiltering() {
+        return filtering;
+    }
+
+    /** Sets the debug flag. */
     public void setDebug(boolean debug) {
         this.debug = debug;
     }
 
+    /** Gets the debug flag. */
+    public boolean getDebug() {
+        return debug;
+    }
+
     /**
      * Set the classpath to be used for this compilation.
      */
@@ -150,6 +194,13 @@
     }
 
     /**
+     * Gets the classpath. 
+     */
+    public Path getClasspath() {
+      return compileClasspath; 
+    }
+
+    /**
      * Creates a nested classpath element.
      */
     public Path createClasspath() {
@@ -174,6 +225,11 @@
         this.verify = verify;
     }
 
+    /** Get verify flag. */
+    public boolean getVerify() {
+      return verify;
+    }
+
     /**
      * Indicates that IIOP compatible stubs should
      * be generated.  This defaults to false 
@@ -183,6 +239,11 @@
         this.iiop = iiop;
     }
 
+    /** Gets iiop flags. */
+    public boolean getIiop() {
+        return iiop;
+    }
+
     /**
      * pass additional arguments for iiop 
      */
@@ -190,6 +251,11 @@
         this.iiopopts = iiopopts;
     }
 
+    /** Gets additional arguments for iiop. */
+    public String getIiopopts() {
+      return iiopopts;
+    }
+
     /**
      * Indicates that IDL output should be 
      * generated.  This defaults to false 
@@ -199,13 +265,61 @@
         this.idl = idl;
     }
 
+    /* Gets IDL flags. */
+    public boolean getIdl() {
+        return idl;
+    }
+
     /**
-     * pass additional arguments for idl compile 
+     * pass additional arguments for idl compile.
      */
     public void setIdlopts(String idlopts) {
         this.idlopts = idlopts;
     }
 
+    /**
+     * Gets additional arguments for idl compile. 
+     */
+    public String getIdlopts() {
+        return idlopts;
+    }
+
+    /** Gets file list to compile. */
+    public Vector getFileList() {
+      return compileList;
+    }
+
+    /**
+     * Include ant's own classpath in this task's classpath?
+     */
+    public void setIncludeantruntime( boolean include ) {
+        includeAntRuntime = include;
+    }
+
+    /**
+     * Gets whether or not the ant classpath is to be included in the
+     * task's classpath.
+     */
+    public boolean getIncludeantruntime() {
+        return includeAntRuntime;
+    }
+
+    /**
+     * Sets whether or not to include the java runtime libraries to this
+     * task's classpath.
+     */
+    public void setIncludejavaruntime( boolean include ) {
+        includeJavaRuntime = include;
+    }
+
+    /**
+     * Gets whether or not the java runtime should be included in this
+     * task's classpath.
+     */
+    public boolean getIncludejavaruntime() {
+        return includeJavaRuntime;
+    }
+
     public void execute() throws BuildException {
         if (baseDir == null) {
             throw new BuildException("base attribute must be set!", location);
@@ -248,56 +362,27 @@
         // XXX
         // need to provide an input stream that we read in from!
 
-        OutputStream logstr = new LogOutputStream(this, Project.MSG_WARN);
-        sun.rmi.rmic.Main compiler = new sun.rmi.rmic.Main(logstr, "rmic");
-        Commandline cmd = new Commandline();
-        
-        cmd.createArgument().setValue("-d");
-        cmd.createArgument().setFile(baseDir);
-        cmd.createArgument().setValue("-classpath");
-        cmd.createArgument().setPath(classpath);
-        if (null != stubVersion) {
-            if ("1.1".equals(stubVersion))
-                cmd.createArgument().setValue("-v1.1");
-            else if ("1.2".equals(stubVersion))
-                cmd.createArgument().setValue("-v1.2");
-            else
-                cmd.createArgument().setValue("-vcompat");
-        }
-        if (null != sourceBase)
-            cmd.createArgument().setValue("-keepgenerated");
-
-        if( iiop ) {
-            cmd.createArgument().setValue("-iiop");
-            if( iiopopts != null ) 
-                cmd.createArgument().setValue(iiopopts);
-        }
-
-        if( idl )  {
-            cmd.createArgument().setValue("-idl");
-            if( idlopts != null ) 
-                cmd.createArgument().setValue(idlopts);
-        }
-        if( debug )  {
-            cmd.createArgument().setValue("-g");
-        }
-
-        int fileCount = compileList.size();
-        if (fileCount > 0) {
-            log("RMI Compiling " + fileCount +
-                " class"+ (fileCount > 1 ? "es" : "")+" to " + baseDir, 
-                Project.MSG_INFO);
+        if (compileList.size() > 0) {
+	    String compiler = project.getProperty("build.rmic");
+
+	    RmicAdapter adapter = RmicAdapterFactory.getRmic(compiler, this );
+            log("Compiling " + compileList.size() + 
+                " source file"
+                + (compileList.size() == 1 ? "" : "s")
+                + (baseDir != null ? " to " + baseDir : ""));
+
+            // now we need to populate the compiler adapter
+            adapter.setRmic( this );
             
-            for (int j = 0; j < fileCount; j++) {
-                cmd.createArgument().setValue((String) compileList.elementAt(j));
+            // finally, lets execute the compiler!!
+            if (!adapter.execute()) {
+		throw new BuildException(FAIL_MSG, location);
             }
-            log("Compilation args: " + cmd.toString(), Project.MSG_VERBOSE);
-            compiler.compile(cmd.getArguments());
         }
 
         // Move the generated source file to the base directory
         if (null != sourceBase) {
-            for (int j = 0; j < fileCount; j++) {
+            for (int j = 0; j < compileList.size(); j++) {
                 moveGeneratedFile(baseDir, sourceBase, (String) compileList.elementAt(j));
             }
         }
@@ -371,14 +456,6 @@
             classpath.addExisting(Path.systemClasspath);
         } else {
             classpath.addExisting(compileClasspath.concatSystemClasspath());
-        }
-
-        // in jdk 1.2, the system classes are not on the visible classpath.
-        if (Project.getJavaVersion().startsWith("1.2")) {
-            String bootcp = System.getProperty("sun.boot.class.path");
-            if (bootcp != null) {
-                classpath.addExisting(new Path(project, bootcp));
-            }
         }
         return classpath;
     }
diff -urN orig/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
--- orig/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java	Thu Jan  1 09:00:00 1970
+++ src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java	Sat Mar 10 23:54:05 2001
@@ -0,0 +1,327 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 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", "Ant", 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 [email protected].
+ *
+ * 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.rmic;
+
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.*;
+import org.apache.tools.ant.types.*;
+
+import java.io.*;
+import java.util.Random;
+import java.util.Vector;
+
+/**
+ * This is the default implementation for the RmicAdapter interface.
+ * Currently, this is a cut-and-paste of the original rmic task and
+ * DefaultCopmpilerAdapter.
+ *
+ * @author James Davidson <a href="mailto:[email protected]";>[email protected]</a>
+ * @author Robin Green <a href="mailto:[email protected]";>[email protected]</a>
+ * @author <a href="mailto:[email protected]";>Stefan Bodewig</a> 
+ * @author <a href="mailto:[email protected]";>J D Glanville</a>
+ * @author Takashi Okamoto <[email protected]>
+ */
+public abstract class DefaultRmicAdapter implements RmicAdapter {
+
+    /* jdg - TODO - all these attributes are currently protected, but they
+     * should probably be private in the near future.
+     */
+
+    private File baseDir;
+    private String classname;
+    private File sourceBase;
+    private String stubVersion;
+    private Path compileClasspath;
+    private boolean verify = false;
+    private boolean filtering = false;
+    private boolean iiop = false;
+    private String  iiopopts;
+    private boolean idl  = false;
+    private String  idlopts;
+    private boolean debug  = false;
+
+    protected Project project;
+    protected Location location;
+    protected boolean includeJavaRuntime;
+    protected boolean includeAntRuntime;
+
+    private Vector compileList;
+    protected Rmic attributes;
+
+    public void setRmic( Rmic attributes ) {
+	this.attributes = attributes;
+
+	baseDir = attributes.getBase();
+	classname = attributes.getClassname();
+	sourceBase = attributes.getSourceBase();
+	stubVersion = attributes.getStubVersion();
+	verify = attributes.getVerify();
+	filtering = attributes.getFiltering();
+	iiop = attributes.getIiop();
+	iiopopts = attributes.getIiopopts();
+	idl = attributes.getIdl();
+	idlopts = attributes.getIdlopts();
+	debug = attributes.getDebug();
+
+	project = attributes.getProject();
+	location = attributes.getLocation();
+
+	compileList = attributes.getFileList();
+	compileClasspath = attributes.getClasspath();
+        includeJavaRuntime = attributes.getIncludejavaruntime();
+
+    }
+
+    public Rmic getRmic() {
+        return attributes;
+    }
+
+    /**
+     * Builds the compilation classpath.
+     *
+     */
+    protected Path getCompileClasspath() {
+        Path classpath = new Path(project);
+
+        // add dest dir to classpath so that previously compiled and
+        // untouched classes are on classpath
+
+        if (baseDir != null) {
+            classpath.setLocation(baseDir);
+        }
+
+        // Combine the build classpath with the system classpath, in an 
+        // order determined by the value of build.classpath
+
+        if (compileClasspath == null) {
+            if ( includeAntRuntime ) {
+                classpath.addExisting(Path.systemClasspath);
+            }
+        } else {
+            if ( includeAntRuntime ) {
+                classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
+            } else {
+                classpath.addExisting(compileClasspath.concatSystemClasspath("ignore"));
+            }
+        }
+
+	if (includeJavaRuntime) {
+            if (System.getProperty("java.vendor").toLowerCase().indexOf("microsoft") >= 0) {
+                // Pull in *.zip from packages directory
+                FileSet msZipFiles = new FileSet();
+                msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
+                msZipFiles.setIncludes("*.ZIP");
+                classpath.addFileset(msZipFiles);
+            }
+            else if (Project.getJavaVersion() == Project.JAVA_1_1) {
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator + "lib"
+                                                + File.separator 
+                                                + "classes.zip"));
+	    }
+            else if (Project.getJavaVersion() == Project.KAFFE) {
+		FileSet kaffeJarFiles = new FileSet();
+                kaffeJarFiles.setDir(new File(System.getProperty("java.home") 
+					      + File.separator + "share"
+					      + File.separator + "kaffe"));
+		
+		kaffeJarFiles.setIncludes("*.jar");
+		classpath.addFileset(kaffeJarFiles);
+            } else {
+                // JDK > 1.1 seems to set java.home to the JRE directory.
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator + "lib"
+                                                + File.separator + "rt.jar"));
+                // Just keep the old version as well and let addExistingToPath
+                // sort it out.
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator +"jre"
+                                                + File.separator + "lib"
+                                                + File.separator + "rt.jar"));
+            }
+        }
+            
+   
+        return classpath;
+    }
+
+    /**
+     * setup rmic argument for rmic.
+     */
+
+    protected Commandline setupRmicCommand() {
+        Commandline cmd = new Commandline();
+        Path classpath = getCompileClasspath();
+
+        cmd.createArgument().setValue("-d");
+        cmd.createArgument().setFile(baseDir);
+        cmd.createArgument().setValue("-classpath");
+        cmd.createArgument().setPath(classpath);
+        if (null != stubVersion) {
+            if ("1.1".equals(stubVersion))
+                cmd.createArgument().setValue("-v1.1");
+            else if ("1.2".equals(stubVersion))
+                cmd.createArgument().setValue("-v1.2");
+            else
+                cmd.createArgument().setValue("-vcompat");
+        }
+        if (null != sourceBase)
+            cmd.createArgument().setValue("-keepgenerated");
+
+        if( iiop ) {
+            cmd.createArgument().setValue("-iiop");
+            if( iiopopts != null ) 
+                cmd.createArgument().setValue(iiopopts);
+        }
+
+        if( idl )  {
+            cmd.createArgument().setValue("-idl");
+            if( idlopts != null ) 
+                cmd.createArgument().setValue(idlopts);
+        }
+        if( debug )  {
+            cmd.createArgument().setValue("-g");
+        }
+
+        logAndAddFilesToCompile(cmd);
+        return cmd;
+     }
+
+    /**
+     * Logs the compilation parameters, adds the files to compile and logs the 
+     * &qout;niceSourceList&quot;
+     */
+    protected void logAndAddFilesToCompile(Commandline cmd) {
+        attributes.log("Compilation args: " + cmd.toString(),
+		       Project.MSG_VERBOSE);
+
+        StringBuffer niceSourceList = new StringBuffer("File");
+        if (compileList.size() != 1) {
+            niceSourceList.append("s");
+        }
+        niceSourceList.append(" to be compiled:");
+
+        for (int i=0; i < compileList.size(); i++) {
+	    String arg = (String)compileList.get(i);
+            cmd.createArgument().setValue(arg);
+	    niceSourceList.append("    " + arg);
+        }
+
+        attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
+    }
+
+    /**
+     * Do the compile with the specified arguments.
+     * @param args - arguments to pass to process on command line
+     * @param firstFileName - index of the first source file in args
+     */
+    protected int executeExternalCompile(String[] args, int firstFileName) {
+        String[] commandArray = null;
+        File tmpFile = null;
+
+        try {
+            /*
+             * Many system have been reported to get into trouble with 
+             * long command lines - no, not only Windows ;-).
+             *
+             * POSIX seems to define a lower limit of 4k, so use a temporary 
+             * file if the total length of the command line exceeds this limit.
+             */
+            if (Commandline.toString(args).length() > 4096) {
+                PrintWriter out = null;
+                try {
+                    tmpFile = new File("jikes"+(new Random(System.currentTimeMillis())).nextLong());
+                    out = new PrintWriter(new FileWriter(tmpFile));
+                    for (int i = firstFileName; i < args.length; i++) {
+                        out.println(args[i]);
+                    }
+                    out.flush();
+                    commandArray = new String[firstFileName+1];
+                    System.arraycopy(args, 0, commandArray, 0, firstFileName);
+                    commandArray[firstFileName] = "@" + tmpFile.getAbsolutePath();
+                } catch (IOException e) {
+                    throw new BuildException("Error creating temporary file", e, location);
+                } finally {
+                    if (out != null) {
+                        try {out.close();} catch (Throwable t) {}
+                    }
+                }
+            } else {
+                commandArray = args;
+            }
+            
+            try {
+                Execute exe = new Execute(new LogStreamHandler(attributes, 
+                                                               Project.MSG_INFO,
+                                                               Project.MSG_WARN));
+                exe.setAntRun(project);
+                exe.setWorkingDirectory(project.getBaseDir());
+                exe.setCommandline(commandArray);
+                exe.execute();
+                return exe.getExitValue();
+            } catch (IOException e) {
+                throw new BuildException("Error running " + args[0] 
+					 + " compiler", e, location);
+            }
+        } finally {
+            if (tmpFile != null) {
+                tmpFile.delete();
+            }
+        }
+    }
+}
diff -urN orig/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java~ src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java~
--- orig/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java~	Thu Jan  1 09:00:00 1970
+++ src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java~	Sat Mar 10 23:54:06 2001
@@ -0,0 +1,325 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 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", "Ant", 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 [email protected].
+ *
+ * 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.rmic;
+
+import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.*;
+import org.apache.tools.ant.types.*;
+
+import java.io.*;
+import java.util.Random;
+import java.util.Vector;
+
+/**
+ * This is the default implementation for the CompilerAdapter interface.
+ * Currently, this is a cut-and-paste of the original rmic task.
+ *
+ * @author Takashi Okamoto <a href="mailto:[email protected]";>[email protected]</a>
+ * @author James Davidson <a href="mailto:[email protected]";>[email protected]</a>
+ * @author Robin Green <a href="mailto:[email protected]";>[email protected]</a>
+ * @author <a href="mailto:[email protected]";>Stefan Bodewig</a> 
+ * @author <a href="mailto:[email protected]";>J D Glanville</a>
+ */
+public abstract class DefaultRmicAdapter implements RmicAdapter {
+
+    /* jdg - TODO - all these attributes are currently protected, but they
+     * should probably be private in the near future.
+     */
+
+    private File baseDir;
+    private String classname;
+    private File sourceBase;
+    private String stubVersion;
+    private Path compileClasspath;
+    private boolean verify = false;
+    private boolean filtering = false;
+    private boolean iiop = false;
+    private String  iiopopts;
+    private boolean idl  = false;
+    private String  idlopts;
+    private boolean debug  = false;
+
+    protected Project project;
+    protected Location location;
+    protected boolean includeAntRuntime;
+    protected boolean includeJavaRuntime;
+
+
+    private Vector compileList;
+    protected Rmic attributes;
+
+    public void setRmic( Rmic attributes ) {
+      this.attributes = attributes;
+
+      this.baseDir = attributes.getBase();
+      this.classname = attributes.getClassname();
+      this.sourceBase = attributes.getSourceBase();
+      this.stubVersion = attributes.getStubVersion();
+      this.verify = attributes.getVerify();
+      this.filtering = attributes.getFiltering();
+      this.iiop = attributes.getIiop();
+      this.iiopopts = attributes.getIiopopts();
+      this.idl = attributes.getIdl();
+      this.idlopts = attributes.getIdlopts();
+      this.debug = attributes.getDebug();
+
+      this.project = attributes.getProject();
+      this.location = attributes.getLocation();
+
+        compileList = attributes.getFileList();
+        compileClasspath = attributes.getClasspath();
+        location = attributes.getLocation();
+	/*
+        includeAntRuntime = attributes.getIncludeantruntime();
+        includeJavaRuntime = attributes.getIncludejavaruntime();
+    */
+
+    }
+
+    public Rmic getRmic() {
+        return attributes;
+    }
+
+    /**
+     * Builds the compilation classpath.
+     *
+     */
+    protected Path getCompileClasspath() {
+        Path classpath = new Path(project);
+
+        // add dest dir to classpath so that previously compiled and
+        // untouched classes are on classpath
+
+        if (baseDir != null) {
+            classpath.setLocation(baseDir);
+        }
+
+        // Combine the build classpath with the system classpath, in an 
+        // order determined by the value of build.classpath
+
+        if (compileClasspath == null) {
+            if ( includeAntRuntime ) {
+                classpath.addExisting(Path.systemClasspath);
+            }
+        } else {
+            if ( includeAntRuntime ) {
+                classpath.addExisting(compileClasspath.concatSystemClasspath("last"));
+            } else {
+                classpath.addExisting(compileClasspath.concatSystemClasspath("ignore"));
+            }
+        }
+
+        if (includeJavaRuntime) {
+            if (System.getProperty("java.vendor").toLowerCase().indexOf("microsoft") >= 0) {
+                // Pull in *.zip from packages directory
+                FileSet msZipFiles = new FileSet();
+                msZipFiles.setDir(new File(System.getProperty("java.home") + File.separator + "Packages"));
+                msZipFiles.setIncludes("*.ZIP");
+                classpath.addFileset(msZipFiles);
+            }
+            else if (Project.getJavaVersion() == Project.JAVA_1_1) {
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator + "lib"
+                                                + File.separator 
+                                                + "classes.zip"));
+            } else {
+                // JDK > 1.1 seems to set java.home to the JRE directory.
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator + "lib"
+                                                + File.separator + "rt.jar"));
+                // Just keep the old version as well and let addExistingToPath
+                // sort it out.
+                classpath.addExisting(new Path(null,
+                                                System.getProperty("java.home")
+                                                + File.separator +"jre"
+                                                + File.separator + "lib"
+                                                + File.separator + "rt.jar"));
+            }
+        }
+            
+        return classpath;
+    }
+
+    /**
+     * Does the command line argument processing common to classic and
+     * modern.  
+     */
+
+    protected Commandline setupRmicCommand() {
+        Commandline cmd = new Commandline();
+        Path classpath = getCompileClasspath();
+
+        cmd.createArgument().setValue("-d");
+        cmd.createArgument().setFile(baseDir);
+        cmd.createArgument().setValue("-classpath");
+        cmd.createArgument().setPath(classpath);
+        if (null != stubVersion) {
+            if ("1.1".equals(stubVersion))
+                cmd.createArgument().setValue("-v1.1");
+            else if ("1.2".equals(stubVersion))
+                cmd.createArgument().setValue("-v1.2");
+            else
+                cmd.createArgument().setValue("-vcompat");
+        }
+        if (null != sourceBase)
+            cmd.createArgument().setValue("-keepgenerated");
+
+        if( iiop ) {
+            cmd.createArgument().setValue("-iiop");
+            if( iiopopts != null ) 
+                cmd.createArgument().setValue(iiopopts);
+        }
+
+        if( idl )  {
+            cmd.createArgument().setValue("-idl");
+            if( idlopts != null ) 
+                cmd.createArgument().setValue(idlopts);
+        }
+        if( debug )  {
+            cmd.createArgument().setValue("-g");
+        }
+
+        logAndAddFilesToCompile(cmd);
+        return cmd;
+    }
+
+    /**
+     * Logs the compilation parameters, adds the files to compile and logs the 
+     * &qout;niceSourceList&quot;
+     */
+    protected void logAndAddFilesToCompile(Commandline cmd) {
+        attributes.log("Compilation args: " + cmd.toString(),
+            Project.MSG_VERBOSE);
+
+        StringBuffer niceSourceList = new StringBuffer("File");
+        if (compileList.size() != 1) {
+            niceSourceList.append("s");
+        }
+        niceSourceList.append(" to be compiled:");
+
+	//        niceSourceList.append(lSep);
+
+        for (int i=0; i < compileList.size(); i++) {
+	  String arg = (String)compileList.get(i);
+            cmd.createArgument().setValue(arg);
+	    //  niceSourceList.append("    " + arg + lSep);
+	    niceSourceList.append("    " + arg);
+        }
+
+        attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
+    }
+
+    /**
+     * Do the compile with the specified arguments.
+     * @param args - arguments to pass to process on command line
+     * @param firstFileName - index of the first source file in args
+     */
+    protected int executeExternalCompile(String[] args, int firstFileName) {
+        String[] commandArray = null;
+        File tmpFile = null;
+
+        try {
+            /*
+             * Many system have been reported to get into trouble with 
+             * long command lines - no, not only Windows ;-).
+             *
+             * POSIX seems to define a lower limit of 4k, so use a temporary 
+             * file if the total length of the command line exceeds this limit.
+             */
+            if (Commandline.toString(args).length() > 4096) {
+                PrintWriter out = null;
+                try {
+                    tmpFile = new File("jikes"+(new Random(System.currentTimeMillis())).nextLong());
+                    out = new PrintWriter(new FileWriter(tmpFile));

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to