BATCH-2698: Remove commons io from test module
Prefer Files.lines over common io's readLines
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
523c8083ab
commit
305b4b8b03
@@ -502,7 +502,6 @@ project('spring-batch-test') {
|
||||
compile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||
compile "org.springframework:spring-test:$springVersion"
|
||||
compile "org.springframework:spring-jdbc:$springVersion"
|
||||
compile "commons-io:commons-io:$commonsIoVersion"
|
||||
compile "commons-collections:commons-collections:$commonsCollectionsVersion"
|
||||
|
||||
testCompile "org.apache.commons:commons-dbcp2:$commonsDdbcpVersion"
|
||||
|
||||
@@ -17,11 +17,19 @@
|
||||
package org.springframework.batch.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystemNotFoundException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
@@ -126,8 +134,8 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
String[] scripts;
|
||||
try {
|
||||
scripts = StringUtils.delimitedListToStringArray(stripComments(IOUtils.readLines(scriptResource
|
||||
.getInputStream(), "UTF-8")), ";");
|
||||
scripts = StringUtils
|
||||
.delimitedListToStringArray(stripComments(getScriptLines(scriptResource)), ";");
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new BeanInitializationException("Cannot load script from [" + scriptResource + "]", e);
|
||||
@@ -155,6 +163,24 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean {
|
||||
|
||||
}
|
||||
|
||||
private List<String> getScriptLines(Resource scriptResource) throws IOException {
|
||||
URI uri = scriptResource.getURI();
|
||||
initFileSystem(uri);
|
||||
return Files.readAllLines(Paths.get(uri), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private void initFileSystem(URI uri) throws IOException {
|
||||
try {
|
||||
FileSystems.getFileSystem(uri);
|
||||
}
|
||||
catch (FileSystemNotFoundException e) {
|
||||
FileSystems.newFileSystem(uri, Collections.emptyMap());
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
FileSystems.getDefault();
|
||||
}
|
||||
}
|
||||
|
||||
private String stripComments(List<String> list) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (String line : list) {
|
||||
|
||||
Reference in New Issue
Block a user