2
2
3
3
import com .illicitonion .scalac .reporters .CompositeReporter ;
4
4
import io .bazel .rulesscala .jar .JarCreator ;
5
- import io .bazel .rulesscala .worker .GenericWorker ;
6
- import io .bazel .rulesscala .worker .Processor ;
5
+ import io .bazel .rulesscala .worker .Worker ;
7
6
import java .io .File ;
8
7
import java .io .FileNotFoundException ;
9
8
import java .io .FileOutputStream ;
32
31
import scala .tools .nsc .reporters .ConsoleReporter ;
33
32
import scala .tools .nsc .reporters .Reporter ;
34
33
35
- class ScalacProcessor implements Processor {
34
+ class ScalacWorker implements Worker . Interface {
36
35
private static boolean isWindows = System .getProperty ("os.name" ).toLowerCase ().contains ("windows" );
37
36
38
37
/** This is the reporter field for scalac, which we want to access */
@@ -47,11 +46,15 @@ class ScalacProcessor implements Processor {
47
46
}
48
47
}
49
48
49
+ public static void main (String [] args ) throws Exception {
50
+ Worker .workerMain (args , new ScalacWorker ());
51
+ }
52
+
50
53
@ Override
51
- public void processRequest ( List < String > args ) throws Exception {
54
+ public void work ( String [] args ) throws Exception {
52
55
Path tmpPath = null ;
53
56
try {
54
- CompileOptions ops = new CompileOptions (args );
57
+ CompileOptions ops = new CompileOptions (Arrays . asList ( args ) );
55
58
56
59
Path outputPath = FileSystems .getDefault ().getPath (ops .outputName );
57
60
tmpPath = Files .createTempDirectory (outputPath .getParent (), "tmp" );
@@ -67,7 +70,7 @@ public void processRequest(List<String> args) throws Exception {
67
70
68
71
String [] scalaSources = collectSrcJarSources (ops .files , scalaJarFiles , javaJarFiles );
69
72
70
- String [] javaSources = GenericWorker . appendToString (ops .javaFiles , javaJarFiles );
73
+ String [] javaSources = appendToString (ops .javaFiles , javaJarFiles );
71
74
if (scalaSources .length == 0 && javaSources .length == 0 ) {
72
75
throw new RuntimeException ("Must have input files from either source jars or local files." );
73
76
}
@@ -99,8 +102,8 @@ public void processRequest(List<String> args) throws Exception {
99
102
100
103
private static String [] collectSrcJarSources (
101
104
String [] files , List <File > scalaJarFiles , List <File > javaJarFiles ) {
102
- String [] scalaSources = GenericWorker . appendToString (files , scalaJarFiles );
103
- return GenericWorker . appendToString (scalaSources , javaJarFiles );
105
+ String [] scalaSources = appendToString (files , scalaJarFiles );
106
+ return appendToString (scalaSources , javaJarFiles );
104
107
}
105
108
106
109
private static List <File > filterFilesByExtension (List <File > files , String extension ) {
@@ -170,7 +173,7 @@ private static boolean matchesFileExtensions(String fileName, String[] extension
170
173
}
171
174
172
175
private static String [] encodeBazelTargets (String [] targets ) {
173
- return Arrays .stream (targets ).map (ScalacProcessor ::encodeBazelTarget ).toArray (String []::new );
176
+ return Arrays .stream (targets ).map (ScalacWorker ::encodeBazelTarget ).toArray (String []::new );
174
177
}
175
178
176
179
private static String encodeBazelTarget (String target ) {
@@ -227,7 +230,7 @@ private static void compileScalaSources(CompileOptions ops, String[] scalaSource
227
230
String [] constParams = {"-classpath" , ops .classpath , "-d" , tmpPath .toString ()};
228
231
229
232
String [] compilerArgs =
230
- GenericWorker . merge (ops .scalaOpts , ops .pluginArgs , constParams , pluginParams , scalaSources );
233
+ merge (ops .scalaOpts , ops .pluginArgs , constParams , pluginParams , scalaSources );
231
234
232
235
MainClass comp = new MainClass () {
233
236
private Global compiler ;
@@ -357,4 +360,30 @@ private static void copyResourceJars(String[] resourceJars, Path dest) throws IO
357
360
extractJar (jarPath , dest .toString (), null );
358
361
}
359
362
}
363
+
364
+ private static <T > String [] appendToString (String [] init , List <T > rest ) {
365
+ String [] tmp = new String [init .length + rest .size ()];
366
+ System .arraycopy (init , 0 , tmp , 0 , init .length );
367
+ int baseIdx = init .length ;
368
+ for (T t : rest ) {
369
+ tmp [baseIdx ] = t .toString ();
370
+ baseIdx += 1 ;
371
+ }
372
+ return tmp ;
373
+ }
374
+
375
+ private static String [] merge (String []... arrays ) {
376
+ int totalLength = 0 ;
377
+ for (String [] arr : arrays ) {
378
+ totalLength += arr .length ;
379
+ }
380
+
381
+ String [] result = new String [totalLength ];
382
+ int offset = 0 ;
383
+ for (String [] arr : arrays ) {
384
+ System .arraycopy (arr , 0 , result , offset , arr .length );
385
+ offset += arr .length ;
386
+ }
387
+ return result ;
388
+ }
360
389
}
0 commit comments