Skip to content

Commit

Permalink
fix - Fallback to Buildship when failed to generate named pipe (micro…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming authored Aug 9, 2024
1 parent 4473d70 commit 2061b3a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public void importToWorkspace(IProgressMonitor monitor) throws OperationCanceled
IPath rootPath = ResourceUtils.filePathFromURI(rootFolder.toURI().toString());
BuildServerConnection buildServer = ImporterPlugin.getBuildServerConnection(rootPath, true);
if (buildServer == null) {
JavaLanguageServerPlugin.logError("Reach the maximum number of attempts to connect to the build server, use BuildShip instead");
this.isResolved = false;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.eclipse.jdt.ls.core.internal.managers.DigestStore;
import org.eclipse.lsp4j.jsonrpc.Launcher;
import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -113,6 +114,7 @@ public static BuildServerConnection getBuildServerConnection(IPath rootPath, boo
instance.buildServers.put(rootPath, Pair.of(server, client));
return server;
} catch (NamedPipeConnectionException e) {
JavaLanguageServerPlugin.logException("Failed to connect to build server using named pipe.", e);
return null;
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void initializeNamedPipe() {
Utils.sendTelemetry(JavaLanguageServerPlugin.getProjectsManager().getConnection(),
telemetry);
if (attempts == MAX_ATTEMPTS) {
throw new NamedPipeConnectionException("Failed to connect to extension", MAX_ATTEMPTS);
throw new NamedPipeConnectionException(String.format("Failed to connect to extension, Max attempts: %d", MAX_ATTEMPTS));
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ private String generateRandomPipeName() {
int bytesLength = Math.min(availableLength / 2, randomLength);

if (bytesLength < 16) {
throw new IllegalArgumentException("Unable to generate a random pipe name with character length less than 16");
throw new NamedPipeConnectionException("Unable to generate a random pipe name with character length less than 16");
}
return Paths.get(tmpDir, generateRandomHex(bytesLength) + ".sock").toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.microsoft.gradle.bs.importer.model;

public class NamedPipeConnectionException extends RuntimeException {
public NamedPipeConnectionException(String message, int maxAttempts) {
super(String.format("%s, Max attempts: %d", message, maxAttempts));
public NamedPipeConnectionException(String message) {
super(message);
}
}

0 comments on commit 2061b3a

Please sign in to comment.