Search in sources :

Example 1 with ModelMapping

use of org.gradle.tooling.internal.consumer.versioning.ModelMapping in project gradle by gradle.

the class InternalBuildActionAdapter method execute.

public T execute(final InternalBuildController buildController) {
    ProtocolToModelAdapter protocolToModelAdapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider());
    BuildController buildControllerAdapter = new BuildControllerAdapter(protocolToModelAdapter, buildController, new ModelMapping(), rootDir);
    if (!versionDetails.maySupportModel(BuildInvocations.class)) {
        buildControllerAdapter = new BuildInvocationsAdapterController(protocolToModelAdapter, buildControllerAdapter);
    }
    return action.execute(buildControllerAdapter);
}
Also used : ProtocolToModelAdapter(org.gradle.tooling.internal.adapter.ProtocolToModelAdapter) ConsumerTargetTypeProvider(org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider) BuildInvocations(org.gradle.tooling.model.gradle.BuildInvocations) BuildController(org.gradle.tooling.BuildController) InternalBuildController(org.gradle.tooling.internal.protocol.InternalBuildController) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping)

Example 2 with ModelMapping

use of org.gradle.tooling.internal.consumer.versioning.ModelMapping in project gradle by gradle.

the class DefaultToolingImplementationLoader method create.

public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, InternalBuildProgressListener progressListener, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
    LOGGER.debug("Using tooling provider from {}", distribution.getDisplayName());
    ClassLoader serviceClassLoader = createImplementationClassLoader(distribution, progressLoggerFactory, progressListener, connectionParameters.getGradleUserHomeDir(), cancellationToken);
    ServiceLocator serviceLocator = new DefaultServiceLocator(serviceClassLoader);
    try {
        Factory<ConnectionVersion4> factory = serviceLocator.findFactory(ConnectionVersion4.class);
        if (factory == null) {
            return new NoToolingApiConnection(distribution);
        }
        // ConnectionVersion4 is a part of the protocol and cannot be easily changed.
        ConnectionVersion4 connection = factory.create();
        ProtocolToModelAdapter adapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider());
        ModelMapping modelMapping = new ModelMapping();
        // Adopting the connection to a refactoring friendly type that the consumer owns
        AbstractConsumerConnection adaptedConnection;
        if (connection instanceof InternalTestExecutionConnection) {
            adaptedConnection = new TestExecutionConsumerConnection(connection, modelMapping, adapter);
        } else if (connection instanceof StoppableConnection) {
            adaptedConnection = new ShutdownAwareConsumerConnection(connection, modelMapping, adapter);
        } else if (connection instanceof InternalCancellableConnection) {
            adaptedConnection = new CancellableConsumerConnection(connection, modelMapping, adapter);
        } else if (connection instanceof ModelBuilder && connection instanceof InternalBuildActionExecutor) {
            adaptedConnection = new ActionAwareConsumerConnection(connection, modelMapping, adapter);
        } else if (connection instanceof ModelBuilder) {
            adaptedConnection = new ModelBuilderBackedConsumerConnection(connection, modelMapping, adapter);
        } else if (connection instanceof BuildActionRunner) {
            adaptedConnection = new BuildActionRunnerBackedConsumerConnection(connection, modelMapping, adapter);
        } else {
            return new UnsupportedOlderVersionConnection(connection, adapter);
        }
        adaptedConnection.configure(connectionParameters);
        if (!adaptedConnection.getVersionDetails().supportsCancellation()) {
            return new ParameterValidatingConsumerConnection(adaptedConnection.getVersionDetails(), new NonCancellableConsumerConnectionAdapter(adaptedConnection));
        }
        return new ParameterValidatingConsumerConnection(adaptedConnection.getVersionDetails(), adaptedConnection);
    } catch (UnsupportedVersionException e) {
        throw e;
    } catch (Throwable t) {
        throw new GradleConnectionException(String.format("Could not create an instance of Tooling API implementation using the specified %s.", distribution.getDisplayName()), t);
    }
}
Also used : NoToolingApiConnection(org.gradle.tooling.internal.consumer.connection.NoToolingApiConnection) ShutdownAwareConsumerConnection(org.gradle.tooling.internal.consumer.connection.ShutdownAwareConsumerConnection) UnsupportedOlderVersionConnection(org.gradle.tooling.internal.consumer.connection.UnsupportedOlderVersionConnection) TestExecutionConsumerConnection(org.gradle.tooling.internal.consumer.connection.TestExecutionConsumerConnection) DefaultServiceLocator(org.gradle.internal.service.DefaultServiceLocator) BuildActionRunner(org.gradle.tooling.internal.protocol.BuildActionRunner) ModelBuilder(org.gradle.tooling.internal.protocol.ModelBuilder) ProtocolToModelAdapter(org.gradle.tooling.internal.adapter.ProtocolToModelAdapter) CancellableConsumerConnection(org.gradle.tooling.internal.consumer.connection.CancellableConsumerConnection) ParameterValidatingConsumerConnection(org.gradle.tooling.internal.consumer.connection.ParameterValidatingConsumerConnection) FilteringClassLoader(org.gradle.internal.classloader.FilteringClassLoader) VisitableURLClassLoader(org.gradle.internal.classloader.VisitableURLClassLoader) BuildActionRunnerBackedConsumerConnection(org.gradle.tooling.internal.consumer.connection.BuildActionRunnerBackedConsumerConnection) InternalTestExecutionConnection(org.gradle.tooling.internal.protocol.test.InternalTestExecutionConnection) NonCancellableConsumerConnectionAdapter(org.gradle.tooling.internal.consumer.connection.NonCancellableConsumerConnectionAdapter) ConsumerTargetTypeProvider(org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider) StoppableConnection(org.gradle.tooling.internal.protocol.StoppableConnection) ActionAwareConsumerConnection(org.gradle.tooling.internal.consumer.connection.ActionAwareConsumerConnection) GradleConnectionException(org.gradle.tooling.GradleConnectionException) ModelBuilderBackedConsumerConnection(org.gradle.tooling.internal.consumer.connection.ModelBuilderBackedConsumerConnection) InternalCancellableConnection(org.gradle.tooling.internal.protocol.InternalCancellableConnection) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping) InternalBuildActionExecutor(org.gradle.tooling.internal.protocol.InternalBuildActionExecutor) DefaultServiceLocator(org.gradle.internal.service.DefaultServiceLocator) ServiceLocator(org.gradle.internal.service.ServiceLocator) ConnectionVersion4(org.gradle.tooling.internal.protocol.ConnectionVersion4) AbstractConsumerConnection(org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection) UnsupportedVersionException(org.gradle.tooling.UnsupportedVersionException)

