62
62
* the DOS epoch. All Jar entries are sorted alphabetically.
63
63
*/
64
64
public class ScalaCInvoker {
65
+ private static List <File > extractJar (String jarPath , String outputFolder ) throws IOException , FileNotFoundException {
66
+ List <File > outputPaths = new ArrayList <File >();
67
+ java .util .jar .JarFile jar = new java .util .jar .JarFile (jarPath );
68
+ java .util .Enumeration e = jar .entries ();
69
+ while (e .hasMoreElements ()) {
70
+ java .util .jar .JarEntry file = (java .util .jar .JarEntry ) e .nextElement ();
71
+ java .io .File f = new java .io .File (outputFolder + java .io .File .separator + file .getName ());
72
+
73
+ if (file .isDirectory ()) { // if its a directory, create it
74
+ f .mkdirs ();
75
+ continue ;
76
+ }
77
+
78
+ File parent = f .getParentFile ();
79
+ System .out .println ("Mkdir: " + parent );
80
+ parent .mkdirs ();
81
+ outputPaths .add (f );
82
+
83
+ java .io .InputStream is = jar .getInputStream (file ); // get the input stream
84
+ java .io .FileOutputStream fos = new java .io .FileOutputStream (f );
85
+ while (is .available () > 0 ) { // write contents of 'is' to 'fos'
86
+ fos .write (is .read ());
87
+ }
88
+ fos .close ();
89
+ is .close ();
90
+ }
91
+ return outputPaths ;
92
+ }
93
+
94
+
65
95
// A UUID that uniquely identifies this running worker process.
66
96
static final UUID workerUuid = UUID .randomUUID ();
67
97
@@ -201,7 +231,8 @@ private static HashMap<String, String> buildArgMap(List<String> lines) {
201
231
throw new RuntimeException ("Bad arg, should have at most 1 space/2 spans. arg: " + line );
202
232
}
203
233
if (lSplit .length > 1 ) {
204
- hm .put (lSplit [0 ].substring (0 , lSplit [0 ].length () - 1 ), lSplit [1 ]);
234
+ String k = lSplit [0 ].substring (0 , lSplit [0 ].length () - 1 );
235
+ hm .put (k , lSplit [1 ]);
205
236
}
206
237
}
207
238
return hm ;
@@ -261,7 +292,33 @@ private static void processRequest(List<String> args) throws Exception {
261
292
String [] scalaOpts = getOrEmpty (argMap , "ScalacOpts" ).split ("," );
262
293
String [] pluginArgs = buildPluginArgs (getOrEmpty (argMap , "Plugins" ));
263
294
String classpath = getOrError (argMap , "Classpath" , "Must supply the classpath arg" );
264
- String [] files = getOrError (argMap , "Files" , "Must supply files to operate on" ).split ("," );
295
+ String [] files = getOrEmpty (argMap , "Files" ).split ("," );
296
+ Path outputPath = FileSystems .getDefault ().getPath (outputName );
297
+
298
+ String [] sourceJars = getOrEmpty (argMap , "SourceJars" ).split ("," );
299
+ List <File > sourceFiles = new ArrayList <File >();
300
+
301
+ for (String jarPath : sourceJars ) {
302
+ if (jarPath .length () > 0 ){
303
+ Path tmpPath = Files .createTempDirectory (outputPath .getParent (), "tmp" );
304
+ sourceFiles .addAll (extractJar (jarPath , tmpPath .toString ()));
305
+ }
306
+ }
307
+
308
+ int sourceFilesSize = sourceFiles .size ();
309
+ String [] tmpFiles = new String [files .length + sourceFilesSize ];
310
+ System .arraycopy (files , 0 , tmpFiles , 0 , files .length );
311
+ int baseIdx = files .length ;
312
+ for (File p : sourceFiles ) {
313
+ tmpFiles [baseIdx ] = p .toString ();
314
+ baseIdx += 1 ;
315
+ }
316
+ files = tmpFiles ;
317
+
318
+ if (files .length == 0 ) {
319
+ throw new Exception ("Must have input files from either source jars or local files." );
320
+ }
321
+
265
322
266
323
boolean iJarEnabled = booleanGetOrFalse (argMap , "EnableIjar" );
267
324
String ijarOutput = null ;
@@ -271,7 +328,6 @@ private static void processRequest(List<String> args) throws Exception {
271
328
ijarCmdPath = getOrError (argMap , "ijarCmdPath" , "Missing required arg ijarCmdPath when ijar enabled" );
272
329
}
273
330
274
- Path outputPath = FileSystems .getDefault ().getPath (outputName );
275
331
Path tmpPath = Files .createTempDirectory (outputPath .getParent (),"tmp" );
276
332
277
333
0 commit comments