FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
processing/java/test/processing/mode/java/UTCompiler.java at master · dzaima/processing · GitHub
dzaima
processing
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
processing
/
java
/
test
/
processing
/
mode
/
java
/
UTCompiler.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (56 loc) · 1.86 KB
Breadcrumbs
processing
/
java
/
test
/
processing
/
mode
/
java
/
UTCompiler.java
Copy path
File metadata and controls
60 lines (56 loc) · 1.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package
processing
.
mode
.
java
;
import
java
.
io
.
File
;
import
java
.
io
.
FileWriter
;
import
java
.
io
.
IOException
;
import
processing
.
app
.
Platform
;
import
processing
.
app
.
exec
.
ProcessHelper
;
import
processing
.
app
.
exec
.
ProcessResult
;
/**
* Utility class for compiling single compilationUnits.
*
* @author Jonathan Feinberg <jdf@pobox.com>
*
*/
class
UTCompiler
{
private
final
String
classpath
;
UTCompiler
(
File
...
classpath
)
throws
IOException
{
final
StringBuilder
sb
=
new
StringBuilder
();
for
(
final
File
f
:
classpath
) {
if
(
sb
.
length
() >
0
)
sb
.
append
(
File
.
pathSeparatorChar
);
sb
.
append
(
f
.
getAbsolutePath
());
}
this
.
classpath
=
sb
.
toString
();
}
ProcessResult
compile
(
final
String
name
,
final
String
program
)
throws
IOException
{
final
File
tmpdir
=
File
.
createTempFile
(
"utcompiler"
,
".tmp"
);
if
(!
tmpdir
.
delete
())
throw
new
IOException
(
"Cannot delete "
+
tmpdir
);
if
(!
tmpdir
.
mkdir
())
throw
new
IOException
(
"Cannot create "
+
tmpdir
);
final
File
javaFile
=
new
File
(
tmpdir
,
name
+
".java"
);
final
FileWriter
java
=
new
FileWriter
(
javaFile
);
try
{
java
.
write
(
program
);
}
finally
{
java
.
close
();
}
try
{
return
new
ProcessHelper
(
"javac"
,
"-sourcepath"
,
tmpdir
.
getAbsolutePath
(),
"-cp"
,
classpath
,
"-nowarn"
,
"-d"
,
tmpdir
.
getAbsolutePath
(),
javaFile
.
getAbsolutePath
()).
execute
();
}
catch
(
InterruptedException
e
) {
throw
new
RuntimeException
(
e
);
}
finally
{
for
(
final
File
f
:
tmpdir
.
listFiles
())
if
(!
f
.
getName
().
startsWith
(
"."
))
if
(!
f
.
delete
())
throw
new
IOException
(
"Can't delete "
+
f
);
if
(!
tmpdir
.
delete
())
throw
new
IOException
(
"Can't delete "
+
tmpdir
);
}
}
}
Back
|
FazBrowse Home
|
New Git URL