private SerializablePrebuiltJarRule(BuildRule rule) { Preconditions.checkState(rule.getBuildable() instanceof PrebuiltJar); this.name = getIntellijNameForRule(rule, null /* basePathToAliasMap */); PrebuiltJar prebuiltJar = (PrebuiltJar) rule.getBuildable(); this.binaryJar = prebuiltJar.getBinaryJar().toString(); if (prebuiltJar.getSourceJar().isPresent()) { this.sourceJar = prebuiltJar.getSourceJar().get().toString(); } else { this.sourceJar = null; } this.javadocUrl = prebuiltJar.getJavadocUrl().orNull(); }
/** * @param rule whose corresponding IntelliJ module name will be returned * @param basePathToAliasMap may be null if rule is a {@link PrebuiltJar} */ private static String getIntellijNameForRule( BuildRule rule, @Nullable Map<String, String> basePathToAliasMap) { // Get basis for the library/module name. String name; if (rule.getBuildable() instanceof PrebuiltJar) { PrebuiltJar prebuiltJar = (PrebuiltJar) rule.getBuildable(); String binaryJar = prebuiltJar.getBinaryJar().toString(); return getIntellijNameForBinaryJar(binaryJar); } else { String basePath = rule.getBuildTarget().getBasePath(); if (basePathToAliasMap.containsKey(basePath)) { name = basePathToAliasMap.get(basePath); } else { name = rule.getBuildTarget().getBasePath(); name = name.replace('/', '_'); // Must add a prefix to ensure that name is non-empty. name = "module_" + name; } // Normalize name. return normalizeIntelliJName(name); } }