From 10289d52c7dac3359e3380cb4e704969d1936e37 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Thu, 7 Mar 2024 12:12:33 +0000 Subject: [PATCH] fix (ide): Bump google-java-formatter from 1.20.0 to 1.21.0 This fixes https://github.com/google/google-java-format/issues/1072. --- .pre-commit-config.yaml | 2 +- .vscode/settings.json | 4 +- .../test/java/dev/enola/cli/EnolaTest.java | 10 ++-- .../java/dev/enola/common/io/iri/IRIs.java | 50 +++++++++++++++++++ .../dev/enola/common/io/resource/URIs.java | 2 + .../dev/enola/common/io/iri/IRIsTest.java | 42 ++++++++++++++++ .../io/resource/MarkdownResourceTest.java | 7 +-- .../java/dev/enola/core/tbd/RosettaTest.java | 24 ++++----- 8 files changed, 117 insertions(+), 24 deletions(-) create mode 100644 common/common/src/main/java/dev/enola/common/io/iri/IRIs.java create mode 100644 common/common/src/test/java/dev/enola/common/io/iri/IRIsTest.java diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8caae3bbb..065b49418 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -112,7 +112,7 @@ repos: hooks: - id: pretty-format-java # Keep this version in sync with the same version in .vscode/settings.json - args: [--autofix, --aosp, --google-java-formatter-version=1.20.0] + args: [--autofix, --aosp, --google-java-formatter-version=1.21.0] - repo: https://github.com/DavidAnson/markdownlint-cli2 rev: v0.12.1 diff --git a/.vscode/settings.json b/.vscode/settings.json index 6eb590f54..89ea48b8b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -71,9 +71,7 @@ "java.format.settings.google.extra": "--aosp", // For 4 instead of 2 spaces! // Keep this version in sync with the same version in .pre-commit-config.yaml // NB: Changes to this are only taken into account on start-up, so need to restart. - "java.format.settings.google.version": "1.20.0", - // TODO Remove when https://github.com/google/google-java-format/issues/1072 is fixed: - "java.format.settings.google.mode": "jar-file", + "java.format.settings.google.version": "1.21.0", // TODO https://github.com/eclipse-jdtls/eclipse.jdt.ls/issues/3050 "java.compile.nullAnalysis.mode": "automatic", "java.completion.importOrder": ["#", "", "javax", "java"], //# is static diff --git a/cli/src/test/java/dev/enola/cli/EnolaTest.java b/cli/src/test/java/dev/enola/cli/EnolaTest.java index ef1f64169..1b5415da7 100644 --- a/cli/src/test/java/dev/enola/cli/EnolaTest.java +++ b/cli/src/test/java/dev/enola/cli/EnolaTest.java @@ -126,11 +126,11 @@ public void get() { .out() .startsWith( """ - id { - ns: "test" - entity: "foobar" - paths: "helo" - """); + id { + ns: "test" + entity: "foobar" + paths: "helo" + """); } @Test diff --git a/common/common/src/main/java/dev/enola/common/io/iri/IRIs.java b/common/common/src/main/java/dev/enola/common/io/iri/IRIs.java new file mode 100644 index 000000000..5a63ae6ff --- /dev/null +++ b/common/common/src/main/java/dev/enola/common/io/iri/IRIs.java @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2024 The Enola Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 dev.enola.common.io.iri; + +import java.net.URI; +import java.net.URISyntaxException; + +/** + * Utility methods for Internationalized Resource Identifiers (IRIs). + * + *

