Search in sources :

Example 1 with SourceRoot

use of com.facebook.buck.rules.SourceRoot in project buck by facebook.

the class Project method addSourceFolders.

private boolean addSourceFolders(SerializableModule module, @Nullable BuildRule buildRule, @Nullable ImmutableList<SourceRoot> sourceRoots, boolean isTestSource) {
    if (buildRule == null || sourceRoots == null) {
        return false;
    }
    if (buildRule.getProperties().is(PACKAGING) && sourceRoots.isEmpty()) {
        return false;
    }
    JavaLibrary javaLibrary;
    if (buildRule instanceof JavaLibrary) {
        javaLibrary = (JavaLibrary) buildRule;
        Path basePath = buildRule.getBuildTarget().getBasePath();
        for (SourcePath path : javaLibrary.getSources()) {
            if (!(path instanceof PathSourcePath)) {
                Path pathToTarget = resolver.getRelativePath(path);
                Path relativePath = basePath.relativize(Paths.get("")).resolve(pathToTarget).getParent();
                String url = "file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(relativePath);
                SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, "");
                module.sourceFolders.add(sourceFolder);
            }
        }
    }
    if (sourceRoots.isEmpty()) {
        // When there is a src_target, but no src_roots were specified, then the current directory is
        // treated as the SourceRoot. This is the common case when a project contains one folder of
        // Java source code with a build file for each Java package. For example, if the project's
        // only source folder were named "java/" and a build file in java/com/example/base/ contained
        // the an extremely simple set of build rules:
        //
        // java_library(
        //   name = 'base',
        //   srcs = glob(['*.java']),
        // }
        //
        // project_config(
        //   src_target = ':base',
        // )
        //
        // then the corresponding .iml file (in the same directory) should contain:
        //
        // <content url="file://$MODULE_DIR$">
        //   <sourceFolder url="file://$MODULE_DIR$"
        //                 isTestSource="false"
        //                 packagePrefix="com.example.base" />
        //   <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" />
        //
        //   <!-- It will have an <excludeFolder> for every "subpackage" of com.example.base. -->
        //   <excludeFolder url="file://$MODULE_DIR$/util" />
        // </content>
        //
        // Note to prevent the <excludeFolder> elements from being included, the project_config()
        // rule should be:
        //
        // project_config(
        //   src_target = ':base',
        //   src_root_includes_subdirectories = True,
        // )
        //
        // Because developers who organize their code this way will have many build files, the default
        // values of project_config() assume this approach to help minimize the tedium in writing all
        // of those project_config() rules.
        String url = "file://$MODULE_DIR$";
        String packagePrefix = javaPackageFinder.findJavaPackage(Preconditions.checkNotNull(module.pathToImlFile));
        SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder(url, isTestSource, packagePrefix);
        module.sourceFolders.add(sourceFolder);
    } else {
        for (SourceRoot sourceRoot : sourceRoots) {
            SerializableModule.SourceFolder sourceFolder = new SerializableModule.SourceFolder("file://$MODULE_DIR$/" + sourceRoot.getName(), isTestSource);
            module.sourceFolders.add(sourceFolder);
        }
    }
    // Include <excludeFolder> elements, as appropriate.
    for (Path relativePath : this.buildFileTree.getChildPaths(buildRule.getBuildTarget())) {
        String excludeFolderUrl = "file://$MODULE_DIR$/" + relativePath;
        SerializableModule.SourceFolder excludeFolder = new SerializableModule.SourceFolder(excludeFolderUrl, /* isTestSource */
        false);
        module.excludeFolders.add(excludeFolder);
    }
    return true;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourceRoot(com.facebook.buck.rules.SourceRoot)

Example 2 with SourceRoot

use of com.facebook.buck.rules.SourceRoot in project buck by facebook.

the class AbstractRuleKeyHasherTest method testUniqueness.

