Search in sources :

Example 11 with LoggingManagerInternal

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

the class InProcessGradleExecuter method createLoggingManager.

private LoggingManagerInternal createLoggingManager(StartParameter startParameter, final StandardOutputListener outputListener) {
    LoggingManagerInternal loggingManager = GLOBAL_SERVICES.getFactory(LoggingManagerInternal.class).create();
    loggingManager.captureSystemSources();
    ConsoleOutput consoleOutput = startParameter.getConsoleOutput();
    if (consoleOutput == ConsoleOutput.Auto) {
        // IDEA runs tests attached to a console, use plain so test can assume never attached to a console
        // Should really run all tests against a plain and a rich console to make these assumptions explicit
        consoleOutput = ConsoleOutput.Plain;
    }
    loggingManager.attachConsole(new TeeOutputStream(System.out, new LineBufferingOutputStream(new TextStream() {

        @Override
        public void text(String text) {
            outputListener.onOutput(text);
        }

        @Override
        public void endOfStream(@Nullable Throwable failure) {
        }
    })), consoleOutput);
    return loggingManager;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) TextStream(org.gradle.internal.io.TextStream)

Example 12 with LoggingManagerInternal

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

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, final StandardOutputListener outputListener, BuildListenerImpl listener) {
    // Augment the environment for the execution
    System.setIn(connectStdIn());
    processEnvironment.maybeSetProcessDir(getWorkingDir());
    for (Map.Entry<String, String> entry : invocation.environmentVars.entrySet()) {
        processEnvironment.maybeSetEnvironmentVariable(entry.getKey(), entry.getValue());
    }
    Map<String, String> implicitJvmSystemProperties = getImplicitJvmSystemProperties();
    System.getProperties().putAll(implicitJvmSystemProperties);
    resetTempDirLocation();
    // TODO: Fix tests that rely on this being set before we process arguments like this...
    StartParameterInternal startParameter = new StartParameterInternal();
    startParameter.setCurrentDir(getWorkingDir());
    // TODO: Reuse more of CommandlineActionFactory
    CommandLineParser parser = new CommandLineParser();
    BuildLayoutFactory buildLayoutFactory = new BuildLayoutFactory();
    ParametersConverter parametersConverter = new ParametersConverter(buildLayoutFactory);
    parametersConverter.configure(parser);
    final Parameters parameters = new Parameters(startParameter);
    parametersConverter.convert(parser.parse(getAllArgs()), parameters);
    BuildActionExecuter<BuildActionParameters> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext();
        LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputListener);
        loggingManager.start();
        try {
            startMeasurement();
            try {
                actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
            } finally {
                stopMeasurement();
            }
        } finally {
            loggingManager.stop();
        }
        return new BuildResult(null, null);
    } catch (ReportedException e) {
        return new BuildResult(null, e.getCause());
    } finally {
        listenerManager.removeListener(listener);
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) Parameters(org.gradle.launcher.cli.Parameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.launcher.cli.action.ExecuteBuildAction) Matchers.containsString(org.hamcrest.Matchers.containsString) BuildLayoutFactory(org.gradle.initialization.layout.BuildLayoutFactory) DefaultBuildRequestContext(org.gradle.initialization.DefaultBuildRequestContext) BuildRequestContext(org.gradle.initialization.BuildRequestContext) BuildResult(org.gradle.BuildResult) ParametersConverter(org.gradle.launcher.cli.ParametersConverter) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) CommandLineParser(org.gradle.cli.CommandLineParser) Map(java.util.Map) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.launcher.cli.action.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) ListenerManager(org.gradle.internal.event.ListenerManager) ReportedException(org.gradle.initialization.ReportedException)

Example 13 with LoggingManagerInternal

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

the class ForegroundDaemonAction method run.

@Override
public void run() {
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    loggingManager.start();
    DaemonServices daemonServices = new DaemonServices(configuration, loggingRegistry, loggingManager, DefaultClassPath.of());
    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)

Example 14 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;
    boolean singleUse;
    String daemonUid;
    DaemonParameters.Priority priority;
    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();
        singleUse = decoder.readBoolean();
        daemonUid = decoder.readString();
        priority = DaemonParameters.Priority.values()[decoder.readSmallInt()];
        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.initializeOnDaemon(gradleHomeDir);
    DaemonServerConfiguration parameters = new DefaultDaemonServerConfiguration(daemonUid, daemonBaseDir, idleTimeoutMs, periodicCheckIntervalMs, singleUse, priority, startupOpts);
    LoggingServiceRegistry loggingRegistry = LoggingServiceRegistry.newCommandLineProcessLogging();
    LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
    DaemonServices daemonServices = new DaemonServices(parameters, loggingRegistry, loggingManager, DefaultClassPath.of(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();
        // TODO: Stop all daemon services
        CompositeStoppable.stoppable(daemonServices.get(GradleUserHomeScopeServiceRegistry.class)).stop();
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ProcessEnvironment(org.gradle.internal.nativeintegration.ProcessEnvironment) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) DaemonContext(org.gradle.launcher.daemon.context.DaemonContext) EOFException(java.io.EOFException) DaemonExpirationStrategy(org.gradle.launcher.daemon.server.expiry.DaemonExpirationStrategy) LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultDaemonServerConfiguration(org.gradle.launcher.daemon.configuration.DefaultDaemonServerConfiguration) EncodedStream(org.gradle.internal.stream.EncodedStream) 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) Daemon(org.gradle.launcher.daemon.server.Daemon) DaemonServices(org.gradle.launcher.daemon.server.DaemonServices) File(java.io.File)

Example 15 with LoggingManagerInternal

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

the class AbstractGradleExecuter method newCommandLineProcessLogging.

private static LoggingServiceRegistry newCommandLineProcessLogging() {
    LoggingServiceRegistry loggingServices = LoggingServiceRegistry.newEmbeddableLogging();
    LoggingManagerInternal rootLoggingManager = loggingServices.get(DefaultLoggingManagerFactory.class).getRoot();
    rootLoggingManager.attachSystemOutAndErr();
    return loggingServices;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) LoggingServiceRegistry(org.gradle.internal.logging.services.LoggingServiceRegistry) DefaultLoggingManagerFactory(org.gradle.internal.logging.services.DefaultLoggingManagerFactory)

Aggregations

LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)16 LoggingServiceRegistry (org.gradle.internal.logging.services.LoggingServiceRegistry)4 BuildRequestContext (org.gradle.initialization.BuildRequestContext)3 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)3 ListenerManager (org.gradle.internal.event.ListenerManager)3 File (java.io.File)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)2 BuildResult (org.gradle.BuildResult)2 StartParameterInternal (org.gradle.api.internal.StartParameterInternal)2 LogLevel (org.gradle.api.logging.LogLevel)2 ConsoleOutput (org.gradle.api.logging.configuration.ConsoleOutput)2 CommandLineParser (org.gradle.cli.CommandLineParser)2 BuildLayoutFactory (org.gradle.initialization.layout.BuildLayoutFactory)2 BuildAction (org.gradle.internal.invocation.BuildAction)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 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)2