Пример #1
0
  private JavaBinaryRule createSampleJavaBinaryRule(BuildRuleResolver ruleResolver) {
    // Create a java_binary that depends on a java_library so it is possible to create a
    // java_binary rule with a classpath entry and a main class.
    JavaLibraryRule javaLibrary =
        ruleResolver.buildAndAddToIndex(
            DefaultJavaLibraryRule.newJavaLibraryRuleBuilder(
                    new FakeAbstractBuildRuleBuilderParams())
                .setBuildTarget(BuildTargetFactory.newInstance("//java/com/facebook/util:util"))
                .addVisibilityPattern(BuildTargetPattern.MATCH_ALL)
                .addSrc("java/com/facebook/util/ManifestGenerator.java"));

    JavaBinaryRule javaBinary =
        ruleResolver.buildAndAddToIndex(
            JavaBinaryRule.newJavaBinaryRuleBuilder(new FakeAbstractBuildRuleBuilderParams())
                .setBuildTarget(
                    BuildTargetFactory.newInstance("//java/com/facebook/util:ManifestGenerator"))
                .setMainClass("com.facebook.util.ManifestGenerator")
                .addDep(javaLibrary.getBuildTarget()));

    return javaBinary;
  }
Пример #2
0
  @Test
  public void testBasicProjectCommand() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver();

    BuildTarget javaLibraryTargetName = BuildTargetFactory.newInstance("//javasrc:java-library");
    DefaultJavaLibraryRule javaLibraryRule =
        ruleResolver.buildAndAddToIndex(
            DefaultJavaLibraryRule.newJavaLibraryRuleBuilder(
                    new FakeAbstractBuildRuleBuilderParams())
                .setBuildTarget(javaLibraryTargetName)
                .addSrc("javasrc/JavaLibrary.java"));

    String projectConfigTargetName = "//javasrc:project-config";
    ProjectConfigRule ruleConfig =
        ruleResolver.buildAndAddToIndex(
            ProjectConfigRule.newProjectConfigRuleBuilder(new FakeAbstractBuildRuleBuilderParams())
                .setBuildTarget(BuildTargetFactory.newInstance(projectConfigTargetName))
                .setSrcTarget(Optional.of(javaLibraryTargetName)));

    BuckConfig buckConfig =
        createBuckConfig(
            Joiner.on("\n").join("[project]", "initial_targets = " + javaLibraryTargetName));

    ProjectCommandForTest command = new ProjectCommandForTest();
    command.createPartialGraphCallReturnValues.push(
        createGraphFromBuildRules(ImmutableList.<BuildRule>of(ruleConfig)));

    command.runCommandWithOptions(createOptions(buckConfig));

    assertTrue(command.createPartialGraphCallReturnValues.isEmpty());

    // The PartialGraph comprises build config rules.
    RawRulePredicate projectConfigPredicate = command.createPartialGraphCallPredicates.get(0);
    checkPredicate(projectConfigPredicate, EMPTY_PARSE_DATA, javaLibraryRule, false);
    checkPredicate(projectConfigPredicate, EMPTY_PARSE_DATA, ruleConfig, true);

    BuildCommandOptions buildOptions = command.buildCommandOptions;
    MoreAsserts.assertContainsOne(
        buildOptions.getArguments(), javaLibraryTargetName.getFullyQualifiedName());
  }