diff --git a/WHATSNEW b/WHATSNEW index bedb6c0cf..50a824a1e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -281,6 +281,11 @@ Other changes: this release of Ant are detected as Java 1.5 and not 1.6. Bugzilla Report 50256. + * It is now possible to write a compiler adapter for that + compiles sources with extensions other than .java (but that still + compile to .class files). + Bugzilla Report 48829. + Changes from Ant 1.8.0 TO Ant 1.8.1 =================================== diff --git a/contributors.xml b/contributors.xml index 8f8879a07..7f9bd361a 100644 --- a/contributors.xml +++ b/contributors.xml @@ -70,6 +70,10 @@ Andreas Ames + + Andrew + Eisenberg + Andrew Everitt diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index 8cad7544b..f74c5f92b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -31,6 +31,7 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterExtension; import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.types.Reference; @@ -934,7 +935,10 @@ public class Javac extends MatchingTask { */ protected void scanDir(File srcDir, File destDir, String[] files) { GlobPatternMapper m = new GlobPatternMapper(); - m.setFrom("*.java"); + String[] extensions = findSupportedFileExtensions(); + + for (int i = 0; i < extensions.length; i++) { + m.setFrom(extensions[i]); m.setTo("*.class"); SourceFileScanner sfs = new SourceFileScanner(this); File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m); @@ -949,6 +953,33 @@ public class Javac extends MatchingTask { compileList.length, newFiles.length); compileList = newCompileList; } + } + } + + private String[] findSupportedFileExtensions() { + String compilerImpl = getCompiler(); + CompilerAdapter adapter = + nestedAdapter != null ? nestedAdapter : + CompilerAdapterFactory.getCompiler(compilerImpl, this, + createCompilerClasspath()); + String[] extensions = null; + if (adapter instanceof CompilerAdapterExtension) { + extensions = + ((CompilerAdapterExtension) adapter).getSupportedFileExtensions(); + } + + if (extensions == null) { + extensions = new String[] { "java" }; + } + + // now process the extensions to ensure that they are the + // right format + for (int i = 0; i < extensions.length; i++) { + if (!extensions[i].startsWith("*.")) { + extensions[i] = "*." + extensions[i]; + } + } + return extensions; } /** diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java index 510dc4e09..b678984c5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java @@ -44,7 +44,9 @@ import org.apache.tools.ant.taskdefs.condition.Os; * * @since Ant 1.3 */ -public abstract class DefaultCompilerAdapter implements CompilerAdapter { +public abstract class DefaultCompilerAdapter + implements CompilerAdapter, CompilerAdapterExtension { + private static final int COMMAND_LINE_LIMIT; static { if (Os.isFamily("os/2")) { @@ -127,6 +129,15 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { return attributes; } + /** + * By default, only recognize files with a Java extension, + * but specialized compilers can recognize multiple kinds + * of files. + */ + public String[] getSupportedFileExtensions() { + return new String[] { "java" }; + } + /** * Get the project this compiler adapter was created in. * @return the owner project