1
1
package io .bazel .rulesscala .scalac ;
2
2
3
3
import io .bazel .rulesscala .jar .JarCreator ;
4
- import io .bazel .rulesscala .worker .GenericWorker ;
5
- import io .bazel .rulesscala .worker .Processor ;
4
+ import io .bazel .rulesscala .worker .Worker ;
6
5
import java .io .File ;
7
6
import java .io .FileNotFoundException ;
8
7
import java .io .FileOutputStream ;
28
27
import scala .tools .nsc .MainClass ;
29
28
import scala .tools .nsc .reporters .ConsoleReporter ;
30
29
31
- class ScalacProcessor implements Processor {
30
+ class ScalacWorker implements Worker . Interface {
32
31
private static boolean isWindows = System .getProperty ("os.name" ).toLowerCase ().contains ("windows" );
33
32
34
33
/** This is the reporter field for scalac, which we want to access */
@@ -43,11 +42,15 @@ class ScalacProcessor implements Processor {
43
42
}
44
43
}
45
44
45
+ public static void main (String args []) throws Exception {
46
+ Worker .workerMain (args , new ScalacWorker ());
47
+ }
48
+
46
49
@ Override
47
- public void processRequest ( List < String > args ) throws Exception {
50
+ public void work ( String [] args ) throws Exception {
48
51
Path tmpPath = null ;
49
52
try {
50
- CompileOptions ops = new CompileOptions (args );
53
+ CompileOptions ops = new CompileOptions (Arrays . asList ( args ) );
51
54
52
55
Path outputPath = FileSystems .getDefault ().getPath (ops .outputName );
53
56
tmpPath = Files .createTempDirectory (outputPath .getParent (), "tmp" );
@@ -63,7 +66,7 @@ public void processRequest(List<String> args) throws Exception {
63
66
64
67
String [] scalaSources = collectSrcJarSources (ops .files , scalaJarFiles , javaJarFiles );
65
68
66
- String [] javaSources = GenericWorker . appendToString (ops .javaFiles , javaJarFiles );
69
+ String [] javaSources = appendToString (ops .javaFiles , javaJarFiles );
67
70
if (scalaSources .length == 0 && javaSources .length == 0 ) {
68
71
throw new RuntimeException ("Must have input files from either source jars or local files." );
69
72
}
@@ -95,8 +98,8 @@ public void processRequest(List<String> args) throws Exception {
95
98
96
99
private static String [] collectSrcJarSources (
97
100
String [] files , List <File > scalaJarFiles , List <File > javaJarFiles ) {
98
- String [] scalaSources = GenericWorker . appendToString (files , scalaJarFiles );
99
- return GenericWorker . appendToString (scalaSources , javaJarFiles );
101
+ String [] scalaSources = appendToString (files , scalaJarFiles );
102
+ return appendToString (scalaSources , javaJarFiles );
100
103
}
101
104
102
105
private static List <File > filterFilesByExtension (List <File > files , String extension ) {
@@ -166,7 +169,7 @@ private static boolean matchesFileExtensions(String fileName, String[] extension
166
169
}
167
170
168
171
private static String [] encodeBazelTargets (String [] targets ) {
169
- return Arrays .stream (targets ).map (ScalacProcessor ::encodeBazelTarget ).toArray (String []::new );
172
+ return Arrays .stream (targets ).map (ScalacWorker ::encodeBazelTarget ).toArray (String []::new );
170
173
}
171
174
172
175
private static String encodeBazelTarget (String target ) {
@@ -223,7 +226,7 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
223
226
String [] constParams = {"-classpath" , ops .classpath , "-d" , tmpPath .toString ()};
224
227
225
228
String [] compilerArgs =
226
- GenericWorker . merge (ops .scalaOpts , ops .pluginArgs , constParams , pluginParams , scalaSources );
229
+ merge (ops .scalaOpts , ops .pluginArgs , constParams , pluginParams , scalaSources );
227
230
228
231
MainClass comp = new MainClass ();
229
232
long start = System .currentTimeMillis ();
@@ -312,4 +315,30 @@ private static void copyResourceJars(String[] resourceJars, Path dest) throws IO
312
315
extractJar (jarPath , dest .toString (), null );
313
316
}
314
317
}
318
+
319
+ private static <T > String [] appendToString (String [] init , List <T > rest ) {
320
+ String [] tmp = new String [init .length + rest .size ()];
321
+ System .arraycopy (init , 0 , tmp , 0 , init .length );
322
+ int baseIdx = init .length ;
323
+ for (T t : rest ) {
324
+ tmp [baseIdx ] = t .toString ();
325
+ baseIdx += 1 ;
326
+ }
327
+ return tmp ;
328
+ }
329
+
330
+ private static String [] merge (String []... arrays ) {
331
+ int totalLength = 0 ;
332
+ for (String [] arr : arrays ) {
333
+ totalLength += arr .length ;
334
+ }
335
+
336
+ String [] result = new String [totalLength ];
337
+ int offset = 0 ;
338
+ for (String [] arr : arrays ) {
339
+ System .arraycopy (arr , 0 , result , offset , arr .length );
340
+ offset += arr .length ;
341
+ }
342
+ return result ;
343
+ }
315
344
}
0 commit comments