Skip to content

Commit

Permalink
modify jar load case
Browse files Browse the repository at this point in the history
  • Loading branch information
strongduanmu committed Dec 17, 2024
1 parent f610446 commit f383870
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.loader.SQLParserTestCaseLoaderCallback;
import org.apache.shardingsphere.test.it.sql.parser.internal.loader.CaseLoaderTemplate;

import java.io.File;

/**
* SQL binder test cases registry.
*/
Expand All @@ -33,7 +35,8 @@ public final class SQLBinderTestCasesRegistry {
private final SQLParserTestCases cases;

private SQLBinderTestCasesRegistry() {
cases = new SQLParserTestCases(CaseLoaderTemplate.load("cases/", new SQLParserTestCaseLoaderCallback()));
File file = new File(SQLBinderTestCasesRegistry.class.getProtectionDomain().getCodeSource().getLocation().getPath());
cases = new SQLParserTestCases(CaseLoaderTemplate.load(file, "cases/", new SQLParserTestCaseLoaderCallback()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.sql.loader.SQLCaseLoaderCallback;
import org.apache.shardingsphere.test.it.sql.parser.internal.loader.CaseLoaderTemplate;

import java.io.File;

/**
* SQL binder cases registry.
*/
Expand All @@ -33,7 +35,8 @@ public final class SQLBinderCasesRegistry {
private final SQLCases cases;

private SQLBinderCasesRegistry() {
cases = new SQLCases(CaseLoaderTemplate.load("sqls/", new SQLCaseLoaderCallback()));
File file = new File(SQLBinderCasesRegistry.class.getProtectionDomain().getCodeSource().getLocation().getPath());
cases = new SQLCases(CaseLoaderTemplate.load(file, "sqls/", new SQLCaseLoaderCallback()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ public final class CaseLoaderTemplate {
* @param <T> type of test case
* @return loaded cases
*/
@SneakyThrows({JAXBException.class, IOException.class})
public static <T> Map<String, T> load(final String rootDirectory, final CaseLoaderCallback<T> callback) {
File file = new File(CaseLoaderTemplate.class.getProtectionDomain().getCodeSource().getLocation().getPath());
return load(file, rootDirectory, callback);
}

/**
* Load test cases.
*
* @param file file
* @param rootDirectory root directory
* @param callback callback of cases loader
* @param <T> type of test case
* @return loaded cases
*/
@SneakyThrows({JAXBException.class, IOException.class})
public static <T> Map<String, T> load(final File file, final String rootDirectory, final CaseLoaderCallback<T> callback) {
return file.isFile() ? callback.loadFromJar(file, rootDirectory) : callback.loadFromDirectory(rootDirectory);
}
}

0 comments on commit f383870

Please sign in to comment.