Esempio n. 1
0
 @Override
 public ImmutableSetMultimap<JavaLibraryRule, String> getTransitiveClasspathEntries() {
   return Classpaths.getClasspathEntries(getDeps());
 }
Esempio n. 2
0
  @Override
  public <A extends Args> BuildRule createBuildRule(
      TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) {

    SourcePathResolver pathResolver = new SourcePathResolver(resolver);
    ImmutableMap<String, SourcePath> nativeLibraries =
        JavaLibraryRules.getNativeLibraries(targetGraph, params.getDeps(), cxxPlatform);
    BuildRuleParams binaryParams = params;

    // If we're packaging native libraries, we'll build the binary JAR in a separate rule and
    // package it into the final fat JAR, so adjust it's params to use a flavored target.
    if (!nativeLibraries.isEmpty()) {
      binaryParams =
          params.copyWithChanges(
              BuildTarget.builder(params.getBuildTarget())
                  .addFlavors(FAT_JAR_INNER_JAR_FLAVOR)
                  .build(),
              params.getDeclaredDeps(),
              params.getExtraDeps());
    }

    // Construct the build rule to build the binary JAR.
    ImmutableSetMultimap<JavaLibrary, Path> transitiveClasspathEntries =
        Classpaths.getClasspathEntries(binaryParams.getDeps());
    BuildRule rule =
        new JavaBinary(
            binaryParams.appendExtraDeps(transitiveClasspathEntries.keys()),
            pathResolver,
            args.mainClass.orNull(),
            args.manifestFile.orNull(),
            args.mergeManifests.or(true),
            args.metaInfDirectory.orNull(),
            args.blacklist.or(ImmutableSortedSet.<String>of()),
            new DefaultDirectoryTraverser(),
            transitiveClasspathEntries,
            javaBinOverride);

    // If we're packaging native libraries, construct the rule to build the fat JAR, which packages
    // up the original binary JAR and any required native libraries.
    if (!nativeLibraries.isEmpty()) {
      BuildRule innerJarRule = rule;
      resolver.addToIndex(innerJarRule);
      SourcePath innerJar = new BuildTargetSourcePath(innerJarRule.getBuildTarget());
      rule =
          new JarFattener(
              params.appendExtraDeps(
                  Suppliers.<Iterable<BuildRule>>ofInstance(
                      pathResolver.filterBuildRuleInputs(
                          ImmutableList.<SourcePath>builder()
                              .add(innerJar)
                              .addAll(nativeLibraries.values())
                              .build()))),
              pathResolver,
              javacOptions,
              innerJar,
              nativeLibraries,
              javaBinOverride);
    }

    return rule;
  }