ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic DefaultRmicAdapter.java KaffeRmic.java RmicAdapter.java RmicAdapterFactory.java SunRmic.java WLRmic.java
Date Fri, 12 Apr 2002 11:44:31 GMT
bodewig     02/04/12 04:44:31

  Modified:    src/main/org/apache/tools/ant/taskdefs Rmic.java
               src/main/org/apache/tools/ant/taskdefs/rmic
                        DefaultRmicAdapter.java KaffeRmic.java
                        RmicAdapter.java RmicAdapterFactory.java
                        SunRmic.java WLRmic.java
  Log:
  Make sure <rmic> resets its internal state even in exceptional
  situations.
  
  Cosmetics.
  
  Revision  Changes    Path
  1.33      +63 -43    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java
  
  Index: Rmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Rmic.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- Rmic.java	10 Apr 2002 08:35:01 -0000	1.32
  +++ Rmic.java	12 Apr 2002 11:44:31 -0000	1.33
  @@ -60,9 +60,11 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
   import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory;
  +import org.apache.tools.ant.types.FilterSetCollection;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.types.Reference;
   import org.apache.tools.ant.util.FileNameMapper;
  +import org.apache.tools.ant.util.FileUtils;
   import org.apache.tools.ant.util.SourceFileScanner;
   
   import java.io.File;
  @@ -99,6 +101,8 @@
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
    * @author Takashi Okamoto tokamoto@rd.nttdata.co.jp
    *
  + * @since Ant 1.1
  + *
    * @ant.task category="java"
    */
   
  @@ -128,6 +132,8 @@
   
       private ClassLoader loader = null;
   
  +    private FileUtils fileUtils = FileUtils.newFileUtils();
  +
       /** Sets the base directory to output generated class. */
       public void setBase(File base) {
           this.baseDir = base;
  @@ -370,7 +376,7 @@
           }
   
           String compiler = project.getProperty("build.rmic");
  -        RmicAdapter adapter = RmicAdapterFactory.getRmic(compiler, this );
  +        RmicAdapter adapter = RmicAdapterFactory.getRmic(compiler, this);
               
           // now we need to populate the compiler adapter
           adapter.setRmic( this );
  @@ -378,56 +384,64 @@
           Path classpath = adapter.getClasspath();
           loader = new AntClassLoader(project, classpath);
   
  -        // scan base dirs to build up compile lists only if a
  -        // specific classname is not given
  -        if (classname == null) {
  -            DirectoryScanner ds = this.getDirectoryScanner(baseDir);
  -            String[] files = ds.getIncludedFiles();
  -            scanDir(baseDir, files, adapter.getMapper());
  -        } else {
  -            // otherwise perform a timestamp comparison - at least
  -            scanDir(baseDir, 
  -                    new String[] {classname.replace('.', File.separatorChar) + ".class"},
  -                    adapter.getMapper());
  -        }
  -        
  -        int fileCount = compileList.size();
  -        if (fileCount > 0) {
  -            log("RMI Compiling " + fileCount +
  -                " class"+ (fileCount > 1 ? "es" : "")+" to " + baseDir, 
  -                Project.MSG_INFO);
  -
  -            // finally, lets execute the compiler!!
  -            if (!adapter.execute()) {
  -                throw new BuildException(FAIL_MSG, location);
  -            }
  -        }
  -
  -        /* 
  -         * Move the generated source file to the base directory.  If
  -         * base directory and sourcebase are the same, the generated
  -         * sources are already in place.
  -         */
  -        if (null != sourceBase && !baseDir.equals(sourceBase)) {
  -            if (idl) {
  -                log("Cannot determine sourcefiles in idl mode, ", 
  -                    Project.MSG_WARN);
  -                log("sourcebase attribute will be ignored.", Project.MSG_WARN);
  +        try {
  +            // scan base dirs to build up compile lists only if a
  +            // specific classname is not given
  +            if (classname == null) {
  +                DirectoryScanner ds = this.getDirectoryScanner(baseDir);
  +                String[] files = ds.getIncludedFiles();
  +                scanDir(baseDir, files, adapter.getMapper());
               } else {
  -                for (int j = 0; j < fileCount; j++) {
  -                    moveGeneratedFile(baseDir, sourceBase,
  -                                      (String) compileList.elementAt(j),
  -                                      adapter);
  +                // otherwise perform a timestamp comparison - at least
  +                scanDir(baseDir, 
  +                        new String[] {classname.replace('.', 
  +                                                        File.separatorChar)
  +                                          + ".class"},
  +                        adapter.getMapper());
  +            }
  +            
  +            int fileCount = compileList.size();
  +            if (fileCount > 0) {
  +                log("RMI Compiling " + fileCount +
  +                    " class"+ (fileCount > 1 ? "es" : "")+" to " + baseDir, 
  +                    Project.MSG_INFO);
  +                
  +                // finally, lets execute the compiler!!
  +                if (!adapter.execute()) {
  +                    throw new BuildException(FAIL_MSG, location);
  +                }
  +            }
  +            
  +            /* 
  +             * Move the generated source file to the base directory.  If
  +             * base directory and sourcebase are the same, the generated
  +             * sources are already in place.
  +             */
  +            if (null != sourceBase && !baseDir.equals(sourceBase) 
  +                && fileCount > 0) {
  +                if (idl) {
  +                    log("Cannot determine sourcefiles in idl mode, ", 
  +                        Project.MSG_WARN);
  +                    log("sourcebase attribute will be ignored.", 
  +                        Project.MSG_WARN);
  +                } else {
  +                    for (int j = 0; j < fileCount; j++) {
  +                        moveGeneratedFile(baseDir, sourceBase,
  +                                          (String) compileList.elementAt(j),
  +                                          adapter);
  +                    }
                   }
               }
  +        } finally {
  +            compileList.removeAllElements();
           }
  -        compileList.removeAllElements();
       }
   
       /**
        * Move the generated source file(s) to the base directory
        *
  -     * @exception org.apache.tools.ant.BuildException When error copying/removing files.
  +     * @exception org.apache.tools.ant.BuildException When error
  +     * copying/removing files.
        */
       private void moveGeneratedFile (File baseDir, File sourceBaseFile,
                                       String classname,
  @@ -458,7 +472,13 @@
   
               File newFile = new File(sourceBaseFile, sourceFileName);
               try {
  -                project.copyFile(oldFile, newFile, filtering);
  +                if (filtering) {
  +                    fileUtils.copyFile(oldFile, newFile, 
  +                        new FilterSetCollection(getProject()
  +                                                .getGlobalFilterSet()));
  +                } else {
  +                    fileUtils.copyFile(oldFile, newFile);
  +                }
                   oldFile.delete();
               } catch (IOException ioe) {
                   String msg = "Failed to copy " + oldFile + " to " +
  
  
  
  1.15      +29 -16    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
  
  Index: DefaultRmicAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DefaultRmicAdapter.java	10 Apr 2002 08:35:01 -0000	1.14
  +++ DefaultRmicAdapter.java	12 Apr 2002 11:44:31 -0000	1.15
  @@ -75,11 +75,13 @@
    * @author David Maclean <a href="mailto:david@cm.co.za">david@cm.co.za</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
    * @author <a href="tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
  + * @since Ant 1.4
    */
   public abstract class DefaultRmicAdapter implements RmicAdapter {
   
       private Rmic attributes;
       private FileNameMapper mapper;
  +    private final static Random rand = new Random();
   
       public DefaultRmicAdapter() {
       }
  @@ -106,8 +108,20 @@
       }        
   
       /**
  -     * This implementation maps *.class to *getStubClassSuffix().class and - if
  -     * stubversion is not 1.2 - to *getSkelClassSuffix().class.
  +     * This implementation returns a mapper that may return up to two
  +     * file names.
  +     *
  +     * <ul>
  +     *   <li>for JRMP it will return *_getStubClassSuffix (and
  +     *   *_getSkelClassSuffix if JDK 1.1 is used)</li>
  +     *
  +     *   <li>for IDL it will return a random name, causing <rmic> to
  +     *     always recompile.</li>
  +     *
  +     *   <li>for IIOP it will return _*_getStubClassSuffix for
  +     *   interfaces and _*_getStubClassSuffix for non-interfaces (and
  +     *   determine the interface and create _*_Stub from that).</li>
  +     * </ul>
        */
       public FileNameMapper getMapper() {
           return mapper;
  @@ -124,23 +138,24 @@
        * Builds the compilation classpath.
        */
       protected Path getCompileClasspath() {
  +        Path classpath = new Path(attributes.getProject());
           // add dest dir to classpath so that previously compiled and
           // untouched classes are on classpath
  -        Path classpath = new Path(attributes.getProject());
           classpath.setLocation(attributes.getBase());
   
           // Combine the build classpath with the system classpath, in an 
  -        // order determined by the value of build.classpath
  -
  +        // order determined by the value of build.sysclasspath
           if (attributes.getClasspath() == null) {
               if ( attributes.getIncludeantruntime() ) {
                   classpath.addExisting(Path.systemClasspath);
               }
           } else {
               if ( attributes.getIncludeantruntime() ) {
  -                classpath.addExisting(attributes.getClasspath().concatSystemClasspath("last"));
  +                classpath.addExisting(attributes.getClasspath()
  +                                      .concatSystemClasspath("last"));
               } else {
  -                classpath.addExisting(attributes.getClasspath().concatSystemClasspath("ignore"));
  +                classpath.addExisting(attributes.getClasspath()
  +                                      .concatSystemClasspath("ignore"));
               }
           }
   
  @@ -198,9 +213,9 @@
                   cmd.createArgument().setValue("-v1.1");
               } else if ("1.2".equals(stubVersion)) {
                   cmd.createArgument().setValue("-v1.2");
  -                   } else {
  +            } else {
                   cmd.createArgument().setValue("-vcompat");
  -                   }
  +            }
           }
   
           if (null != attributes.getSourceBase()) {
  @@ -260,21 +275,19 @@
           attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
       }
   
  -    private final static Random rand = new Random();
  -
       /**
        * Mapper that may return up to two file names.
        *
        * <ul>
  -     *   <li>for JRMP it will return *_Stub (and *_Skel if JDK 1.1 is
  -     *     used)</li>
  +     *   <li>for JRMP it will return *_getStubClassSuffix (and
  +     *   *_getSkelClassSuffix if JDK 1.1 is used)</li>
        *
        *   <li>for IDL it will return a random name, causing <rmic> to
        *     always recompile.</li>
        *
  -     *   <li>for IIOP it will return _*_Stub for interfaces and _*_Tie
  -     *     for non-interfaces (and determine the interface and create
  -     *     _*_Stub from that).</p>
  +     *   <li>for IIOP it will return _*_getStubClassSuffix for
  +     *   interfaces and _*_getStubClassSuffix for non-interfaces (and
  +     *   determine the interface and create _*_Stub from that).</li>
        * </ul>
        */
       private class RmicFileNameMapper implements FileNameMapper {
  
  
  
  1.7       +10 -8     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java
  
  Index: KaffeRmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- KaffeRmic.java	26 Jan 2002 20:18:12 -0000	1.6
  +++ KaffeRmic.java	12 Apr 2002 11:44:31 -0000	1.7
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -59,7 +59,6 @@
   
   import org.apache.tools.ant.types.Commandline;
   
  -
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Method;
   
  @@ -67,6 +66,7 @@
    * The implementation of the rmic for Kaffe
    *
    * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
  + * @since Ant 1.4
    */
   public class KaffeRmic extends DefaultRmicAdapter {
   
  @@ -84,15 +84,17 @@
   
               return ok.booleanValue();
           } catch (ClassNotFoundException ex) {
  -            throw new BuildException("Cannot use Kaffe rmic, as it is not available"+
  -                                     " A common solution is to set the environment variable"+
  -                                     " JAVA_HOME or CLASSPATH.", getRmic().getLocation()
);
  -        }
  -        catch (Exception ex) {
  +            throw new BuildException("Cannot use Kaffe rmic, as it is not "
  +                                     + "available.  A common solution is to "
  +                                     + "set the environment variable "
  +                                     + "JAVA_HOME or CLASSPATH.", 
  +                                     getRmic().getLocation() );
  +        } catch (Exception ex) {
               if (ex instanceof BuildException) {
                   throw (BuildException) ex;
               } else {
  -                throw new BuildException("Error starting Kaffe rmic: ", ex, getRmic().getLocation());
  +                throw new BuildException("Error starting Kaffe rmic: ", 
  +                                         ex, getRmic().getLocation());
               }
           }
       }
  
  
  
  1.6       +2 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java
  
  Index: RmicAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RmicAdapter.java	22 Nov 2001 08:46:55 -0000	1.5
  +++ RmicAdapter.java	12 Apr 2002 11:44:31 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -71,6 +71,7 @@
    *
    * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
    * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
  + * @since Ant 1.4
    */
   
   public interface RmicAdapter {
  
  
  
  1.5       +6 -4      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java
  
  Index: RmicAdapterFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- RmicAdapterFactory.java	22 Nov 2001 08:46:55 -0000	1.4
  +++ RmicAdapterFactory.java	12 Apr 2002 11:44:31 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -63,10 +63,11 @@
    *
    * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
    * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
  + * @since 1.4
    */
   public class RmicAdapterFactory {
   
  -    /** This is a singlton -- can't create instances!! */
  +    /** This is a singleton -- can't create instances!! */
       private RmicAdapterFactory() {
       }
   
  @@ -74,7 +75,7 @@
        * Based on the parameter passed in, this method creates the necessary
        * factory desired.
        *
  -     * The current mapping for rmic names are as follows:
  +     * <p>The current mapping for rmic names are as follows:</p>
        * <ul><li>sun = SUN's rmic
        * <li>kaffe = Kaffe's rmic
        * <li><i>a fully quallified classname</i> = the name of a rmic
  @@ -103,7 +104,8 @@
                       Class.forName("kaffe.tools.compiler.Compiler");
                       rmicType = "kaffe";
                   } catch (ClassNotFoundException cnfk) {
  -                    throw new BuildException("Couldn\'t guess rmic implementation");
  +                    throw new BuildException("Couldn\'t guess rmic "
  +                                             + "implementation");
                   }
               }
           }
  
  
  
  1.5       +15 -10    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java
  
  Index: SunRmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SunRmic.java	22 Nov 2001 08:46:55 -0000	1.4
  +++ SunRmic.java	12 Apr 2002 11:44:31 -0000	1.5
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -68,6 +68,7 @@
    * The implementation of the rmic for SUN's JDK.
    *
    * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
  + * @since Ant 1.4
    */
   public class SunRmic extends DefaultRmicAdapter {
   
  @@ -77,7 +78,8 @@
   
           // Create an instance of the rmic, redirecting output to
           // the project log
  -        LogOutputStream logstr = new LogOutputStream(getRmic(), Project.MSG_WARN);
  +        LogOutputStream logstr = new LogOutputStream(getRmic(), 
  +                                                     Project.MSG_WARN);
   
           try {
               Class c = Class.forName("sun.rmi.rmic.Main");
  @@ -87,19 +89,22 @@
   
               Method doRmic = c.getMethod("compile", 
                                           new Class [] { String[].class });
  -            Boolean ok = (Boolean)doRmic.invoke(rmic, 
  -                                                (new Object[] {cmd.getArguments()} ));
  +            Boolean ok = 
  +                (Boolean)doRmic.invoke(rmic, 
  +                                       (new Object[] {cmd.getArguments()} ));
               return ok.booleanValue();
           } catch (ClassNotFoundException ex) {
  -            throw new BuildException("Cannot use SUN rmic, as it is not available"+
  -                                     " A common solution is to set the environment variable"+
  -                                     " JAVA_HOME or CLASSPATH.", getRmic().getLocation()
);
  -        }
  -        catch (Exception ex) {
  +            throw new BuildException("Cannot use SUN rmic, as it is not "
  +                                     + "available.  A common solution is to "
  +                                     + "set the environment variable "
  +                                     + "JAVA_HOME or CLASSPATH.",
  +                                     getRmic().getLocation() );
  +        } catch (Exception ex) {
               if (ex instanceof BuildException) {
                   throw (BuildException) ex;
               } else {
  -                throw new BuildException("Error starting SUN rmic: ", ex, getRmic().getLocation());
  +                throw new BuildException("Error starting SUN rmic: ", 
  +                                         ex, getRmic().getLocation());
               }
           } finally {
               try {
  
  
  
  1.9       +8 -6      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java
  
  Index: WLRmic.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- WLRmic.java	11 Jan 2002 13:48:08 -0000	1.8
  +++ WLRmic.java	12 Apr 2002 11:44:31 -0000	1.9
  @@ -66,6 +66,7 @@
    * The implementation of the rmic for WebLogic
    *
    * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
  + * @since Ant 1.4
    */
   public class WLRmic extends DefaultRmicAdapter {
   
  @@ -90,15 +91,16 @@
               doRmic.invoke(null, new Object[] {cmd.getArguments()  });
               return true;
           } catch (ClassNotFoundException ex) {
  -            throw new BuildException("Cannot use WebLogic rmic, as it is not available"+
  -                                     " A common solution is to set the environment variable"+
  -                                     " CLASSPATH.", getRmic().getLocation() );
  -        }
  -        catch (Exception ex) {
  +            throw new BuildException("Cannot use WebLogic rmic, as it is not "
  +                                     + "available.  A common solution is to "
  +                                     + "set the environment variable "
  +                                     + "CLASSPATH.", getRmic().getLocation() );
  +        } catch (Exception ex) {
               if (ex instanceof BuildException) {
                   throw (BuildException) ex;
               } else {
  -                throw new BuildException("Error starting WebLogic rmic: ", ex, getRmic().getLocation());
  +                throw new BuildException("Error starting WebLogic rmic: ", ex,
  +                                         getRmic().getLocation());
               }
           } finally {
               if (loader != null) {
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message