@@ -138,6 +138,10 @@ public void onWillUpdate(Collection<IProject> projects, IProgressMonitor monitor
138
138
}
139
139
for (IPath rootPath : roots ) {
140
140
BuildServerConnection connection = ImporterPlugin .getBuildServerConnection (rootPath );
141
+ if (connection == null ) {
142
+ JavaLanguageServerPlugin .logInfo ("Skip reloading " + rootPath + " because the connection is not available." );
143
+ continue ;
144
+ }
141
145
connection .workspaceReload ().join ();
142
146
}
143
147
}
@@ -156,14 +160,18 @@ public void update(IProject project, boolean force, IProgressMonitor monitor) th
156
160
return ;
157
161
}
158
162
BuildServerConnection connection = ImporterPlugin .getBuildServerConnection (rootPath );
163
+ if (connection == null ) {
164
+ JavaLanguageServerPlugin .logError ("Cannot find build server connection for root: " + rootPath );
165
+ return ;
166
+ }
159
167
Map <URI , List <BuildTarget >> buildTargetMap = Utils .getBuildTargetsMappedByProjectPath (connection );
160
168
for (URI uri : buildTargetMap .keySet ()) {
161
169
IProject projectFromUri = ProjectUtils .getProjectFromUri (uri .toString ());
162
170
if (projectFromUri == null || !Utils .isGradleBuildServerProject (projectFromUri )) {
163
171
continue ;
164
172
}
165
- updateClasspath (projectFromUri , monitor );
166
- updateProjectDependencies (projectFromUri , monitor );
173
+ updateClasspath (connection , projectFromUri , monitor );
174
+ updateProjectDependencies (connection , projectFromUri , monitor );
167
175
// TODO: in case that the projects/build targets are created or removed,
168
176
// we can use the server->client notification: 'buildTarget/didChange' to support this case.
169
177
}
@@ -180,29 +188,28 @@ public String buildToolName() {
180
188
* add Java nature if necessary.
181
189
* @throws CoreException
182
190
*/
183
- public void updateClasspath (IProject project , IProgressMonitor monitor ) throws CoreException {
191
+ public void updateClasspath (BuildServerConnection connection , IProject project , IProgressMonitor monitor ) throws CoreException {
184
192
IPath rootPath = ProjectUtils .findBelongedWorkspaceRoot (project .getLocation ());
185
193
if (rootPath == null ) {
186
194
JavaLanguageServerPlugin .logError ("Cannot find workspace root for project: " + project .getName ());
187
195
return ;
188
196
}
189
- BuildServerConnection buildServer = ImporterPlugin .getBuildServerConnection (rootPath );
190
197
// use map to dedupe the classpath entries having the same path field.
191
198
Map <IPath , IClasspathEntry > classpathMap = new LinkedHashMap <>();
192
- List <BuildTarget > buildTargets = Utils .getBuildTargetsByProjectUri (buildServer , project .getLocationURI ());
199
+ List <BuildTarget > buildTargets = Utils .getBuildTargetsByProjectUri (connection , project .getLocationURI ());
193
200
// put test targets to the end of the list
194
201
moveTestTargetsToEnd (buildTargets );
195
202
196
203
for (BuildTarget buildTarget : buildTargets ) {
197
204
boolean isTest = buildTarget .getTags ().contains (BuildTargetTag .TEST );
198
- OutputPathsResult outputResult = buildServer .buildTargetOutputPaths (
205
+ OutputPathsResult outputResult = connection .buildTargetOutputPaths (
199
206
new OutputPathsParams (Arrays .asList (buildTarget .getId ()))).join ();
200
207
String sourceOutputUri = getOutputUriByKind (outputResult .getItems (), OUTPUT_KIND_SOURCE );
201
208
IPath sourceOutputFullPath = getOutputFullPath (sourceOutputUri , project );
202
209
if (sourceOutputFullPath == null ) {
203
210
JavaLanguageServerPlugin .logError ("Cannot find source output path for build target: " + buildTarget .getId ());
204
211
} else {
205
- SourcesResult sourcesResult = buildServer .buildTargetSources (
212
+ SourcesResult sourcesResult = connection .buildTargetSources (
206
213
new SourcesParams (Arrays .asList (buildTarget .getId ()))).join ();
207
214
List <IClasspathEntry > sourceEntries = getSourceEntries (rootPath , project , sourcesResult , sourceOutputFullPath , isTest , monitor );
208
215
for (IClasspathEntry entry : sourceEntries ) {
@@ -214,7 +221,7 @@ public void updateClasspath(IProject project, IProgressMonitor monitor) throws C
214
221
IPath resourceOutputFullPath = getOutputFullPath (resourceOutputUri , project );
215
222
// resource output is nullable according to Gradle API definition.
216
223
if (resourceOutputFullPath != null ) {
217
- ResourcesResult resourcesResult = buildServer .buildTargetResources (
224
+ ResourcesResult resourcesResult = connection .buildTargetResources (
218
225
new ResourcesParams (Arrays .asList (buildTarget .getId ()))).join ();
219
226
List <IClasspathEntry > resourceEntries = getResourceEntries (project , resourcesResult , resourceOutputFullPath , isTest );
220
227
for (IClasspathEntry entry : resourceEntries ) {
@@ -246,7 +253,7 @@ public void updateClasspath(IProject project, IProgressMonitor monitor) throws C
246
253
247
254
for (BuildTarget buildTarget : buildTargets ) {
248
255
boolean isTest = buildTarget .getTags ().contains (BuildTargetTag .TEST );
249
- DependencyModulesResult dependencyModuleResult = buildServer .buildTargetDependencyModules (
256
+ DependencyModulesResult dependencyModuleResult = connection .buildTargetDependencyModules (
250
257
new DependencyModulesParams (Arrays .asList (buildTarget .getId ()))).join ();
251
258
List <IClasspathEntry > dependencyEntries = getDependencyJars (dependencyModuleResult , isTest , isModular );
252
259
for (IClasspathEntry entry : dependencyEntries ) {
@@ -257,7 +264,7 @@ public void updateClasspath(IProject project, IProgressMonitor monitor) throws C
257
264
javaProject .setRawClasspath (classpathMap .values ().toArray (new IClasspathEntry [0 ]), monitor );
258
265
259
266
// process jpms arguments.
260
- JavacOptionsResult javacOptions = buildServer .buildTargetJavacOptions (new JavacOptionsParams (
267
+ JavacOptionsResult javacOptions = connection .buildTargetJavacOptions (new JavacOptionsParams (
261
268
buildTargets .stream ().map (BuildTarget ::getId ).collect (Collectors .toList ()))).join ();
262
269
List <String > compilerArgs = new LinkedList <>();
263
270
for (JavacOptionsItem item : javacOptions .getItems ()) {
@@ -276,14 +283,13 @@ public void updateClasspath(IProject project, IProgressMonitor monitor) throws C
276
283
* Update the project dependencies of the project.
277
284
* @throws CoreException
278
285
*/
279
- public void updateProjectDependencies (IProject project , IProgressMonitor monitor ) throws CoreException {
286
+ public void updateProjectDependencies (BuildServerConnection connection , IProject project , IProgressMonitor monitor ) throws CoreException {
280
287
IPath rootPath = ProjectUtils .findBelongedWorkspaceRoot (project .getLocation ());
281
288
if (rootPath == null ) {
282
289
JavaLanguageServerPlugin .logError ("Cannot find workspace root for project: " + project .getName ());
283
290
return ;
284
291
}
285
- BuildServerConnection buildServer = ImporterPlugin .getBuildServerConnection (rootPath );
286
- List <BuildTarget > buildTargets = Utils .getBuildTargetsByProjectUri (buildServer , project .getLocationURI ());
292
+ List <BuildTarget > buildTargets = Utils .getBuildTargetsByProjectUri (connection , project .getLocationURI ());
287
293
Set <BuildTargetIdentifier > projectDependencies = new LinkedHashSet <>();
288
294
for (BuildTarget buildTarget : buildTargets ) {
289
295
projectDependencies .addAll (buildTarget .getDependencies ());
0 commit comments