diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a32c55d..7a191df4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - java: [8, 11, 17] + java: [21] os: [ubuntu-latest, windows-latest, macos-latest] steps: diff --git a/build.gradle b/build.gradle index 88ea6807..339f1131 100644 --- a/build.gradle +++ b/build.gradle @@ -139,28 +139,18 @@ publishing { } } } - - // Don't sign the artifacts if we didn't get a key and password to use. - if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) { - signing { - useInMemoryPgpKeys( - (String) project.property("signingKey"), - (String) project.property("signingPassword")) - sign(publishing.publications["mavenJava"]) - } - } } dependencies { - implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.20.0" + implementation "org.eclipse.lsp4j:org.eclipse.lsp4j:0.23.1" implementation "software.amazon.smithy:smithy-build:[smithyVersion, 2.0[" implementation "software.amazon.smithy:smithy-cli:[smithyVersion, 2.0[" implementation "software.amazon.smithy:smithy-model:[smithyVersion, 2.0[" implementation "software.amazon.smithy:smithy-syntax:[smithyVersion, 2.0[" testImplementation "org.junit.jupiter:junit-jupiter:5.10.0" - testImplementation "org.hamcrest:hamcrest:2.1" + testImplementation "org.hamcrest:hamcrest:2.2" testRuntimeOnly "org.junit.platform:junit-platform-launcher" } @@ -209,8 +199,9 @@ tasks.named("checkstyleTest") { } java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } } jar { @@ -224,6 +215,8 @@ jar { exclude "META-INF/*.DSA" exclude "META-INF/*.RSA" exclude "reflect.properties" + // Included by dependencies in later versions of java, causes duplicate entries in the output jar + exclude "**/module-info.class" } manifest { attributes("Main-Class": "software.amazon.smithy.lsp.Main") diff --git a/src/main/java/software/amazon/smithy/lsp/SelectorParams.java b/src/main/java/software/amazon/smithy/lsp/SelectorParams.java index 18772a4c..e285b5ee 100644 --- a/src/main/java/software/amazon/smithy/lsp/SelectorParams.java +++ b/src/main/java/software/amazon/smithy/lsp/SelectorParams.java @@ -15,8 +15,8 @@ package software.amazon.smithy.lsp; +import org.eclipse.lsp4j.jsonrpc.util.Preconditions; import org.eclipse.lsp4j.jsonrpc.validation.NonNull; -import org.eclipse.lsp4j.util.Preconditions; public class SelectorParams { @NonNull diff --git a/src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java b/src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java index 61b7ff16..fbf65c64 100644 --- a/src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java +++ b/src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java @@ -95,7 +95,6 @@ import software.amazon.smithy.lsp.document.Document; import software.amazon.smithy.lsp.document.DocumentParser; import software.amazon.smithy.lsp.document.DocumentShape; -import software.amazon.smithy.lsp.ext.LspLog; import software.amazon.smithy.lsp.ext.serverstatus.OpenProject; import software.amazon.smithy.lsp.ext.serverstatus.ServerStatus; import software.amazon.smithy.lsp.handler.CompletionHandler; @@ -197,12 +196,6 @@ public CompletableFuture initialize(InitializeParams params) { Object initializationOptions = params.getInitializationOptions(); if (initializationOptions instanceof JsonObject) { JsonObject jsonObject = (JsonObject) initializationOptions; - if (jsonObject.has("logToFile")) { - String setting = jsonObject.get("logToFile").getAsString(); - if (setting.equals("enabled")) { - LspLog.enable(); - } - } if (jsonObject.has("diagnostics.minimumSeverity")) { String configuredMinimumSeverity = jsonObject.get("diagnostics.minimumSeverity").getAsString(); Optional severity = Severity.fromString(configuredMinimumSeverity); diff --git a/src/main/java/software/amazon/smithy/lsp/ext/LspLog.java b/src/main/java/software/amazon/smithy/lsp/ext/LspLog.java deleted file mode 100644 index a5305b1e..00000000 --- a/src/main/java/software/amazon/smithy/lsp/ext/LspLog.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package software.amazon.smithy.lsp.ext; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.nio.file.Paths; -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import software.amazon.smithy.utils.ListUtils; - -/** - * This log interface buffers the messages until the server receives information - * about workspace root. - *

