Search in sources :

Example 11 with LogLevel

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);
}
Also used : OperationIdentifier(org.gradle.internal.operations.OperationIdentifier) StyledTextOutputEvent(org.gradle.internal.logging.events.StyledTextOutputEvent) LogLevel(org.gradle.api.logging.LogLevel)

Example 12 with LogLevel

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;
}
Also used : ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap) Map(java.util.Map) LogLevel(org.gradle.api.logging.LogLevel) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace)

Example 13 with LogLevel

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());
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath) EncodedStream(org.gradle.process.internal.streams.EncodedStream) DataOutputStream(java.io.DataOutputStream) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) LogLevel(org.gradle.api.logging.LogLevel) URL(java.net.URL) OutputStreamBackedEncoder(org.gradle.internal.serialize.OutputStreamBackedEncoder) File(java.io.File) MultiChoiceAddressSerializer(org.gradle.internal.remote.internal.inet.MultiChoiceAddressSerializer)

Example 14 with LogLevel

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());
}
Also used : RhinoCoffeeScriptCompiler(org.gradle.plugins.javascript.coffeescript.compile.internal.rhino.RhinoCoffeeScriptCompiler) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) DefaultCoffeeScriptCompileSpec(org.gradle.plugins.javascript.coffeescript.compile.internal.DefaultCoffeeScriptCompileSpec) RhinoCoffeeScriptCompiler(org.gradle.plugins.javascript.coffeescript.compile.internal.rhino.RhinoCoffeeScriptCompiler) DefaultCoffeeScriptCompileSpec(org.gradle.plugins.javascript.coffeescript.compile.internal.DefaultCoffeeScriptCompileSpec) LogLevel(org.gradle.api.logging.LogLevel) TaskAction(org.gradle.api.tasks.TaskAction)

Example 15 with LogLevel

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"));
    }
}
Also used : DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) DefaultRhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.DefaultRhinoWorkerHandleFactory) RhinoWorkerHandleFactory(org.gradle.plugins.javascript.rhino.worker.internal.RhinoWorkerHandleFactory) FileWriter(java.io.FileWriter) UncheckedIOException(org.gradle.api.UncheckedIOException) Logger(org.gradle.api.logging.Logger) URI(java.net.URI) LogLevel(org.gradle.api.logging.LogLevel) LinkedHashMap(java.util.LinkedHashMap) JsHintSpec(org.gradle.plugins.javascript.jshint.internal.JsHintSpec) JsHintResult(org.gradle.plugins.javascript.jshint.internal.JsHintResult) GsonBuilder(com.google.gson.GsonBuilder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) GradleException(org.gradle.api.GradleException) JsHintProtocol(org.gradle.plugins.javascript.jshint.internal.JsHintProtocol) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) OutputFile(org.gradle.api.tasks.OutputFile) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

LogLevel (org.gradle.api.logging.LogLevel)20 File (java.io.File)6 IOException (java.io.IOException)3 UncheckedIOException (org.gradle.api.UncheckedIOException)3 TaskAction (org.gradle.api.tasks.TaskAction)3 LogEventSerializer (org.gradle.internal.logging.serializer.LogEventSerializer)3 LogLevelChangeEventSerializer (org.gradle.internal.logging.serializer.LogLevelChangeEventSerializer)3 Injector (com.google.inject.Injector)2 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 BufferedWriter (java.io.BufferedWriter)2 DataOutputStream (java.io.DataOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 URL (java.net.URL)2 Charset (java.nio.charset.Charset)2 Map (java.util.Map)2 FileCollection (org.gradle.api.file.FileCollection)2 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)2 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)2 StyledTextOutputEvent (org.gradle.internal.logging.events.StyledTextOutputEvent)2