@Test
public void testUniqueness() {
    List<HASH> hashes = new ArrayList<>();
    hashes.add(newHasher().hash());
    hashes.add(newHasher().putKey("").hash());
    hashes.add(newHasher().putKey("42").hash());
    hashes.add(newHasher().putKey("4").putKey("2").hash());
    hashes.add(newHasher().putNull().hash());
    hashes.add(newHasher().putBoolean(true).hash());
    hashes.add(newHasher().putBoolean(false).hash());
    for (Number number : getNumbersForUniquenessTest()) {
        hashes.add(newHasher().putNumber(number).hash());
    }
    hashes.add(newHasher().putString("").hash());
    hashes.add(newHasher().putString("42").hash());
    hashes.add(newHasher().putString("4").putString("2").hash());
    hashes.add(newHasher().putBytes(new byte[0]).hash());
    hashes.add(newHasher().putBytes(new byte[] { 42 }).hash());
    hashes.add(newHasher().putBytes(new byte[] { 42, 42 }).hash());
    hashes.add(newHasher().putPattern(Pattern.compile("")).hash());
    hashes.add(newHasher().putPattern(Pattern.compile("42")).hash());
    hashes.add(newHasher().putPattern(Pattern.compile("4")).putPattern(Pattern.compile("2")).hash());
    hashes.add(newHasher().putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c")).hash());
    hashes.add(newHasher().putSha1(Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd")).hash());
    hashes.add(newHasher().putPath(Paths.get(""), HashCode.fromInt(0)).hash());
    hashes.add(newHasher().putPath(Paths.get(""), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putPath(Paths.get("42"), HashCode.fromInt(0)).hash());
    hashes.add(newHasher().putPath(Paths.get("42"), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(0)).hash());
    hashes.add(newHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(0)).hash());
    hashes.add(newHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash());
    hashes.add(newHasher().putNonHashingPath("").hash());
    hashes.add(newHasher().putNonHashingPath("42").hash());
    hashes.add(newHasher().putNonHashingPath("4").putNonHashingPath("2").hash());
    hashes.add(newHasher().putSourceRoot(new SourceRoot("")).hash());
    hashes.add(newHasher().putSourceRoot(new SourceRoot("42")).hash());
    hashes.add(newHasher().putSourceRoot(new SourceRoot("4")).putSourceRoot(new SourceRoot("2")).hash());
    hashes.add(newHasher().putRuleKey(RULE_KEY_1).hash());
    hashes.add(newHasher().putRuleKey(RULE_KEY_2).hash());
    hashes.add(newHasher().putBuildRuleType(BuildRuleType.of("")).hash());
    hashes.add(newHasher().putBuildRuleType(BuildRuleType.of("42")).hash());
    hashes.add(newHasher().putBuildRuleType(BuildRuleType.of("4")).putBuildRuleType(BuildRuleType.of("2")).hash());
    hashes.add(newHasher().putBuildTarget(TARGET_1).hash());
    hashes.add(newHasher().putBuildTarget(TARGET_2).hash());
    hashes.add(newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash());
    hashes.add(newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_2)).hash());
    hashes.add(newHasher().putContainer(RuleKeyHasher.Container.LIST, 0).hash());
    hashes.add(newHasher().putContainer(RuleKeyHasher.Container.LIST, 42).hash());
    hashes.add(newHasher().putContainer(RuleKeyHasher.Container.MAP, 0).hash());
    hashes.add(newHasher().putContainer(RuleKeyHasher.Container.MAP, 42).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).hash());
    hashes.add(newHasher().putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).hash());
    // all of the hashes should be different
    for (int i = 0; i < hashes.size(); i++) {
        for (int j = 0; j < i; j++) {
            assertNotEquals(String.format("Collision [%d] = [%d]", i, j), hashes.get(i), hashes.get(j));
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SourceRoot(com.facebook.buck.rules.SourceRoot) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 3 with SourceRoot

use of com.facebook.buck.rules.SourceRoot in project buck by facebook.

the class CountingRuleKeyHasherTest method testForwarding.

@Test
public void testForwarding() {
    assertEquals(newGuavaHasher().hash(), newCountHasher().hash());
    assertEquals(newGuavaHasher().putKey("").hash(), newCountHasher().putKey("").hash());
    assertEquals(newGuavaHasher().putKey("42").hash(), newCountHasher().putKey("42").hash());
    assertEquals(newGuavaHasher().putKey("4").putKey("2").hash(), newCountHasher().putKey("4").putKey("2").hash());
    assertEquals(newGuavaHasher().putNull().hash(), newCountHasher().putNull().hash());
    assertEquals(newGuavaHasher().putBoolean(true).hash(), newCountHasher().putBoolean(true).hash());
    assertEquals(newGuavaHasher().putBoolean(false).hash(), newCountHasher().putBoolean(false).hash());
    assertEquals(newGuavaHasher().putNumber(0).hash(), newCountHasher().putNumber(0).hash());
    assertEquals(newGuavaHasher().putNumber(42).hash(), newCountHasher().putNumber(42).hash());
    assertEquals(newGuavaHasher().putNumber((long) 0).hash(), newCountHasher().putNumber((long) 0).hash());
    assertEquals(newGuavaHasher().putNumber((long) 42).hash(), newCountHasher().putNumber((long) 42).hash());
    assertEquals(newGuavaHasher().putNumber((short) 0).hash(), newCountHasher().putNumber((short) 0).hash());
    assertEquals(newGuavaHasher().putNumber((short) 42).hash(), newCountHasher().putNumber((short) 42).hash());
    assertEquals(newGuavaHasher().putNumber((byte) 0).hash(), newCountHasher().putNumber((byte) 0).hash());
    assertEquals(newGuavaHasher().putNumber((byte) 42).hash(), newCountHasher().putNumber((byte) 42).hash());
    assertEquals(newGuavaHasher().putNumber((float) 0).hash(), newCountHasher().putNumber((float) 0).hash());
    assertEquals(newGuavaHasher().putNumber((float) 42).hash(), newCountHasher().putNumber((float) 42).hash());
    assertEquals(newGuavaHasher().putNumber((double) 0).hash(), newCountHasher().putNumber((double) 0).hash());
    assertEquals(newGuavaHasher().putNumber((double) 42).hash(), newCountHasher().putNumber((double) 42).hash());
    assertEquals(newGuavaHasher().putString("").hash(), newCountHasher().putString("").hash());
    assertEquals(newGuavaHasher().putString("42").hash(), newCountHasher().putString("42").hash());
    assertEquals(newGuavaHasher().putString("4").putString("2").hash(), newCountHasher().putString("4").putString("2").hash());
    assertEquals(newGuavaHasher().putBytes(new byte[0]).hash(), newCountHasher().putBytes(new byte[0]).hash());
    assertEquals(newGuavaHasher().putBytes(new byte[] { 42 }).hash(), newCountHasher().putBytes(new byte[] { 42 }).hash());
    assertEquals(newGuavaHasher().putBytes(new byte[] { 42, 42 }).hash(), newCountHasher().putBytes(new byte[] { 42, 42 }).hash());
    assertEquals(newGuavaHasher().putPattern(Pattern.compile("")).hash(), newCountHasher().putPattern(Pattern.compile("")).hash());
    assertEquals(newGuavaHasher().putPattern(Pattern.compile("42")).hash(), newCountHasher().putPattern(Pattern.compile("42")).hash());
    assertEquals(newGuavaHasher().putPattern(Pattern.compile("4")).putPattern(Pattern.compile("2")).hash(), newCountHasher().putPattern(Pattern.compile("4")).putPattern(Pattern.compile("2")).hash());
    assertEquals(newGuavaHasher().putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c")).hash(), newCountHasher().putSha1(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c")).hash());
    assertEquals(newGuavaHasher().putSha1(Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd")).hash(), newCountHasher().putSha1(Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd")).hash());
    assertEquals(newGuavaHasher().putPath(Paths.get(""), HashCode.fromInt(0)).hash(), newCountHasher().putPath(Paths.get(""), HashCode.fromInt(0)).hash());
    assertEquals(newGuavaHasher().putPath(Paths.get(""), HashCode.fromInt(42)).hash(), newCountHasher().putPath(Paths.get(""), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putPath(Paths.get("42"), HashCode.fromInt(0)).hash(), newCountHasher().putPath(Paths.get("42"), HashCode.fromInt(0)).hash());
    assertEquals(newGuavaHasher().putPath(Paths.get("42"), HashCode.fromInt(42)).hash(), newCountHasher().putPath(Paths.get("42"), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash(), newCountHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(0)).hash(), newCountHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(0)).hash());
    assertEquals(newGuavaHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(42)).hash(), newCountHasher().putArchiveMemberPath(newArchiveMember("", ""), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(0)).hash(), newCountHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(0)).hash());
    assertEquals(newGuavaHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(42)).hash(), newCountHasher().putArchiveMemberPath(newArchiveMember("42", "42"), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash(), newCountHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newGuavaHasher().putNonHashingPath("").hash(), newCountHasher().putNonHashingPath("").hash());
    assertEquals(newGuavaHasher().putNonHashingPath("42").hash(), newCountHasher().putNonHashingPath("42").hash());
    assertEquals(newGuavaHasher().putNonHashingPath("4").putNonHashingPath("2").hash(), newCountHasher().putNonHashingPath("4").putNonHashingPath("2").hash());
    assertEquals(newGuavaHasher().putSourceRoot(new SourceRoot("")).hash(), newCountHasher().putSourceRoot(new SourceRoot("")).hash());
    assertEquals(newGuavaHasher().putSourceRoot(new SourceRoot("42")).hash(), newCountHasher().putSourceRoot(new SourceRoot("42")).hash());
    assertEquals(newGuavaHasher().putSourceRoot(new SourceRoot("4")).putSourceRoot(new SourceRoot("2")).hash(), newCountHasher().putSourceRoot(new SourceRoot("4")).putSourceRoot(new SourceRoot("2")).hash());
    assertEquals(newGuavaHasher().putRuleKey(RULE_KEY_1).hash(), newCountHasher().putRuleKey(RULE_KEY_1).hash());
    assertEquals(newGuavaHasher().putRuleKey(RULE_KEY_2).hash(), newCountHasher().putRuleKey(RULE_KEY_2).hash());
    assertEquals(newGuavaHasher().putBuildRuleType(BuildRuleType.of("")).hash(), newCountHasher().putBuildRuleType(BuildRuleType.of("")).hash());
    assertEquals(newGuavaHasher().putBuildRuleType(BuildRuleType.of("42")).hash(), newCountHasher().putBuildRuleType(BuildRuleType.of("42")).hash());
    assertEquals(newGuavaHasher().putBuildRuleType(BuildRuleType.of("4")).putBuildRuleType(BuildRuleType.of("2")).hash(), newCountHasher().putBuildRuleType(BuildRuleType.of("4")).putBuildRuleType(BuildRuleType.of("2")).hash());
    assertEquals(newGuavaHasher().putBuildTarget(TARGET_1).hash(), newCountHasher().putBuildTarget(TARGET_1).hash());
    assertEquals(newGuavaHasher().putBuildTarget(TARGET_2).hash(), newCountHasher().putBuildTarget(TARGET_2).hash());
    assertEquals(newGuavaHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash(), newCountHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash());
    assertEquals(newGuavaHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_2)).hash(), newCountHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_2)).hash());
    assertEquals(newGuavaHasher().putContainer(RuleKeyHasher.Container.LIST, 0).hash(), newCountHasher().putContainer(RuleKeyHasher.Container.LIST, 0).hash());
    assertEquals(newGuavaHasher().putContainer(RuleKeyHasher.Container.LIST, 42).hash(), newCountHasher().putContainer(RuleKeyHasher.Container.LIST, 42).hash());
    assertEquals(newGuavaHasher().putContainer(RuleKeyHasher.Container.MAP, 0).hash(), newCountHasher().putContainer(RuleKeyHasher.Container.MAP, 0).hash());
    assertEquals(newGuavaHasher().putContainer(RuleKeyHasher.Container.MAP, 42).hash(), newCountHasher().putContainer(RuleKeyHasher.Container.MAP, 42).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.SUPPLIER).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.OPTIONAL).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_LEFT).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.EITHER_RIGHT).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.BUILD_RULE).hash());
    assertEquals(newGuavaHasher().putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).hash(), newCountHasher().putWrapper(RuleKeyHasher.Wrapper.APPENDABLE).hash());
}
Also used : SourceRoot(com.facebook.buck.rules.SourceRoot) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Example 4 with SourceRoot

