Skip to content

Commit 2af2a57

Browse files
committed
GROOVY-11607: groovyc: fileset lists files
3_0_X backport
1 parent 8577625 commit 2af2a57

3 files changed

Lines changed: 33 additions & 11 deletions

File tree

subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.codehaus.groovy.control.CompilationUnit;
3838
import org.codehaus.groovy.control.CompilerConfiguration;
3939
import org.codehaus.groovy.control.SourceExtensionHandler;
40-
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
4140
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
4241
import org.codehaus.groovy.tools.ErrorReporter;
4342
import org.codehaus.groovy.tools.FileSystemCompiler;
@@ -870,17 +869,19 @@ public void execute() throws BuildException {
870869

871870
if (javac != null) jointCompilation = true;
872871

873-
// scan source directories and dest directory to build up
874-
// compile lists
875-
String[] list = src.list();
876-
for (String filename : list) {
872+
// scan source directories and dest directory to build up compile lists
873+
for (String filename : src.list()) {
877874
File file = getProject().resolveFile(filename);
878875
if (!file.exists()) {
879876
throw new BuildException("srcdir \"" + file.getPath() + "\" does not exist!", getLocation());
880877
}
881-
DirectoryScanner ds = this.getDirectoryScanner(file);
882-
String[] files = ds.getIncludedFiles();
883-
scanDir(file, destDir != null ? destDir : file, files);
878+
if (file.isDirectory()) {
879+
DirectoryScanner ds = getDirectoryScanner(file);
880+
scanDir(file, destDir != null ? destDir : file, ds.getIncludedFiles());
881+
} else { // GROOVY-11607: fileset lists files
882+
compileList = Arrays.copyOf(compileList, compileList.length + 1);
883+
compileList[compileList.length - 1] = file;
884+
}
884885
}
885886

886887
compile();
@@ -892,7 +893,7 @@ public void execute() throws BuildException {
892893
}
893894

894895
/**
895-
* Clear the list of files to be compiled and copied.
896+
* Clears the list of files to be compiled and copied.
896897
*/
897898
protected void resetFileLists() {
898899
compileList = EMPTY_FILE_ARRAY;
@@ -1260,8 +1261,9 @@ private PrintWriter printWriter(File tempFile) throws IOException {
12601261
}
12611262

12621263
private String[] makeCommandLine(List<String> commandLineList) {
1263-
log.info("Compilation arguments:\n" + DefaultGroovyMethods.join((Iterable<String>) commandLineList, "\n"));
1264-
return commandLineList.toArray(EMPTY_STRING_ARRAY);
1264+
String[] commandLine = commandLineList.toArray(EMPTY_STRING_ARRAY);
1265+
log.info("Compilation arguments:\n" + String.join("\n", commandLine));
1266+
return commandLine;
12651267
}
12661268

12671269
private void runForked(String[] commandLine) {

subprojects/groovy-ant/src/test-resources/org/codehaus/groovy/ant/GroovycTest.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@
186186
<java classname="org.codehaus.groovy.ant.ParameterMetadataCheck"/>
187187
</target>
188188

189+
<!-- GROOVY-11607 -->
190+
<target name="plainForkedCompilation_NestingSrcElementCheck">
191+
<groovyc destdir="${destPath}" fork="true">
192+
<src>
193+
<fileset dir="${srcPath}">
194+
<include name="GroovycTest*.*"/>
195+
<exclude name="GroovycTest.xml"/>
196+
<exclude name="GroovycTest2.java"/>
197+
</fileset>
198+
</src>
199+
</groovyc>
200+
<java classname="org.codehaus.groovy.ant.GroovycTest1"/>
201+
</target>
202+
189203
<target name="clean">
190204
<delete quiet="true">
191205
<fileset dir="${destPath}/org/codehaus/groovy/ant">

subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovycTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,10 @@ public void testJointCompilationPropagatesParameters() throws Exception {
313313
Method m = c.getDeclaredMethod("main", String[].class);
314314
assertEquals("args", m.getParameters()[0].getName());
315315
}
316+
317+
// GROOVY-11607
318+
public void testPlainForkedCompilation_NestingSrcElementCheck() {
319+
ensureExecutes("plainForkedCompilation_NestingSrcElementCheck");
320+
ensureNotPresent("GroovycTest2"); // excluded from src > fileset
321+
}
316322
}

0 commit comments

Comments
 (0)