use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.
the class MainClassFinderTest method testFindMainClass_extension.
@Test
public void testFindMainClass_extension() throws URISyntaxException, IOException {
Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/extension").toURI());
MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
Assert.assertSame(Result.Type.MAIN_CLASS_FOUND, mainClassFinderResult.getType());
MatcherAssert.assertThat(mainClassFinderResult.getFoundMainClass(), CoreMatchers.containsString("main.MainClass"));
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.
the class MainClassFinderTest method testMainClass_synthetic.
@Test
public void testMainClass_synthetic() throws URISyntaxException, IOException {
Path rootDirectory = Paths.get(Resources.getResource("core/class-finder-tests/synthetic").toURI());
MainClassFinder.Result mainClassFinderResult = MainClassFinder.find(new DirectoryWalker(rootDirectory).walk(), logEventConsumer);
Assert.assertSame(MainClassFinder.Result.Type.MAIN_CLASS_FOUND, mainClassFinderResult.getType());
MatcherAssert.assertThat(mainClassFinderResult.getFoundMainClass(), CoreMatchers.containsString("HelloWorldKt"));
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.
the class TarExtractor method preserveModificationTimes.
/**
* Preserve modification timestamps of files and directories in a tar file. If a directory is not
* an entry in the tar file and reproducible timestamps are enabled then its modification
* timestamp is set to a constant value. Note that the modification timestamps of symbolic links
* are not preserved even with reproducible timestamps enabled.
*
* @param destination target root for unzipping
* @param entries list of entries in tar file
* @param enableReproducibleTimestamps whether or not reproducible timestamps should be used
* @throws IOException when I/O error occurs
*/
private static void preserveModificationTimes(Path destination, List<TarArchiveEntry> entries, boolean enableReproducibleTimestamps) throws IOException {
if (enableReproducibleTimestamps) {
FileTime epochPlusOne = FileTime.fromMillis(1000L);
new DirectoryWalker(destination).filter(Files::isDirectory).walk(path -> Files.setLastModifiedTime(path, epochPlusOne));
}
for (TarArchiveEntry entry : entries) {
// the target to change
if (!entry.isSymbolicLink()) {
Files.setLastModifiedTime(destination.resolve(entry.getName()), FileTime.from(entry.getModTime().toInstant()));
}
}
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.
the class MavenProjectPropertiesTest method zipUpDirectory.
private static Path zipUpDirectory(Path sourceRoot, Path targetZip) throws IOException {
try (ZipOutputStream zipOut = new ZipOutputStream(Files.newOutputStream(targetZip))) {
for (Path source : new DirectoryWalker(sourceRoot).filterRoot().walk()) {
StringJoiner pathJoiner = new StringJoiner("/", "", "");
sourceRoot.relativize(source).forEach(element -> pathJoiner.add(element.toString()));
String zipEntryPath = Files.isDirectory(source) ? pathJoiner.toString() + '/' : pathJoiner.toString();
ZipEntry entry = new ZipEntry(zipEntryPath);
zipOut.putNextEntry(entry);
if (!Files.isDirectory(source)) {
try (InputStream in = Files.newInputStream(source)) {
ByteStreams.copy(in, zipOut);
}
}
zipOut.closeEntry();
}
}
return targetZip;
}
use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.
the class TestProject method copyProject.
private void copyProject() throws IOException {
projectRoot = ResourceExtractor.extractResourcePath(TestProject.class, PROJECTS_PATH_IN_RESOURCES + projectDir, newFolder(), true).toPath();
// Puts the correct plugin version into the test project pom.xml.
Path gradleProperties = Paths.get("gradle.properties");
Properties properties = new Properties();
properties.load(Files.newInputStream(gradleProperties));
String pluginVersion = properties.getProperty("version");
new DirectoryWalker(projectRoot).filter(TestProject::isPomXml).walk(pomXml -> Files.write(pomXml, new String(Files.readAllBytes(pomXml), StandardCharsets.UTF_8).replace("@@PluginVersion@@", pluginVersion).getBytes(StandardCharsets.UTF_8)));
}
Aggregations