use of org.gradle.internal.event.ListenerManager in project gradle by gradle.
the class ProgressLoggingConsumerActionExecutor method run.
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
ConsumerOperationParameters parameters = action.getParameters();
ProgressListenerAdapter listener = new ProgressListenerAdapter(parameters.getProgressListener());
ListenerManager listenerManager = loggingProvider.getListenerManager();
listenerManager.addListener(listener);
try {
ProgressLogger progressLogger = loggingProvider.getProgressLoggerFactory().newOperation(ProgressLoggingConsumerActionExecutor.class);
progressLogger.setDescription("Build");
progressLogger.started();
try {
return actionExecutor.run(action);
} finally {
progressLogger.completed();
}
} finally {
listenerManager.removeListener(listener);
}
}
use of org.gradle.internal.event.ListenerManager 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;
}
use of org.gradle.internal.event.ListenerManager in project gradle by gradle.
the class InProcessGradleExecuter method executeBuild.
private BuildResult executeBuild(GradleInvocation invocation, StandardOutputListener outputListener, StandardOutputListener errorListener, 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...
StartParameter startParameter = new StartParameter();
startParameter.setCurrentDir(getWorkingDir());
startParameter.setShowStacktrace(ShowStacktrace.ALWAYS);
CommandLineParser parser = new CommandLineParser();
ParametersConverter parametersConverter = new ParametersConverter();
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(outputListener, errorListener);
startMeasurement();
actionExecuter.execute(action, buildRequestContext, buildActionParameters, GLOBAL_SERVICES);
return new BuildResult(null, null);
} catch (ReportedException e) {
return new BuildResult(null, e.getCause());
} finally {
stopMeasurement();
listenerManager.removeListener(listener);
}
}
Aggregations