Example 3 with ModelMapping

use of org.gradle.tooling.internal.consumer.versioning.ModelMapping in project gradle by gradle.

the class Exceptions method unsupportedModel.

public static UnknownModelException unsupportedModel(Class<?> modelType, String targetVersion) {
    ModelMapping modelMapping = new ModelMapping();
    String versionAdded = modelMapping.getVersionAdded(modelType);
    if (versionAdded != null) {
        return new UnknownModelException(String.format("The version of Gradle you are using (%s) does not support building a model of type '%s'. Support for building '%s' models was added in Gradle %s and is available in all later versions.", targetVersion, modelType.getSimpleName(), modelType.getSimpleName(), versionAdded));
    } else {
        return new UnknownModelException(String.format("The version of Gradle you are using (%s) does not support building a model of type '%s'. Support for building custom tooling models was added in Gradle 1.6 and is available in all later versions.", targetVersion, modelType.getSimpleName()));
    }
}
Also used : UnknownModelException(org.gradle.tooling.UnknownModelException) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping)

Example 4 with ModelMapping

use of org.gradle.tooling.internal.consumer.versioning.ModelMapping in project gradle by gradle.

the class ProviderConnection method run.

public Object run(String modelName, BuildCancellationToken cancellationToken, ProviderOperationParameters providerParameters) {
    List<String> tasks = providerParameters.getTasks();
    if (modelName.equals(ModelIdentifier.NULL_MODEL) && tasks == null) {
        throw new IllegalArgumentException("No model type or tasks specified.");
    }
    Parameters params = initParams(providerParameters);
    Class<?> type = new ModelMapping().getProtocolTypeFromModelName(modelName);
    if (type == InternalBuildEnvironment.class) {
        //we don't really need to launch the daemon to acquire information needed for BuildEnvironment
        if (tasks != null) {
            throw new IllegalArgumentException("Cannot run tasks and fetch the build environment model.");
        }
        return new DefaultBuildEnvironment(new DefaultBuildIdentifier(providerParameters.getProjectDir()), params.gradleUserhome, GradleVersion.current().getVersion(), params.daemonParams.getEffectiveJvm().getJavaHome(), params.daemonParams.getEffectiveJvmArgs());
    }
    StartParameter startParameter = new ProviderStartParameterConverter().toStartParameter(providerParameters, params.properties);
    ProgressListenerConfiguration listenerConfig = ProgressListenerConfiguration.from(providerParameters);
    BuildAction action = new BuildModelAction(startParameter, modelName, tasks != null, listenerConfig.clientSubscriptions);
    return run(action, cancellationToken, listenerConfig, providerParameters, params);
}
Also used : DefaultBuildEnvironment(org.gradle.tooling.internal.build.DefaultBuildEnvironment) StartParameter(org.gradle.StartParameter) 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) BuildLayoutParameters(org.gradle.initialization.BuildLayoutParameters) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping) DefaultBuildIdentifier(org.gradle.tooling.internal.gradle.DefaultBuildIdentifier) InternalBuildAction(org.gradle.tooling.internal.protocol.InternalBuildAction) BuildAction(org.gradle.internal.invocation.BuildAction)

Aggregations

ModelMapping (org.gradle.tooling.internal.consumer.versioning.ModelMapping)4 ProtocolToModelAdapter (org.gradle.tooling.internal.adapter.ProtocolToModelAdapter)2 ConsumerTargetTypeProvider (org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider)2 StartParameter (org.gradle.StartParameter)1 BuildLayoutParameters (org.gradle.initialization.BuildLayoutParameters)1 FilteringClassLoader (org.gradle.internal.classloader.FilteringClassLoader)1 VisitableURLClassLoader (org.gradle.internal.classloader.VisitableURLClassLoader)1 BuildAction (org.gradle.internal.invocation.BuildAction)1 DefaultServiceLocator (org.gradle.internal.service.DefaultServiceLocator)1 ServiceLocator (org.gradle.internal.service.ServiceLocator)1 DaemonParameters (org.gradle.launcher.daemon.configuration.DaemonParameters)1 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)1 BuildController (org.gradle.tooling.BuildController)1 GradleConnectionException (org.gradle.tooling.GradleConnectionException)1 UnknownModelException (org.gradle.tooling.UnknownModelException)1 UnsupportedVersionException (org.gradle.tooling.UnsupportedVersionException)1 DefaultBuildEnvironment (org.gradle.tooling.internal.build.DefaultBuildEnvironment)1 AbstractConsumerConnection (org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection)1 ActionAwareConsumerConnection (org.gradle.tooling.internal.consumer.connection.ActionAwareConsumerConnection)1 BuildActionRunnerBackedConsumerConnection (org.gradle.tooling.internal.consumer.connection.BuildActionRunnerBackedConsumerConnection)1