Search in sources :

Example 1 with StartParameterInternal

use of org.gradle.api.internal.StartParameterInternal in project gradle by gradle.

the class BuildStateFactory method buildSrcStartParameterFor.

private StartParameterInternal buildSrcStartParameterFor(File buildSrcDir, StartParameter containingBuildParameters) {
    final StartParameterInternal buildSrcStartParameter = (StartParameterInternal) containingBuildParameters.newBuild();
    buildSrcStartParameter.setCurrentDir(buildSrcDir);
    buildSrcStartParameter.setProjectProperties(containingBuildParameters.getProjectProperties());
    buildSrcStartParameter.doNotSearchUpwards();
    buildSrcStartParameter.setProfile(containingBuildParameters.isProfile());
    return buildSrcStartParameter;
}
Also used : StartParameterInternal(org.gradle.api.internal.StartParameterInternal)

Example 2 with StartParameterInternal

use of org.gradle.api.internal.StartParameterInternal in project gradle by gradle.

the class InProcessGradleExecuter method executeBuild.

private BuildResult executeBuild(GradleInvocation invocation, OutputStream outputStream, OutputStream errorStream, 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);
    // TODO: Reuse more of CommandlineActionFactory
    CommandLineParser parser = new CommandLineParser();
    FileCollectionFactory fileCollectionFactory = TestFiles.fileCollectionFactory();
    ParametersConverter parametersConverter = new ParametersConverter(new BuildLayoutFactory(), fileCollectionFactory);
    parametersConverter.configure(parser);
    Parameters parameters = parametersConverter.convert(parser.parse(getAllArgs()), getWorkingDir());
    BuildActionExecuter<BuildActionParameters, BuildRequestContext> actionExecuter = GLOBAL_SERVICES.get(BuildActionExecuter.class);
    ListenerManager listenerManager = GLOBAL_SERVICES.get(ListenerManager.class);
    listenerManager.addListener(listener);
    try {
        // TODO: Reuse more of BuildActionsFactory
        StartParameterInternal startParameter = parameters.getStartParameter();
        BuildAction action = new ExecuteBuildAction(startParameter);
        BuildActionParameters buildActionParameters = createBuildActionParameters(startParameter);
        BuildRequestContext buildRequestContext = createBuildRequestContext();
        LoggingManagerInternal loggingManager = createLoggingManager(startParameter, outputStream, errorStream);
        loggingManager.start();
        try {
            startMeasurement();
            try {
                BuildActionResult result = actionExecuter.execute(action, buildActionParameters, buildRequestContext);
                if (result.getException() != null) {
                    return new BuildResult(null, result.getException());
                }
                if (result.getFailure() != null) {
                    PayloadSerializer payloadSerializer = new PayloadSerializer(new TestClassLoaderRegistry());
                    return new BuildResult(null, (RuntimeException) payloadSerializer.deserialize(result.getFailure()));
                }
                return new BuildResult(null, null);
            } finally {
                stopMeasurement();
            }
        } finally {
            loggingManager.stop();
        }
    } finally {
        listenerManager.removeListener(listener);
    }
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) Parameters(org.gradle.launcher.cli.Parameters) PayloadSerializer(org.gradle.tooling.internal.provider.serialization.PayloadSerializer) DefaultBuildActionParameters(org.gradle.launcher.exec.DefaultBuildActionParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) Hashing.hashString(org.gradle.internal.hash.Hashing.hashString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.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) BuildActionResult(org.gradle.launcher.exec.BuildActionResult) CommandLineParser(org.gradle.cli.CommandLineParser) SerializeMap(org.gradle.tooling.internal.provider.serialization.SerializeMap) Map(java.util.Map) DeserializeMap(org.gradle.tooling.internal.provider.serialization.DeserializeMap) HashMap(java.util.HashMap) ExecuteBuildAction(org.gradle.tooling.internal.provider.action.ExecuteBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 3 with StartParameterInternal

use of org.gradle.api.internal.StartParameterInternal in project gradle by gradle.

the class BuildSessionLifecycleBuildActionExecuter method execute.

@Override
public BuildActionResult execute(BuildAction action, BuildActionParameters actionParameters, BuildRequestContext requestContext) {
    StartParameterInternal startParameter = action.getStartParameter();
    if (action.isCreateModel()) {
        // When creating a model, do not use continuous mode
        startParameter.setContinuous(false);
    }
    ActionImpl actionWrapper = new ActionImpl(action, requestContext);
    try {
        try (CrossBuildSessionState crossBuildSessionState = new CrossBuildSessionState(globalServices, startParameter)) {
            try (BuildSessionState buildSessionState = new BuildSessionState(userHomeServiceRegistry, crossBuildSessionState, startParameter, requestContext, actionParameters.getInjectedPluginClasspath(), requestContext.getCancellationToken(), requestContext.getClient(), requestContext.getEventConsumer())) {
                return buildSessionState.run(actionWrapper);
            }
        }
    } catch (Throwable t) {
        if (actionWrapper.result == null) {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(t);
        } else {
            // whereas console failure logging based on the _thrown exception_ happens up outside session scope. It would be better to refactor so that a result can be returned from here
            throw UncheckedException.throwAsUncheckedException(actionWrapper.result.addFailure(t).getBuildFailure());
        }
    }
}
Also used : CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) CrossBuildSessionState(org.gradle.internal.session.CrossBuildSessionState) BuildSessionState(org.gradle.internal.session.BuildSessionState) StartParameterInternal(org.gradle.api.internal.StartParameterInternal)

