use of com.google.cloud.tools.jib.api.LogEvent in project jib by google.
the class PluginConfigurationProcessorTest method testPluginConfigurationProcessor_defaults.
@Test
public void testPluginConfigurationProcessor_defaults() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
ContainerBuildPlan buildPlan = processCommonConfiguration();
assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
verify(containerizer).setBaseImageLayersCache(Containerizer.DEFAULT_BASE_CACHE_DIRECTORY);
verify(containerizer).setApplicationLayersCache(appCacheDirectory);
ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
verify(logger, never()).accept(argThat(isLogWarn));
}
use of com.google.cloud.tools.jib.api.LogEvent in project jib by google.
the class TaskCommon method disableHttpLogging.
/**
* Disables annoying Apache HTTP client logging.
*/
static void disableHttpLogging() {
// Disables Apache HTTP client logging.
OutputEventListenerBackedLoggerContext context = (OutputEventListenerBackedLoggerContext) LoggerFactory.getILoggerFactory();
OutputEventListener defaultOutputEventListener = context.getOutputEventListener();
context.setOutputEventListener(event -> {
org.gradle.internal.logging.events.LogEvent logEvent = (org.gradle.internal.logging.events.LogEvent) event;
if (!logEvent.getCategory().contains("org.apache")) {
defaultOutputEventListener.onOutput(event);
}
});
// property is undefined: https://github.com/GoogleContainerTools/jib/issues/2356
if (System.getProperty("java.util.logging.config.file") == null) {
// Disables Google HTTP client logging.
java.util.logging.Logger.getLogger(HttpTransport.class.getName()).setLevel(Level.OFF);
}
}
use of com.google.cloud.tools.jib.api.LogEvent in project jib by google.
the class War method call.
@Override
public Integer call() {
commonCliOptions.validate();
SingleThreadedExecutor executor = new SingleThreadedExecutor();
ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
if (!Files.exists(warFile)) {
logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + warFile);
return 1;
}
if (Files.isDirectory(warFile)) {
logger.log(LogEvent.Level.ERROR, "The file path provided is for a directory. Please provide a path to a WAR: " + warFile);
return 1;
}
Path warFileParentDir = Verify.verifyNotNull(warFile.toAbsolutePath().getParent());
CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, warFileParentDir);
ArtifactProcessor processor = ArtifactProcessors.fromWar(warFile, cacheDirectories, this, commonContainerConfigCliOptions);
JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(processor, commonCliOptions, commonContainerConfigCliOptions, logger);
Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
// Enable registry mirrors
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainer jibContainer = containerBuilder.containerize(containerizer);
JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
} catch (InterruptedException ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
Thread.currentThread().interrupt();
return 1;
} catch (Exception ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
return 1;
} finally {
JibCli.finishUpdateChecker(logger, updateCheckFuture);
executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
}
return 0;
}
use of com.google.cloud.tools.jib.api.LogEvent in project jib by google.
the class PluginConfigurationProcessorTest method testEntrypoint_extraClasspathNonWarPackaging.
@Test
public void testEntrypoint_extraClasspathNonWarPackaging() throws IOException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
when(rawConfiguration.getExtraClasspath()).thenReturn(Collections.singletonList("/foo"));
when(projectProperties.isWarProject()).thenReturn(false);
ContainerBuildPlan buildPlan = processCommonConfiguration();
assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/foo:/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
verify(logger, never()).accept(argThat(isLogWarn));
}
use of com.google.cloud.tools.jib.api.LogEvent in project jib by google.
the class Build method call.
@Override
public Integer call() {
commonCliOptions.validate();
Path buildFile = getBuildFile();
SingleThreadedExecutor executor = new SingleThreadedExecutor();
ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
if (!Files.isReadable(buildFile)) {
logger.log(LogEvent.Level.ERROR, "The Build File YAML either does not exist or cannot be opened for reading: " + buildFile);
return 1;
}
if (!Files.isRegularFile(buildFile)) {
logger.log(LogEvent.Level.ERROR, "Build File YAML path is a not a file: " + buildFile);
return 1;
}
CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, contextRoot);
Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
JibContainerBuilder containerBuilder = BuildFiles.toJibContainerBuilder(contextRoot, buildFile, this, commonCliOptions, logger);
// Enable registry mirrors
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainer jibContainer = containerBuilder.containerize(containerizer);
JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
} catch (InterruptedException ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
Thread.currentThread().interrupt();
return 1;
} catch (Exception ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
return 1;
} finally {
JibCli.finishUpdateChecker(logger, updateCheckFuture);
executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
}
return 0;
}
Aggregations