use of com.facebook.buck.rules.SourceRoot in project buck by facebook.

the class DefaultRuleKeyFactoryTest method testBothKeysAndValuesGetHashed.

@Test
public void testBothKeysAndValuesGetHashed() {
    assertKeysGetHashed(null);
    assertBothKeysAndValuesGetHashed(true, false);
    assertBothKeysAndValuesGetHashed((double) 123, (double) 42);
    assertBothKeysAndValuesGetHashed((float) 123, (float) 42);
    // (int)
    assertBothKeysAndValuesGetHashed(123, 42);
    assertBothKeysAndValuesGetHashed((long) 123, (long) 42);
    assertBothKeysAndValuesGetHashed((short) 123, (short) 42);
    assertBothKeysAndValuesGetHashed((byte) 123, (byte) 42);
    assertBothKeysAndValuesGetHashed(new byte[] { 1, 2, 3 }, new byte[] { 4, 2 });
    assertBothKeysAndValuesGetHashed(DummyEnum.BLACK, DummyEnum.WHITE);
    assertBothKeysAndValuesGetHashed("abc", "def");
    assertBothKeysAndValuesGetHashed(Pattern.compile("regex1"), Pattern.compile("regex2"));
    assertBothKeysAndValuesGetHashed(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"), Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd"));
    assertBothKeysAndValuesGetHashed(new RuleKey("a002b39af204cdfaa5fdb67816b13867c32ac52c"), new RuleKey("b67816b13867c32ac52ca002b39af204cdfaa5fd"));
    assertBothKeysAndValuesGetHashed(BuildRuleType.of("rule_type"), BuildRuleType.of("type2"));
    assertBothKeysAndValuesGetHashed(BuildTargetFactory.newInstance(Paths.get("/root"), "//example/base:one"), BuildTargetFactory.newInstance(Paths.get("/root"), "//example/base:two"));
    assertBothKeysAndValuesGetHashed(new SourceRoot("root1"), new SourceRoot("root2"));
    // wrapper types
    assertBothKeysAndValuesGetHashed(Optional.of("abc"), Optional.of("def"));
    assertBothKeysAndValuesGetHashed(Either.ofLeft("abc"), Either.ofLeft("def"));
    assertBothKeysAndValuesGetHashed(Either.ofRight("def"), Either.ofRight("ghi"));
    assertBothKeysAndValuesGetHashed(Suppliers.ofInstance("abc"), Suppliers.ofInstance("def"));
    // iterables & maps
    assertBothKeysAndValuesGetHashed(Arrays.asList(1, 2, 3), Arrays.asList(4, 2));
    assertBothKeysAndValuesGetHashed(ImmutableList.of("abc", "xy"), ImmutableList.of("xy", "abc"));
    assertBothKeysAndValuesGetHashed(ImmutableMap.of("key", "v1"), ImmutableMap.of("key", "v2"));
    // nested
    assertBothKeysAndValuesGetHashed(ImmutableMap.of("key", Optional.of(ImmutableList.of(1, 2, 3))), ImmutableMap.of("key", Optional.of(ImmutableList.of(1, 2, 4))));
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) SourceRoot(com.facebook.buck.rules.SourceRoot) Test(org.junit.Test)

