use of org.gradle.api.logging.LogLevel in project gradle by gradle.
the class StyledTextOutputEventSerializer method read.
@Override
public StyledTextOutputEvent read(Decoder decoder) throws Exception {
long timestamp = decoder.readLong();
String category = decoder.readString();
LogLevel logLevel = logLevelSerializer.read(decoder);
OperationIdentifier buildOperationId = decoder.readBoolean() ? new OperationIdentifier(decoder.readSmallLong()) : null;
List<StyledTextOutputEvent.Span> spans = spanSerializer.read(decoder);
return new StyledTextOutputEvent(timestamp, category, logLevel, buildOperationId, spans);
}
use of org.gradle.api.logging.LogLevel in project gradle by gradle.
the class LoggingCommandLineConverter method convert.
public LoggingConfiguration convert(ParsedCommandLine commandLine, LoggingConfiguration loggingConfiguration) throws CommandLineArgumentException {
for (Map.Entry<String, LogLevel> entry : logLevelMap.entrySet()) {
if (commandLine.hasOption(entry.getKey())) {
loggingConfiguration.setLogLevel(entry.getValue());
}
}
for (Map.Entry<String, ShowStacktrace> entry : showStacktraceMap.entrySet()) {
if (commandLine.hasOption(entry.getKey())) {
loggingConfiguration.setShowStacktrace(entry.getValue());
}
}
if (commandLine.hasOption(CONSOLE)) {
String value = commandLine.option(CONSOLE).getValue();
String consoleValue = StringUtils.capitalize(value.toLowerCase(Locale.ENGLISH));
try {
ConsoleOutput consoleOutput = ConsoleOutput.valueOf(consoleValue);
loggingConfiguration.setConsoleOutput(consoleOutput);
} catch (IllegalArgumentException e) {
throw new CommandLineArgumentException(String.format("Unrecognized value '%s' for %s.", value, CONSOLE));
}
}
return loggingConfiguration;
}
use of org.gradle.api.logging.LogLevel in project gradle by gradle.
the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.
@Override
public void prepareJavaCommand(Object workerId, String displayName, DefaultWorkerProcessBuilder processBuilder, List<URL> implementationClassPath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
LogLevel logLevel = processBuilder.getLogLevel();
Set<String> sharedPackages = processBuilder.getSharedPackages();
Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
ClassPath workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN");
execSpec.setMain("worker." + GradleWorkerMain.class.getName());
boolean useOptionsFile = shouldUseOptionsFile(execSpec);
if (useOptionsFile) {
// Use an options file to pass across application classpath
File optionsFile = temporaryFileProvider.createTemporaryFile("gradle-worker-classpath", "txt");
List<String> jvmArgs = writeOptionsFile(workerMainClassPath.getAsFiles(), applicationClasspath, optionsFile);
execSpec.jvmArgs(jvmArgs);
} else {
// Use a dummy security manager, which hacks the application classpath into the system ClassLoader
execSpec.classpath(workerMainClassPath.getAsFiles());
execSpec.systemProperty("java.security.manager", "worker." + BootstrapSecurityManager.class.getName());
}
// Serialize configuration for the worker process to it stdin
StreamByteBuffer buffer = new StreamByteBuffer();
try {
DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
if (!useOptionsFile) {
// Serialize the application classpath, this is consumed by BootstrapSecurityManager
outstr.writeInt(applicationClasspath.size());
for (File file : applicationClasspath) {
outstr.writeUTF(file.getAbsolutePath());
}
// Serialize the actual security manager type, this is consumed by BootstrapSecurityManager
outstr.writeUTF(requestedSecurityManager == null ? "" : requestedSecurityManager.toString());
}
// Serialize the shared packages, this is consumed by GradleWorkerMain
outstr.writeInt(sharedPackages.size());
for (String str : sharedPackages) {
outstr.writeUTF(str);
}
// Serialize the worker implementation classpath, this is consumed by GradleWorkerMain
outstr.writeInt(implementationClassPath.size());
for (URL entry : implementationClassPath) {
outstr.writeUTF(entry.toString());
}
// Serialize the worker config, this is consumed by SystemApplicationClassLoaderWorker
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
encoder.writeSmallInt(logLevel.ordinal());
encoder.writeBoolean(publishProcessInfo);
encoder.writeString(gradleUserHomeDir.getAbsolutePath());
new MultiChoiceAddressSerializer().write(encoder, (MultiChoiceAddress) serverAddress);
// Serialize the worker, this is consumed by SystemApplicationClassLoaderWorker
ActionExecutionWorker worker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, gradleUserHomeDir);
byte[] serializedWorker = GUtil.serialize(worker);
encoder.writeBinary(serializedWorker);
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
execSpec.setStandardInput(buffer.getInputStream());
}
use of org.gradle.api.logging.LogLevel in project gradle by gradle.
the class CoffeeScriptCompile method doCompile.
@TaskAction
public void doCompile() {
RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
CoffeeScriptCompileSpec spec = new DefaultCoffeeScriptCompileSpec();
spec.setCoffeeScriptJs(getCoffeeScriptJs().getSingleFile());
spec.setDestinationDir(getDestinationDir());
spec.setSource(getSource());
spec.setOptions(getOptions());
LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
CoffeeScriptCompiler compiler = new RhinoCoffeeScriptCompiler(handleFactory, getRhinoClasspath(), logLevel, getProject().getProjectDir());
setDidWork(compiler.compile(spec).getDidWork());
}
use of org.gradle.api.logging.LogLevel in project gradle by gradle.
the class JsHint method doJsHint.
@TaskAction
public void doJsHint() {
RhinoWorkerHandleFactory handleFactory = new DefaultRhinoWorkerHandleFactory(getWorkerProcessBuilderFactory());
LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
JsHintProtocol worker = handleFactory.create(getRhinoClasspath(), JsHintProtocol.class, JsHintWorker.class, logLevel, getProject().getProjectDir());
JsHintSpec spec = new JsHintSpec();
// flatten because we need to serialize
spec.setSource(getSource().getFiles());
spec.setEncoding(getEncoding());
spec.setJsHint(getJsHint().getSingleFile());
JsHintResult result = worker.process(spec);
setDidWork(true);
// TODO - this is all terribly lame. We need some proper reporting here (which means implementing Reporting).
Logger logger = getLogger();
boolean anyErrors = false;
Map<String, Map<?, ?>> reportData = new LinkedHashMap<String, Map<?, ?>>(result.getResults().size());
for (Map.Entry<File, Map<String, Object>> fileEntry : result.getResults().entrySet()) {
File file = fileEntry.getKey();
Map<String, Object> data = fileEntry.getValue();
reportData.put(file.getAbsolutePath(), data);
if (data.containsKey("errors")) {
anyErrors = true;
URI projectDirUri = getProject().getProjectDir().toURI();
@SuppressWarnings("unchecked") Map<String, Object> errors = (Map<String, Object>) data.get("errors");
if (!errors.isEmpty()) {
URI relativePath = projectDirUri.relativize(file.toURI());
logger.warn("JsHint errors for file: {}", relativePath.getPath());
for (Map.Entry<String, Object> errorEntry : errors.entrySet()) {
@SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) errorEntry.getValue();
int line = Float.valueOf(error.get("line").toString()).intValue();
int character = Float.valueOf(error.get("character").toString()).intValue();
String reason = error.get("reason").toString();
logger.warn(" {}:{} > {}", new Object[] { line, character, reason });
}
}
}
}
File jsonReportFile = getJsonReport();
if (jsonReportFile != null) {
try {
FileWriter reportWriter = new FileWriter(jsonReportFile);
new GsonBuilder().setPrettyPrinting().create().toJson(reportData, reportWriter);
reportWriter.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
if (anyErrors) {
throw new TaskExecutionException(this, new GradleException("JsHint detected errors"));
}
}
Aggregations