Search in sources :

Example 16 with LogLevel

use of org.gradle.api.logging.LogLevel in project webpieces by deanhiller.

the class TemplateCompile method compileImpl.

public void compileImpl(TemplateCompileOptions options) throws IOException {
    File buildDir = getProject().getBuildDir();
    // need to make customizable...
    File groovySrcGen = new File(buildDir, "groovysrc");
    log.log(LogLevel.LIFECYCLE, "putting groovy scripts in: " + groovySrcGen);
    Charset encoding = Charset.forName(options.getEncoding());
    TemplateCompileConfig config = new TemplateCompileConfig(false);
    config.setFileEncoding(encoding);
    config.setPluginClient(true);
    config.setGroovySrcWriteDirectory(groovySrcGen);
    log.log(LogLevel.LIFECYCLE, "Custom tags: " + options.getCustomTags());
    config.setCustomTagsFromPlugin(options.getCustomTags());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    File destinationDir = getDestinationDirectory().getAsFile().get();
    log.log(LogLevel.LIFECYCLE, "Writing class files to destDir: " + destinationDir);
    File routeIdFile = new File(destinationDir, ProdConstants.ROUTE_META_FILE);
    if (routeIdFile.exists())
        routeIdFile.delete();
    routeIdFile.createNewFile();
    log.log(LogLevel.LIFECYCLE, "routeId file: " + routeIdFile);
    FileCollection srcCollection = getSource();
    Set<File> files = srcCollection.getFiles();
    File firstFile = files.iterator().next();
    File baseDir = findBase(firstFile);
    try (FileOutputStream routeOut = new FileOutputStream(routeIdFile);
        OutputStreamWriter write = new OutputStreamWriter(routeOut, encoding.name());
        BufferedWriter bufWrite = new BufferedWriter(write)) {
        Injector injector = Guice.createInjector(new StubModule(), new DevTemplateModule(config, new PluginCompileCallback(destinationDir, bufWrite)));
        HtmlToJavaClassCompiler compiler = injector.getInstance(HtmlToJavaClassCompiler.class);
        GroovyClassLoader cl = new GroovyClassLoader();
        for (File f : files) {
            String fullName = findFullName(baseDir, f);
            log.log(LogLevel.INFO, "file compile name={}, file={}", fullName, f);
            String source = readSource(f);
            compiler.compile(cl, fullName, source);
        }
    }
    setDidWork(true);
}
Also used : Charset(java.nio.charset.Charset) HtmlToJavaClassCompiler(org.webpieces.templatingdev.impl.HtmlToJavaClassCompiler) FileCollection(org.gradle.api.file.FileCollection) LogLevel(org.gradle.api.logging.LogLevel) BufferedWriter(java.io.BufferedWriter) GroovyClassLoader(groovy.lang.GroovyClassLoader) StubModule(org.webpieces.templatingdev.api.StubModule) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Injector(com.google.inject.Injector) FileOutputStream(java.io.FileOutputStream) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 17 with LogLevel

use of org.gradle.api.logging.LogLevel in project gradle by gradle.

the class LogEventSerializer method read.

@Override
public LogEvent read(Decoder decoder) throws Exception {
    long timestamp = decoder.readLong();
    String category = decoder.readString();
    LogLevel logLevel = logLevelSerializer.read(decoder);
    String message = decoder.readNullableString();
    Throwable throwable = throwableSerializer.read(decoder);
    OperationIdentifier buildOperationId = decoder.readBoolean() ? new OperationIdentifier(decoder.readSmallLong()) : null;
    return new LogEvent(timestamp, category, logLevel, message, throwable, buildOperationId);
}
Also used : LogEvent(org.gradle.internal.logging.events.LogEvent) OperationIdentifier(org.gradle.internal.operations.OperationIdentifier) LogLevel(org.gradle.api.logging.LogLevel)

Example 18 with LogLevel

use of org.gradle.api.logging.LogLevel in project gradle by gradle.

