Skip to content

Commit 01880be

Browse files
committed
Always write temporary projects for non-Maven sources
When compiling a .java file that is contained in, say, a Downloads/ directory, we definitely do not want to compile all of the .java files available in the complete Downloads/** directory structure. Now, we could special-case .java files containing the source for a class in the default package, while still trying to discover .java files recursively when the class is in a package and the directory structure agrees with the package name. But that would just violate the Law of the Least Surprise and confuse people. So let's just make a temporary project in *every* case where we do not find a pom.xml file in the expected location. Incidentally, this makes sure that we always include pom.xml files in the generated .jar files. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4db01e4 commit 01880be

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ private MavenProject getMavenProject(final BuildEnvironment env,
296296
final File pom = new File(path, "pom.xml");
297297
if (pom.exists()) return env.parse(pom, null);
298298
}
299-
final File rootDirectory = file.getParentFile();
300-
final String artifactId = fakeArtifactId(env, file.getName());
301-
return fakePOM(env, rootDirectory, artifactId, mainClass);
299+
return writeTemporaryProject(env, new FileReader(file));
302300
}
303301

304302
private static String getFullClassName(final File file) throws IOException {
@@ -405,7 +403,6 @@ private static MavenProject fakePOM(final BuildEnvironment env,
405403
append(pom, project, "version", DEFAULT_VERSION);
406404

407405
final Element build = append(pom, project, "build", null);
408-
append(pom, build, "sourceDirectory", directory.getPath());
409406

410407
if (mainClass != null) {
411408
final Element plugins = append(pom, build, "plugins", null);

0 commit comments

Comments
 (0)