4
4
package com .microsoft .java .bs .core .internal .server ;
5
5
6
6
import static org .junit .jupiter .api .Assertions .assertEquals ;
7
- import static org .junit .jupiter .api .Assertions .assertFalse ;
8
7
import static org .junit .jupiter .api .Assertions .assertNotNull ;
9
8
import static org .junit .jupiter .api .Assertions .assertTrue ;
10
9
14
13
import java .io .PipedOutputStream ;
15
14
import java .nio .file .Paths ;
16
15
import java .util .ArrayList ;
17
- import java .util .HashSet ;
18
16
import java .util .List ;
19
- import java .util .Set ;
20
17
import java .util .concurrent .ExecutorService ;
21
18
import java .util .concurrent .Executors ;
22
19
import java .util .function .BiConsumer ;
20
+ import java .util .function .IntSupplier ;
23
21
import java .util .stream .Collectors ;
24
22
25
- import ch .epfl .scala .bsp4j .DependencyModulesParams ;
26
- import ch .epfl .scala .bsp4j .DependencyModulesResult ;
27
- import ch .epfl .scala .bsp4j .DependencySourcesParams ;
28
- import ch .epfl .scala .bsp4j .DependencySourcesResult ;
29
- import ch .epfl .scala .bsp4j .MavenDependencyModule ;
30
- import ch .epfl .scala .bsp4j .MavenDependencyModuleArtifact ;
31
- import org .junit .jupiter .api .AfterAll ;
32
- import org .junit .jupiter .api .BeforeAll ;
33
- import org .junit .jupiter .api .Test ;
34
-
35
- import com .microsoft .java .bs .core .Launcher ;
36
- import com .microsoft .java .bs .core .internal .gradle .GradleApiConnector ;
37
- import com .microsoft .java .bs .core .internal .managers .BuildTargetManager ;
38
- import com .microsoft .java .bs .core .internal .managers .PreferenceManager ;
39
- import com .microsoft .java .bs .core .internal .services .BuildTargetService ;
40
- import com .microsoft .java .bs .core .internal .services .LifecycleService ;
41
- import com .microsoft .java .bs .core .internal .utils .JsonUtils ;
42
- import com .microsoft .java .bs .gradle .model .SupportedLanguages ;
43
-
44
23
import ch .epfl .scala .bsp4j .BuildClient ;
45
24
import ch .epfl .scala .bsp4j .BuildClientCapabilities ;
46
25
import ch .epfl .scala .bsp4j .BuildServer ;
51
30
import ch .epfl .scala .bsp4j .CompileParams ;
52
31
import ch .epfl .scala .bsp4j .CompileReport ;
53
32
import ch .epfl .scala .bsp4j .CompileResult ;
33
+ import ch .epfl .scala .bsp4j .DependencyModulesParams ;
34
+ import ch .epfl .scala .bsp4j .DependencyModulesResult ;
35
+ import ch .epfl .scala .bsp4j .DependencySourcesParams ;
36
+ import ch .epfl .scala .bsp4j .DependencySourcesResult ;
54
37
import ch .epfl .scala .bsp4j .DidChangeBuildTarget ;
55
38
import ch .epfl .scala .bsp4j .InitializeBuildParams ;
56
39
import ch .epfl .scala .bsp4j .JavaBuildServer ;
57
40
import ch .epfl .scala .bsp4j .JvmBuildServer ;
58
41
import ch .epfl .scala .bsp4j .LogMessageParams ;
42
+ import ch .epfl .scala .bsp4j .MavenDependencyModule ;
43
+ import ch .epfl .scala .bsp4j .MavenDependencyModuleArtifact ;
59
44
import ch .epfl .scala .bsp4j .PublishDiagnosticsParams ;
60
45
import ch .epfl .scala .bsp4j .ShowMessageParams ;
61
46
import ch .epfl .scala .bsp4j .StatusCode ;
62
47
import ch .epfl .scala .bsp4j .TaskFinishParams ;
63
48
import ch .epfl .scala .bsp4j .TaskProgressParams ;
64
49
import ch .epfl .scala .bsp4j .TaskStartParams ;
65
50
import ch .epfl .scala .bsp4j .WorkspaceBuildTargetsResult ;
51
+ import org .junit .jupiter .api .AfterAll ;
52
+ import org .junit .jupiter .api .BeforeAll ;
53
+ import org .junit .jupiter .api .Test ;
54
+
55
+ import com .microsoft .java .bs .core .Launcher ;
56
+ import com .microsoft .java .bs .core .internal .gradle .GradleApiConnector ;
57
+ import com .microsoft .java .bs .core .internal .managers .BuildTargetManager ;
58
+ import com .microsoft .java .bs .core .internal .managers .PreferenceManager ;
59
+ import com .microsoft .java .bs .core .internal .services .BuildTargetService ;
60
+ import com .microsoft .java .bs .core .internal .services .LifecycleService ;
61
+ import com .microsoft .java .bs .core .internal .utils .JsonUtils ;
62
+ import com .microsoft .java .bs .gradle .model .SupportedLanguages ;
66
63
67
64
// TODO: Move to a dedicated source set for integration tests
68
65
class BuildTargetServerIntegrationTest {
@@ -73,24 +70,38 @@ private interface TestServer extends BuildServer, JavaBuildServer, JvmBuildServe
73
70
private static class TestClient implements BuildClient {
74
71
75
72
private final List <TaskStartParams > startReports = new ArrayList <>();
76
- private final List <TaskFinishParams > finishReports = new ArrayList <>();
77
- private final Set <CompileReport > compileReports = new HashSet <>();
73
+ private final List <String > finishReports = new ArrayList <>();
74
+ private final List <CompileReport > compileReports = new ArrayList <>();
75
+ private final List <CompileResult > compileResults = new ArrayList <>();
78
76
79
77
void clearMessages () {
80
78
startReports .clear ();
81
79
finishReports .clear ();
82
80
compileReports .clear ();
81
+ compileResults .clear ();
82
+ }
83
+
84
+ void waitOnStartReports (int size ) {
85
+ waitOnMessages ("Start Reports" , size , startReports ::size );
86
+ }
87
+
88
+ void waitOnFinishReports (int size ) {
89
+ waitOnMessages ("Finish Reports" , size , finishReports ::size );
90
+ }
91
+
92
+ void waitOnCompileReports (int size ) {
93
+ waitOnMessages ("Compile Reports" , size , compileReports ::size );
94
+ }
95
+
96
+ void waitOnCompileResults (int size ) {
97
+ waitOnMessages ("Compile Results" , size , compileResults ::size );
83
98
}
84
99
85
- void waitOnMessages (int startMessagesSize ,
86
- int finishMessagesSize ,
87
- int compileReportsSize ) {
100
+ private void waitOnMessages (String message , int size , IntSupplier sizeSupplier ) {
88
101
// set to 5000ms because it seems reasonable
89
102
long timeoutMs = 5000 ;
90
103
long endTime = System .currentTimeMillis () + timeoutMs ;
91
- while ((startReports .size () < startMessagesSize
92
- || finishReports .size () < finishMessagesSize
93
- || compileReports .size () < compileReportsSize )
104
+ while (sizeSupplier .getAsInt () < size
94
105
&& System .currentTimeMillis () < endTime ) {
95
106
synchronized (this ) {
96
107
long waitTime = endTime - System .currentTimeMillis ();
@@ -103,9 +114,7 @@ void waitOnMessages(int startMessagesSize,
103
114
}
104
115
}
105
116
}
106
- assertEquals (startMessagesSize , startReports .size (), "Start Report count error" );
107
- assertEquals (finishMessagesSize , finishReports .size (), "Finish Reports count error" );
108
- assertEquals (compileReportsSize , compileReports .size (), "Compile Reports count error" );
117
+ assertEquals (size , sizeSupplier .getAsInt (), message + " count error" );
109
118
}
110
119
111
120
private CompileReport findCompileReport (BuildTargetIdentifier btId ) {
@@ -150,9 +159,11 @@ public void onBuildTaskFinish(TaskFinishParams params) {
150
159
if (params .getDataKind () != null ) {
151
160
if (params .getDataKind ().equals ("compile-report" )) {
152
161
compileReports .add (JsonUtils .toModel (params .getData (), CompileReport .class ));
162
+ } else if (params .getDataKind ().equals ("compile-result" )) {
163
+ compileResults .add (JsonUtils .toModel (params .getData (), CompileResult .class ));
153
164
}
154
165
}
155
- finishReports .add (params );
166
+ finishReports .add (params . getMessage () );
156
167
synchronized (this ) {
157
168
notify ();
158
169
}
@@ -174,11 +185,13 @@ static void beforeClass() {
174
185
String pluginDir = Paths .get (System .getProperty ("user.dir" ),
175
186
"build" , "libs" , "plugins" ).toString ();
176
187
System .setProperty (Launcher .PROP_PLUGIN_DIR , pluginDir );
188
+ System .setProperty ("bsp.plugin.reloadworkspace.disabled" , "true" );
177
189
}
178
190
179
191
@ AfterAll
180
192
static void afterClass () {
181
193
System .clearProperty (Launcher .PROP_PLUGIN_DIR );
194
+ System .clearProperty ("bsp.plugin.reloadworkspace.disabled" );
182
195
}
183
196
184
197
private InitializeBuildParams getInitializeBuildParams (String projectDir ) {
@@ -257,22 +270,6 @@ private void withNewTestServer(String project, BiConsumer<TestServer, TestClient
257
270
}
258
271
}
259
272
260
- private BuildTargetIdentifier getBt (List <BuildTargetIdentifier > btIds ,
261
- String projectPathSection , String sourceSetName ) {
262
- String sourceSet = "?sourceset=" + sourceSetName ;
263
- List <BuildTargetIdentifier > matching = btIds .stream ()
264
- .filter (id -> id .getUri ().contains (projectPathSection ))
265
- .filter (id -> id .getUri ().endsWith (sourceSet ))
266
- .collect (Collectors .toList ());
267
- assertFalse (matching .isEmpty (), () -> "Build Target " + projectPathSection
268
- + " with source set " + sourceSetName + " not found in "
269
- + btIds .stream ().map (Object ::toString ).collect (Collectors .joining (", " )));
270
- assertEquals (1 , matching .size (), () -> "Too many Build Targets like " + projectPathSection
271
- + " with source set " + sourceSetName + " found in "
272
- + btIds .stream ().map (Object ::toString ).collect (Collectors .joining (", " )));
273
- return matching .get (0 );
274
- }
275
-
276
273
@ Test
277
274
void testCompilingSingleProjectServer () {
278
275
withNewTestServer ("junit5-jupiter-starter-gradle" , (gradleBuildServer , client ) -> {
@@ -314,18 +311,28 @@ void testCompilingSingleProjectServer() {
314
311
CleanCacheResult cleanResult = gradleBuildServer
315
312
.buildTargetCleanCache (cleanCacheParams ).join ();
316
313
assertTrue (cleanResult .getCleaned ());
317
- client .waitOnMessages (2 , 2 , 1 );
314
+ client .waitOnStartReports (2 );
315
+ client .waitOnFinishReports (2 );
316
+ client .waitOnCompileReports (0 );
317
+ client .waitOnCompileResults (0 );
318
318
client .clearMessages ();
319
319
320
320
// compile targets
321
321
CompileParams compileParams = new CompileParams (btIds );
322
+ compileParams .setOriginId ("originId" );
322
323
CompileResult compileResult = gradleBuildServer .buildTargetCompile (compileParams ).join ();
323
324
assertEquals (StatusCode .OK , compileResult .getStatusCode ());
324
- client .waitOnMessages (2 , 2 , 1 );
325
- BuildTargetIdentifier testBt = getBt (btIds , "/junit5-jupiter-starter-gradle/" , "test" );
326
- CompileReport compileReportTest = client .findCompileReport (testBt );
327
- assertEquals (0 , compileReportTest .getWarnings ());
328
- assertEquals (0 , compileReportTest .getErrors ());
325
+ client .waitOnStartReports (6 );
326
+ client .waitOnFinishReports (6 );
327
+ client .waitOnCompileReports (6 );
328
+ client .waitOnCompileResults (0 );
329
+ for (BuildTargetIdentifier btId : btIds ) {
330
+ CompileReport compileReport = client .findCompileReport (btId );
331
+ assertEquals ("originId" , compileReport .getOriginId ());
332
+ // TODO compile results are not yet implemented so always zero for now.
333
+ assertEquals (0 , compileReport .getWarnings ());
334
+ assertEquals (0 , compileReport .getErrors ());
335
+ }
329
336
client .clearMessages ();
330
337
});
331
338
}
0 commit comments