the class WorkerLoggingSerializer method create.

public static SerializerRegistry create() {
    DefaultSerializerRegistry registry = new DefaultSerializerRegistry(false);
    BaseSerializerFactory factory = new BaseSerializerFactory();
    Serializer<LogLevel> logLevelSerializer = factory.getSerializerFor(LogLevel.class);
    Serializer<Throwable> throwableSerializer = factory.getSerializerFor(Throwable.class);
    // Log events
    registry.register(LogEvent.class, new LogEventSerializer(logLevelSerializer, throwableSerializer));
    registry.register(StyledTextOutputEvent.class, new StyledTextOutputEventSerializer(logLevelSerializer, new ListSerializer<StyledTextOutputEvent.Span>(new SpanSerializer(factory.getSerializerFor(StyledTextOutput.Style.class)))));
    registry.register(LogLevelChangeEvent.class, new LogLevelChangeEventSerializer(logLevelSerializer));
    return registry;
}
Also used : LogLevelChangeEventSerializer(org.gradle.internal.logging.serializer.LogLevelChangeEventSerializer) ListSerializer(org.gradle.internal.serialize.ListSerializer) SpanSerializer(org.gradle.internal.logging.serializer.SpanSerializer) DefaultSerializerRegistry(org.gradle.internal.serialize.DefaultSerializerRegistry) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) LogLevel(org.gradle.api.logging.LogLevel) LogEventSerializer(org.gradle.internal.logging.serializer.LogEventSerializer) BaseSerializerFactory(org.gradle.internal.serialize.BaseSerializerFactory) StyledTextOutputEventSerializer(org.gradle.internal.logging.serializer.StyledTextOutputEventSerializer) StyledTextOutputEvent(org.gradle.internal.logging.events.StyledTextOutputEvent)

Example 19 with LogLevel

use of org.gradle.api.logging.LogLevel in project gradle by gradle.

the class DaemonMessageSerializer method create.

public static Serializer<Message> create(Serializer<BuildAction> buildActionSerializer) {
    BaseSerializerFactory factory = new BaseSerializerFactory();
    Serializer<LogLevel> logLevelSerializer = factory.getSerializerFor(LogLevel.class);
    Serializer<Throwable> throwableSerializer = factory.getSerializerFor(Throwable.class);
    DefaultSerializerRegistry registry = new DefaultSerializerRegistry();
    // Lifecycle messages
    registry.register(Build.class, new BuildSerializer(buildActionSerializer));
    registry.register(Cancel.class, new CancelSerializer());
    registry.register(DaemonUnavailable.class, new DaemonUnavailableSerializer());
    registry.register(BuildStarted.class, new BuildStartedSerializer());
    registry.register(Failure.class, new FailureSerializer(throwableSerializer));
    registry.register(Success.class, new SuccessSerializer());
    registry.register(Finished.class, new FinishedSerializer());
    // Build events
    registry.register(BuildEvent.class, new BuildEventSerializer());
    // Input events
    registry.register(ForwardInput.class, new ForwardInputSerializer());
    registry.register(CloseInput.class, new CloseInputSerializer());
    // Output events
    registry.register(LogEvent.class, new LogEventSerializer(logLevelSerializer, throwableSerializer));
    registry.register(UserInputRequestEvent.class, new UserInputRequestEventSerializer());
    registry.register(PromptOutputEvent.class, new PromptOutputEventSerializer());
    registry.register(UserInputResumeEvent.class, new UserInputResumeEventSerializer());
    registry.register(StyledTextOutputEvent.class, new StyledTextOutputEventSerializer(logLevelSerializer, new ListSerializer<>(new SpanSerializer(factory.getSerializerFor(StyledTextOutput.Style.class)))));
    registry.register(ProgressStartEvent.class, new ProgressStartEventSerializer());
    registry.register(ProgressCompleteEvent.class, new ProgressCompleteEventSerializer());
    registry.register(ProgressEvent.class, new ProgressEventSerializer());
    registry.register(LogLevelChangeEvent.class, new LogLevelChangeEventSerializer(logLevelSerializer));
    registry.register(OutputMessage.class, new OutputMessageSerializer(registry.build(OutputEvent.class)));
    // Default for everything else
    registry.useJavaSerialization(Message.class);
    return registry.build(Message.class);
}
Also used : LogLevelChangeEventSerializer(org.gradle.internal.logging.serializer.LogLevelChangeEventSerializer) ListSerializer(org.gradle.internal.serialize.ListSerializer) PromptOutputEventSerializer(org.gradle.internal.logging.serializer.PromptOutputEventSerializer) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) ProgressEventSerializer(org.gradle.internal.logging.serializer.ProgressEventSerializer) LogLevel(org.gradle.api.logging.LogLevel) UserInputRequestEventSerializer(org.gradle.internal.logging.serializer.UserInputRequestEventSerializer) LogEventSerializer(org.gradle.internal.logging.serializer.LogEventSerializer) BaseSerializerFactory(org.gradle.internal.serialize.BaseSerializerFactory) StyledTextOutputEventSerializer(org.gradle.internal.logging.serializer.StyledTextOutputEventSerializer) UserInputResumeEventSerializer(org.gradle.internal.logging.serializer.UserInputResumeEventSerializer) SpanSerializer(org.gradle.internal.logging.serializer.SpanSerializer) DefaultSerializerRegistry(org.gradle.internal.serialize.DefaultSerializerRegistry) ProgressCompleteEventSerializer(org.gradle.internal.logging.serializer.ProgressCompleteEventSerializer) ProgressStartEventSerializer(org.gradle.internal.logging.serializer.ProgressStartEventSerializer)

