Skip to content

Commit 81d66a5

Browse files
authored
Allow folders as classpath entries (#45)
The IJ parser allows for folders to be part of the classpath. This behaviour is useful for supplying folders of compiled .class or source files.
1 parent 387a38a commit 81d66a5

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

cli/src/main/java/net/neoforged/jst/cli/intellij/ClasspathSetup.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public static void addLibrary(Logger logger, Path libraryPath, IntelliJEnvironme
104104
if (!Files.exists(libraryPath)) {
105105
throw new UncheckedIOException(new NoSuchFileException(libraryPath.toString()));
106106
}
107-
ijEnv.addJarToClassPath(libraryPath);
107+
if (Files.isDirectory(libraryPath)) ijEnv.addFolderToClasspath(libraryPath);
108+
else ijEnv.addJarToClassPath(libraryPath);
108109
logger.debug("Added %s", libraryPath);
109110
}
110111
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public C1 get()La/b/c/Reference;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package a.b.c;
2+
3+
public record Reference(int a) {
4+
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import a.b.c.Reference;
2+
3+
public class C1 {
4+
public Reference get() {
5+
return new Reference(1);
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import a.b.c.Reference;
2+
3+
public class C1 {
4+
private Reference get() {
5+
return new Reference(1);
6+
}
7+
}

tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package net.neoforged.jst.tests;
22

3+
import com.intellij.util.ArrayUtil;
34
import net.neoforged.jst.cli.Main;
45
import org.assertj.core.util.CanIgnoreReturnValue;
56
import org.junit.jupiter.api.BeforeEach;
@@ -286,6 +287,11 @@ void testImplicitConstructors() throws Exception {
286287
void testIllegal() throws Exception {
287288
runATTest("illegal");
288289
}
290+
291+
@Test
292+
void testFolderClasspathEntries() throws Exception {
293+
runATTest("folder_classpath_entry", "--classpath=" + testDataRoot.resolve("accesstransformer/folder_classpath_entry/deps"));
294+
}
289295
}
290296

291297
@Nested
@@ -350,10 +356,15 @@ protected final void runInterfaceInjectionTest(String testDirName, Path tempDir,
350356
}
351357
}
352358

353-
protected final void runATTest(String testDirName) throws Exception {
359+
protected final void runATTest(String testDirName, final String... extraArgs) throws Exception {
354360
testDirName = "accesstransformer/" + testDirName;
355361
var atPath = testDataRoot.resolve(testDirName).resolve("accesstransformer.cfg");
356-
runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), "--enable-accesstransformers", "--access-transformer", atPath.toString());
362+
runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), ArrayUtil.mergeArrays(
363+
new String[]{
364+
"--enable-accesstransformers", "--access-transformer", atPath.toString()
365+
},
366+
extraArgs
367+
));
357368
}
358369

359370
protected final void runParchmentTest(String testDirName, String mappingsFilename) throws Exception {

0 commit comments

Comments
 (0)