Skip to content

Commit

Permalink
Allow folders as classpath entries (#45)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lynxplay authored Feb 16, 2025
1 parent 387a38a commit 81d66a5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public static void addLibrary(Logger logger, Path libraryPath, IntelliJEnvironme
if (!Files.exists(libraryPath)) {
throw new UncheckedIOException(new NoSuchFileException(libraryPath.toString()));
}
ijEnv.addJarToClassPath(libraryPath);
if (Files.isDirectory(libraryPath)) ijEnv.addFolderToClasspath(libraryPath);
else ijEnv.addJarToClassPath(libraryPath);
logger.debug("Added %s", libraryPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
public C1 get()La/b/c/Reference;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package a.b.c;

public record Reference(int a) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import a.b.c.Reference;

public class C1 {
public Reference get() {
return new Reference(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import a.b.c.Reference;

public class C1 {
private Reference get() {
return new Reference(1);
}
}
15 changes: 13 additions & 2 deletions tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.neoforged.jst.tests;

import com.intellij.util.ArrayUtil;
import net.neoforged.jst.cli.Main;
import org.assertj.core.util.CanIgnoreReturnValue;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -286,6 +287,11 @@ void testImplicitConstructors() throws Exception {
void testIllegal() throws Exception {
runATTest("illegal");
}

@Test
void testFolderClasspathEntries() throws Exception {
runATTest("folder_classpath_entry", "--classpath=" + testDataRoot.resolve("accesstransformer/folder_classpath_entry/deps"));
}
}

@Nested
Expand Down Expand Up @@ -350,10 +356,15 @@ protected final void runInterfaceInjectionTest(String testDirName, Path tempDir,
}
}

protected final void runATTest(String testDirName) throws Exception {
protected final void runATTest(String testDirName, final String... extraArgs) throws Exception {
testDirName = "accesstransformer/" + testDirName;
var atPath = testDataRoot.resolve(testDirName).resolve("accesstransformer.cfg");
runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), "--enable-accesstransformers", "--access-transformer", atPath.toString());
runTest(testDirName, txt -> txt.replace(atPath.toAbsolutePath().toString(), "{atpath}"), ArrayUtil.mergeArrays(
new String[]{
"--enable-accesstransformers", "--access-transformer", atPath.toString()
},
extraArgs
));
}

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

0 comments on commit 81d66a5

Please sign in to comment.