/** * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an * alias defined earlier in the {@code alias} section. The mapping produced by this method * reflects the result of resolving all aliases as values in the {@code alias} section. */ private static ImmutableMap<String, BuildTarget> createAliasToBuildTargetMap( ImmutableMap<String, String> rawAliasMap) { // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to // be preserved, and (2) the ability to inspect the Map while building it up. LinkedHashMap<String, BuildTarget> aliasToBuildTarget = Maps.newLinkedHashMap(); for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) { String alias = aliasEntry.getKey(); validateAliasName(alias); // Determine whether the mapping is to a build target or to an alias. String value = aliasEntry.getValue(); BuildTarget buildTarget; if (isValidAliasName(value)) { buildTarget = aliasToBuildTarget.get(value); if (buildTarget == null) { throw new HumanReadableException("No alias for: %s.", value); } } else { // Here we parse the alias values with a BuildTargetParser to be strict. We could be looser // and just grab everything between "//" and ":" and assume it's a valid base path. buildTarget = BuildTargetParser.INSTANCE.parse(value, BuildTargetPatternParser.fullyQualified()); } aliasToBuildTarget.put(alias, buildTarget); } return ImmutableMap.copyOf(aliasToBuildTarget); }
protected BuildRule resolve(BuildTarget target, BuildRuleResolver resolver, String input) throws MacroException { BuildTarget other; try { other = BuildTargetParser.INSTANCE.parse( input, BuildTargetPatternParser.forBaseName(target.getBaseName())); } catch (BuildTargetParseException e) { throw new MacroException(e.getMessage(), e); } Optional<BuildRule> rule = resolver.getRuleOptional(other); if (!rule.isPresent()) { throw new MacroException(String.format("no rule %s", other)); } return rule.get(); }
public BuildTarget getBuildTargetForFullyQualifiedTarget(String target) { return BuildTargetParser.INSTANCE.parse(target, BuildTargetPatternParser.fullyQualified()); }
@Override public ImmutableList<BuildTarget> extractParseTimeDeps(BuildTarget target, String input) { return ImmutableList.of( BuildTargetParser.INSTANCE.parse( input, BuildTargetPatternParser.forBaseName(target.getBaseName()))); }