use of com.facebook.buck.util.PatternAndMessage in project buck by facebook.
the class UnexpectedFlavorException method createWithSuggestions.
public static UnexpectedFlavorException createWithSuggestions(Cell cell, BuildTarget target) {
// Get the specific message
String exceptionMessage = createDefaultMessage(cell, target);
// Get some suggestions on how to solve it.
String suggestions = "";
Optional<ImmutableSet<PatternAndMessage>> configMessagesForFlavors = cell.getBuckConfig().getUnexpectedFlavorsMessages();
for (Flavor flavor : target.getFlavors()) {
boolean foundInConfig = false;
if (configMessagesForFlavors.isPresent()) {
for (PatternAndMessage flavorPattern : configMessagesForFlavors.get()) {
if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
foundInConfig = true;
suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
}
}
}
if (!foundInConfig) {
for (PatternAndMessage flavorPattern : suggestedMessagesForFlavors) {
if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
}
}
}
}
if (!suggestions.isEmpty()) {
exceptionMessage += "\nHere are some things you can try to get the following " + "flavors to work::\n" + suggestions;
}
return new UnexpectedFlavorException(exceptionMessage);
}
Aggregations