- * This places the log messages into a file in the workspace, rather than - * pre-defined location on filesystem. - */ -public final class LspLog { - private static FileWriter fw = null; - private static Optional> buffer = Optional.of(new ArrayList<>()); - private static boolean enabled = false; - - private LspLog() { - } - - /** - * Clears out the buffered messages. - */ - public static void clearBuffer() { - synchronized (buffer) { - buffer.ifPresent(List::clear); - } - } - - /** - * Produces a snapshot of the current log buffer. - * - * @return a copy of the messages currently in the buffer - */ - public static List getBuffer() { - return ListUtils.copyOf(buffer.orElse(Collections.emptyList())); - } - - /** - * Sets workspace folder for the logger. - *

- * All the pending messages in the buffer will be flushed to the file created in - * the workspace - * - * @param folder workspace folder where log file will be created - */ - public static void setWorkspaceFolder(File folder) { - if (!enabled) { - return; - } - - try { - fw = new FileWriter(Paths.get(folder.getAbsolutePath(), "/.smithy.lsp.log").toFile()); - synchronized (buffer) { - buffer.ifPresent(buf -> buf.forEach(LspLog::println)); - buffer = Optional.empty(); - } - } catch (IOException e) { - // TODO: handle exception - } - - } - - /** - * Enables writing LspLog to a file. - */ - public static void enable() { - enabled = true; - } - - private static String currentTime() { - return LocalTime.now().withNano(0).format(DateTimeFormatter.ISO_LOCAL_TIME); - } - - /** - * Write a line to the log. - * - * @param message object to write, will be converted to String - */ - public static void println(Object message) { - if (!enabled) { - return; - } - String sanitizedMessage = getStringifiedMessage(message); - String timestamped = "[" + currentTime() + "] " + sanitizedMessage; - try { - if (fw != null) { - fw.append(timestamped + "\n").flush(); - } else { - synchronized (buffer) { - buffer.ifPresent(buf -> buf.add(sanitizedMessage)); - } - } - } catch (Exception e) { - - } - } - - private static String getStringifiedMessage(Object message) { - if (message == null) { - return "null"; - } else if (message instanceof Throwable) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - ((Throwable) message).printStackTrace(pw); - return sw.toString(); - } else { - return message.toString(); - } - } -} diff --git a/src/main/java/software/amazon/smithy/lsp/project/SmithyBuildExtensions.java b/src/main/java/software/amazon/smithy/lsp/project/SmithyBuildExtensions.java index 35e2a576..211a9086 100644 --- a/src/main/java/software/amazon/smithy/lsp/project/SmithyBuildExtensions.java +++ b/src/main/java/software/amazon/smithy/lsp/project/SmithyBuildExtensions.java @@ -18,11 +18,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.logging.Logger; import java.util.stream.Collectors; import software.amazon.smithy.build.model.MavenConfig; import software.amazon.smithy.build.model.MavenRepository; import software.amazon.smithy.build.model.SmithyBuildConfig; -import software.amazon.smithy.lsp.ext.LspLog; import software.amazon.smithy.utils.ListUtils; import software.amazon.smithy.utils.SmithyBuilder; import software.amazon.smithy.utils.ToSmithyBuilder; @@ -32,6 +32,8 @@ * top-level {@code mavenRepositories} and {@code mavenDependencies} properties. */ public final class SmithyBuildExtensions implements ToSmithyBuilder { + private static final Logger LOGGER = Logger.getLogger(SmithyBuildExtensions.class.getName()); + private final List imports; private final List mavenRepositories; private final List mavenDependencies; @@ -157,7 +159,7 @@ public Builder mavenRepositories(Collection mavenRepositories) { .map(repo -> MavenRepository.builder().url(repo).build()) .collect(Collectors.toList())) .build(); - LspLog.println("Read deprecated `mavenRepositories` in smithy-build.json. Update smithy-build.json to " + LOGGER.warning("Read deprecated `mavenRepositories` in smithy-build.json. Update smithy-build.json to " + "{\"maven\": {\"repositories\": [{\"url\": \"repo url\"}]}}"); } @@ -181,7 +183,7 @@ public Builder mavenDependencies(Collection mavenDependencies) { config = config.toBuilder() .dependencies(mavenDependencies) .build(); - LspLog.println("Read deprecated `mavenDependencies` in smithy-build.json. Update smithy-build.json to " + LOGGER.warning("Read deprecated `mavenDependencies` in smithy-build.json. Update smithy-build.json to " + "{\"maven\": {\"dependencies\": [\"dependencyA\", \"dependencyB\"]}}"); } this.maven = config;