org.gradle.tooling.internal.consumer.DefaultProjectConnection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.tooling.internal.consumer;
import org.gradle.tooling.BuildAction;
import org.gradle.tooling.BuildActionExecuter;
import org.gradle.tooling.BuildLauncher;
import org.gradle.tooling.ModelBuilder;
import org.gradle.tooling.ProjectConnection;
import org.gradle.tooling.ResultHandler;
import org.gradle.tooling.TestLauncher;
import org.gradle.tooling.internal.consumer.async.AsyncConsumerActionExecutor;
class DefaultProjectConnection implements ProjectConnection {
private final AsyncConsumerActionExecutor connection;
private final ConnectionParameters parameters;
public DefaultProjectConnection(AsyncConsumerActionExecutor connection, ConnectionParameters parameters) {
this.connection = connection;
this.parameters = parameters;
}
public void close() {
connection.stop();
}
public T getModel(Class modelType) {
return model(modelType).get();
}
public void getModel(final Class modelType, final ResultHandler super T> handler) {
model(modelType).get(handler);
}
public BuildLauncher newBuild() {
return new ProjectConnectionBuildLauncher(connection, parameters);
}
@Override
public TestLauncher newTestLauncher() {
return new DefaultTestLauncher(connection, parameters);
}
public ModelBuilder model(Class modelType) {
if (!modelType.isInterface()) {
throw new IllegalArgumentException(String.format("Cannot fetch a model of type '%s' as this type is not an interface.", modelType.getName()));
}
return new DefaultModelBuilder(modelType, connection, parameters);
}
public BuildActionExecuter action(final BuildAction buildAction) {
return new DefaultBuildActionExecuter(buildAction, connection, parameters);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy