Skip to content

Commit

Permalink
classpath and sourcepath work
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Nov 22, 2023
1 parent 61e097f commit 039b39e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
16 changes: 11 additions & 5 deletions src/main/java/io/github/astrarre/sfu/impl/SFUImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SFUImpl implements SourceFixerUpper {
UNWRAP = MethodHandles.privateLookupIn(ClientCodeWrapper.class, MethodHandles.lookup())
.findVirtual(ClientCodeWrapper.class, "unwrap",
MethodType.methodType(JavaFileObject.class, JavaFileObject.class));
} catch (NoSuchMethodException | IllegalAccessException e) {
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -83,12 +83,14 @@ public SourceFixerUpper classpath(Path root) {

@Override
public void process() throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, charset);
JavacTool compiler = JavacTool.create();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavacTool javac = JavacTool.create();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, charset);

JavacTaskImpl task = (JavacTaskImpl) javac.getTask(null,
fileManager.setLocationFromPaths(StandardLocation.CLASS_PATH, classpath);
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath);

JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null,
fileManager,
diagnostics,
List.of("-proc:none"),
Expand Down Expand Up @@ -125,6 +127,10 @@ public void process() throws IOException {
Files.createDirectories(sourceFile.output.getParent());
Files.writeString(sourceFile.output, builder.toString(), charset);
}

for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
System.err.println(diagnostic);
}
}

record WrappedJavaFileObject(JavaFileObject object, Path output) implements JavaFileObject {
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/io/github/astrarre/sfu/test/RemappingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class RemappingTests {
Path originals = root.resolve("original");
Path remapped = root.resolve("remapped");
Path mappings = root.resolve("mappings");
Path classpaths = root.resolve("classpath");
Path sourcepaths = root.resolve("sourcepath");

public RemappingTests() throws IOException {
}
Expand All @@ -35,6 +37,8 @@ public void remap(String testCase) throws IOException {
Path original = originals.resolve(testCase);
Path output = tempRoot.resolve(testCase);
Path test = remapped.resolve(testCase);
Path classpath = classpaths.resolve(testCase + ".jar");
Path sourcepath = sourcepaths.resolve(testCase + ".jar");

MemoryMappingTree tree = new MemoryMappingTree();

Expand All @@ -51,6 +55,14 @@ public void remap(String testCase) throws IOException {
}
});

if (Files.exists(classpath)) {
sfu.classpath(classpath);
}

if (Files.exists(sourcepath)) {
sfu.sourcepath(sourcepath);
}

sfu.process();

verifyDirsAreEqual(output, test, false);
Expand Down
Binary file added src/test/resources/classpath/verbatim.jar
Binary file not shown.
6 changes: 5 additions & 1 deletion src/test/resources/original/verbatim/A.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import it.*;
import sources.*;

// insert junk into this file; it should be converted 1 <=> 1
public class A<WE_DO_A_LITTLE_TROLLING extends Object> {
public class A<WE_DO_A_LITTLE_TROLLING extends Object> implements Thing {
Exist lol;
}
6 changes: 5 additions & 1 deletion src/test/resources/remapped/verbatim/A.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import it.*;
import sources.*;

// insert junk into this file; it should be converted 1 <=> 1
public class A<WE_DO_A_LITTLE_TROLLING extends Object> {
public class A<WE_DO_A_LITTLE_TROLLING extends Object> implements Thing {
Exist lol;
}
Binary file added src/test/resources/sourcepath/verbatim.jar
Binary file not shown.

0 comments on commit 039b39e

Please sign in to comment.