Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reference to Spring Framework #1786

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions schemacrawler-testdb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</properties>

<dependencies>

<dependency>
<groupId>us.fatehi</groupId>
<artifactId>schemacrawler-utility</artifactId>
Expand All @@ -30,6 +31,7 @@
<version>4.7.6</version>
<scope>provided</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
/*
* ======================================================================== SchemaCrawler
* http://www.schemacrawler.com Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>. All
* rights reserved. ------------------------------------------------------------------------
*
* SchemaCrawler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* SchemaCrawler and the accompanying materials are made available under the terms of the Eclipse
* Public License v1.0, GNU General Public License v3 or GNU Lesser General Public License v3.
*
* You may elect to redistribute this code under any of these licenses.
*
* The Eclipse Public License is available at: http://www.eclipse.org/legal/epl-v10.html
*
* The GNU General Public License v3 and the GNU Lesser General Public License v3 are available at:
* http://www.gnu.org/licenses/
*
* ========================================================================
*/
========================================================================
SchemaCrawler
http://www.schemacrawler.com
Copyright (c) 2000-2025, Sualeh Fatehi <sualeh@hotmail.com>.
All rights reserved.
------------------------------------------------------------------------

SchemaCrawler is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

SchemaCrawler and the accompanying materials are made available under
the terms of the Eclipse Public License v1.0, GNU General Public License
v3 or GNU Lesser General Public License v3.

You may elect to redistribute this code under any of these licenses.

The Eclipse Public License is available at:
http://www.eclipse.org/legal/epl-v10.html

The GNU General Public License v3 and the GNU Lesser General Public
License v3 are available at:
http://www.gnu.org/licenses/

========================================================================
*/

package schemacrawler.integration.test;

Expand All @@ -30,7 +37,12 @@
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -39,22 +51,20 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.io.support.ResourcePatternUtils;
import static us.fatehi.utility.Utility.isBlank;
import us.fatehi.utility.ioresource.ClasspathInputResource;

public class DatabaseScriptsTest {

private class DatabaseScriptSection {
private static class DatabaseScriptSection {

private final Pattern scriptNamePattern =
Pattern.compile("((\\d{2})_([a-z_]+))(_(\\d{2})_([a-z_]+))?_[A-Z].sql");
Expand All @@ -71,11 +81,11 @@ private class DatabaseScriptSection {
section = new int[2];
name = new String[2];

section[0] = Integer.valueOf(matcher.group(2));
section[0] = Integer.parseInt(matcher.group(2));
name[0] = matcher.group(3);

if (matcher.group(4) != null) {
section[1] = Integer.valueOf(matcher.group(5));
section[1] = Integer.parseInt(matcher.group(5));
name[1] = matcher.group(6);
}
}
Expand All @@ -85,24 +95,16 @@ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final DatabaseScriptSection other = (DatabaseScriptSection) obj;
if (!getEnclosingInstance().equals(other.getEnclosingInstance())) {
return false;
}
return Arrays.equals(name, other.name) && Arrays.equals(section, other.section);
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getEnclosingInstance().hashCode();
result = prime * result + Arrays.hashCode(name);
result = prime * result + Arrays.hashCode(section);
return result;
return Objects.hash(Arrays.hashCode(name), Arrays.hashCode(section));
}

public boolean matches(final String line) {
Expand All @@ -119,21 +121,15 @@ public String toString() {
}
return String.format("%02d_%s_%02d_%s", section[0], name[0], section[1], name[1]);
}

private DatabaseScriptsTest getEnclosingInstance() {
return DatabaseScriptsTest.this;
}
}

private static final Pattern fileNamePattern = Pattern.compile(".*\\/(.*\\..*)");

private Collection<DatabaseScriptSection> booksDatabaseScriptSections;

@Autowired private ResourceLoader resourceLoader;

@Test
public void booksDatabaseScripts() throws Exception {
final List<String> scripts = loadResources("classpath*:/**/*.scripts.txt");
final List<String> scripts = loadResources("**/*.scripts.txt");
assertThat(scripts, hasSize(15));
final List<String> failedScripts = new ArrayList<>();
for (final String scriptName : scripts) {
Expand Down Expand Up @@ -178,8 +174,8 @@ public void booksDatabaseScripts() throws Exception {
}

@BeforeEach
public void setup() throws IOException {
booksDatabaseScriptSections = makeScriptSections("classpath*:/**/db/books/*.sql");
public void setup() throws Exception {
booksDatabaseScriptSections = makeScriptSections("**/db/books/*.sql");
assertThat(booksDatabaseScriptSections.size(), is(32));
}

Expand All @@ -194,22 +190,31 @@ private String getScriptName(final String path) {
return scriptName;
}

private List<String> loadResources(final String pattern) throws IOException {
final Resource[] resources =
ResourcePatternUtils.getResourcePatternResolver(resourceLoader).getResources(pattern);
final List<String> scripts = new ArrayList<>();
for (final Resource classpathResource : resources) {
final String scriptName = getScriptName(classpathResource.getURL().getPath());
scripts.add(scriptName);
private List<String> loadResources(final String pattern) throws Exception {

final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);

final URI uri = ClassLoader.getSystemResource("").toURI();
final Path resourcesPath = Paths.get(uri).resolve("../../src/main/resources");
System.out.println(resourcesPath);
try (final Stream<Path> paths = Files.walk(resourcesPath)) {
final List<String> resources =
paths
.filter(pathMatcher::matches)
.map(path -> resourcesPath.relativize(path))
.map(Path::toString)
.map(path -> path.replace('\\', '/'))
.collect(Collectors.toList());
resources.sort(naturalOrder());
return resources;
}
scripts.sort(naturalOrder());
return scripts;
}

private Collection<DatabaseScriptSection> makeScriptSections(final String pattern)
throws IOException {
throws Exception {
final Set<DatabaseScriptSection> scripts = new HashSet<>();
for (final String scriptName : loadResources(pattern)) {
for (final String path : loadResources(pattern)) {
final String scriptName = getScriptName(path);
final DatabaseScriptSection databaseScriptSection = new DatabaseScriptSection(scriptName);
scripts.add(databaseScriptSection);
}
Expand Down
9 changes: 1 addition & 8 deletions schemacrawler/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>us.fatehi</groupId>
Expand Down Expand Up @@ -68,13 +68,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.3.39</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down

This file was deleted.

Loading
Loading