diff --git a/pom.xml b/pom.xml index 923df3f..c343f9a 100644 --- a/pom.xml +++ b/pom.xml @@ -139,7 +139,7 @@ de.flapdoodle.embed de.flapdoodle.embed.process - 2.0.2 + 2.0.3 diff --git a/src/main/java/de/flapdoodle/embed/process/store/CachedPostgresArtifactStore.java b/src/main/java/de/flapdoodle/embed/process/store/CachedPostgresArtifactStore.java index 2bd34c4..3aff962 100644 --- a/src/main/java/de/flapdoodle/embed/process/store/CachedPostgresArtifactStore.java +++ b/src/main/java/de/flapdoodle/embed/process/store/CachedPostgresArtifactStore.java @@ -13,15 +13,15 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import static de.flapdoodle.embed.process.config.store.FileType.Executable; import static de.flapdoodle.embed.process.config.store.FileType.Library; import static de.flapdoodle.embed.process.extract.ImmutableExtractedFileSet.builder; import static java.nio.file.Files.exists; +import static java.nio.file.Files.walk; import static java.nio.file.Paths.get; -import static org.apache.commons.io.FileUtils.iterateFiles; -import static org.apache.commons.io.filefilter.TrueFileFilter.TRUE; public class CachedPostgresArtifactStore extends PostgresArtifactStore { private static final Logger LOGGER = LoggerFactory.getLogger(CachedPostgresArtifactStore.class); @@ -49,14 +49,16 @@ public IExtractedFileSet extractFileSet(Distribution distribution) throws IOExce "pgsql" + "-" + distribution.getVersion().asInDownloadPath(), "pgsql"); if (exists(path)) { final Builder extracted = builder(dir).baseDirIsGenerated(false); - iterateFiles(path.toFile(), TRUE, TRUE).forEachRemaining(file -> { - FileType type = Library; - if (filesSet.entries().stream() - .anyMatch(entry -> entry.matchingPattern().matcher(file.getPath()).matches())) { - type = Executable; - } - extracted.file(type, file); - }); + walk(path) + .filter(Files::isRegularFile) + .forEach(file -> { + FileType type = Library; + if (filesSet.entries().stream() + .anyMatch(entry -> entry.matchingPattern().matcher(file.toString()).matches())) { + type = Executable; + } + extracted.file(type, file.toFile()); + }); return extracted.build(); } else { return super.extractFileSet(distribution); diff --git a/src/main/java/de/flapdoodle/embed/process/store/PostgresArtifactStore.java b/src/main/java/de/flapdoodle/embed/process/store/PostgresArtifactStore.java index 0ac275f..b8a7c2d 100644 --- a/src/main/java/de/flapdoodle/embed/process/store/PostgresArtifactStore.java +++ b/src/main/java/de/flapdoodle/embed/process/store/PostgresArtifactStore.java @@ -18,7 +18,7 @@ import java.io.IOException; import java.util.EnumSet; -import static org.apache.commons.io.FileUtils.deleteQuietly; +import static de.flapdoodle.embed.process.io.file.Files.forceDelete; /** * @author Ilya Sadykov @@ -46,16 +46,16 @@ public IDirectory getTempDir() { public void removeFileSet(Distribution distribution, IExtractedFileSet all) { for (FileType type : EnumSet.complementOf(EnumSet.of(FileType.Executable))) { for (File file : all.files(type)) { - if (file.exists() && !deleteQuietly(file)) + if (file.exists() && !forceDelete(file)) LOGGER.trace("Could not delete {} NOW: {}", type, file); } } File exe = all.executable(); - if (exe.exists() && !deleteQuietly(exe)) { + if (exe.exists() && !forceDelete(exe)) { LOGGER.trace("Could not delete executable NOW: {}", exe); } - if (all.baseDirIsGenerated() && !deleteQuietly(all.baseDir())) { + if (all.baseDirIsGenerated() && !forceDelete(all.baseDir())) { LOGGER.trace("Could not delete generatedBaseDir: {}", all.baseDir()); } } diff --git a/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java b/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java index ad837d5..3e65b2a 100644 --- a/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java +++ b/src/main/java/ru/yandex/qatools/embed/postgresql/PostgresProcess.java @@ -36,11 +36,11 @@ import static de.flapdoodle.embed.process.io.file.Files.forceDelete; import static java.lang.System.currentTimeMillis; import static java.lang.Thread.sleep; +import static java.nio.file.Files.lines; import static java.util.Arrays.asList; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; -import static org.apache.commons.io.FileUtils.readLines; import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.slf4j.LoggerFactory.getLogger; import static ru.yandex.qatools.embed.postgresql.Command.CreateDb; @@ -188,7 +188,7 @@ protected void onBeforeProcess(IRuntimeConfig runtimeConfig) super.onBeforeProcess(runtimeConfig); PostgresConfig config = getConfig(); - final File dbDir = config.storage().dbDir(); + final File dbDir = config.storage().dbDir(); if (dbDir.exists() && dbDir.listFiles() != null && dbDir.listFiles().length > 0) { return; } @@ -241,10 +241,10 @@ protected void deleteTempFiles() { @Override protected final void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { - final Storage storage = getConfig().storage(); - final Path pidFilePath = Paths.get(storage.dbDir().getAbsolutePath(), "postmaster.pid"); - final File pidFile = new File(pidFilePath.toAbsolutePath().toString()); - int timeout = TIMEOUT; + final Storage storage = getConfig().storage(); + final Path pidFilePath = Paths.get(storage.dbDir().getAbsolutePath(), "postmaster.pid"); + final File pidFile = new File(pidFilePath.toAbsolutePath().toString()); + int timeout = TIMEOUT; while (!pidFile.exists() && ((timeout = timeout - 100) > 0)) { try { sleep(100); @@ -252,7 +252,8 @@ protected final void onAfterProcessStart(ProcessControl process, } int pid = -1; try { - pid = Integer.valueOf(readLines(pidFilePath.toFile()).get(0)); + pid = lines(pidFilePath).findFirst().map(Integer::valueOf) + .orElseThrow(() -> new IllegalStateException("Pid file is empty")); } catch (Exception e) { LOGGER.error("Failed to read PID file ({})", e.getMessage(), e); } @@ -266,11 +267,11 @@ protected final void onAfterProcessStart(ProcessControl process, int trial = 0; do { String output = runCmd(getConfig(), - runtimeConfig, - CreateDb, - "", - new HashSet<>(singleton("database creation failed")), - storage.dbName()); + runtimeConfig, + CreateDb, + "", + new HashSet<>(singleton("database creation failed")), + storage.dbName()); try { if (isEmpty(output) || !output.contains("could not connect to database")) { this.processReady = true; diff --git a/src/test/java/ru/yandex/qatools/embed/postgresql/TestDownloads.java b/src/test/java/ru/yandex/qatools/embed/postgresql/TestDownloads.java index a93f36e..a95c83a 100644 --- a/src/test/java/ru/yandex/qatools/embed/postgresql/TestDownloads.java +++ b/src/test/java/ru/yandex/qatools/embed/postgresql/TestDownloads.java @@ -6,6 +6,7 @@ import de.flapdoodle.embed.process.distribution.Platform; import de.flapdoodle.embed.process.store.IArtifactStore; import de.flapdoodle.embed.process.store.PostgresArtifactStoreBuilder; +import org.junit.Ignore; import org.junit.Test; import ru.yandex.qatools.embed.postgresql.distribution.Version; @@ -18,6 +19,7 @@ public class TestDownloads { @Test + @Ignore public void testDownloads() throws IOException { IArtifactStore artifactStore = new PostgresArtifactStoreBuilder().defaults(Command.Postgres).build(); diff --git a/src/test/java/ru/yandex/qatools/embed/postgresql/TestPostgresCachedDirStarter.java b/src/test/java/ru/yandex/qatools/embed/postgresql/TestPostgresCachedDirStarter.java index 6192bc6..a912421 100644 --- a/src/test/java/ru/yandex/qatools/embed/postgresql/TestPostgresCachedDirStarter.java +++ b/src/test/java/ru/yandex/qatools/embed/postgresql/TestPostgresCachedDirStarter.java @@ -8,14 +8,12 @@ import java.io.File; -import static org.apache.commons.io.FileUtils.getTempDirectory; - public class TestPostgresCachedDirStarter extends TestPostgresStarter { @Override protected IRuntimeConfig buildRuntimeConfig() { // turns off the default functionality of unzipping on every run. - final String tmpDir = new File(getTempDirectory(), "pgembed").getPath(); + final String tmpDir = new File(System.getProperty("java.io.tmpdir"), "pgembed").getPath(); final Command cmd = Command.Postgres; final FixedPath cachedDir = new FixedPath(tmpDir); return new RuntimeConfigBuilder()