Search in sources :

Example 1 with PatternAndMessage

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Flavor(com.facebook.buck.model.Flavor) PatternAndMessage(com.facebook.buck.util.PatternAndMessage)

Aggregations

Flavor (com.facebook.buck.model.Flavor)1 PatternAndMessage (com.facebook.buck.util.PatternAndMessage)1 ImmutableSet (com.google.common.collect.ImmutableSet)1