use of org.gradle.tooling.internal.consumer.connection.NoToolingApiConnection 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);
}
}
Aggregations