Search in sources :

Example 1 with UnknownModelException

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

the class DefaultBuildController method getModel.

/**
 * This is used by consumers 4.4 and later
 */
@Override
public BuildResult<?> getModel(@Nullable Object target, ModelIdentifier modelIdentifier, Object parameter) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    assertCanQuery();
    if (cancellationToken.isCancellationRequested()) {
        throw new BuildCancelledException(String.format("Could not build '%s' model. Build cancelled.", modelIdentifier.getName()));
    }
    ToolingModelScope scope = getTarget(target, modelIdentifier, parameter != null);
    Object model;
    try {
        if (parameter == null) {
            model = scope.getModel(modelIdentifier.getName(), null);
        } else {
            model = scope.getModel(modelIdentifier.getName(), parameterFactory(parameter));
        }
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) new InternalUnsupportedModelException().initCause(e);
    }
    return new ProviderBuildResult<>(model);
}
Also used : InternalUnsupportedModelException(org.gradle.tooling.internal.protocol.InternalUnsupportedModelException) ToolingModelScope(org.gradle.tooling.provider.model.internal.ToolingModelScope) UnknownModelException(org.gradle.tooling.provider.model.UnknownModelException) ProviderBuildResult(org.gradle.tooling.internal.provider.connection.ProviderBuildResult) BuildCancelledException(org.gradle.api.BuildCancelledException)

Example 2 with UnknownModelException

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

the class DefaultBuildController method getToolingModelBuilder.

private ToolingModelBuilder getToolingModelBuilder(ProjectInternal project, ModelIdentifier modelIdentifier) {
    ToolingModelBuilderRegistry modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);
    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    return builder;
}
Also used : InternalUnsupportedModelException(org.gradle.tooling.internal.protocol.InternalUnsupportedModelException) ToolingModelBuilderRegistry(org.gradle.tooling.provider.model.ToolingModelBuilderRegistry) UnknownModelException(org.gradle.tooling.provider.model.UnknownModelException) ToolingModelBuilder(org.gradle.tooling.provider.model.ToolingModelBuilder) ParameterizedToolingModelBuilder(org.gradle.tooling.provider.model.ParameterizedToolingModelBuilder)

Aggregations

InternalUnsupportedModelException (org.gradle.tooling.internal.protocol.InternalUnsupportedModelException)2 UnknownModelException (org.gradle.tooling.provider.model.UnknownModelException)2 BuildCancelledException (org.gradle.api.BuildCancelledException)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 ToolingModelBuilderRegistry (org.gradle.tooling.provider.model.ToolingModelBuilderRegistry)1 ToolingModelScope (org.gradle.tooling.provider.model.internal.ToolingModelScope)1