use of org.gradle.platform.base.VariantComponent in project gradle by gradle.
the class LocalLibraryDependencyResolver method doResolve.
private LibraryResolutionResult doResolve(String selectorProjectPath, String libraryName) {
try {
ModelRegistry projectModel = projectModelResolver.resolveProjectModel(selectorProjectPath);
Collection<VariantComponent> candidates = libraryResolver.resolveCandidates(projectModel, libraryName);
if (candidates.isEmpty()) {
return LibraryResolutionResult.emptyResolutionResult(binaryType);
}
return LibraryResolutionResult.of(binaryType, candidates, libraryName, binaryPredicate);
} catch (UnknownProjectException e) {
return LibraryResolutionResult.projectNotFound(binaryType);
}
}
use of org.gradle.platform.base.VariantComponent 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);
}
}
use of org.gradle.platform.base.VariantComponent in project gradle by gradle.
the class LibraryResolutionResult method resolve.
private void resolve(String libraryName) {
if (libraryName == null) {
VariantComponent singleMatchingLibrary = getSingleMatchingLibrary();
if (singleMatchingLibrary == null) {
return;
}
libraryName = singleMatchingLibrary.getName();
}
selectedLibrary = libsMatchingRequirements.get(libraryName);
nonMatchingLibrary = libsNotMatchingRequirements.get(libraryName);
}
use of org.gradle.platform.base.VariantComponent in project gradle by gradle.
the class LibraryResolutionResult method toResolutionErrorMessage.
public String toResolutionErrorMessage(LibraryComponentSelector selector) {
List<String> candidateLibraries = formatLibraryNames(getCandidateLibraries());
String projectPath = selector.getProjectPath();
String libraryName = selector.getLibraryName();
StringBuilder sb = new StringBuilder("Project '").append(projectPath).append("'");
if (libraryName == null || !hasLibraries()) {
if (isProjectNotFound()) {
sb.append(" not found.");
} else if (!hasLibraries()) {
sb.append(" doesn't define any library.");
} else {
sb.append(" contains more than one library. Please select one of ");
Joiner.on(", ").appendTo(sb, candidateLibraries);
}
} else {
VariantComponent notMatchingRequirements = getNonMatchingLibrary();
if (notMatchingRequirements != null) {
sb.append(" contains a library named '").append(libraryName).append("' but it doesn't have any binary of type ").append(binaryType.getSimpleName());
} else {
sb.append(" does not contain library '").append(libraryName).append("'. Did you want to use ");
if (candidateLibraries.size() == 1) {
sb.append(candidateLibraries.get(0));
} else {
sb.append("one of ");
Joiner.on(", ").appendTo(sb, candidateLibraries);
}
sb.append("?");
}
}
return sb.toString();
}
use of org.gradle.platform.base.VariantComponent in project gradle by gradle.
the class LibraryResolutionResult method of.
public static LibraryResolutionResult of(Class<? extends Binary> binaryType, Collection<? extends VariantComponent> libraries, String libraryName, Predicate<? super VariantComponent> libraryFilter) {
LibraryResolutionResult result = new LibraryResolutionResult(binaryType);
for (VariantComponent librarySpec : libraries) {
if (libraryFilter.apply(librarySpec)) {
result.libsMatchingRequirements.put(librarySpec.getName(), librarySpec);
} else {
result.libsNotMatchingRequirements.put(librarySpec.getName(), librarySpec);
}
}
result.resolve(libraryName);
return result;
}
Aggregations