This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
commit 148a8bad9f3998e0d5face599f6113e135a5320c Author: Andrus Adamchik <[email protected]> AuthorDate: Sun May 10 18:46:40 2026 -0400 Remove cayenne-test-utilities dependency from cayenne-gradle-plugin, cayenne-maven-plugin-itest, cayenne-wocompat - cayenne-maven-plugin-itest: dependency was declared but never used - cayenne-gradle-plugin: replace ResourceUtil.getResource() with Class.getResource() and inline SQLReader logic as a private method - cayenne-wocompat: delete WOCompatCase base class; replace manual temp directory setup with JUnit 5 @TempDir in PropertyListSerializationTest --- cayenne-gradle-plugin/pom.xml | 6 --- .../java/org/apache/cayenne/tools/DbImportIT.java | 30 ++++++++++--- cayenne-maven-plugin-itest/pom.xml | 7 --- modeler/cayenne-wocompat/pom.xml | 6 --- .../wocompat/PropertyListSerializationTest.java | 48 ++++++++------------- .../apache/cayenne/wocompat/unit/WOCompatCase.java | 50 ---------------------- 6 files changed, 42 insertions(+), 105 deletions(-) diff --git a/cayenne-gradle-plugin/pom.xml b/cayenne-gradle-plugin/pom.xml index c82b7aed7..5764590e2 100644 --- a/cayenne-gradle-plugin/pom.xml +++ b/cayenne-gradle-plugin/pom.xml @@ -169,12 +169,6 @@ <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> -<dependency> - <groupId>org.apache.cayenne.build-tools</groupId> - <artifactId>cayenne-test-utilities</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.apache.derby</groupId> <artifactId>derby</artifactId> diff --git a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java index ab5a9b96e..bedbe03eb 100644 --- a/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java +++ b/cayenne-gradle-plugin/src/test/java/org/apache/cayenne/tools/DbImportIT.java @@ -19,16 +19,18 @@ package org.apache.cayenne.tools; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStreamReader; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; +import java.util.Collection; import java.util.Objects; - -import org.apache.cayenne.test.jdbc.SQLReader; -import org.apache.cayenne.test.resource.ResourceUtil; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; import org.gradle.testkit.runner.TaskOutcome; @@ -158,7 +160,7 @@ public class DbImportIT extends BaseTaskIT { } private String prepareDerbyDatabase(String sqlFile) throws Exception { - URL sqlUrl = Objects.requireNonNull(ResourceUtil.getResource(getClass(), sqlFile + ".sql")); + URL sqlUrl = Objects.requireNonNull(getClass().getResource(sqlFile + ".sql"), "Resource not found: " + sqlFile + ".sql"); String dbUrl = "jdbc:derby:" + projectDir.getAbsolutePath() + "/build/" + sqlFile; // Try to open connection, it may fail at first time, so ignore it @@ -168,7 +170,7 @@ public class DbImportIT extends BaseTaskIT { try (Connection connection = DriverManager.getConnection(dbUrl + ";create=true")) { try (Statement stmt = connection.createStatement()) { - for (String sql : SQLReader.statements(sqlUrl, ";")) { + for (String sql : parseSqlStatements(sqlUrl)) { stmt.execute(sql); } } @@ -182,4 +184,22 @@ public class DbImportIT extends BaseTaskIT { return dbUrl + ";create=true"; } + + private static Collection<String> parseSqlStatements(URL sqlSource) throws Exception { + var statements = new ArrayList<String>(); + try (var reader = new BufferedReader(new InputStreamReader(sqlSource.openStream(), StandardCharsets.UTF_8))) { + String line; + var statement = new StringBuilder(); + while ((line = reader.readLine()) != null) { + if (line.startsWith("-- ")) continue; + line = line.trim(); + boolean end = line.endsWith(";"); + if (end) line = line.substring(0, line.length() - 1); + if (!line.isEmpty()) statement.append('\n').append(line); + if (end) { statements.add(statement.toString()); statement = new StringBuilder(); } + } + if (!statement.isEmpty()) statements.add(statement.toString()); + } + return statements; + } } \ No newline at end of file diff --git a/cayenne-maven-plugin-itest/pom.xml b/cayenne-maven-plugin-itest/pom.xml index e4f48490f..9ff1955c2 100644 --- a/cayenne-maven-plugin-itest/pom.xml +++ b/cayenne-maven-plugin-itest/pom.xml @@ -40,13 +40,6 @@ <artifactId>junit-jupiter</artifactId> <scope>compile</scope> </dependency> - <dependency> - <groupId>org.apache.cayenne.build-tools</groupId> - <artifactId>cayenne-test-utilities</artifactId> - <version>${project.version}</version> - <scope>compile</scope> - </dependency> - <dependency> <groupId>org.apache.cayenne</groupId> <artifactId>cayenne-di</artifactId> diff --git a/modeler/cayenne-wocompat/pom.xml b/modeler/cayenne-wocompat/pom.xml index 5c4aac7d8..969921215 100644 --- a/modeler/cayenne-wocompat/pom.xml +++ b/modeler/cayenne-wocompat/pom.xml @@ -46,12 +46,6 @@ <artifactId>junit-jupiter</artifactId> <scope>test</scope> </dependency> -<dependency> - <groupId>org.apache.cayenne.build-tools</groupId> - <artifactId>cayenne-test-utilities</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> diff --git a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/PropertyListSerializationTest.java b/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/PropertyListSerializationTest.java index fc9530f79..bb8174702 100644 --- a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/PropertyListSerializationTest.java +++ b/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/PropertyListSerializationTest.java @@ -19,10 +19,11 @@ package org.apache.cayenne.wocompat; -import org.apache.cayenne.wocompat.unit.WOCompatCase; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,11 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -public class PropertyListSerializationTest extends WOCompatCase { +public class PropertyListSerializationTest { + + @TempDir + Path tempDir; @Test public void listPlist() throws Exception { - File plistFile = new File(setupTestDirectory("listPlist"), "test-array.plist"); + File plistFile = tempDir.resolve("test-array.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("str"); list.add(5); @@ -52,7 +56,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void mapPlist() throws Exception { - File plistFile = new File(setupTestDirectory("mapPlist"), "test-map.plist"); + File plistFile = tempDir.resolve("test-map.plist").toFile(); Map<String, Object> map = new HashMap<>(); map.put("key1", "val"); map.put("key2", 5); @@ -68,9 +72,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void emptyString() throws Exception { - File plistFile = new File( - setupTestDirectory("emptyString"), - "test-empty-string.plist"); + File plistFile = tempDir.resolve("test-empty-string.plist").toFile(); Map<String, Object> map = new HashMap<>(); map.put("a", ""); @@ -85,9 +87,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithQuotes() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithQuotes"), - "test-quotes.plist"); + File plistFile = tempDir.resolve("test-quotes.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("s\"tr"); list.add(5); @@ -103,9 +103,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void nestedPlist() throws Exception { - File plistFile = new File( - setupTestDirectory("nestedPlist"), - "test-nested.plist"); + File plistFile = tempDir.resolve("test-nested.plist").toFile(); Map<String, Object> map = new HashMap<>(); map.put("key1", "val"); map.put("key2", 5); @@ -126,9 +124,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithSpaces() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithSpaces"), - "test-spaces.plist"); + File plistFile = tempDir.resolve("test-spaces.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("s tr"); list.add(5); @@ -144,9 +140,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithBraces() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithBraces"), - "test-braces.plist"); + File plistFile = tempDir.resolve("test-braces.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("s{t)r"); list.add(5); @@ -162,9 +156,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithSlashes() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithSlashes"), - "test-slashes.plist"); + File plistFile = tempDir.resolve("test-slashes.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("s/t\\r"); list.add(5); @@ -180,9 +172,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithQuotes1() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithQuotes1"), - "test-quotes1.plist"); + File plistFile = tempDir.resolve("test-quotes1.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("like"); list.add("key"); @@ -199,9 +189,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithPlusMinus() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithPlusMinus"), - "test-plus-minus.plist"); + File plistFile = tempDir.resolve("test-plus-minus.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("a+b"); list.add("a-b"); @@ -218,9 +206,7 @@ public class PropertyListSerializationTest extends WOCompatCase { @Test public void stringWithLessGreater() throws Exception { - File plistFile = new File( - setupTestDirectory("stringWithLessGreater"), - "test-less-greater.plist"); + File plistFile = tempDir.resolve("test-less-greater.plist").toFile(); List<Object> list = new ArrayList<>(); list.add("a<b"); list.add("a>b"); diff --git a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/unit/WOCompatCase.java b/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/unit/WOCompatCase.java deleted file mode 100644 index f7720aacc..000000000 --- a/modeler/cayenne-wocompat/src/test/java/org/apache/cayenne/wocompat/unit/WOCompatCase.java +++ /dev/null @@ -1,50 +0,0 @@ -/***************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.cayenne.wocompat.unit; - -import org.apache.cayenne.CayenneRuntimeException; -import org.apache.cayenne.test.file.FileUtil; - -import java.io.File; - -public class WOCompatCase { - - protected File setupTestDirectory(String subfolder) { - String classPath = getClass().getName().replace('.', '/'); - String location = "target/testrun/" + classPath + "/" + subfolder; - File testDirectory = new File(location); - - // delete old tests - if (testDirectory.exists()) { - if (!FileUtil.delete(location, true)) { - throw new CayenneRuntimeException( - "Error deleting test directory '%s'", - location); - } - } - - if (!testDirectory.mkdirs()) { - throw new CayenneRuntimeException( - "Error creating test directory '%s'", - location); - } - - return testDirectory; - } -}
