buildSrc/src/main/rocker/com/uber/okbuck/template/core/Rule.java [16:133]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@SuppressWarnings("unchecked")
public abstract class Rule<T extends Rule> extends DefaultRockerModel {

  private static final ImmutableSet<String> DEFAULT_VISIBILITY = ImmutableSet.of("PUBLIC");

  protected String ruleType = "";
  protected String name = "";
  protected boolean fileConfiguredVisibility = false;
  protected Collection visibility = ImmutableSet.of();
  protected Collection deps = ImmutableSet.of();
  protected Collection labels = ImmutableSet.of();
  protected Collection extraBuckOpts = ImmutableSet.of();

  public String name() {
    return name;
  }

  public T name(String name) {
    this.name = name;
    return (T) this;
  }

  public String buckName() {
    return ":" + name;
  }

  public T ruleType(String ruleType) {
    this.ruleType = ruleType;
    return (T) this;
  }

  public String ruleType() {
    return ruleType;
  }

  public T deps(Collection deps) {
    this.deps = deps;
    return (T) this;
  }

  public T labels(Collection labels) {
    this.labels = labels;
    return (T) this;
  }

  public T fileConfiguredVisibility(boolean enable) {
    this.fileConfiguredVisibility = enable;
    return (T) this;
  }

  public T visibility(Collection visibility) {
    this.visibility = visibility;
    return (T) this;
  }

  public T defaultVisibility() {
    this.visibility = DEFAULT_VISIBILITY;
    return (T) this;
  }

  public T extraBuckOpts(Collection extraBuckOpts) {
    this.extraBuckOpts = extraBuckOpts;
    return (T) this;
  }

  protected static boolean valid(Map m) {
    return m != null && !m.isEmpty();
  }

  protected static boolean valid(Collection c) {
    return c != null && !c.isEmpty();
  }

  protected static boolean valid(String s) {
    return s != null && !s.isEmpty();
  }

  protected static boolean valid(Integer i) {
    return i != null;
  }

  public void render(OutputStream os) {
    render((contentType, charsetName) -> new OutputStreamOutput(contentType, os, charsetName));
  }

  public void render(Path path) {
    render(path.toFile());
  }

  public void render(File file) {
    try {
      file.getParentFile().mkdirs();
      render(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
      throw new IllegalStateException(e);
    }
  }

  protected static ImmutableSortedSet<String> sorted(Collection c) {
    ImmutableSortedSet.Builder<String> builder = new ImmutableSortedSet.Builder<>(targetComparator);
    for (Object o : c) {
      builder.add(o.toString());
    }
    return builder.build();
  }

  private static Comparator<String> targetComparator =
      (String a, String b) -> {
        // Buildifier sorting order   => "."      , ":"      , "-", "/"
        // Java sorting order         => "-"      , "."      , "/", ":"
        // Replace "." with "#" & replace ":" with "$"
        // Java sorting order becomes => "." ("#"), ":" ("$"), "-", "/"

        String aMod = a.replace(".", "#").replace(":", "$");
        String bMod = b.replace(".", "#").replace(":", "$");

        return aMod.compareTo(bMod);
      };
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



plugin/src/main/rocker/com/uber/okbuck/template/core/Rule.java [16:133]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@SuppressWarnings("unchecked")
public abstract class Rule<T extends Rule> extends DefaultRockerModel {

  private static final ImmutableSet<String> DEFAULT_VISIBILITY = ImmutableSet.of("PUBLIC");

  protected String ruleType = "";
  protected String name = "";
  protected boolean fileConfiguredVisibility = false;
  protected Collection visibility = ImmutableSet.of();
  protected Collection deps = ImmutableSet.of();
  protected Collection labels = ImmutableSet.of();
  protected Collection extraBuckOpts = ImmutableSet.of();

  public String name() {
    return name;
  }

  public T name(String name) {
    this.name = name;
    return (T) this;
  }

  public String buckName() {
    return ":" + name;
  }

  public T ruleType(String ruleType) {
    this.ruleType = ruleType;
    return (T) this;
  }

  public String ruleType() {
    return ruleType;
  }

  public T deps(Collection deps) {
    this.deps = deps;
    return (T) this;
  }

  public T labels(Collection labels) {
    this.labels = labels;
    return (T) this;
  }

  public T fileConfiguredVisibility(boolean enable) {
    this.fileConfiguredVisibility = enable;
    return (T) this;
  }

  public T visibility(Collection visibility) {
    this.visibility = visibility;
    return (T) this;
  }

  public T defaultVisibility() {
    this.visibility = DEFAULT_VISIBILITY;
    return (T) this;
  }

  public T extraBuckOpts(Collection extraBuckOpts) {
    this.extraBuckOpts = extraBuckOpts;
    return (T) this;
  }

  protected static boolean valid(Map m) {
    return m != null && !m.isEmpty();
  }

  protected static boolean valid(Collection c) {
    return c != null && !c.isEmpty();
  }

  protected static boolean valid(String s) {
    return s != null && !s.isEmpty();
  }

  protected static boolean valid(Integer i) {
    return i != null;
  }

  public void render(OutputStream os) {
    render((contentType, charsetName) -> new OutputStreamOutput(contentType, os, charsetName));
  }

  public void render(Path path) {
    render(path.toFile());
  }

  public void render(File file) {
    try {
      file.getParentFile().mkdirs();
      render(new FileOutputStream(file));
    } catch (FileNotFoundException e) {
      throw new IllegalStateException(e);
    }
  }

  protected static ImmutableSortedSet<String> sorted(Collection c) {
    ImmutableSortedSet.Builder<String> builder = new ImmutableSortedSet.Builder<>(targetComparator);
    for (Object o : c) {
      builder.add(o.toString());
    }
    return builder.build();
  }

  private static Comparator<String> targetComparator =
      (String a, String b) -> {
        // Buildifier sorting order   => "."      , ":"      , "-", "/"
        // Java sorting order         => "-"      , "."      , "/", ":"
        // Replace "." with "#" & replace ":" with "$"
        // Java sorting order becomes => "." ("#"), ":" ("$"), "-", "/"

        String aMod = a.replace(".", "#").replace(":", "$");
        String bMod = b.replace(".", "#").replace(":", "$");

        return aMod.compareTo(bMod);
      };
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