See RFC 3987. + */ +public final class IRIs { + // see also (new) class dev.enola.common.io.resource.URIs + + /** + * Resolves an IRI reference against a base IRI and returns the resulting IRI as a String. + * + *

See Section §4 of RFC + * 3986. + * + *

This is currently implemented using {@link java.net.URI#resolve()}. This works great, but + * it creates (two) intermediate URI objects. If this ever becomes a problem for performance, + * this implementation could be optimized to work directly on Strings. + */ + public static String resolve(String base, String reference) throws URISyntaxException { + return toURI(base).resolve(reference).toString(); + } + + public static URI toURI(String iri) throws URISyntaxException { + return new URI(iri); + } + + private IRIs() {} +} diff --git a/common/common/src/main/java/dev/enola/common/io/resource/URIs.java b/common/common/src/main/java/dev/enola/common/io/resource/URIs.java index 16ff1ec60..688bcaa0b 100644 --- a/common/common/src/main/java/dev/enola/common/io/resource/URIs.java +++ b/common/common/src/main/java/dev/enola/common/io/resource/URIs.java @@ -32,6 +32,8 @@ import java.util.Map; public final class URIs { + // see also class dev.enola.common.io.iri.IRIs + // TODO Move this from package io.resource to package io.iri // URI Query Parameter Names private static final String MEDIA_TYPE = "mediaType"; diff --git a/common/common/src/test/java/dev/enola/common/io/iri/IRIsTest.java b/common/common/src/test/java/dev/enola/common/io/iri/IRIsTest.java new file mode 100644 index 000000000..644388e38 --- /dev/null +++ b/common/common/src/test/java/dev/enola/common/io/iri/IRIsTest.java @@ -0,0 +1,42 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * Copyright 2024 The Enola Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License 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 dev.enola.common.io.iri; + +import static com.google.common.truth.Truth.assertThat; + +import org.junit.Test; + +import java.net.URI; +import java.net.URISyntaxException; + +public class IRIsTest { + + @Test + public void toURI() throws URISyntaxException { + var iri = "https://en.wiktionary.org/wiki/Ῥόδος"; + assertThat(IRIs.toURI(iri)).isEqualTo(new URI(iri)); + } + + @Test + public void resolve() throws URISyntaxException { + var base = "https://en.wiktionary.org/wiki/Ῥόδος"; + var rel = "ῥόα"; + var expected = "https://en.wiktionary.org/wiki/ῥόα"; + assertThat(IRIs.resolve(base, rel)).isEqualTo(expected); + } +} diff --git a/common/common/src/test/java/dev/enola/common/io/resource/MarkdownResourceTest.java b/common/common/src/test/java/dev/enola/common/io/resource/MarkdownResourceTest.java index e4618323a..75e429fbe 100644 --- a/common/common/src/test/java/dev/enola/common/io/resource/MarkdownResourceTest.java +++ b/common/common/src/test/java/dev/enola/common/io/resource/MarkdownResourceTest.java @@ -41,7 +41,7 @@ public class MarkdownResourceTest { ... --> - """; + """; String FRONTMATTER = """ @@ -51,11 +51,12 @@ public class MarkdownResourceTest { """; - String MD = """ + String MD = + """ # Thaw Blough! **It rocks...** - """; + """; @Test public void commentFrontmatterMarkdown() throws IOException { diff --git a/core/impl/src/test/java/dev/enola/core/tbd/RosettaTest.java b/core/impl/src/test/java/dev/enola/core/tbd/RosettaTest.java index 10e71615c..ea1002879 100644 --- a/core/impl/src/test/java/dev/enola/core/tbd/RosettaTest.java +++ b/core/impl/src/test/java/dev/enola/core/tbd/RosettaTest.java @@ -64,18 +64,18 @@ public void testTextprotoToYaml() throws Exception { var expectedOut = StringResource.of( """ - id: - ns: demo - entity: bar - paths: [abc, def] - related: - one: - ns: demo - entity: baz - paths: [uvw] - link: {wiki:\ - 'https://en.wikipedia.org/w/index.php?fulltext=Search&search=def'} - """, + id: + ns: demo + entity: bar + paths: [abc, def] + related: + one: + ns: demo + entity: baz + paths: [uvw] + link: {wiki:\ + 'https://en.wikipedia.org/w/index.php?fulltext=Search&search=def'} + """, YAML_UTF_8); assertThat(out.charSource().read()).isEqualTo(expectedOut.charSource().read()); }