1
1
package io .bazel .rulesscala .scalac ;
2
2
3
- import java .io .File ;
4
- import java .io .FileNotFoundException ;
5
- import java .io .IOException ;
6
- import java .nio .file .FileSystems ;
7
- import java .nio .file .Files ;
8
- import java .nio .file .Path ;
9
3
import java .util .ArrayList ;
10
4
import java .util .HashMap ;
11
5
import java .util .List ;
@@ -18,14 +12,12 @@ public class CompileOptions {
18
12
final public String [] pluginArgs ;
19
13
final public String classpath ;
20
14
final public String [] files ;
21
- final public Path outputPath ;
22
15
final public String [] sourceJars ;
23
16
final public boolean iJarEnabled ;
24
17
final public String ijarOutput ;
25
18
final public String ijarCmdPath ;
26
- final public Path tmpPath ;
27
19
28
- public CompileOptions (List <String > args ) throws IOException , FileNotFoundException {
20
+ public CompileOptions (List <String > args ) {
29
21
Map <String , String > argMap = buildArgMap (args );
30
22
31
23
outputName = getOrError (argMap , "JarOutput" , "Missing required arg JarOutput" );
@@ -34,21 +26,9 @@ public CompileOptions(List<String> args) throws IOException, FileNotFoundExcepti
34
26
scalaOpts = getOrEmpty (argMap , "ScalacOpts" ).split ("," );
35
27
pluginArgs = buildPluginArgs (getOrEmpty (argMap , "Plugins" ));
36
28
classpath = getOrError (argMap , "Classpath" , "Must supply the classpath arg" );
37
- outputPath = FileSystems . getDefault (). getPath ( outputName );
29
+ files = getOrEmpty ( argMap , "Files" ). split ( "," );
38
30
39
31
sourceJars = getOrEmpty (argMap , "SourceJars" ).split ("," );
40
- List <File > sourceFiles = new ArrayList <File >();
41
-
42
- for (String jarPath : sourceJars ) {
43
- if (jarPath .length () > 0 ){
44
- Path tmpPath = Files .createTempDirectory (outputPath .getParent (), "tmp" );
45
- sourceFiles .addAll (extractJar (jarPath , tmpPath .toString ()));
46
- }
47
- }
48
- files = appendToString (getOrEmpty (argMap , "Files" ).split ("," ), sourceFiles );
49
- if (files .length == 0 ) {
50
- throw new RuntimeException ("Must have input files from either source jars or local files." );
51
- }
52
32
iJarEnabled = booleanGetOrFalse (argMap , "EnableIjar" );
53
33
if (iJarEnabled ) {
54
34
ijarOutput = getOrError (argMap , "ijarOutput" , "Missing required arg ijarOutput when ijar enabled" );
@@ -58,18 +38,6 @@ public CompileOptions(List<String> args) throws IOException, FileNotFoundExcepti
58
38
ijarOutput = null ;
59
39
ijarCmdPath = null ;
60
40
}
61
- tmpPath = Files .createTempDirectory (outputPath .getParent (),"tmp" );
62
- }
63
-
64
- private static <T > String [] appendToString (String [] init , List <T > rest ) {
65
- String [] tmp = new String [init .length + rest .size ()];
66
- System .arraycopy (init , 0 , tmp , 0 , init .length );
67
- int baseIdx = init .length ;
68
- for (T t : rest ) {
69
- tmp [baseIdx ] = t .toString ();
70
- baseIdx += 1 ;
71
- }
72
- return tmp ;
73
41
}
74
42
75
43
private static HashMap <String , String > buildArgMap (List <String > lines ) {
@@ -129,33 +97,4 @@ public static String[] buildPluginArgs(String packedPlugins) {
129
97
}
130
98
return result ;
131
99
}
132
- private static List <File > extractJar (String jarPath ,
133
- String outputFolder ) throws IOException , FileNotFoundException {
134
-
135
- List <File > outputPaths = new ArrayList <File >();
136
- java .util .jar .JarFile jar = new java .util .jar .JarFile (jarPath );
137
- java .util .Enumeration e = jar .entries ();
138
- while (e .hasMoreElements ()) {
139
- java .util .jar .JarEntry file = (java .util .jar .JarEntry ) e .nextElement ();
140
- File f = new File (outputFolder + java .io .File .separator + file .getName ());
141
-
142
- if (file .isDirectory ()) { // if its a directory, create it
143
- f .mkdirs ();
144
- continue ;
145
- }
146
-
147
- File parent = f .getParentFile ();
148
- parent .mkdirs ();
149
- outputPaths .add (f );
150
-
151
- java .io .InputStream is = jar .getInputStream (file ); // get the input stream
152
- java .io .FileOutputStream fos = new java .io .FileOutputStream (f );
153
- while (is .available () > 0 ) { // write contents of 'is' to 'fos'
154
- fos .write (is .read ());
155
- }
156
- fos .close ();
157
- is .close ();
158
- }
159
- return outputPaths ;
160
- }
161
100
}
0 commit comments