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) {