From 2061b3a3513ea2324cc328874300d54e9a0d6e7e Mon Sep 17 00:00:00 2001 From: Jiaming <71547730+Jiaaming@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:22:53 +0800 Subject: [PATCH] fix - Fallback to Buildship when failed to generate named pipe (#1576) --- .../gradle/bs/importer/GradleBuildServerProjectImporter.java | 1 - .../src/com/microsoft/gradle/bs/importer/ImporterPlugin.java | 2 ++ .../src/com/microsoft/gradle/bs/importer/NamedPipeStream.java | 4 ++-- .../bs/importer/model/NamedPipeConnectionException.java | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java index 218dc2db0..914437e3f 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/GradleBuildServerProjectImporter.java @@ -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; } diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java index 17e60253f..1c7a5bf45 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/ImporterPlugin.java @@ -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; @@ -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, diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java index 4909cdecd..98de9ab1b 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/NamedPipeStream.java @@ -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)); } } @@ -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(); } diff --git a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/NamedPipeConnectionException.java b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/NamedPipeConnectionException.java index aa0377f1b..3ecc797c7 100644 --- a/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/NamedPipeConnectionException.java +++ b/extension/jdtls.ext/com.microsoft.gradle.bs.importer/src/com/microsoft/gradle/bs/importer/model/NamedPipeConnectionException.java @@ -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); } }