Search in sources :

Example 6 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class DefaultGradleLauncherFactory method doNewInstance.

private DefaultGradleLauncher doNewInstance(StartParameter startParameter, GradleLauncher parent, BuildCancellationToken cancellationToken, BuildRequestMetaData requestMetaData, BuildEventConsumer buildEventConsumer, final BuildSessionScopeServices sessionScopeServices, List<?> servicesToStop) {
    BuildScopeServices serviceRegistry = BuildScopeServices.forSession(sessionScopeServices);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    serviceRegistry.add(BuildEventConsumer.class, buildEventConsumer);
    serviceRegistry.add(BuildCancellationToken.class, cancellationToken);
    NestedBuildFactoryImpl nestedBuildFactory = new NestedBuildFactoryImpl(sessionScopeServices);
    serviceRegistry.add(NestedBuildFactory.class, nestedBuildFactory);
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggingManagerInternal loggingManager = serviceRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.setLevelInternal(startParameter.getLogLevel());
    //this hooks up the ListenerManager and LoggingConfigurer so you can call Gradle.addListener() with a StandardOutputListener.
    loggingManager.addStandardOutputListener(listenerManager.getBroadcaster(StandardOutputListener.class));
    loggingManager.addStandardErrorListener(listenerManager.getBroadcaster(StandardOutputListener.class));
    LoggerProvider loggerProvider = (parent == null) ? buildProgressLogger : LoggerProvider.NO_OP;
    listenerManager.useLogger(new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class), loggerProvider));
    if (parent == null) {
        listenerManager.useLogger(new BuildLogger(Logging.getLogger(BuildLogger.class), serviceRegistry.get(StyledTextOutputFactory.class), startParameter, requestMetaData));
    }
    if (startParameter.isBuildCacheEnabled()) {
        listenerManager.addListener(serviceRegistry.get(TaskExecutionStatisticsEventAdapter.class));
        listenerManager.addListener(new CacheStatisticsReporter(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
        listenerManager.addListener(new ReportGeneratingProfileListener(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    BuildScanRequest buildScanRequest = serviceRegistry.get(BuildScanRequest.class);
    if (startParameter.isBuildScan()) {
        if (!startParameter.getSystemPropertiesArgs().containsKey("scan")) {
            startParameter.getSystemPropertiesArgs().put("scan", "true");
        }
        buildScanRequest.markRequested();
        listenerManager.addListener(new BuildScanRequestListener());
    }
    if (startParameter.isNoBuildScan()) {
        if (!startParameter.getSystemPropertiesArgs().containsKey("scan")) {
            startParameter.getSystemPropertiesArgs().put("scan", "false");
        }
        buildScanRequest.markDisabled();
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    BuildOutputCleanupListener buildOutputCleanupListener = serviceRegistry.get(BuildOutputCleanupListener.class);
    listenerManager.addListener(buildOutputCleanupListener);
    ShowStacktrace showStacktrace = startParameter.getShowStacktrace();
    switch(showStacktrace) {
        case ALWAYS:
        case ALWAYS_FULL:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(true);
            break;
        default:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(false);
    }
    DeprecationLogger.useLocationReporter(usageLocationReporter);
    SettingsLoaderFactory settingsLoaderFactory = serviceRegistry.get(SettingsLoaderFactory.class);
    SettingsLoader settingsLoader = parent != null ? settingsLoaderFactory.forNestedBuild() : settingsLoaderFactory.forTopLevelBuild();
    GradleInternal parentBuild = parent == null ? null : parent.getGradle();
    GradleInternal gradle = serviceRegistry.get(Instantiator.class).newInstance(DefaultGradle.class, parentBuild, startParameter, serviceRegistry.get(ServiceRegistryFactory.class));
    DefaultGradleLauncher gradleLauncher = new DefaultGradleLauncher(gradle, serviceRegistry.get(InitScriptHandler.class), settingsLoader, serviceRegistry.get(BuildConfigurer.class), serviceRegistry.get(ExceptionAnalyser.class), loggingManager, gradle.getBuildListenerBroadcaster(), listenerManager.getBroadcaster(ModelConfigurationListener.class), listenerManager.getBroadcaster(BuildCompletionListener.class), serviceRegistry.get(BuildOperationExecutor.class), gradle.getServices().get(BuildConfigurationActionExecuter.class), gradle.getServices().get(BuildExecuter.class), serviceRegistry, servicesToStop);
    nestedBuildFactory.setParent(gradleLauncher);
    return gradleLauncher;
}
Also used : CacheStatisticsReporter(org.gradle.internal.buildevents.CacheStatisticsReporter) ExceptionAnalyser(org.gradle.api.internal.ExceptionAnalyser) BuildScanRequestListener(org.gradle.internal.scan.BuildScanRequestListener) Instantiator(org.gradle.internal.reflect.Instantiator) GradleInternal(org.gradle.api.internal.GradleInternal) StandardOutputListener(org.gradle.api.logging.StandardOutputListener) ReportGeneratingProfileListener(org.gradle.profile.ReportGeneratingProfileListener) BuildExecuter(org.gradle.execution.BuildExecuter) LoggerProvider(org.gradle.internal.progress.LoggerProvider) ScriptUsageLocationReporter(org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter) BuildConfigurer(org.gradle.configuration.BuildConfigurer) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) BuildConfigurationActionExecuter(org.gradle.execution.BuildConfigurationActionExecuter) ProfileEventAdapter(org.gradle.profile.ProfileEventAdapter) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) TaskExecutionStatisticsEventAdapter(org.gradle.caching.internal.tasks.TaskExecutionStatisticsEventAdapter) BuildScanRequest(org.gradle.internal.scan.BuildScanRequest) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace) BuildOperationExecutor(org.gradle.internal.progress.BuildOperationExecutor) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) BuildOutputCleanupListener(org.gradle.internal.cleanup.BuildOutputCleanupListener) TaskExecutionLogger(org.gradle.internal.buildevents.TaskExecutionLogger) BuildLogger(org.gradle.internal.buildevents.BuildLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 7 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class SystemApplicationClassLoaderWorker method createLoggingManager.

LoggingManagerInternal createLoggingManager() {
    LoggingManagerInternal loggingManagerInternal = LoggingServiceRegistry.newEmbeddableLogging().newInstance(LoggingManagerInternal.class);
    loggingManagerInternal.captureSystemSources();
    return loggingManagerInternal;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal)

Example 8 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class ForegroundDaemonAction method run.

public void run() {
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.start();
    DaemonServices daemonServices = new DaemonServices(configuration, loggingRegistry, loggingManager, new DefaultClassPath());
    Daemon daemon = daemonServices.get(Daemon.class);
    DaemonRegistry daemonRegistry = daemonServices.get(DaemonRegistry.class);
    DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
    daemon.start();
    try {
        daemonRegistry.markState(daemon.getAddress(), Idle);
        daemon.stopOnExpiration(expirationStrategy, configuration.getPeriodicCheckIntervalMs());
    } finally {
        daemon.stop();
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) DaemonRegistry(org.gradle.launcher.daemon.registry.DaemonRegistry) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 9 with LoggingManagerInternal

use of org.gradle.internal.logging.LoggingManagerInternal in project gradle by gradle.

the class DaemonMain method doAction.

@Override
protected void doAction(String[] args, ExecutionListener listener) {
    //The first argument is not really used but it is very useful in diagnosing, i.e. running 'jps -m'
    if (args.length != 1) {
        invalidArgs("Following arguments are required: <gradle-version>");
    }
    // Read configuration from stdin
    List<String> startupOpts;
    File gradleHomeDir;
    File daemonBaseDir;
    int idleTimeoutMs;
    int periodicCheckIntervalMs;
    String daemonUid;
    List<File> additionalClassPath;
    KryoBackedDecoder decoder = new KryoBackedDecoder(new EncodedStream.EncodedInput(System.in));
    try {
        gradleHomeDir = new File(decoder.readString());
        daemonBaseDir = new File(decoder.readString());
        idleTimeoutMs = decoder.readSmallInt();
        periodicCheckIntervalMs = decoder.readSmallInt();
        daemonUid = decoder.readString();
        int argCount = decoder.readSmallInt();
        startupOpts = new ArrayList<String>(argCount);
        for (int i = 0; i < argCount; i++) {
            startupOpts.add(decoder.readString());
        }
        int additionalClassPathLength = decoder.readSmallInt();
        additionalClassPath = new ArrayList<File>(additionalClassPathLength);
        for (int i = 0; i < additionalClassPathLength; i++) {
            additionalClassPath.add(new File(decoder.readString()));
        }
    } catch (EOFException e) {
        throw new UncheckedIOException(e);
    }
    NativeServices.initialize(gradleHomeDir);
    DaemonServerConfiguration parameters = new DefaultDaemonServerConfiguration(daemonUid, daemonBaseDir, idleTimeoutMs, periodicCheckIntervalMs, startupOpts);
    LoggingServiceRegistry loggingRegistry = LoggingServiceRegistry.newCommandLineProcessLogging();
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    DaemonServices daemonServices = new DaemonServices(parameters, loggingRegistry, loggingManager, new DefaultClassPath(additionalClassPath));
    File daemonLog = daemonServices.getDaemonLogFile();
    // Any logging prior to this point will not end up in the daemon log file.
    initialiseLogging(loggingManager, daemonLog);
    // Detach the process from the parent terminal/console
    ProcessEnvironment processEnvironment = daemonServices.get(ProcessEnvironment.class);
    processEnvironment.maybeDetachProcess();
    LOGGER.debug("Assuming the daemon was started with following jvm opts: {}", startupOpts);
    Daemon daemon = daemonServices.get(Daemon.class);
    daemon.start();
    try {
        DaemonContext daemonContext = daemonServices.get(DaemonContext.class);
        Long pid = daemonContext.getPid();
        daemonStarted(pid, daemon.getUid(), daemon.getAddress(), daemonLog);
        DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
        daemon.stopOnExpiration(expirationStrategy, parameters.getPeriodicCheckIntervalMs());
    } finally {
        daemon.stop();
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) EncodedStream(org.gradle.process.internal.streams.EncodedStream) UncheckedIOException(org.gradle.api.UncheckedIOException) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) EntryPoint(org.gradle.launcher.bootstrap.EntryPoint) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) KryoBackedDecoder(org.gradle.internal.serialize.kryo.KryoBackedDecoder) DaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DaemonServerConfiguration) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) DaemonContext(org.gradle.launcher.daemon.context.DaemonContext) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) EOFException(java.io.EOFException) File(java.io.File) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Aggregations

LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)9 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)2 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)2 Daemon (org.gradle.launcher.daemon.server.Daemon)2 DaemonServices (org.gradle.launcher.daemon.server.DaemonServices)2 DaemonExpirationStrategy (org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 UncheckedIOException (org.gradle.api.UncheckedIOException)1 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)1 GradleInternal (org.gradle.api.internal.GradleInternal)1 LogLevel (org.gradle.api.logging.LogLevel)1 StandardOutputListener (org.gradle.api.logging.StandardOutputListener)1 ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)1 TaskExecutionStatisticsEventAdapter (org.gradle.caching.internal.tasks.TaskExecutionStatisticsEventAdapter)1 BuildConfigurer (org.gradle.configuration.BuildConfigurer)1 BuildConfigurationActionExecuter (org.gradle.execution.BuildConfigurationActionExecuter)1