Browse Source

Make sure <rmic> resets its internal state even in exceptional

situations.

Cosmetics.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272399 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
5db106732c
7 changed files with 133 additions and 88 deletions
  1. +63
    -43
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  2. +29
    -16
      src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java
  3. +10
    -8
      src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java
  4. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java
  5. +6
    -4
      src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java
  6. +15
    -10
      src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java
  7. +8
    -6
      src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java

+ 63
- 43
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -60,9 +60,11 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapter; import org.apache.tools.ant.taskdefs.rmic.RmicAdapter;
import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; 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.Path;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.FileNameMapper; import org.apache.tools.ant.util.FileNameMapper;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.SourceFileScanner; import org.apache.tools.ant.util.SourceFileScanner;


import java.io.File; import java.io.File;
@@ -99,6 +101,8 @@ import java.util.Vector;
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author Takashi Okamoto tokamoto@rd.nttdata.co.jp * @author Takashi Okamoto tokamoto@rd.nttdata.co.jp
* *
* @since Ant 1.1
*
* @ant.task category="java" * @ant.task category="java"
*/ */


@@ -128,6 +132,8 @@ public class Rmic extends MatchingTask {


private ClassLoader loader = null; private ClassLoader loader = null;


private FileUtils fileUtils = FileUtils.newFileUtils();

/** Sets the base directory to output generated class. */ /** Sets the base directory to output generated class. */
public void setBase(File base) { public void setBase(File base) {
this.baseDir = base; this.baseDir = base;
@@ -370,7 +376,7 @@ public class Rmic extends MatchingTask {
} }


String compiler = project.getProperty("build.rmic"); 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 // now we need to populate the compiler adapter
adapter.setRmic( this ); adapter.setRmic( this );
@@ -378,56 +384,64 @@ public class Rmic extends MatchingTask {
Path classpath = adapter.getClasspath(); Path classpath = adapter.getClasspath();
loader = new AntClassLoader(project, classpath); 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 { } 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 * 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, private void moveGeneratedFile (File baseDir, File sourceBaseFile,
String classname, String classname,
@@ -458,7 +472,13 @@ public class Rmic extends MatchingTask {


File newFile = new File(sourceBaseFile, sourceFileName); File newFile = new File(sourceBaseFile, sourceFileName);
try { try {
project.copyFile(oldFile, newFile, filtering);
if (filtering) {
fileUtils.copyFile(oldFile, newFile,
new FilterSetCollection(getProject()
.getGlobalFilterSet()));
} else {
fileUtils.copyFile(oldFile, newFile);
}
oldFile.delete(); oldFile.delete();
} catch (IOException ioe) { } catch (IOException ioe) {
String msg = "Failed to copy " + oldFile + " to " + String msg = "Failed to copy " + oldFile + " to " +


+ 29
- 16
src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java View File

@@ -75,11 +75,13 @@ import java.util.Vector;
* @author David Maclean <a href="mailto:david@cm.co.za">david@cm.co.za</a> * @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="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @since Ant 1.4
*/ */
public abstract class DefaultRmicAdapter implements RmicAdapter { public abstract class DefaultRmicAdapter implements RmicAdapter {


private Rmic attributes; private Rmic attributes;
private FileNameMapper mapper; private FileNameMapper mapper;
private final static Random rand = new Random();


public DefaultRmicAdapter() { public DefaultRmicAdapter() {
} }
@@ -106,8 +108,20 @@ public abstract class DefaultRmicAdapter implements RmicAdapter {
} }


/** /**
* 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() { public FileNameMapper getMapper() {
return mapper; return mapper;
@@ -124,23 +138,24 @@ public abstract class DefaultRmicAdapter implements RmicAdapter {
* Builds the compilation classpath. * Builds the compilation classpath.
*/ */
protected Path getCompileClasspath() { protected Path getCompileClasspath() {
Path classpath = new Path(attributes.getProject());
// add dest dir to classpath so that previously compiled and // add dest dir to classpath so that previously compiled and
// untouched classes are on classpath // untouched classes are on classpath
Path classpath = new Path(attributes.getProject());
classpath.setLocation(attributes.getBase()); classpath.setLocation(attributes.getBase());


// Combine the build classpath with the system classpath, in an // 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.getClasspath() == null) {
if ( attributes.getIncludeantruntime() ) { if ( attributes.getIncludeantruntime() ) {
classpath.addExisting(Path.systemClasspath); classpath.addExisting(Path.systemClasspath);
} }
} else { } else {
if ( attributes.getIncludeantruntime() ) { if ( attributes.getIncludeantruntime() ) {
classpath.addExisting(attributes.getClasspath().concatSystemClasspath("last"));
classpath.addExisting(attributes.getClasspath()
.concatSystemClasspath("last"));
} else { } else {
classpath.addExisting(attributes.getClasspath().concatSystemClasspath("ignore"));
classpath.addExisting(attributes.getClasspath()
.concatSystemClasspath("ignore"));
} }
} }


@@ -198,9 +213,9 @@ public abstract class DefaultRmicAdapter implements RmicAdapter {
cmd.createArgument().setValue("-v1.1"); cmd.createArgument().setValue("-v1.1");
} else if ("1.2".equals(stubVersion)) { } else if ("1.2".equals(stubVersion)) {
cmd.createArgument().setValue("-v1.2"); cmd.createArgument().setValue("-v1.2");
} else {
} else {
cmd.createArgument().setValue("-vcompat"); cmd.createArgument().setValue("-vcompat");
}
}
} }


if (null != attributes.getSourceBase()) { if (null != attributes.getSourceBase()) {
@@ -260,21 +275,19 @@ public abstract class DefaultRmicAdapter implements RmicAdapter {
attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE);
} }


private final static Random rand = new Random();

/** /**
* Mapper that may return up to two file names. * Mapper that may return up to two file names.
* *
* <ul> * <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 * <li>for IDL it will return a random name, causing <rmic> to
* always recompile.</li> * 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> * </ul>
*/ */
private class RmicFileNameMapper implements FileNameMapper { private class RmicFileNameMapper implements FileNameMapper {


+ 10
- 8
src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -59,7 +59,6 @@ import org.apache.tools.ant.Project;


import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;



import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;


@@ -67,6 +66,7 @@ import java.lang.reflect.Method;
* The implementation of the rmic for Kaffe * The implementation of the rmic for Kaffe
* *
* @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @since Ant 1.4
*/ */
public class KaffeRmic extends DefaultRmicAdapter { public class KaffeRmic extends DefaultRmicAdapter {


@@ -84,15 +84,17 @@ public class KaffeRmic extends DefaultRmicAdapter {


return ok.booleanValue(); return ok.booleanValue();
} catch (ClassNotFoundException ex) { } 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) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting Kaffe rmic: ", ex, getRmic().getLocation());
throw new BuildException("Error starting Kaffe rmic: ",
ex, getRmic().getLocation());
} }
} }
} }


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -71,6 +71,7 @@ import org.apache.tools.ant.util.FileNameMapper;
* *
* @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @since Ant 1.4
*/ */


public interface RmicAdapter { public interface RmicAdapter {


+ 6
- 4
src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -63,10 +63,11 @@ import org.apache.tools.ant.Task;
* *
* @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @author <a href="mailto:jayglanville@home.com">J D Glanville</a> * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
* @since 1.4
*/ */
public class RmicAdapterFactory { public class RmicAdapterFactory {


/** This is a singlton -- can't create instances!! */
/** This is a singleton -- can't create instances!! */
private RmicAdapterFactory() { private RmicAdapterFactory() {
} }


@@ -74,7 +75,7 @@ public class RmicAdapterFactory {
* Based on the parameter passed in, this method creates the necessary * Based on the parameter passed in, this method creates the necessary
* factory desired. * 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 * <ul><li>sun = SUN's rmic
* <li>kaffe = Kaffe's rmic * <li>kaffe = Kaffe's rmic
* <li><i>a fully quallified classname</i> = the name of a rmic * <li><i>a fully quallified classname</i> = the name of a rmic
@@ -103,7 +104,8 @@ public class RmicAdapterFactory {
Class.forName("kaffe.tools.compiler.Compiler"); Class.forName("kaffe.tools.compiler.Compiler");
rmicType = "kaffe"; rmicType = "kaffe";
} catch (ClassNotFoundException cnfk) { } catch (ClassNotFoundException cnfk) {
throw new BuildException("Couldn\'t guess rmic implementation");
throw new BuildException("Couldn\'t guess rmic "
+ "implementation");
} }
} }
} }


+ 15
- 10
src/main/org/apache/tools/ant/taskdefs/rmic/SunRmic.java View File

@@ -1,7 +1,7 @@
/* /*
* The Apache Software License, Version 1.1 * 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. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,7 @@ import java.lang.reflect.Method;
* The implementation of the rmic for SUN's JDK. * The implementation of the rmic for SUN's JDK.
* *
* @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @since Ant 1.4
*/ */
public class SunRmic extends DefaultRmicAdapter { public class SunRmic extends DefaultRmicAdapter {


@@ -77,7 +78,8 @@ public class SunRmic extends DefaultRmicAdapter {


// Create an instance of the rmic, redirecting output to // Create an instance of the rmic, redirecting output to
// the project log // the project log
LogOutputStream logstr = new LogOutputStream(getRmic(), Project.MSG_WARN);
LogOutputStream logstr = new LogOutputStream(getRmic(),
Project.MSG_WARN);


try { try {
Class c = Class.forName("sun.rmi.rmic.Main"); Class c = Class.forName("sun.rmi.rmic.Main");
@@ -87,19 +89,22 @@ public class SunRmic extends DefaultRmicAdapter {


Method doRmic = c.getMethod("compile", Method doRmic = c.getMethod("compile",
new Class [] { String[].class }); 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(); return ok.booleanValue();
} catch (ClassNotFoundException ex) { } 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) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting SUN rmic: ", ex, getRmic().getLocation());
throw new BuildException("Error starting SUN rmic: ",
ex, getRmic().getLocation());
} }
} finally { } finally {
try { try {


+ 8
- 6
src/main/org/apache/tools/ant/taskdefs/rmic/WLRmic.java View File

@@ -66,6 +66,7 @@ import java.lang.reflect.Method;
* The implementation of the rmic for WebLogic * The implementation of the rmic for WebLogic
* *
* @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a> * @author <a href="mailto:tokamoto@rd.nttdata.co.jp">Takashi Okamoto</a>
* @since Ant 1.4
*/ */
public class WLRmic extends DefaultRmicAdapter { public class WLRmic extends DefaultRmicAdapter {


@@ -90,15 +91,16 @@ public class WLRmic extends DefaultRmicAdapter {
doRmic.invoke(null, new Object[] {cmd.getArguments() }); doRmic.invoke(null, new Object[] {cmd.getArguments() });
return true; return true;
} catch (ClassNotFoundException ex) { } 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) { if (ex instanceof BuildException) {
throw (BuildException) ex; throw (BuildException) ex;
} else { } else {
throw new BuildException("Error starting WebLogic rmic: ", ex, getRmic().getLocation());
throw new BuildException("Error starting WebLogic rmic: ", ex,
getRmic().getLocation());
} }
} finally { } finally {
if (loader != null) { if (loader != null) {


Loading…
Cancel
Save