Java Code Examples for org.gradle.tooling.provider.model.ToolingModelBuilderRegistry#getBuilder()

The following examples show how to use org.gradle.tooling.provider.model.ToolingModelBuilderRegistry#getBuilder() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultBuildController.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) 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()));
    }
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 2
Source File: BuildModelAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildActionResult run(BuildController buildController) {
    GradleInternal gradle = buildController.getGradle();

    if (runTasks) {
        buildController.run();
    } else {
        buildController.configure();
        // Currently need to force everything to be configured
        gradle.getServices().get(ProjectConfigurer.class).configureHierarchy(gradle.getRootProject());
    }

    ToolingModelBuilderRegistry builderRegistry = getToolingModelBuilderRegistry(gradle);
    ToolingModelBuilder builder;
    try {
        builder = builderRegistry.getBuilder(modelName);
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException)new InternalUnsupportedModelException().initCause(e);
    }

    Object result;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        result = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelName, gradle.getDefaultProject(), true);
    } else {
        result = builder.buildAll(modelName, gradle.getDefaultProject());
    }

    PayloadSerializer payloadSerializer = gradle.getServices().get(PayloadSerializer.class);
    return new BuildActionResult(payloadSerializer.serialize(result), null);
}
 
Example 3
Source File: DefaultBuildController.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 4
Source File: DefaultBuildController.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) 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()));
    }
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}
 
Example 5
Source File: BuildModelAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildActionResult run(BuildController buildController) {
    GradleInternal gradle = buildController.getGradle();

    if (runTasks) {
        buildController.run();
    } else {
        buildController.configure();
        // Currently need to force everything to be configured
        gradle.getServices().get(ProjectConfigurer.class).configureHierarchy(gradle.getRootProject());
    }

    ToolingModelBuilderRegistry builderRegistry = getToolingModelBuilderRegistry(gradle);
    ToolingModelBuilder builder;
    try {
        builder = builderRegistry.getBuilder(modelName);
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException)new InternalUnsupportedModelException().initCause(e);
    }

    Object result;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        result = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelName, gradle.getDefaultProject(), true);
    } else {
        result = builder.buildAll(modelName, gradle.getDefaultProject());
    }

    PayloadSerializer payloadSerializer = gradle.getServices().get(PayloadSerializer.class);
    return new BuildActionResult(payloadSerializer.serialize(result), null);
}
 
Example 6
Source File: DefaultBuildController.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public BuildResult<?> getModel(Object target, ModelIdentifier modelIdentifier) throws BuildExceptionVersion1, InternalUnsupportedModelException {
    ToolingModelBuilderRegistry modelBuilderRegistry;
    ProjectInternal project;
    boolean isImplicitProject;
    if (target == null) {
        project = gradle.getDefaultProject();
        isImplicitProject = true;
    } else if (target instanceof GradleProjectIdentity) {
        GradleProjectIdentity gradleProject = (GradleProjectIdentity) target;
        project = gradle.getRootProject().project(gradleProject.getPath());
        isImplicitProject = false;
    } else {
        throw new IllegalArgumentException("Don't know how to build models for " + target);
    }
    modelBuilderRegistry = project.getServices().get(ToolingModelBuilderRegistry.class);

    ToolingModelBuilder builder;
    try {
        builder = modelBuilderRegistry.getBuilder(modelIdentifier.getName());
    } catch (UnknownModelException e) {
        throw (InternalUnsupportedModelException) (new InternalUnsupportedModelException()).initCause(e);
    }
    Object model;
    if (builder instanceof ProjectSensitiveToolingModelBuilder) {
        model = ((ProjectSensitiveToolingModelBuilder) builder).buildAll(modelIdentifier.getName(), project, isImplicitProject);
    } else {
        model = builder.buildAll(modelIdentifier.getName(), project);
    }
    return new ProviderBuildResult<Object>(model);
}