Search in sources :

Example 1 with ParameterizedToolingModelBuilder

use of org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder in project gradle by gradle.

the class DefaultBuildController method getModel.

/**
 * This is used by consumers 4.4 and later
 */
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier, Object parameter) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    BuildCancellationToken cancellationToken = gradle.getServices().get(BuildCancellationToken.class);
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ProjectInternal project = getTargetProject(target);
    ToolingModelBuilder builder = getToolingModelBuilder(project, modelIdentifier);
    String modelName = modelIdentifier.getName();
    Object model;
    if (parameter == null) {
        model = builder.buildAll(modelName, project);
    } else if (builder instanceof ParameterizedToolingModelBuilder<?>) {
        model = getParameterizedModel(project, modelName, (ParameterizedToolingModelBuilder<?>) builder, parameter);
    } else {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(new UnknownModelException(String.format("No parameterized builders are available to build a model of type '%s'.", modelName)));
    }
    return new ProviderBuildResult<Object>(model);
}
Also used : InternalUnsupportedModelException(org.gradle.tooling.internal.protocol.InternalUnsupportedModelException) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) UnknownModelException(org.gradle.tooling.provider.model.UnknownModelException) ProviderBuildResult(org.gradle.tooling.internal.provider.connection.ProviderBuildResult) BuildCancellationToken(org.gradle.initialization.BuildCancellationToken) ToolingModelBuilder(org.gradle.tooling.provider.model.ToolingModelBuilder) ParameterizedToolingModelBuilder(org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder) BuildCancelledException(org.gradle.api.BuildCancelledException)

Aggregations

BuildCancelledException (org.gradle.api.BuildCancelledException)1 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)1 BuildCancellationToken (org.gradle.initialization.BuildCancellationToken)1 InternalUnsupportedModelException (org.gradle.tooling.internal.protocol.InternalUnsupportedModelException)1 ProviderBuildResult (org.gradle.tooling.internal.provider.connection.ProviderBuildResult)1 ParameterizedToolingModelBuilder (org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder)1 ToolingModelBuilder (org.gradle.tooling.provider.model.ToolingModelBuilder)1 UnknownModelException (org.gradle.tooling.provider.model.UnknownModelException)1