diff --git a/src/main/java/spoon/support/compiler/jdt/JDTBasedSpoonCompiler.java b/src/main/java/spoon/support/compiler/jdt/JDTBasedSpoonCompiler.java index fe4125ed85e..26e8f182d9e 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTBasedSpoonCompiler.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTBasedSpoonCompiler.java @@ -392,7 +392,7 @@ protected CompilationUnitDeclaration[] buildUnits(JDTBuilder jdtBuilder, SpoonFo .classpathOptions(new ClasspathOptions().encoding(this.encoding).classpath(classpath)) // .complianceOptions(new ComplianceOptions().compliance(javaCompliance)) // .advancedOptions(new AdvancedOptions().preserveUnusedVars().continueExecution().enableJavadoc()) // - .sources(new SourceOptions().sources()) // no sources, handled by the JDTBatchCompiler + .sources(new SourceOptions().sources(sourcesFolder.getAllJavaFiles())) // no sources, handled by the JDTBatchCompiler .build(); } else { args = jdtBuilder.build(); diff --git a/src/test/java/spoon/LauncherTest.java b/src/test/java/spoon/LauncherTest.java index 05077104a37..3c387929b45 100644 --- a/src/test/java/spoon/LauncherTest.java +++ b/src/test/java/spoon/LauncherTest.java @@ -1,6 +1,7 @@ package spoon; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import spoon.compiler.Environment; @@ -8,6 +9,8 @@ import spoon.support.JavaOutputProcessor; import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -68,4 +71,25 @@ public void testInitEnvironment() throws Exception { } + @Test + public void testLauncherInEmptyWorkingDir() throws Exception { + + // Contract: Spoon can be launched in an empty folder as a working directory + // See: https://github.com/INRIA/spoon/pull/1208 + // This test does not fail (it's not enough to change user.dir we should launch process inside that dir) but it explains the problem + final Launcher launcher = new Launcher(); + Path path = Files.createTempDirectory("emptydir"); + + String oldUserDir = System.getProperty("user.dir"); + System.setProperty("user.dir", path.toFile().getAbsolutePath()); + + // path should exist, otherwise it would crash on a filenotfoundexception before showing the bug + launcher.addInputResource(oldUserDir+"/src/test/java/spoon/LauncherTest.java"); + try { + launcher.buildModel(); + } finally { + System.setProperty("user.dir", oldUserDir); + } + } + } \ No newline at end of file