コード例 #1
0
  @Test
  public void shouldSetUpAPrivateLibraryIfGivenAMavenCoordWithoutDeps() throws Exception {
    resolver.resolve("com.example:no-deps:jar:1.0");

    Path groupDir = thirdParty.resolve("example");
    assertTrue(Files.exists(groupDir));

    Path original = repo.resolve("com/example/no-deps/1.0/no-deps-1.0.jar");
    HashCode expected = MorePaths.asByteSource(original).hash(Hashing.sha1());
    Path jarFile = groupDir.resolve("no-deps-1.0.jar");
    HashCode seen = MorePaths.asByteSource(jarFile).hash(Hashing.sha1());
    assertEquals(expected, seen);

    List<Map<String, Object>> rules = buildFileParser.getAll(groupDir.resolve("BUCK"));

    assertEquals(1, rules.size());
    Map<String, Object> rule = rules.get(0);
    // Name is derived from the project identifier
    assertEquals("no-deps", rule.get("name"));

    // The binary jar should be set
    assertEquals("no-deps-1.0.jar", rule.get("binaryJar"));

    // There was no source jar in the repo
    assertTrue(rule.containsKey("sourceJar"));
    assertNull(rule.get("sourceJar"));

    // Nothing depends on this, so it's not visible
    assertEquals(ImmutableList.of(), rule.get("visibility"));

    // And it doesn't depend on anything
    assertEquals(ImmutableList.of(), rule.get("deps"));
  }
コード例 #2
0
  @Test
  public void shouldIncludeSourceJarIfOneIsPresent() throws Exception {
    resolver.resolve("com.example:with-sources:jar:1.0");

    Path groupDir = thirdParty.resolve("example");
    List<Map<String, Object>> rules = buildFileParser.getAll(groupDir.resolve("BUCK"));

    Map<String, Object> rule = rules.get(0);
    assertEquals("with-sources-1.0-sources.jar", rule.get("sourceJar"));
  }
コード例 #3
0
  @Test
  public void shouldSetVisibilityOfTargetToGiveDependenciesAccess() throws Exception {
    resolver.resolve("com.example:with-deps:jar:1.0");

    Path exampleDir = thirdPartyRelative.resolve("example");
    Map<String, Object> withDeps =
        buildFileParser.getAll(buckRepoRoot.resolve(exampleDir).resolve("BUCK")).get(0);
    Path otherDir = thirdPartyRelative.resolve("othercorp");
    Map<String, Object> noDeps =
        buildFileParser.getAll(buckRepoRoot.resolve(otherDir).resolve("BUCK")).get(0);

    @SuppressWarnings("unchecked")
    List<String> visibility = (List<String>) noDeps.get("visibility");
    assertEquals(1, visibility.size());
    assertEquals(ImmutableList.of(String.format("//%s:with-deps", exampleDir)), visibility);
    assertEquals(ImmutableList.of(), noDeps.get("deps"));

    assertEquals(ImmutableList.of(), withDeps.get("visibility"));
    @SuppressWarnings("unchecked")
    List<String> deps = (List<String>) withDeps.get("deps");
    assertEquals(1, deps.size());
    assertEquals(ImmutableList.of(String.format("//%s:no-deps", otherDir)), deps);
  }
コード例 #4
0
  @Test
  public void shouldOmitTargetsInTheSameBuildFileInVisibilityArguments() throws Exception {
    resolver.resolve("com.example:deps-in-same-project:jar:1.0");

    Path exampleDir = thirdPartyRelative.resolve("example");
    List<Map<String, Object>> allTargets =
        buildFileParser.getAll(buckRepoRoot.resolve(exampleDir).resolve("BUCK"));

    assertEquals(2, allTargets.size());

    Map<String, Object> noDeps = null;
    for (Map<String, Object> target : allTargets) {
      if ("no-deps".equals(target.get("name"))) {
        noDeps = target;
        break;
      }
    }
    assertNotNull(noDeps);

    // Although the "deps-in-same-project" could be in the visibility param, it doesn't need to be
    // because it's declared in the same build file.
    assertEquals(0, ((Collection<?>) noDeps.get("visibility")).size());
  }