Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

bump embed.process to 2.0.3 (fixes #132). remove commons-io from deps #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -241,18 +241,19 @@ 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);
} catch (InterruptedException ie) { /* safe to ignore */ }
}
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);
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down