Browse Source

support sources with extensions other than .java in javac. Submitted by Andrew Eisenberg. PR 48829.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1040170 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 14 years ago
parent
commit
4a07176abb
4 changed files with 53 additions and 2 deletions
  1. +5
    -0
      WHATSNEW
  2. +4
    -0
      contributors.xml
  3. +32
    -1
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  4. +12
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java

+ 5
- 0
WHATSNEW View File

@@ -281,6 +281,11 @@ Other changes:
this release of Ant are detected as Java 1.5 and not 1.6. this release of Ant are detected as Java 1.5 and not 1.6.
Bugzilla Report 50256. Bugzilla Report 50256.


* It is now possible to write a compiler adapter for <javac> 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 Changes from Ant 1.8.0 TO Ant 1.8.1
=================================== ===================================




+ 4
- 0
contributors.xml View File

@@ -70,6 +70,10 @@
<first>Andreas</first> <first>Andreas</first>
<last>Ames</last> <last>Ames</last>
</name> </name>
<name>
<first>Andrew</first>
<last>Eisenberg</last>
</name>
<name> <name>
<first>Andrew</first> <first>Andrew</first>
<last>Everitt</last> <last>Everitt</last>


+ 32
- 1
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -31,6 +31,7 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; 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.taskdefs.compilers.CompilerAdapterFactory;
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;
@@ -934,7 +935,10 @@ public class Javac extends MatchingTask {
*/ */
protected void scanDir(File srcDir, File destDir, String[] files) { protected void scanDir(File srcDir, File destDir, String[] files) {
GlobPatternMapper m = new GlobPatternMapper(); 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"); m.setTo("*.class");
SourceFileScanner sfs = new SourceFileScanner(this); SourceFileScanner sfs = new SourceFileScanner(this);
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m); File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
@@ -949,6 +953,33 @@ public class Javac extends MatchingTask {
compileList.length, newFiles.length); compileList.length, newFiles.length);
compileList = newCompileList; 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;
} }


/** /**


+ 12
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -44,7 +44,9 @@ import org.apache.tools.ant.taskdefs.condition.Os;
* *
* @since Ant 1.3 * @since Ant 1.3
*/ */
public abstract class DefaultCompilerAdapter implements CompilerAdapter {
public abstract class DefaultCompilerAdapter
implements CompilerAdapter, CompilerAdapterExtension {

private static final int COMMAND_LINE_LIMIT; private static final int COMMAND_LINE_LIMIT;
static { static {
if (Os.isFamily("os/2")) { if (Os.isFamily("os/2")) {
@@ -127,6 +129,15 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
return attributes; 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. * Get the project this compiler adapter was created in.
* @return the owner project * @return the owner project


Loading…
Cancel
Save