4
4
5
5
import com .google .common .collect .Iterables ;
6
6
7
+ import java .io .*;
8
+ import java .nio .charset .StandardCharsets ;
7
9
import java .io .IOException ;
8
10
import java .nio .file .Files ;
9
11
import java .nio .file .Path ;
@@ -45,13 +47,11 @@ public List<BazelTarget> queryAllTargets() throws IOException {
45
47
@ Override
46
48
public Set <String > queryForImpactedTargets (Set <String > impactedTargets ) throws IOException {
47
49
Set <String > impactedTestTargets = new HashSet <>();
48
- for (List <String > partition : Iterables .partition (impactedTargets , 100 )) {
49
- String targetQuery = partition .stream ().collect (Collectors .joining (" + " ));
50
- List <Build .Target > targets = performBazelQuery (String .format ("rdeps(//..., %s)" , targetQuery ));
51
- for (Build .Target target : targets ) {
52
- if (target .hasRule ()) {
53
- impactedTestTargets .add (target .getRule ().getName ());
54
- }
50
+ String targetQuery = impactedTargets .stream ().collect (Collectors .joining (" + " ));
51
+ List <Build .Target > targets = performBazelQuery (String .format ("rdeps(//..., %s)" , targetQuery ));
52
+ for (Build .Target target : targets ) {
53
+ if (target .hasRule ()) {
54
+ impactedTestTargets .add (target .getRule ().getName ());
55
55
}
56
56
}
57
57
return impactedTestTargets ;
@@ -60,13 +60,11 @@ public Set<String> queryForImpactedTargets(Set<String> impactedTargets) throws I
60
60
@ Override
61
61
public Set <String > queryForTestTargets (Set <String > targets ) throws IOException {
62
62
Set <String > impactedTestTargets = new HashSet <>();
63
- for (List <String > partition : Iterables .partition (targets , 100 )) {
64
- String targetQuery = partition .stream ().collect (Collectors .joining (" + " ));
65
- List <Build .Target > testTargets = performBazelQuery (String .format ("kind(test, %s)" , targetQuery ));
66
- for (Build .Target target : testTargets ) {
67
- if (target .hasRule ()) {
68
- impactedTestTargets .add (target .getRule ().getName ());
69
- }
63
+ String targetQuery = targets .stream ().collect (Collectors .joining (" + " ));
64
+ List <Build .Target > testTargets = performBazelQuery (String .format ("kind(test, %s)" , targetQuery ));
65
+ for (Build .Target target : testTargets ) {
66
+ if (target .hasRule ()) {
67
+ impactedTestTargets .add (target .getRule ().getName ());
70
68
}
71
69
}
72
70
return impactedTestTargets ;
@@ -101,8 +99,10 @@ public Set<BazelSourceFileTarget> convertFilepathsToSourceTargets(Set<Path> file
101
99
}
102
100
103
101
private List <Build .Target > performBazelQuery (String query ) throws IOException {
102
+ Path tempFile = Files .createTempFile (null , ".txt" );
103
+ Files .write (tempFile , query .getBytes (StandardCharsets .UTF_8 ));
104
+
104
105
List <String > cmd = new ArrayList <String >();
105
-
106
106
cmd .add ((bazelPath .toString ()));
107
107
cmd .addAll (this .startupOptions );
108
108
cmd .add ("query" );
@@ -112,7 +112,8 @@ private List<Build.Target> performBazelQuery(String query) throws IOException {
112
112
cmd .add ("--show_progress=false" );
113
113
cmd .add ("--show_loading_progress=false" );
114
114
cmd .addAll (this .commandOptions );
115
- cmd .add (query );
115
+ cmd .add ("--query_file" );
116
+ cmd .add (tempFile .toString ());
116
117
117
118
ProcessBuilder pb = new ProcessBuilder (cmd ).directory (workingDirectory .toFile ());
118
119
Process process = pb .start ();
@@ -122,6 +123,9 @@ private List<Build.Target> performBazelQuery(String query) throws IOException {
122
123
if (target == null ) break ; // EOF
123
124
targets .add (target );
124
125
}
126
+
127
+ Files .delete (tempFile );
128
+
125
129
return targets ;
126
130
}
127
131
}
0 commit comments