Example 20 with LogLevel

use of org.gradle.api.logging.LogLevel in project gradle by gradle.

the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.

@Override
public void prepareJavaCommand(long workerId, String displayName, WorkerProcessBuilder processBuilder, List<URL> implementationClassPath, List<URL> implementationModulePath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
    Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
    Set<File> applicationModulePath = processBuilder.getApplicationModulePath();
    LogLevel logLevel = processBuilder.getLogLevel();
    Set<String> sharedPackages = processBuilder.getSharedPackages();
    Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
    List<File> workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN").getAsFiles();
    boolean runAsModule = !applicationModulePath.isEmpty() && execSpec.getModularity().getInferModulePath().get();
    if (runAsModule) {
        execSpec.getMainModule().set("gradle.worker");
    }
    execSpec.getMainClass().set("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(runAsModule, workerMainClassPath, implementationModulePath, applicationClasspath, applicationModulePath, optionsFile);
        execSpec.jvmArgs(jvmArgs);
    } else {
        // Use a dummy security manager, which hacks the application classpath into the system ClassLoader
        execSpec.classpath(workerMainClassPath);
        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
        if (runAsModule || implementationModulePath == null) {
            outstr.writeInt(implementationClassPath.size());
            for (URL entry : implementationClassPath) {
                outstr.writeUTF(entry.toString());
            }
        // We do not serialize the module path. Instead, implementation modules are directly added to the application module path when
        // starting the worker process. Implementation modules are hidden to the application modules by module visibility.
        } else {
            outstr.writeInt(implementationClassPath.size() + implementationModulePath.size());
            for (URL entry : implementationClassPath) {
                outstr.writeUTF(entry.toString());
            }
            for (URL entry : implementationModulePath) {
                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);
        encoder.writeSmallLong(workerId);
        encoder.writeString(displayName);
        // Serialize the worker action, this is consumed by SystemApplicationClassLoaderWorker
        byte[] serializedWorker = GUtil.serialize(processBuilder.getWorker());
        encoder.writeBinary(serializedWorker);
        encoder.flush();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    execSpec.setStandardInput(buffer.getInputStream());
}
Also used : EncodedStream(org.gradle.internal.stream.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)

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