From 72057b743d0756230b69d8a9255cc33740b975c9 Mon Sep 17 00:00:00 2001 From: vinoyang Date: Thu, 27 Mar 2025 10:38:39 +0800 Subject: [PATCH] chore(java): introduce spotless plugin (#2278) --- .../java/com/lancedb/lancedb/Connection.java | 63 ++++++++-------- .../com/lancedb/lancedb/ConnectionTest.java | 47 +++++++----- java/pom.xml | 74 ++++++++++++++++++- 3 files changed, 133 insertions(+), 51 deletions(-) diff --git a/java/core/src/main/java/com/lancedb/lancedb/Connection.java b/java/core/src/main/java/com/lancedb/lancedb/Connection.java index c5908757..c7ac3035 100644 --- a/java/core/src/main/java/com/lancedb/lancedb/Connection.java +++ b/java/core/src/main/java/com/lancedb/lancedb/Connection.java @@ -1,16 +1,25 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: Copyright The LanceDB 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 + * + * http://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 com.lancedb.lancedb; import io.questdb.jar.jni.JarJniLoader; + import java.io.Closeable; import java.util.List; import java.util.Optional; -/** - * Represents LanceDB database. - */ +/** Represents LanceDB database. */ public class Connection implements Closeable { static { JarJniLoader.loadLib(Connection.class, "/nativelib", "lancedb_jni"); @@ -18,14 +27,11 @@ public class Connection implements Closeable { private long nativeConnectionHandle; - /** - * Connect to a LanceDB instance. - */ + /** Connect to a LanceDB instance. */ public static native Connection connect(String uri); /** - * Get the names of all tables in the database. The names are sorted in - * ascending order. + * Get the names of all tables in the database. The names are sorted in ascending order. * * @return the table names */ @@ -34,8 +40,7 @@ public class Connection implements Closeable { } /** - * Get the names of filtered tables in the database. The names are sorted in - * ascending order. + * Get the names of filtered tables in the database. The names are sorted in ascending order. * * @param limit The number of results to return. * @return the table names @@ -45,12 +50,11 @@ public class Connection implements Closeable { } /** - * Get the names of filtered tables in the database. The names are sorted in - * ascending order. + * Get the names of filtered tables in the database. The names are sorted in ascending order. * * @param startAfter If present, only return names that come lexicographically after the supplied - * value. This can be combined with limit to implement pagination - * by setting this to the last table name from the previous page. + * value. This can be combined with limit to implement pagination by setting this to the last + * table name from the previous page. * @return the table names */ public List tableNames(String startAfter) { @@ -58,12 +62,11 @@ public class Connection implements Closeable { } /** - * Get the names of filtered tables in the database. The names are sorted in - * ascending order. + * Get the names of filtered tables in the database. The names are sorted in ascending order. * * @param startAfter If present, only return names that come lexicographically after the supplied - * value. This can be combined with limit to implement pagination - * by setting this to the last table name from the previous page. + * value. This can be combined with limit to implement pagination by setting this to the last + * table name from the previous page. * @param limit The number of results to return. * @return the table names */ @@ -72,22 +75,19 @@ public class Connection implements Closeable { } /** - * Get the names of filtered tables in the database. The names are sorted in - * ascending order. + * Get the names of filtered tables in the database. The names are sorted in ascending order. * * @param startAfter If present, only return names that come lexicographically after the supplied - * value. This can be combined with limit to implement pagination - * by setting this to the last table name from the previous page. + * value. This can be combined with limit to implement pagination by setting this to the last + * table name from the previous page. * @param limit The number of results to return. * @return the table names */ - public native List tableNames( - Optional startAfter, Optional limit); + public native List tableNames(Optional startAfter, Optional limit); /** - * Closes this connection and releases any system resources associated with it. If - * the connection is - * already closed, then invoking this method has no effect. + * Closes this connection and releases any system resources associated with it. If the connection + * is already closed, then invoking this method has no effect. */ @Override public void close() { @@ -98,8 +98,7 @@ public class Connection implements Closeable { } /** - * Native method to release the Lance connection resources associated with the - * given handle. + * Native method to release the Lance connection resources associated with the given handle. * * @param handle The native handle to the connection resource. */ diff --git a/java/core/src/test/java/com/lancedb/lancedb/ConnectionTest.java b/java/core/src/test/java/com/lancedb/lancedb/ConnectionTest.java index b526722b..fa3adf8e 100644 --- a/java/core/src/test/java/com/lancedb/lancedb/ConnectionTest.java +++ b/java/core/src/test/java/com/lancedb/lancedb/ConnectionTest.java @@ -1,27 +1,35 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: Copyright The LanceDB 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 + * + * http://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 com.lancedb.lancedb; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.nio.file.Path; -import java.util.List; -import java.net.URL; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import java.net.URL; +import java.nio.file.Path; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class ConnectionTest { private static final String[] TABLE_NAMES = { - "dataset_version", - "new_empty_dataset", - "test", - "write_stream" + "dataset_version", "new_empty_dataset", "test", "write_stream" }; - @TempDir - static Path tempDir; // Temporary directory for the tests + @TempDir static Path tempDir; // Temporary directory for the tests private static URL lanceDbURL; @BeforeAll @@ -53,18 +61,21 @@ public class ConnectionTest { @Test void tableNamesStartAfter() { try (Connection conn = Connection.connect(lanceDbURL.toString())) { - assertTableNamesStartAfter(conn, TABLE_NAMES[0], 3, TABLE_NAMES[1], TABLE_NAMES[2], TABLE_NAMES[3]); + assertTableNamesStartAfter( + conn, TABLE_NAMES[0], 3, TABLE_NAMES[1], TABLE_NAMES[2], TABLE_NAMES[3]); assertTableNamesStartAfter(conn, TABLE_NAMES[1], 2, TABLE_NAMES[2], TABLE_NAMES[3]); assertTableNamesStartAfter(conn, TABLE_NAMES[2], 1, TABLE_NAMES[3]); assertTableNamesStartAfter(conn, TABLE_NAMES[3], 0); - assertTableNamesStartAfter(conn, "a_dataset", 4, TABLE_NAMES[0], TABLE_NAMES[1], TABLE_NAMES[2], TABLE_NAMES[3]); + assertTableNamesStartAfter( + conn, "a_dataset", 4, TABLE_NAMES[0], TABLE_NAMES[1], TABLE_NAMES[2], TABLE_NAMES[3]); assertTableNamesStartAfter(conn, "o_dataset", 2, TABLE_NAMES[2], TABLE_NAMES[3]); assertTableNamesStartAfter(conn, "v_dataset", 1, TABLE_NAMES[3]); assertTableNamesStartAfter(conn, "z_dataset", 0); } } - private void assertTableNamesStartAfter(Connection conn, String startAfter, int expectedSize, String... expectedNames) { + private void assertTableNamesStartAfter( + Connection conn, String startAfter, int expectedSize, String... expectedNames) { List tableNames = conn.tableNames(startAfter); assertEquals(expectedSize, tableNames.size()); for (int i = 0; i < expectedNames.length; i++) { @@ -74,7 +85,7 @@ public class ConnectionTest { @Test void tableNamesLimit() { - try (Connection conn = Connection.connect(lanceDbURL.toString())) { + try (Connection conn = Connection.connect(lanceDbURL.toString())) { for (int i = 0; i <= TABLE_NAMES.length; i++) { List tableNames = conn.tableNames(i); assertEquals(i, tableNames.size()); diff --git a/java/pom.xml b/java/pom.xml index d45dfee9..5bb69559 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -29,6 +29,25 @@ UTF-8 15.0.0 + false + 2.30.0 + 1.7 + package + + /* + * 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 + * + * http://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. + */ + @@ -127,7 +146,8 @@ google_checks.xml true - true + false + false warning false @@ -141,6 +161,10 @@ + + com.diffplug.spotless + spotless-maven-plugin + @@ -179,6 +203,54 @@ maven-install-plugin 2.5.2 + + com.diffplug.spotless + spotless-maven-plugin + ${spotless.version} + + ${spotless.skip} + + true + + + + src/main/java/**/*.java + src/test/java/**/*.java + + + ${spotless.java.googlejavaformat.version} + + + + + com.lancedb.lance,,javax,java,\# + + + + + + + src/main/scala/**/*.scala + src/main/scala-*/**/*.scala + src/test/scala/**/*.scala + src/test/scala-*/**/*.scala + + + + ${spotless.license.header} + ${spotless.delimiter} + + + + + spotless-check + validate + + apply + + + +