55import io .bazel .rulesscala .worker .Worker ;
66import java .io .BufferedInputStream ;
77import java .io .BufferedOutputStream ;
8+ import java .io .UnsupportedEncodingException ;
89import java .nio .file .FileSystem ;
910import java .nio .file .FileSystems ;
1011import java .nio .file .FileVisitResult ;
1718import java .nio .file .attribute .BasicFileAttributes ;
1819import org .jacoco .core .instr .Instrumenter ;
1920import org .jacoco .core .runtime .OfflineInstrumentationAccessGenerator ;
21+ import java .net .URLDecoder ;
22+ import java .util .Arrays ;
23+ import java .util .List ;
24+ import java .util .stream .Collectors ;
2025
2126public final class JacocoInstrumenter implements Worker .Interface {
2227
@@ -27,19 +32,17 @@ public static void main(String[] args) throws Exception {
2732 @ Override
2833 public void work (String [] args ) throws Exception {
2934 Instrumenter jacoco = new Instrumenter (new OfflineInstrumentationAccessGenerator ());
30- for (String arg : args ) {
31- processArg (jacoco , arg );
32- }
35+ processArg (jacoco , args );
3336 }
3437
35- private void processArg (Instrumenter jacoco , String arg ) throws Exception {
36- String [] parts = arg .split ("=" );
37- if (parts .length != 3 ) {
38- throw new Exception ("expected `in_path=out_path=srcs` form for argument: " + arg );
38+ private void processArg (Instrumenter jacoco , String [] args ) throws Exception {
39+ if (args .length < 3 ) {
40+ throw new Exception ("expected format `in_path out_path src1 src2 ... srcN` for arguments: " + Arrays .asList (args ));
3941 }
40- Path inPath = Paths .get (parts [0 ]);
41- Path outPath = Paths .get (parts [1 ]);
42- String srcs = parts [2 ];
42+
43+ Path inPath = Paths .get (args [0 ]);
44+ Path outPath = Paths .get (args [1 ]);
45+ String [] srcs = Arrays .copyOfRange (args , 2 , args .length );
4346
4447 // Use a directory for coverage metadata that is unique to each built jar. Avoids
4548 // multiple threads performing read/write/delete actions on the instrumented classes directory.
@@ -73,7 +76,7 @@ private void processArg(Instrumenter jacoco, String arg) throws Exception {
7376 Path pathsForCoverage = instrumentedClassesDirectory .resolve ("-paths-for-coverage.txt" );
7477 Files .write (
7578 pathsForCoverage ,
76- srcs . replace ( "," , " \n " ).getBytes (java .nio .charset .StandardCharsets .UTF_8 )
79+ String . join ( " \n ", srcs ).getBytes (java .nio .charset .StandardCharsets .UTF_8 )
7780 );
7881
7982 jarCreator .addEntry (instrumentedClassesDirectory .relativize (pathsForCoverage ).toString (), pathsForCoverage );
0 commit comments