fix - Fallback to Buildship when failed to generate named pipe (#1576)

This commit is contained in:
Jiaming 2024-08-09 14:22:53 +08:00 коммит произвёл GitHub
Родитель 4473d70c13
Коммит 2061b3a351
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -191,7 +191,6 @@ public class GradleBuildServerProjectImporter extends AbstractProjectImporter {
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;
}

Просмотреть файл

@ -11,6 +11,7 @@ import org.eclipse.core.runtime.IPath;
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 class ImporterPlugin extends Plugin {
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,

Просмотреть файл

@ -92,7 +92,7 @@ public class NamedPipeStream {
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 @@ public class NamedPipeStream {
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();
}

Просмотреть файл

@ -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);
}
}