use of org.eclipse.jkube.kit.common.PrefixedLogger in project jkube by eclipse.
the class SpringBootWatcher method runRemoteSpringApplication.
private void runRemoteSpringApplication(String url) {
log.info("Running RemoteSpringApplication against endpoint: " + url);
String remoteSecret = validateSpringBootDevtoolsSettings();
ClassLoader classLoader = getClass().getClassLoader();
if (classLoader instanceof URLClassLoader) {
URLClassLoader pluginClassLoader = (URLClassLoader) classLoader;
try (URLClassLoader projectClassLoader = ClassUtil.createProjectClassLoader(getContext().getBuildContext().getProject().getCompileClassPathElements(), log)) {
URLClassLoader[] classLoaders = { projectClassLoader, pluginClassLoader };
StringBuilder buffer = new StringBuilder("java -cp ");
int count = 0;
for (URLClassLoader urlClassLoader : classLoaders) {
URL[] urLs = urlClassLoader.getURLs();
for (URL u : urLs) {
if (count++ > 0) {
buffer.append(File.pathSeparator);
}
try {
URI uri = u.toURI();
File file = new File(uri);
buffer.append(file.getCanonicalPath());
} catch (Exception e) {
throw new IllegalStateException("Failed to create classpath: " + e, e);
}
}
}
// Add dev tools to the classpath (the main class is not read from BOOT-INF/lib)
try {
File devtools = getSpringBootDevToolsJar(getContext().getBuildContext().getProject());
buffer.append(File.pathSeparator);
buffer.append(devtools.getCanonicalPath());
} catch (Exception e) {
throw new IllegalStateException("Failed to include devtools in the classpath: " + e, e);
}
buffer.append(" -Dspring.devtools.remote.secret=");
buffer.append(remoteSecret);
buffer.append(" org.springframework.boot.devtools.RemoteSpringApplication ");
buffer.append(url);
try {
String command = buffer.toString();
log.debug("Running: " + command);
final Process process = Runtime.getRuntime().exec(command);
final AtomicBoolean outputEnabled = new AtomicBoolean(true);
Runtime.getRuntime().addShutdownHook(new Thread("jkube:watch [spring-boot] shutdown hook") {
@Override
public void run() {
log.info("Terminating the Spring remote client...");
outputEnabled.set(false);
process.destroy();
}
});
KitLogger logger = new PrefixedLogger("Spring-Remote", log);
Thread stdOutPrinter = startOutputProcessor(logger, process.getInputStream(), false, outputEnabled);
Thread stdErrPrinter = startOutputProcessor(logger, process.getErrorStream(), true, outputEnabled);
int status = process.waitFor();
stdOutPrinter.join();
stdErrPrinter.join();
if (status != 0) {
log.warn("Process returned status: %s", status);
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
} catch (Exception e) {
throw new RuntimeException("Failed to run RemoteSpringApplication: " + e, e);
}
} catch (IOException e) {
log.warn("Instructed to use project classpath, but cannot. Continuing build if we can: ", e);
}
} else {
throw new IllegalStateException("ClassLoader must be a URLClassLoader but it is: " + classLoader.getClass().getName());
}
}
use of org.eclipse.jkube.kit.common.PrefixedLogger in project jkube by eclipse.
the class AssemblyManagerCreateDockerTarArchiveTest method withoutDockerfileAndFinalCustomizer.
@Test
public void withoutDockerfileAndFinalCustomizer() throws IOException {
// Given
final JKubeConfiguration jKubeConfiguration = createJKubeConfiguration();
final BuildConfiguration buildConfiguration = BuildConfiguration.builder().build();
final AtomicBoolean customized = new AtomicBoolean(false);
final ArchiverCustomizer finalCustomizer = ac -> {
customized.set(true);
return ac;
};
// When
File dockerArchiveFile = assemblyManager.createDockerTarArchive("no-docker-file-and-customizer", jKubeConfiguration, buildConfiguration, prefixedLogger, finalCustomizer);
// Then
assertTargetHasDockerDirectories("no-docker-file-and-customizer");
ArchiveAssertions.assertThat(dockerArchiveFile).isFile().hasName("docker-build.tar").hasSameContentAsDirectory(getExpectedDirectory("without-dockerfile-and-final-customizer"));
assertDockerFile("no-docker-file-and-customizer").hasContent(DOCKERFILE_DEFAULT_FALLBACK_CONTENT);
assertBuildDirectoryFileTree("no-docker-file-and-customizer").containsExactlyInAnyOrder("Dockerfile", "jkube-generated-layer-final-artifact", "jkube-generated-layer-final-artifact/maven", "jkube-generated-layer-final-artifact/maven/test-0.1.0.jar", "maven");
assertThat(customized).isTrue();
}
Aggregations