diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 197f593e9..d41e55099 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -60,9 +60,11 @@ import org.apache.tools.ant.DirectoryScanner; 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 @@ import java.util.Vector; * @author Stefan Bodewig * @author Takashi Okamoto tokamoto@rd.nttdata.co.jp * + * @since Ant 1.1 + * * @ant.task category="java" */ @@ -128,6 +132,8 @@ public class Rmic extends MatchingTask { 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 @@ public class Rmic extends MatchingTask { } 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 @@ public class Rmic extends MatchingTask { 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 @@ public class Rmic extends MatchingTask { 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 " + diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java b/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java index 8dcd6ae2f..76a866c64 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/DefaultRmicAdapter.java @@ -75,11 +75,13 @@ import java.util.Vector; * @author David Maclean david@cm.co.za * @author Stefan Bodewig * @author Takashi Okamoto + * @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 @@ 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. + * + * */ public FileNameMapper getMapper() { return mapper; @@ -124,23 +138,24 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { * 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 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { 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 @@ public abstract class DefaultRmicAdapter implements RmicAdapter { attributes.log(niceSourceList.toString(), Project.MSG_VERBOSE); } - private final static Random rand = new Random(); - /** * Mapper that may return up to two file names. * * */ private class RmicFileNameMapper implements FileNameMapper { diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java b/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java index e371e4bb8..06b289f0d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/KaffeRmic.java @@ -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.Project; import org.apache.tools.ant.types.Commandline; - import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -67,6 +66,7 @@ import java.lang.reflect.Method; * The implementation of the rmic for Kaffe * * @author Takashi Okamoto + * @since Ant 1.4 */ public class KaffeRmic extends DefaultRmicAdapter { @@ -84,15 +84,17 @@ public class KaffeRmic extends DefaultRmicAdapter { 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()); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java index 81817b003..6e04f7fd4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapter.java @@ -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 @@ import org.apache.tools.ant.util.FileNameMapper; * * @author Takashi Okamoto * @author Stefan Bodewig + * @since Ant 1.4 */ public interface RmicAdapter { diff --git a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java index 651978378..eb4fd0b4b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java @@ -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 @@ import org.apache.tools.ant.Task; * * @author Takashi Okamoto * @author J D Glanville + * @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 @@ public class RmicAdapterFactory { * Based on the parameter passed in, this method creates the necessary * factory desired. * - * The current mapping for rmic names are as follows: + *

The current mapping for rmic names are as follows:

*