use of org.gradle.api.attributes.Category in project gradle by gradle.
the class PublicationErrorChecker method checkForUnpublishableAttributes.
/**
* Checks that the given component does not have any attributes that are not allowed to be published.
*
* @param component the component to check
* @param documentationRegistry for creating helpful links in error messages upon failing the check
* @throws PublishException if the component uses attributes invalid for publication
*/
public static void checkForUnpublishableAttributes(SoftwareComponentInternal component, DocumentationRegistry documentationRegistry) {
for (final UsageContext usageContext : component.getUsages()) {
Optional<Attribute<?>> category = usageContext.getAttributes().keySet().stream().filter(a -> Category.CATEGORY_ATTRIBUTE.getName().equals(a.getName())).findFirst();
category.ifPresent(c -> {
Object value = usageContext.getAttributes().getAttribute(c);
if (value != null && Category.VERIFICATION.equals(value.toString())) {
throw new PublishException("Cannot publish module metadata for component '" + component.getName() + "' which would include a variant '" + usageContext.getName() + "' that contains a '" + Category.CATEGORY_ATTRIBUTE.getName() + "' attribute with a value of '" + Category.VERIFICATION + "'. This attribute is reserved for test verification output and is not publishable. See: " + documentationRegistry.getDocumentationFor("variant_attributes.html", "sec:verification_category"));
}
});
}
}
Aggregations