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);
}
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);
}
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;
}
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);
}
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());
}
Aggregations