use of com.google.cloud.tools.jib.api.LayerConfiguration in project component-runtime by Talend.
the class ConnectorLoader method createConnectorLayer.
public ConnectorLayer createConnectorLayer(final AbsoluteUnixPath rootContainerPath, final Path workDir, final Path car) {
String gav = null;
final Map<String, Path> toCopy = new HashMap<>();
try (final JarInputStream jarInputStream = new JarInputStream(Files.newInputStream(car))) {
JarEntry entry;
while ((entry = jarInputStream.getNextJarEntry()) != null) {
if ("TALEND-INF/metadata.properties".equals(entry.getName())) {
// don't close, it is the jar!
gav = IO.loadProperties(new BufferedReader(new InputStreamReader(jarInputStream)).lines().collect(joining("\n"))).getProperty("component_coordinates");
continue;
}
if (!entry.getName().startsWith("MAVEN-INF/repository/")) {
continue;
}
final String relativeName = entry.getName().substring("MAVEN-INF/repository/".length());
final Path local = workDir.resolve(relativeName);
if (entry.isDirectory()) {
if (!Files.exists(local)) {
Files.createDirectories(local);
}
} else {
if (local.getParent() != null && !Files.exists(local.getParent())) {
Files.createDirectories(local.getParent());
}
Files.copy(jarInputStream, local);
if (entry.getLastModifiedTime() != null) {
Files.setLastModifiedTime(local, entry.getLastModifiedTime());
}
toCopy.put(relativeName, local);
}
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return new ConnectorLayer(toCopy.entrySet().stream().collect(Collector.of(LayerConfiguration::builder, (builder, entry) -> {
try {
builder.addEntry(new LayerEntry(entry.getValue(), rootContainerPath.resolve(entry.getKey()), FilePermissions.DEFAULT_FILE_PERMISSIONS, Instant.ofEpochMilli(Files.getLastModifiedTime(entry.getValue()).toMillis())));
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}, (builder1, builder2) -> {
builder2.build().getLayerEntries().forEach(builder1::addEntry);
return builder1;
})).build(), toCopy, requireNonNull(gav, "GAV was not found in '" + car + "', ensure it is a valid component archive."));
}
Aggregations