Example 4 with StartParameterInternal

use of org.gradle.api.internal.StartParameterInternal in project gradle by gradle.

the class FileSystemWatchingBuildActionRunner method run.

@Override
public Result run(BuildAction action, BuildTreeLifecycleController buildController) {
    StartParameterInternal startParameter = action.getStartParameter();
    WatchMode watchFileSystemMode = startParameter.getWatchFileSystemMode();
    VfsLogging verboseVfsLogging = startParameter.isVfsVerboseLogging() ? VfsLogging.VERBOSE : VfsLogging.NORMAL;
    WatchLogging debugWatchLogging = startParameter.isWatchFileSystemDebugLogging() ? WatchLogging.DEBUG : WatchLogging.NORMAL;
    LOGGER.info("Watching the file system is configured to be {}", watchFileSystemMode.getDescription());
    boolean continuousBuild = startParameter.isContinuous() || !deploymentRegistry.getRunningDeployments().isEmpty();
    if (continuousBuild && watchFileSystemMode == WatchMode.DEFAULT) {
        // Try to watch as much as possible when using continuous build.
        watchFileSystemMode = WatchMode.ENABLED;
    }
    if (watchFileSystemMode.isEnabled()) {
        dropVirtualFileSystemIfRequested(startParameter, virtualFileSystem);
    }
    if (verboseVfsLogging == VfsLogging.VERBOSE) {
        logVfsStatistics("since last build", statStatisticsCollector, fileHasherStatisticsCollector, directorySnapshotterStatisticsCollector);
    }
    if (action.getStartParameter().getProjectCacheDir() != null) {
        // See https://github.com/gradle/gradle/issues/17262
        switch(watchFileSystemMode) {
            case ENABLED:
                throw new IllegalStateException("Enabling file system watching via --watch-fs (or via the " + StartParameterBuildOptions.WatchFileSystemOption.GRADLE_PROPERTY + " property) with --project-cache-dir also specified is not supported; remove either option to fix this problem");
            case DEFAULT:
                LOGGER.info("File system watching is disabled because --project-cache-dir is specified");
                watchFileSystemMode = WatchMode.DISABLED;
                break;
            default:
                break;
        }
    }
    LOGGER.debug("Watching the file system computed to be {}", watchFileSystemMode.getDescription());
    boolean actuallyWatching = virtualFileSystem.afterBuildStarted(watchFileSystemMode, verboseVfsLogging, debugWatchLogging, buildOperationRunner);
    LOGGER.info("File system watching is {}", actuallyWatching ? "active" : "inactive");
    // noinspection Convert2Lambda
    eventEmitter.emitNowForCurrent(new FileSystemWatchingSettingsFinalizedProgressDetails() {

        @Override
        public boolean isEnabled() {
            return actuallyWatching;
        }
    });
    if (continuousBuild) {
        if (!actuallyWatching) {
            throw new IllegalStateException("Continuous build does not work when file system watching is disabled");
        }
    }
    try {
        return delegate.run(action, buildController);
    } finally {
        int maximumNumberOfWatchedHierarchies = VirtualFileSystemServices.getMaximumNumberOfWatchedHierarchies(startParameter);
        virtualFileSystem.beforeBuildFinished(watchFileSystemMode, verboseVfsLogging, debugWatchLogging, buildOperationRunner, maximumNumberOfWatchedHierarchies);
        if (verboseVfsLogging == VfsLogging.VERBOSE) {
            logVfsStatistics("during current build", statStatisticsCollector, fileHasherStatisticsCollector, directorySnapshotterStatisticsCollector);
        }
    }
}
Also used : WatchMode(org.gradle.internal.watch.registry.WatchMode) FileSystemWatchingSettingsFinalizedProgressDetails(org.gradle.internal.watch.options.FileSystemWatchingSettingsFinalizedProgressDetails) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) VfsLogging(org.gradle.internal.watch.vfs.VfsLogging) WatchLogging(org.gradle.internal.watch.vfs.WatchLogging)

