Search in sources :

Example 1 with ModelIdentifier

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

the class ModelBuilderBackedModelProducer method produceModel.

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, operationParameters);
    } catch (InternalUnsupportedModelException e) {
        throw Exceptions.unknownModel(type, 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)

Example 2 with ModelIdentifier

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

the class InternalBuildActionAdapter method execute.

/**
 * This is used by providers 1.8-rc-1 to 4.3
 */
public T execute(final InternalBuildController buildController) {
    ProtocolToModelAdapter protocolToModelAdapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider());
    BuildController buildControllerAdapter = new BuildControllerAdapter(protocolToModelAdapter, new InternalBuildControllerAdapter() {

        @Override
        public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier, Object parameter) {
            return buildController.getModel(target, modelIdentifier);
        }
    }, new ModelMapping(), rootDir);
    buildControllerAdapter = new BuildControllerWithoutParameterSupport(versionDetails, buildControllerAdapter);
    if (!versionDetails.maySupportModel(BuildInvocations.class)) {
        buildControllerAdapter = new BuildInvocationsAdapterController(protocolToModelAdapter, buildControllerAdapter);
    }
    return action.execute(buildControllerAdapter);
}
Also used : ConsumerTargetTypeProvider(org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider) BuildInvocations(org.gradle.tooling.model.gradle.BuildInvocations) BuildController(org.gradle.tooling.BuildController) InternalBuildController(org.gradle.tooling.internal.protocol.InternalBuildController) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping) BuildResult(org.gradle.tooling.internal.protocol.BuildResult) ProtocolToModelAdapter(org.gradle.tooling.internal.adapter.ProtocolToModelAdapter) ModelIdentifier(org.gradle.tooling.internal.protocol.ModelIdentifier)

Example 3 with ModelIdentifier

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

the class BuildControllerAdapter method getModel.

public <T> T getModel(Model target, Class<T> modelType) throws UnknownModelException {
    ModelIdentifier modelIdentifier = modelMapping.getModelIdentifierFromModelType(modelType);
    Object originalTarget = target == null ? null : adapter.unpack(target);
    BuildResult<?> result;
    try {
        result = buildController.getModel(originalTarget, modelIdentifier);
    } 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 4 with ModelIdentifier

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

the class BuildControllerAdapter method getModel.

@Override
public <T, P> T getModel(Model target, Class<T> modelType, Class<P> parameterType, Action<? super P> parameterInitializer) throws UnsupportedVersionException {
    ModelIdentifier modelIdentifier = modelMapping.getModelIdentifierFromModelType(modelType);
    Object originalTarget = target == null ? null : adapter.unpack(target);
    P parameter = initializeParameter(parameterType, parameterInitializer);
    BuildResult<?> result;
    try {
        result = buildController.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 5 with ModelIdentifier

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

the class InternalBuildActionAdapter method execute.

/**
 * This is used by providers 4.4 and later
 */
public T execute(final InternalBuildControllerVersion2 buildController) {
    ProtocolToModelAdapter protocolToModelAdapter = new ProtocolToModelAdapter(new ConsumerTargetTypeProvider());
    BuildController buildControllerAdapter = new BuildControllerAdapter(protocolToModelAdapter, new InternalBuildControllerAdapter() {

        @Override
        public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier, Object parameter) {
            return buildController.getModel(target, modelIdentifier, parameter);
        }
    }, new ModelMapping(), rootDir);
    return action.execute(buildControllerAdapter);
}
Also used : BuildResult(org.gradle.tooling.internal.protocol.BuildResult) ProtocolToModelAdapter(org.gradle.tooling.internal.adapter.ProtocolToModelAdapter) ConsumerTargetTypeProvider(org.gradle.tooling.internal.consumer.converters.ConsumerTargetTypeProvider) ModelIdentifier(org.gradle.tooling.internal.protocol.ModelIdentifier) BuildController(org.gradle.tooling.BuildController) InternalBuildController(org.gradle.tooling.internal.protocol.InternalBuildController) ModelMapping(org.gradle.tooling.internal.consumer.versioning.ModelMapping)

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