Search in sources :

Example 6 with ShowStacktrace

use of org.gradle.api.logging.configuration.ShowStacktrace 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 ShowStacktrace

use of org.gradle.api.logging.configuration.ShowStacktrace in project gradle by gradle.

the class LoggingCommandLineConverter method convert.

public LoggingConfiguration convert(ParsedCommandLine commandLine, LoggingConfiguration loggingConfiguration) throws CommandLineArgumentException {
    for (Map.Entry<String, LogLevel> entry : logLevelMap.entrySet()) {
        if (commandLine.hasOption(entry.getKey())) {
            loggingConfiguration.setLogLevel(entry.getValue());
        }
    }
    for (Map.Entry<String, ShowStacktrace> entry : showStacktraceMap.entrySet()) {
        if (commandLine.hasOption(entry.getKey())) {
            loggingConfiguration.setShowStacktrace(entry.getValue());
        }
    }
    if (commandLine.hasOption(CONSOLE)) {
        String value = commandLine.option(CONSOLE).getValue();
        String consoleValue = StringUtils.capitalize(value.toLowerCase(Locale.ENGLISH));
        try {
            ConsoleOutput consoleOutput = ConsoleOutput.valueOf(consoleValue);
            loggingConfiguration.setConsoleOutput(consoleOutput);
        } catch (IllegalArgumentException e) {
            throw new CommandLineArgumentException(String.format("Unrecognized value '%s' for %s.", value, CONSOLE));
        }
    }
    return loggingConfiguration;
}
Also used : ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) CommandLineArgumentException(org.gradle.cli.CommandLineArgumentException) BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap) Map(java.util.Map) LogLevel(org.gradle.api.logging.LogLevel) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace)

Example 8 with ShowStacktrace

use of org.gradle.api.logging.configuration.ShowStacktrace in project gradle by gradle.

the class DefaultGradleLauncherFactory method doNewInstance.