Example 5 with StartParameterInternal

use of org.gradle.api.internal.StartParameterInternal in project gradle by gradle.

the class ProviderConnection method runClientAction.

public Object runClientAction(Object clientAction, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    SerializedPayload serializedAction = payloadSerializer.serialize(clientAction);
    Parameters params = initParams(providerParameters);
    StartParameterInternal startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.buildLayout, params.properties);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters, consumerVersion);
    BuildAction action = new ClientProvidedBuildAction(startParameter, serializedAction, tasks != null, listenerConfig.clientSubscriptions);
    return run(action, cancellationToken, listenerConfig, listenerConfig.buildEventConsumer, providerParameters, params);
}
Also used : SerializedPayload(org.gradle.tooling.internal.provider.serialization.SerializedPayload) ProviderConnectionParameters(org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters) ProviderOperationParameters(org.gradle.tooling.internal.provider.connection.ProviderOperationParameters) DaemonParameters(org.gradle.launcher.daemon.configuration.DaemonParameters) BuildActionParameters(org.gradle.launcher.exec.BuildActionParameters) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) StartParameterInternal(org.gradle.api.internal.StartParameterInternal) ClientProvidedBuildAction(org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction)

Aggregations

StartParameterInternal (org.gradle.api.internal.StartParameterInternal)17 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)6 BuildAction (org.gradle.internal.invocation.BuildAction)5 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)5 ProviderConnectionParameters (org.gradle.tooling.internal.provider.connection.ProviderConnectionParameters)4 ProviderOperationParameters (org.gradle.tooling.internal.provider.connection.ProviderOperationParameters)4 File (java.io.File)3 CommandLineParser (org.gradle.cli.CommandLineParser)3 BuildSessionState (org.gradle.internal.session.BuildSessionState)3 CrossBuildSessionState (org.gradle.internal.session.CrossBuildSessionState)3 ClientProvidedBuildAction (org.gradle.tooling.internal.provider.action.ClientProvidedBuildAction)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BuildResult (org.gradle.BuildResult)2 CommandLineArgumentException (org.gradle.cli.CommandLineArgumentException)2 BuildRequestContext (org.gradle.initialization.BuildRequestContext)2 BuildRequestMetaData (org.gradle.initialization.BuildRequestMetaData)2 DefaultBuildRequestContext (org.gradle.initialization.DefaultBuildRequestContext)2 DefaultBuildRequestMetaData (org.gradle.initialization.DefaultBuildRequestMetaData)2 NoOpBuildEventConsumer (org.gradle.initialization.NoOpBuildEventConsumer)2