Search in sources :

Example 6 with ModelIdentifier

use of org.gradle.tooling.internal.protocol.ModelIdentifier in project gradle by gradle.

the class UnparameterizedBuildController method getModel.

@Override
public <T, P> T getModel(Model target, Class<T> modelType, Class<P> parameterType, Action<? super P> parameterInitializer) throws UnsupportedVersionException, UnknownModelException {
    ModelIdentifier modelIdentifier = modelMapping.getModelIdentifierFromModelType(modelType);
    Object originalTarget = target == null ? null : adapter.unpack(target);
    P parameter = initializeParameter(parameterType, parameterInitializer);
    BuildResult<?> result;
    try {
        result = getModel(originalTarget, modelIdentifier, parameter);
    } catch (InternalUnsupportedModelException e) {
        throw Exceptions.unknownModel(modelType, e);
    }
    ViewBuilder<T> viewBuilder = resultAdapter.builder(modelType);
    applyCompatibilityMapping(viewBuilder, new DefaultProjectIdentifier(rootDir, getProjectPath(target)));
    return viewBuilder.build(result.getModel());
}
Also used : InternalUnsupportedModelException(org.gradle.tooling.internal.protocol.InternalUnsupportedModelException) ModelIdentifier(org.gradle.tooling.internal.protocol.ModelIdentifier) DefaultProjectIdentifier(org.gradle.tooling.internal.gradle.DefaultProjectIdentifier)

Example 7 with ModelIdentifier

use of org.gradle.tooling.internal.protocol.ModelIdentifier in project gradle by gradle.

the class CancellableModelBuilderBackedModelProducer method produceModel.

@Override
public <T> T produceModel(Class<T> type, ConsumerOperationParameters operationParameters) {
    if (!versionDetails.maySupportModel(type)) {
        throw Exceptions.unsupportedModel(type, versionDetails.getVersion());
    }
    final ModelIdentifier modelIdentifier = modelMapping.getModelIdentifierFromModelType(type);
    BuildResult<?> result;
    try {
        result = builder.getModel(modelIdentifier, new BuildCancellationTokenAdapter(operationParameters.getCancellationToken()), operationParameters);
    } catch (InternalUnsupportedModelException e) {
        throw Exceptions.unknownModel(type, e);
    } catch (RuntimeException e) {
        throw exceptionTransformer.transform(e);
    }
    return applyCompatibilityMapping(adapter.builder(type), operationParameters).build(result.getModel());
}
Also used : InternalUnsupportedModelException(org.gradle.tooling.internal.protocol.InternalUnsupportedModelException) ModelIdentifier(org.gradle.tooling.internal.protocol.ModelIdentifier) BuildCancellationTokenAdapter(org.gradle.tooling.internal.consumer.parameters.BuildCancellationTokenAdapter)

Aggregations

ModelIdentifier (org.gradle.tooling.internal.protocol.ModelIdentifier)7 InternalUnsupportedModelException (org.gradle.tooling.internal.protocol.InternalUnsupportedModelException)5 DefaultProjectIdentifier (org.gradle.tooling.internal.gradle.DefaultProjectIdentifier)3 BuildController (org.gradle.tooling.BuildController)2 ProtocolToModelAdapter (org.gradle.tooling.internal.adapter.ProtocolToModelAdapter)2 ConsumerTargetTypeProvider (org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider)2 ModelMapping (org.gradle.tooling.internal.consumer.versioning.ModelMapping)2 BuildResult (org.gradle.tooling.internal.protocol.BuildResult)2 InternalBuildController (org.gradle.tooling.internal.protocol.InternalBuildController)2 BuildCancellationTokenAdapter (org.gradle.tooling.internal.consumer.parameters.BuildCancellationTokenAdapter)1 BuildInvocations (org.gradle.tooling.model.gradle.BuildInvocations)1