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/07/04 12:04:30 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs/rmic DefaultRmicAdapter.java

bodewig     01/07/04 03:04:29

  Modified:    src/main/org/apache/tools/ant/taskdefs Rmic.java
               src/main/org/apache/tools/ant/taskdefs/rmic
                        DefaultRmicAdapter.java
  Log:
  Changes to rmic based on discussion with Rob van Oostrum
  <rv...@ezgov.com> and Larry V. Streepy, Jr.
  <st...@healthlanguage.com> on the ant-user mailing list:
  
  (1) don't even try to perform uptodate checks for IDL mode or when the
  -always(generate) option for IIOP mode has been specified
  
  (2) ignore -keepgenerated in IDL mode (we don't know what to keep)
  
  (3) use the correct target file names in IIOP mode.
  
  PR: 1625
  
  Revision  Changes    Path
  1.24      +52 -28    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.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- Rmic.java	2001/06/26 13:42:16	1.23
  +++ Rmic.java	2001/07/04 10:04:17	1.24
  @@ -65,6 +65,7 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.rmi.Remote;
   import java.util.Vector;
   
   /**
  @@ -400,10 +401,16 @@
   
           // Move the generated source file to the base directory
           if (null != sourceBase) {
  -            for (int j = 0; j < fileCount; j++) {
  -                moveGeneratedFile(baseDir, sourceBase,
  -                                  (String) compileList.elementAt(j),
  -                                  adapter);
  +            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);
  +                }
               }
           }
           compileList.removeAllElements();
  @@ -446,8 +453,20 @@
        */
       protected void scanDir(File baseDir, String files[],
                              FileNameMapper mapper) {
  -        SourceFileScanner sfs = new SourceFileScanner(this);
  -        String[] newFiles = sfs.restrict(files, baseDir, baseDir, mapper);
  +
  +        String[] newFiles = files;
  +        if (idl) {
  +            log("will leave uptodate test to rmic implementation in idl mode.",
  +                Project.MSG_VERBOSE);
  +        } else if (iiop 
  +                   && iiopopts != null && iiopopts.indexOf("-always") > -1) {
  +            log("no uptodate test as -always option has been specified",
  +                Project.MSG_VERBOSE);
  +        } else {
  +            SourceFileScanner sfs = new SourceFileScanner(this);
  +            newFiles = sfs.restrict(files, baseDir, baseDir, mapper);
  +        }
  +
           for (int i = 0; i < newFiles.length; i++) {
               String classname = newFiles[i].replace(File.separatorChar, '.');
               classname = classname.substring(0, classname.lastIndexOf(".class"));
  @@ -461,8 +480,8 @@
       public boolean isValidRmiRemote(String classname) {
           try {
               Class testClass = loader.loadClass(classname);
  -            // One cannot RMIC an interface
  -            if (testClass.isInterface()) {
  +            // One cannot RMIC an interface for "classic" RMI (JRMP)
  +            if (testClass.isInterface() && !iiop && !idl) {
                   return false;
               }
               return isValidRmiRemote(testClass);
  @@ -482,30 +501,35 @@
       }
   
       /**
  -     * Check to see if the class or (super)interfaces implement
  -     * java.rmi.Remote.
  +     * Returns the topmost interface that extends Remote for a given
  +     * class - if one exists.
        */
  -    private boolean isValidRmiRemote (Class testClass) {
  -        Class rmiRemote = java.rmi.Remote.class;
  -        
  -        if (rmiRemote.equals(testClass)) {
  -            // This class is java.rmi.Remote
  -            return true;
  -        }
  -            
  -        Class [] interfaces = testClass.getInterfaces();
  -        if (interfaces != null) {
  -            for (int i = 0; i < interfaces.length; i++) {
  -                if (rmiRemote.equals(interfaces[i])) {
  -                    // This class directly implements java.rmi.Remote
  -                    return true;
  -                }
  -                if (isValidRmiRemote(interfaces[i])) {
  -                    return true;
  +    public Class getRemoteInterface(Class testClass) {
  +        if (Remote.class.isAssignableFrom(testClass)) {
  +            Class [] interfaces = testClass.getInterfaces();
  +            if (interfaces != null) {
  +                for (int i = 0; i < interfaces.length; i++) {
  +                    if (Remote.class.isAssignableFrom(interfaces[i])) {
  +                        return interfaces[i];
  +                    }
                   }
               }
           }
  -        return false;
  +        return null;
  +    }
  +
  +    /**
  +     * Check to see if the class or (super)interfaces implement
  +     * java.rmi.Remote.
  +     */
  +    private boolean isValidRmiRemote (Class testClass) {
  +        return getRemoteInterface(testClass) != null;
       }
  +
  +    /**
  +     * Classloader for the user-specified classpath.
  +     */
  +    public ClassLoader getLoader() {return loader;}
  +
   }
   
  
  
  
  1.6       +67 -9     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultRmicAdapter.java	2001/06/26 13:42:19	1.5
  +++ DefaultRmicAdapter.java	2001/07/04 10:04:26	1.6
  @@ -60,6 +60,7 @@
   import org.apache.tools.ant.util.*;
   
   import java.io.File;
  +import java.util.Random;
   import java.util.Vector;
   
   /**
  @@ -320,6 +321,8 @@
           }
       }
   
  +    private final static Random rand = new Random();
  +
       /**
        * Mapper that possibly returns two file names, *_Stub and *_Skel.
        */
  @@ -352,20 +355,31 @@
                   !attributes.isValidRmiRemote(classname)) {
                   return null;
               }
  +
  +            /*
  +             * fallback in case we have trouble loading the class or
  +             * don't know how to handle it (there is no easy way to
  +             * know what IDL mode would generate.
  +             *
  +             * This is supposed to make Ant always recompile the
  +             * class, as a file of that name should not exist.
  +             */
  +            String[] target = new String[] {name+".tmp."+rand.nextLong()};
   
  -            if (!attributes.getIiop()) {
  +            if (!attributes.getIiop() && !attributes.getIdl()) {
  +                // JRMP with simple naming convention
                   if ("1.2".equals(attributes.getStubVersion())) {
  -                    return new String[] {
  +                    target = new String[] {
                           base + getStubClassSuffix() + ".class"
                       };
                   } else {
  -                    return new String[] {
  +                    target = new String[] {
                           base + getStubClassSuffix() + ".class",
                           base + getSkelClassSuffix() + ".class",
                       };
                   }
  -            } else {
  -                int lastSlash = base.lastIndexOf("/");
  +            } else if (!attributes.getIdl()) {
  +                int lastSlash = base.lastIndexOf(File.separatorChar);
   
                   String dirname = "";
                   /*
  @@ -382,11 +396,55 @@
   
                   String filename = base.substring(index);
   
  -                return new String[] {
  -                    dirname + "_" + filename + getStubClassSuffix() + ".class",
  -                    dirname + "_" + filename + getTieClassSuffix() + ".class"
  -                };
  +                try {
  +                    Class c = attributes.getLoader().loadClass(classname);
  +
  +                    if (c.isInterface()) {
  +                        // only stub, no tie
  +                        target = new String[] {
  +                            dirname + "_" + filename + getStubClassSuffix() 
  +                            + ".class"
  +                        };
  +                    } else {
  +                        /*
  +                         * stub is derived from implementation, 
  +                         * tie from interface name.
  +                         */
  +                        Class interf = attributes.getRemoteInterface(c);
  +                        String iName = interf.getName();
  +                        String iDir = "";
  +                        int iIndex = -1;
  +                        int lastDot = iName.lastIndexOf(".");
  +                        if (lastDot == -1) {
  +                            // no package
  +                            iIndex = 0;
  +                        } else {
  +                            iIndex = lastDot + 1;
  +                            iDir = iName.substring(0, iIndex);
  +                            iDir = iDir.replace('.', File.separatorChar);
  +                        }
  +                        
  +                        target = new String[] {
  +                            dirname + "_" + filename + getTieClassSuffix() 
  +                            + ".class",
  +                            iDir + "_" + iName.substring(iIndex) 
  +                            + getStubClassSuffix() + ".class"
  +                        };
  +                    }
  +                } catch (ClassNotFoundException e) {
  +                    attributes.log("Unable to verify class " + classname
  +                                   + ". It could not be found.", 
  +                                   Project.MSG_WARN);
  +                } catch (NoClassDefFoundError e) {
  +                    attributes.log("Unable to verify class " + classname
  +                                   + ". It is not defined.", Project.MSG_WARN);
  +                } catch (Throwable t) {
  +                    attributes.log("Unable to verify class " + classname
  +                                   + ". Loading caused Exception: "
  +                                   + t.getMessage(), Project.MSG_WARN);
  +                }
               }
  +            return target;
           }
       }