private DefaultGradleLauncher doNewInstance(BuildDefinition buildDefinition, @Nullable GradleLauncher parent, BuildCancellationToken cancellationToken, BuildRequestMetaData requestMetaData, BuildEventConsumer buildEventConsumer, final BuildTreeScopeServices buildTreeScopeServices, List<?> servicesToStop) {
    BuildScopeServices serviceRegistry = new BuildScopeServices(buildTreeScopeServices);
    serviceRegistry.add(BuildDefinition.class, buildDefinition);
    serviceRegistry.add(BuildRequestMetaData.class, requestMetaData);
    serviceRegistry.add(BuildClientMetaData.class, requestMetaData.getClient());
    serviceRegistry.add(BuildEventConsumer.class, buildEventConsumer);
    serviceRegistry.add(BuildCancellationToken.class, cancellationToken);
    serviceRegistry.add(BuildIdentity.class, new DefaultBuildIdentity(buildDefinition, parent == null));
    NestedBuildFactoryImpl nestedBuildFactory = new NestedBuildFactoryImpl(buildTreeScopeServices);
    serviceRegistry.add(NestedBuildFactory.class, nestedBuildFactory);
    StartParameter startParameter = buildDefinition.getStartParameter();
    ListenerManager listenerManager = serviceRegistry.get(ListenerManager.class);
    LoggerProvider loggerProvider = (parent == null) ? buildProgressLogger : LoggerProvider.NO_OP;
    listenerManager.useLogger(new TaskExecutionLogger(serviceRegistry.get(ProgressLoggerFactory.class), loggerProvider));
    if (parent == null) {
        BuildStartedTime buildStartedTime = serviceRegistry.get(BuildStartedTime.class);
        Clock clock = serviceRegistry.get(Clock.class);
        listenerManager.useLogger(new BuildLogger(Logging.getLogger(BuildLogger.class), serviceRegistry.get(StyledTextOutputFactory.class), startParameter, requestMetaData, buildStartedTime, clock));
    }
    listenerManager.addListener(serviceRegistry.get(TaskExecutionStatisticsEventAdapter.class));
    listenerManager.addListener(new TaskExecutionStatisticsReporter(serviceRegistry.get(StyledTextOutputFactory.class)));
    listenerManager.addListener(serviceRegistry.get(ProfileEventAdapter.class));
    if (startParameter.isProfile()) {
        listenerManager.addListener(new ReportGeneratingProfileListener(serviceRegistry.get(StyledTextOutputFactory.class)));
    }
    ScriptUsageLocationReporter usageLocationReporter = new ScriptUsageLocationReporter();
    listenerManager.addListener(usageLocationReporter);
    ShowStacktrace showStacktrace = startParameter.getShowStacktrace();
    switch(showStacktrace) {
        case ALWAYS:
        case ALWAYS_FULL:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(true);
            break;
        default:
            LoggingDeprecatedFeatureHandler.setTraceLoggingEnabled(false);
    }
    DeprecationLogger.init(usageLocationReporter, startParameter.getWarningMode());
    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(BuildLoader.class), serviceRegistry.get(BuildConfigurer.class), serviceRegistry.get(ExceptionAnalyser.class), 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 : ExceptionAnalyser(org.gradle.api.internal.ExceptionAnalyser) TaskExecutionStatisticsReporter(org.gradle.internal.buildevents.TaskExecutionStatisticsReporter) Instantiator(org.gradle.internal.reflect.Instantiator) Clock(org.gradle.internal.time.Clock) GradleInternal(org.gradle.api.internal.GradleInternal) 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) StartParameter(org.gradle.StartParameter) BuildConfigurationActionExecuter(org.gradle.execution.BuildConfigurationActionExecuter) ProfileEventAdapter(org.gradle.profile.ProfileEventAdapter) BuildScopeServices(org.gradle.internal.service.scopes.BuildScopeServices) TaskExecutionStatisticsEventAdapter(org.gradle.api.internal.tasks.execution.statistics.TaskExecutionStatisticsEventAdapter) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace) BuildOperationExecutor(org.gradle.internal.operations.BuildOperationExecutor) ServiceRegistryFactory(org.gradle.internal.service.scopes.ServiceRegistryFactory) TaskExecutionLogger(org.gradle.internal.buildevents.TaskExecutionLogger) BuildStartedTime(org.gradle.internal.buildevents.BuildStartedTime) BuildLogger(org.gradle.internal.buildevents.BuildLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 9 with ShowStacktrace

use of org.gradle.api.logging.configuration.ShowStacktrace in project neow3j by neow3j.

the class Neow3jCompileAction method execute.

@Override
public void execute(Neow3jCompileTask neow3jPluginCompile) {
    if (!neow3jPluginCompile.getClassName().isPresent()) {
        throw new IllegalArgumentException(format("The parameter '%s' needs to be set in the " + "'%s' declaration in your build.gradle file.", CLASSNAME_NAME, EXTENSION_NAME));
    }
    String canonicalClassName = neow3jPluginCompile.getClassName().get();
    File projectBuildDir = neow3jPluginCompile.getProject().getBuildDir();
    Boolean debugSymbols = neow3jPluginCompile.getDebug().get();
    File outputDir = neow3jPluginCompile.getOutputDir().getAsFile().get();
    URLClassLoader classLoader = constructClassLoader(neow3jPluginCompile, projectBuildDir);
    CompilationUnit compilationUnit = compile(neow3jPluginCompile, canonicalClassName, debugSymbols, classLoader);
    try {
        Path outDir = createDirectories(outputDir.toPath());
        String contractName = compilationUnit.getManifest().getName();
        if (contractName == null || contractName.length() == 0) {
            throw new IllegalStateException("No contract name is set in the contract's " + "manifest.");
        }
        String nefFileName = writeNefFile(compilationUnit.getNefFile(), contractName, outDir);
        String manifestFileName = writeContractManifestFile(compilationUnit.getManifest(), outDir);
        // if everything goes fine, print info
        System.out.println("Compilation succeeded!");
        System.out.println("NEF file: " + nefFileName);
        System.out.println("Manifest file: " + manifestFileName);
        if (debugSymbols) {
            // Pack the debug info into a ZIP archive.
            String debugInfoZipFileName = Neow3jPluginUtils.writeDebugInfoZip(compilationUnit.getDebugInfo(), contractName, outDir);
            System.out.println("Debug info zip file: " + debugInfoZipFileName);
        }
    } catch (Exception e) {
        System.out.println("Smart contract compilation failed.");
        ShowStacktrace showStacktrace = neow3jPluginCompile.getProject().getGradle().getStartParameter().getShowStacktrace();
        if (showStacktrace.equals(ShowStacktrace.ALWAYS)) {
            throw new RuntimeException(e);
        } else {
            throw new RuntimeException(e.getMessage());
        }
    }
}
Also used : CompilationUnit(io.neow3j.compiler.CompilationUnit) Path(java.nio.file.Path) URLClassLoader(java.net.URLClassLoader) ContractUtils.writeContractManifestFile(io.neow3j.contract.ContractUtils.writeContractManifestFile) File(java.io.File) ContractUtils.writeNefFile(io.neow3j.contract.ContractUtils.writeNefFile) MalformedURLException(java.net.MalformedURLException) ShowStacktrace(org.gradle.api.logging.configuration.ShowStacktrace)

Aggregations

ShowStacktrace (org.gradle.api.logging.configuration.ShowStacktrace)9 GradleInternal (org.gradle.api.internal.GradleInternal)3 ListenerManager (org.gradle.internal.event.ListenerManager)3 ScriptUsageLocationReporter (org.gradle.internal.featurelifecycle.ScriptUsageLocationReporter)3 CompilationUnit (io.neow3j.compiler.CompilationUnit)2 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 StartParameter (org.gradle.StartParameter)2 ExceptionAnalyser (org.gradle.api.internal.ExceptionAnalyser)2 BuildConfigurer (org.gradle.configuration.BuildConfigurer)2 BuildConfigurationActionExecuter (org.gradle.execution.BuildConfigurationActionExecuter)2 BuildExecuter (org.gradle.execution.BuildExecuter)2 BuildLogger (org.gradle.internal.buildevents.BuildLogger)2 TaskExecutionLogger (org.gradle.internal.buildevents.TaskExecutionLogger)2 LoggerProvider (org.gradle.internal.progress.LoggerProvider)2 Instantiator (org.gradle.internal.reflect.Instantiator)2 BuildScopeServices (org.gradle.internal.service.scopes.BuildScopeServices)2 ServiceRegistryFactory (org.gradle.internal.service.scopes.ServiceRegistryFactory)2