use of org.gradle.language.base.internal.resolve.LibraryResolveException in project gradle by gradle.
the class LocalLibraryDependencyResolver method resolveLibraryAndChooseBinary.
private void resolveLibraryAndChooseBinary(BuildableComponentIdResolveResult result, LibraryComponentSelector selector) {
final String selectorProjectPath = selector.getProjectPath();
final String libraryName = selector.getLibraryName();
final String variant = selector.getVariant();
LibraryResolutionResult resolutionResult = doResolve(selectorProjectPath, libraryName);
VariantComponent selectedLibrary = resolutionResult.getSelectedLibrary();
if (selectedLibrary == null) {
String message = resolutionResult.toResolutionErrorMessage(selector);
ModuleVersionResolveException failure = new ModuleVersionResolveException(selector, new LibraryResolveException(message));
result.failed(failure);
return;
}
final Collection<? extends Binary> matchingVariants = chooseMatchingVariants(selectedLibrary, variant);
if (matchingVariants.isEmpty()) {
// no compatible variant found
final Iterable<? extends Binary> values = selectedLibrary.getVariants();
result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {
@Nullable
@Override
public String create() {
return errorMessageBuilder.noCompatibleVariantErrorMessage(libraryName, values);
}
}));
} else if (matchingVariants.size() > 1) {
result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {
@Nullable
@Override
public String create() {
return errorMessageBuilder.multipleCompatibleVariantsErrorMessage(libraryName, matchingVariants);
}
}));
} else {
Binary selectedBinary = matchingVariants.iterator().next();
// TODO:Cedric This is not quite right. We assume that if we are asking for a specific binary, then we resolve to the assembly instead
// of the jar, but it should be somehow parameterized
LocalComponentMetadata metaData;
if (variant == null) {
metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, false);
} else {
metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, true);
}
result.resolved(metaData);
}
}
Aggregations