@@ -43,20 +43,23 @@ public class JavaCompiler extends InternalCompiler
43
43
@ Override
44
44
public byte [] compile (String contents , String fullyQualifiedName )
45
45
{
46
- String fileStart = TEMP_DIRECTORY + FS + "temp" + MiscUtils .randomString (12 ) + FS ;
47
- String fileStart2 = TEMP_DIRECTORY + FS + "temp" + MiscUtils .randomString (12 ) + FS ;
48
- File java = new File (fileStart + FS + fullyQualifiedName + ".java" );
49
- File clazz = new File (fileStart2 + FS + fullyQualifiedName + ".class" );
50
- File cp = new File (TEMP_DIRECTORY + FS + "cpath_" + MiscUtils .randomString (12 ) + ".jar" );
51
- File tempD = new File (fileStart + FS + fullyQualifiedName .substring (0 , fullyQualifiedName .length () -
46
+ final String fileStart = TEMP_DIRECTORY + FS + "temp" + MiscUtils .randomString (12 ) + FS ;
47
+ final String fileStart2 = TEMP_DIRECTORY + FS + "temp" + MiscUtils .randomString (12 ) + FS ;
48
+
49
+ final File javaFile = new File (fileStart + FS + fullyQualifiedName + ".java" );
50
+ final File classFile = new File (fileStart2 + FS + fullyQualifiedName + ".class" );
51
+ final File classPath = new File (TEMP_DIRECTORY + FS + "cpath_" + MiscUtils .randomString (12 ) + ".jar" );
52
+ final File tempDirectory = new File (fileStart + FS + fullyQualifiedName .substring (0 , fullyQualifiedName .length () -
52
53
fullyQualifiedName .split ("/" )[fullyQualifiedName .split ("/" ).length - 1 ].length ()));
53
54
54
- tempD .mkdirs ();
55
+ //create the temp directories
56
+ tempDirectory .mkdirs ();
55
57
new File (fileStart2 ).mkdirs ();
56
58
57
59
if (Configuration .javac .isEmpty () || !new File (Configuration .javac ).exists ())
58
60
{
59
- BytecodeViewer .showMessage ("You need to set your Javac path, this requires the JDK to be downloaded." + NL + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)" );
61
+ BytecodeViewer .showMessage ("You need to set your Javac path, this requires the JDK to be downloaded."
62
+ + NL + "(C:/Program Files/Java/JDK_xx/bin/javac.exe)" );
60
63
ExternalResources .getSingleton ().selectJavac ();
61
64
}
62
65
@@ -66,8 +69,11 @@ public byte[] compile(String contents, String fullyQualifiedName)
66
69
return null ;
67
70
}
68
71
69
- DiskWriter .replaceFile (java .getAbsolutePath (), contents , false );
70
- JarUtils .saveAsJar (BytecodeViewer .getLoadedClasses (), cp .getAbsolutePath ());
72
+ //write the file we're assembling to disk
73
+ DiskWriter .replaceFile (javaFile .getAbsolutePath (), contents , false );
74
+
75
+ //write the entire temporary classpath to disk
76
+ JarUtils .saveAsJar (BytecodeViewer .getLoadedClasses (), classPath .getAbsolutePath ());
71
77
72
78
boolean cont = true ;
73
79
try
@@ -77,10 +83,10 @@ public byte[] compile(String contents, String fullyQualifiedName)
77
83
78
84
if (Configuration .library .isEmpty ())
79
85
pb = new ProcessBuilder (Configuration .javac , "-d" , fileStart2 ,
80
- "-classpath" , cp .getAbsolutePath (), java .getAbsolutePath ());
86
+ "-classpath" , classPath .getAbsolutePath (), javaFile .getAbsolutePath ());
81
87
else
82
88
pb = new ProcessBuilder (Configuration .javac , "-d" , fileStart2 ,
83
- "-classpath" , cp .getAbsolutePath () + System .getProperty ("path.separator" ) + Configuration .library , java .getAbsolutePath ());
89
+ "-classpath" , classPath .getAbsolutePath () + System .getProperty ("path.separator" ) + Configuration .library , javaFile .getAbsolutePath ());
84
90
85
91
Process process = pb .start ();
86
92
BytecodeViewer .createdProcesses .add (process );
@@ -111,6 +117,7 @@ public byte[] compile(String contents, String fullyQualifiedName)
111
117
}
112
118
113
119
log .append (NL ).append (NL ).append (TranslatedStrings .ERROR2 ).append (NL ).append (NL );
120
+
114
121
try (InputStream is = process .getErrorStream ();
115
122
InputStreamReader isr = new InputStreamReader (is );
116
123
BufferedReader br = new BufferedReader (isr ))
@@ -123,7 +130,7 @@ public byte[] compile(String contents, String fullyQualifiedName)
123
130
log .append (NL ).append (NL ).append (TranslatedStrings .EXIT_VALUE_IS ).append (" " ).append (exitValue );
124
131
System .out .println (log );
125
132
126
- if (!clazz .exists ())
133
+ if (!classFile .exists ())
127
134
throw new Exception (log .toString ());
128
135
}
129
136
catch (Exception e )
@@ -132,12 +139,12 @@ public byte[] compile(String contents, String fullyQualifiedName)
132
139
e .printStackTrace ();
133
140
}
134
141
135
- cp .delete ();
142
+ classPath .delete ();
136
143
137
144
if (cont )
138
145
try
139
146
{
140
- return org .apache .commons .io .FileUtils .readFileToByteArray (clazz );
147
+ return org .apache .commons .io .FileUtils .readFileToByteArray (classFile );
141
148
}
142
149
catch (IOException e )
143
150
{
0 commit comments