io.github.cdklabs.cdk.docker.image.deployment.$Module Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cdk-docker-image-deployment Show documentation
Show all versions of cdk-docker-image-deployment Show documentation
This module allows you to copy docker image assets to a repository you control. This can be necessary if you want to build a Docker image in one CDK app and consume it in a different app or outside the CDK.
package io.github.cdklabs.cdk.docker.image.deployment;
import static java.util.Arrays.asList;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import software.amazon.jsii.JsiiModule;
@software.amazon.jsii.Internal
public final class $Module extends JsiiModule {
private static final Map MODULE_TYPES = load();
private static Map load() {
final Map result = new HashMap<>();
final ClassLoader cl = $Module.class.getClassLoader();
try (final InputStream is = cl.getResourceAsStream("io/github/cdklabs/cdk/docker/image/deployment/$Module.txt");
final Reader rd = new InputStreamReader(is, StandardCharsets.UTF_8);
final BufferedReader br = new BufferedReader(rd)) {
br.lines()
.filter(line -> !line.trim().isEmpty())
.forEach(line -> {
final String[] parts = line.split("=", 2);
final String fqn = parts[0];
final String className = parts[1];
result.put(fqn, className);
});
}
catch (final IOException exception) {
throw new UncheckedIOException(exception);
}
return result;
}
private final Map> cache = new HashMap<>();
public $Module() {
super("cdk-docker-image-deployment", "0.0.618", $Module.class, "[email protected]");
}
@Override
public List> getDependencies() {
return asList(software.amazon.awscdk.$Module.class, software.constructs.$Module.class);
}
@Override
protected Class> resolveClass(final String fqn) throws ClassNotFoundException {
if (!MODULE_TYPES.containsKey(fqn)) {
throw new ClassNotFoundException("Unknown JSII type: " + fqn);
}
String className = MODULE_TYPES.get(fqn);
if (!this.cache.containsKey(className)) {
this.cache.put(className, this.findClass(className));
}
return this.cache.get(className);
}
private Class> findClass(final String binaryName) {
try {
return Class.forName(binaryName);
}
catch (final ClassNotFoundException exception) {
throw new RuntimeException(exception);
}
}
}