コード例 #1
0
 public void testSourceFilesAreCorrectlyMarkedAsSourceOrGenerated() throws Exception {
   scratch.file(
       "com/google/example/BUILD",
       "genrule(",
       "   name = 'gen',",
       "   outs = ['gen.java'],",
       "   cmd = '',",
       ")",
       "java_library(",
       "    name = 'lib',",
       "    srcs = ['Test.java', ':gen'],",
       ")");
   Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:lib");
   RuleIdeInfo ruleIdeInfo = getRuleInfoAndVerifyLabel("//com/google/example:lib", ruleIdeInfos);
   assertThat(ruleIdeInfo.getJavaRuleIdeInfo().getSourcesList())
       .containsExactly(
           ArtifactLocation.newBuilder()
               .setRootPath(targetConfig.getGenfilesDirectory().getPath().getPathString())
               .setRelativePath("com/google/example/gen.java")
               .setIsSource(false)
               .build(),
           ArtifactLocation.newBuilder()
               .setRootPath(directories.getWorkspace().getPathString())
               .setRelativePath("com/google/example/Test.java")
               .setIsSource(true)
               .build());
 }
コード例 #2
0
  public void testJavaBinary() throws Exception {
    scratch.file(
        "com/google/example/BUILD",
        "java_library(",
        "   name = 'foobar',",
        "   srcs = ['FooBar.java'],",
        ")",
        "java_binary(",
        "   name = 'foobar-exe',",
        "   main_class = 'MyMainClass',",
        "   srcs = ['FooBarMain.java'],",
        "   deps = [':foobar'],",
        ")");
    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:foobar-exe");
    RuleIdeInfo binaryInfo =
        getRuleInfoAndVerifyLabel("//com/google/example:foobar-exe", ruleIdeInfos);
    assertThat(binaryInfo.getKind()).isEqualTo(Kind.JAVA_BINARY);
    assertThat(relativePathsForSourcesOf(binaryInfo))
        .containsExactly("com/google/example/FooBarMain.java");
    assertThat(binaryInfo.getDependenciesList()).containsExactly("//com/google/example:foobar");
    assertThat(transform(binaryInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString("com/google/example", "foobar-exe.jar", null, "foobar-exe-src.jar"));

    assertThat(getIdeResolveFiles())
        .containsExactly(
            "com/google/example/libfoobar.jar",
            "com/google/example/libfoobar-ijar.jar",
            "com/google/example/libfoobar-src.jar",
            "com/google/example/foobar-exe.jar",
            "com/google/example/foobar-exe-src.jar");
  }
コード例 #3
0
  public void testJavaLibraryWithGeneratedSourcesHasGenJars() throws Exception {
    scratch.file(
        "java/com/google/example/BUILD",
        "java_library(",
        "  name = 'test',",
        "  srcs = ['Test.java'],",
        "  plugins = [':plugin']",
        ")",
        "java_plugin(",
        "  name = 'plugin',",
        "  processor_class = 'com.google.example.Plugin',",
        "  deps = ['plugin_lib'],",
        ")",
        "java_library(",
        "  name = 'plugin_lib',",
        "  srcs = ['Plugin.java'],",
        ")");
    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//java/com/google/example:test");
    RuleIdeInfo ruleIdeInfo =
        getRuleInfoAndVerifyLabel("//java/com/google/example:test", ruleIdeInfos);

    assertThat(
            transform(
                ruleIdeInfo.getJavaRuleIdeInfo().getGeneratedJarsList(),
                LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString("java/com/google/example", "libtest-gen.jar", null, "libtest-gensrc.jar"));
    assertThat(getIdeResolveFiles())
        .containsExactly(
            "java/com/google/example/libtest.jar",
            "java/com/google/example/libtest-ijar.jar",
            "java/com/google/example/libtest-src.jar",
            "java/com/google/example/libtest-gen.jar",
            "java/com/google/example/libtest-gensrc.jar");
  }
コード例 #4
0
  public void testJavaTest() throws Exception {
    scratch.file(
        "java/com/google/example/BUILD",
        "java_library(",
        "   name = 'foobar',",
        "   srcs = ['FooBar.java'],",
        ")",
        "java_test(",
        "   name = 'FooBarTest',",
        "   srcs = ['FooBarTest.java'],",
        "   deps = [':foobar'],",
        ")");
    Map<String, RuleIdeInfo> ruleIdeInfos =
        buildRuleIdeInfo("//java/com/google/example:FooBarTest");
    RuleIdeInfo testInfo =
        getRuleInfoAndVerifyLabel("//java/com/google/example:FooBarTest", ruleIdeInfos);
    assertThat(testInfo.getKind()).isEqualTo(Kind.JAVA_TEST);
    assertThat(relativePathsForSourcesOf(testInfo))
        .containsExactly("java/com/google/example/FooBarTest.java");
    assertThat(testInfo.getDependenciesList()).containsExactly("//java/com/google/example:foobar");
    assertThat(transform(testInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString("java/com/google/example", "FooBarTest.jar", null, "FooBarTest-src.jar"));

    assertThat(getIdeResolveFiles())
        .containsExactly(
            "java/com/google/example/libfoobar.jar",
            "java/com/google/example/libfoobar-ijar.jar",
            "java/com/google/example/libfoobar-src.jar",
            "java/com/google/example/FooBarTest.jar",
            "java/com/google/example/FooBarTest-src.jar");
  }
コード例 #5
0
  public void testSimpleJavaLibrary() throws Exception {
    Path buildFilePath =
        scratch.file(
            "com/google/example/BUILD",
            "java_library(",
            "    name = 'simple',",
            "    srcs = ['simple/Simple.java']",
            ")");
    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:simple");
    assertThat(ruleIdeInfos.size()).isEqualTo(1);
    RuleIdeInfo ruleIdeInfo =
        getRuleInfoAndVerifyLabel("//com/google/example:simple", ruleIdeInfos);
    assertThat(ruleIdeInfo.getBuildFile()).isEqualTo(buildFilePath.toString());
    assertThat(ruleIdeInfo.getKind()).isEqualTo(Kind.JAVA_LIBRARY);
    assertThat(ruleIdeInfo.getDependenciesCount()).isEqualTo(0);
    assertThat(relativePathsForSourcesOf(ruleIdeInfo))
        .containsExactly("com/google/example/simple/Simple.java");
    assertThat(
            transform(ruleIdeInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString(
                "com/google/example", "libsimple.jar", "libsimple-ijar.jar", "libsimple-src.jar"));

    assertThat(getIdeResolveFiles())
        .containsExactly(
            "com/google/example/libsimple.jar",
            "com/google/example/libsimple-ijar.jar",
            "com/google/example/libsimple-src.jar");
  }
コード例 #6
0
  public void testJavaImport() throws Exception {
    scratch.file(
        "com/google/example/BUILD",
        "java_import(",
        "   name = 'imp',",
        "   jars = ['a.jar', 'b.jar'],",
        "   srcjar = 'impsrc.jar',",
        ")",
        "java_library(",
        "   name = 'lib',",
        "   srcs = ['Lib.java'],",
        "   deps = [':imp'],",
        ")");

    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:lib");
    final RuleIdeInfo libInfo = getRuleInfoAndVerifyLabel("//com/google/example:lib", ruleIdeInfos);
    RuleIdeInfo impInfo = getRuleInfoAndVerifyLabel("//com/google/example:imp", ruleIdeInfos);
    assertThat(impInfo.getKind()).isEqualTo(Kind.JAVA_IMPORT);
    assertThat(libInfo.getDependenciesList()).containsExactly("//com/google/example:imp");

    JavaRuleIdeInfo javaRuleIdeInfo = impInfo.getJavaRuleIdeInfo();
    assertThat(javaRuleIdeInfo).isNotNull();
    assertThat(transform(javaRuleIdeInfo.getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString("com/google/example", "a.jar", null, "impsrc.jar"),
            jarString("com/google/example", "b.jar", null, "impsrc.jar"))
        .inOrder();

    assertThat(getIdeResolveFiles())
        .containsExactly(
            "com/google/example/liblib.jar",
            "com/google/example/liblib-ijar.jar",
            "com/google/example/liblib-src.jar");
  }
コード例 #7
0
  public void testAndroidBinary() throws Exception {
    scratch.file(
        "com/google/example/BUILD",
        "android_library(",
        "  name = 'l1',",
        "  manifest = 'Manifesto.xml',",
        "  custom_package = 'com.google.example',",
        "  resource_files = ['r1/values/a.xml'],",
        ")",
        "android_binary(",
        "  name = 'b',",
        "  srcs = ['Main.java'],",
        "  deps = [':l1'],",
        "  manifest = 'Abracadabra.xml',",
        "  custom_package = 'com.google.example',",
        "  resource_files = ['res/drawable/a.png', 'res/drawable/b.png'],",
        ")");
    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:b");
    RuleIdeInfo ruleInfo = getRuleInfoAndVerifyLabel("//com/google/example:b", ruleIdeInfos);
    assertThat(ruleInfo.getKind()).isEqualTo(Kind.ANDROID_BINARY);
    assertThat(relativePathsForSourcesOf(ruleInfo)).containsExactly("com/google/example/Main.java");
    assertThat(transform(ruleInfo.getJavaRuleIdeInfo().getJarsList(), LIBRARY_ARTIFACT_TO_STRING))
        .containsExactly(
            jarString("com/google/example", "libb.jar", "libb-ijar.jar", "libb-src.jar"),
            jarString(
                "com/google/example",
                "b_resources.jar",
                "b_resources-ijar.jar",
                "b_resources-src.jar"));
    assertThat(
            transform(
                ruleInfo.getAndroidRuleIdeInfo().getResourcesList(), ARTIFACT_TO_RELATIVE_PATH))
        .containsExactly("com/google/example/res");
    assertThat(ruleInfo.getAndroidRuleIdeInfo().getManifest().getRelativePath())
        .isEqualTo("com/google/example/Abracadabra.xml");
    assertThat(ruleInfo.getAndroidRuleIdeInfo().getJavaPackage()).isEqualTo("com.google.example");
    assertThat(ruleInfo.getAndroidRuleIdeInfo().getApk().getRelativePath())
        .isEqualTo("com/google/example/b.apk");

    assertThat(ruleInfo.getDependenciesList()).containsExactly("//com/google/example:l1");

    assertThat(getIdeResolveFiles())
        .containsExactly(
            "com/google/example/libb.jar",
            "com/google/example/libb-ijar.jar",
            "com/google/example/libb-src.jar",
            "com/google/example/b_resources.jar",
            "com/google/example/b_resources-ijar.jar",
            "com/google/example/b_resources-src.jar",
            "com/google/example/libl1.jar",
            "com/google/example/libl1-src.jar",
            "com/google/example/l1_resources.jar",
            "com/google/example/l1_resources-ijar.jar",
            "com/google/example/l1_resources-src.jar");
  }
コード例 #8
0
  public void testJavaLibraryWithoutGeneratedSourcesHasNoGenJars() throws Exception {
    scratch.file(
        "java/com/google/example/BUILD",
        "java_library(",
        "  name = 'no_plugin',",
        "  srcs = ['Test.java'],",
        ")");
    Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//java/com/google/example:no_plugin");
    RuleIdeInfo ruleIdeInfo =
        getRuleInfoAndVerifyLabel("//java/com/google/example:no_plugin", ruleIdeInfos);

    assertThat(ruleIdeInfo.getJavaRuleIdeInfo().getGeneratedJarsList()).isEmpty();
  }