77
88import javax .tools .*;
99import java .io .*;
10- import java .net .URISyntaxException ;
11- import java .net .URL ;
10+ import java .net .*;
1211import java .nio .charset .StandardCharsets ;
1312import java .nio .file .*;
1413import java .util .*;
1514
1615public 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