Example 5 with SourceRoot

use of com.facebook.buck.rules.SourceRoot in project buck by facebook.

the class AbstractRuleKeyHasherTest method testConsistency.

@Test
public void testConsistency() {
    // same sequence of operations should produce the same hash
    assertEquals(newHasher().hash(), newHasher().hash());
    assertEquals(newHasher().putKey("abc").hash(), newHasher().putKey("abc").hash());
    assertEquals(newHasher().putNull().hash(), newHasher().putNull().hash());
    assertEquals(newHasher().putBoolean(false).hash(), newHasher().putBoolean(false).hash());
    assertEquals(newHasher().putBoolean(true).hash(), newHasher().putBoolean(true).hash());
    assertEquals(newHasher().putNumber(4).hash(), newHasher().putNumber(4).hash());
    assertEquals(newHasher().putNumber((long) 4).hash(), newHasher().putNumber((long) 4).hash());
    assertEquals(newHasher().putNumber((short) 4).hash(), newHasher().putNumber((short) 4).hash());
    assertEquals(newHasher().putNumber((byte) 4).hash(), newHasher().putNumber((byte) 4).hash());
    assertEquals(newHasher().putNumber((float) 4).hash(), newHasher().putNumber((float) 4).hash());
    assertEquals(newHasher().putNumber((double) 4).hash(), newHasher().putNumber((double) 4).hash());
    assertEquals(newHasher().putBytes(new byte[] { 42 }).hash(), newHasher().putBytes(new byte[] { 42 }).hash());
    assertEquals(newHasher().putPattern(Pattern.compile("42")).hash(), newHasher().putPattern(Pattern.compile("42")).hash());
    assertEquals(newHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash(), newHasher().putPath(Paths.get("42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash(), newHasher().putArchiveMemberPath(newArchiveMember("42/42", "42/42"), HashCode.fromInt(42)).hash());
    assertEquals(newHasher().putNonHashingPath("42").hash(), newHasher().putNonHashingPath("42").hash());
    assertEquals(newHasher().putSourceRoot(new SourceRoot("42")).hash(), newHasher().putSourceRoot(new SourceRoot("42")).hash());
    assertEquals(newHasher().putRuleKey(RULE_KEY_1).hash(), newHasher().putRuleKey(RULE_KEY_1).hash());
    assertEquals(newHasher().putBuildRuleType(BuildRuleType.of("42")).hash(), newHasher().putBuildRuleType(BuildRuleType.of("42")).hash());
    assertEquals(newHasher().putBuildTarget(TARGET_1).hash(), newHasher().putBuildTarget(TARGET_1).hash());
    assertEquals(newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash(), newHasher().putBuildTargetSourcePath(new DefaultBuildTargetSourcePath(TARGET_1)).hash());
}
Also used : SourceRoot(com.facebook.buck.rules.SourceRoot) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) Test(org.junit.Test)

Aggregations

SourceRoot (com.facebook.buck.rules.SourceRoot)6 Test (org.junit.Test)5 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)4 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)1 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 RuleKey (com.facebook.buck.rules.RuleKey)1 SourcePath (com.facebook.buck.rules.SourcePath)1 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)1 HashCode (com.google.common.hash.HashCode)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1