Skip to content

Commit ce62776

Browse files
authored
file only
1 parent 693e99c commit ce62776

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/main/java/mods/Hileb/shotaasm/impl/compiler/Compiler.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
public class Compiler {
1616

17-
public List<String> options = null;
17+
public List<File> classpath = null;
1818

1919
private final Map<String, VirtualJavaFileObject> javaFileObjectMap = new HashMap<>();
2020
private Map<String, byte[]> results = new HashMap<>();
@@ -25,8 +25,8 @@ public Compiler(){
2525
this(null);
2626
}
2727

28-
public Compiler(List<String> options) {
29-
this.options = options;
28+
public Compiler(List<File> options) {
29+
this.classpath = options;
3030
}
3131

3232
public void addSource(String name, String content) {
@@ -62,10 +62,13 @@ public CompileError compile() {
6262
if (compiler == null) return new CompileError("Could not found JavaCompiler, might not run in jdk.");
6363
else {
6464
try(StandardJavaFileManager standardJavaFileManager = compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8)) {
65+
if (this.classpath != null)
66+
standardJavaFileManager.setLocation(StandardLocation.CLASS_PATH, classpath);
6567
VirtualFileManager fileManager = new VirtualFileManager(standardJavaFileManager, this.javaFileObjectMap);
68+
6669
try {
6770
StringWriter stringWriter = new StringWriter();
68-
JavaCompiler.CompilationTask task = compiler.getTask(stringWriter, fileManager, (DiagnosticListener<? super JavaFileObject>)(Object) listener, options, null, javaFileObjectMap.values());
71+
JavaCompiler.CompilationTask task = compiler.getTask(stringWriter, fileManager, (DiagnosticListener<? super JavaFileObject>)(Object) listener, null, null, javaFileObjectMap.values());
6972
if (task.call() == Boolean.TRUE) {
7073
this.results = fileManager.getClasses();
7174
return null;

src/main/java/mods/Hileb/shotaasm/impl/compiler/CompilerFactory.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,35 @@
77

88
import javax.tools.*;
99
import java.io.*;
10-
import java.net.URISyntaxException;
11-
import java.net.URL;
10+
import java.net.*;
1211
import java.nio.charset.StandardCharsets;
1312
import java.nio.file.*;
1413
import java.util.*;
1514

1615
public class CompilerFactory{
17-
public List<String> options = null;
16+
public List<File> classpath = null;
1817

1918
public CompilerFactory(URL[] classpath) {
20-
this.options = new ArrayList<>();
21-
this.options.add("-classpath");
22-
this.options.add(buildClasspath(classpath));
23-
this.options.add("-Xlint:unchecked");
19+
this.classpath = new ArrayList<>();
20+
for(URL url : classpath) {
21+
if ("file".equals(url.getProtocol())) {
22+
try {
23+
this.classpath.add(new File(url.toURI()));
24+
} catch (URISyntaxException e) {}
25+
}
26+
}
2427

2528
if (ShotaASM.DEBUG) {
2629
ShotaASM.LOGGER.info("Java Compiler Factory Debug.");
2730
String s0 = "";
28-
for (String s : this.options) {
31+
for (File s : this.classpath) {
2932
s0 = s0 + s;
3033
}
31-
ShotaASM.LOGGER.info("Options : {}", s0);
34+
ShotaASM.LOGGER.info("Classpath : {}", s0);
3235
}
3336
}
3437

3538
public Compiler compiler(){
3639
return new Compiler(this.options);
3740
}
38-
39-
public static String buildClasspath(URL[] urls) {
40-
if (urls == null || urls.length == 0) return System.getProperty("java.class.path");
41-
42-
StringBuilder classpath = new StringBuilder(System.getProperty("java.class.path"));
43-
for (URL url : urls) {
44-
try {
45-
//Attempt to handle different URL schemes. This is not exhaustive, but covers common cases.
46-
if("file".equals(url.getProtocol())){
47-
//Handle potential space in file path
48-
classpath.append(File.pathSeparator).append(url.getPath().replace(" ", "%20"));
49-
} else {
50-
classpath.append(File.pathSeparator).append(url.toString());
51-
}
52-
} catch (Exception e) {
53-
ShotaASM.LOGGER.error("Error processing URL {} because of {}", url, e);
54-
}
55-
}
56-
return classpath.toString();
57-
}
5841
}

0 commit comments

Comments
 (0)