private File createOrGetBaseDir(IDownloadConfig runtime) { File dir = runtime.getArtifactStorePath().asFile(); createOrCheckDir(dir); return dir; }
private File getArtifact(IDownloadConfig runtime, Distribution distribution) { File dir = createOrGetBaseDir(runtime); File artifactFile = new File(dir, runtime.getPackageResolver().getPath(distribution)); if ((artifactFile.exists()) && (artifactFile.isFile())) return artifactFile; return null; }
@Override public IArtifactStore build() { return new PostgresArtifactStore(get(DOWNLOAD_CONFIG), get(TEMP_DIR_FACTORY), get(EXECUTABLE_NAMING), get(DOWNLOADER)); } }
@Override public IExtractedFileSet extractFileSet(Distribution distribution) throws IOException { try { final File dir = this.eDir.asFile(); final FileSet filesSet = downloadConfig.getPackageResolver().getFileSet(distribution); final Path path = get(dir.getPath(), "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); }); return extracted.build(); } else { return super.extractFileSet(distribution); } } catch (Exception e) { LOGGER.error("Failed to extract file set", e); return new EmptyFileSet(); } } }
protected final boolean sendStopToPostgresqlInstance() { final boolean result = shutdownPostgres(getConfig(), runtimeConfig); if (runtimeConfig.getArtifactStore() instanceof PostgresArtifactStore) { final IDirectory tempDir = ((PostgresArtifactStore) runtimeConfig.getArtifactStore()).getTempDir(); if (tempDir != null && tempDir.asFile() != null && tempDir.isGenerated()) { LOGGER.info("Cleaning up after the embedded process (removing {})...", tempDir.asFile().getAbsolutePath()); forceDelete(tempDir.asFile()); } } return result; }
@Override public IExtractedFileSet extractFileSet(Distribution distribution) throws IOException { IPackageResolver packageResolver = downloadConfig.getPackageResolver(); File artifact = getArtifact(downloadConfig, distribution); final ArchiveType archiveType = packageResolver.getArchiveType(distribution); IExtractor extractor = Extractors.getExtractor(archiveType); try { final FileSet fileSet = packageResolver.getFileSet(distribution); return extractor.extract(downloadConfig, artifact, new PostgresFilesToExtract(tempDirFactory, executableNaming, fileSet, distribution)); } catch (Exception e) { LOGGER.error("Failed to extract file set:", e); return new EmptyFileSet(); } }
IDownloadConfig downloadCfg = ((PostgresArtifactStore) artifactStore).getDownloadConfig();