com.google.common.collect.ImmutableCollection.Builder Java Examples

The following examples show how to use com.google.common.collect.ImmutableCollection.Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NdkLibraryDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    NdkLibraryDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  toolchainProvider
      .getByNameIfPresent(
          NdkCxxPlatformsProvider.DEFAULT_NAME,
          buildTarget.getTargetConfiguration(),
          NdkCxxPlatformsProvider.class)
      .ifPresent(
          ndkCxxPlatformsProvider ->
              ndkCxxPlatformsProvider
                  .getNdkCxxPlatforms()
                  .values()
                  .forEach(
                      platform ->
                          extraDepsBuilder.addAll(
                              platform.getParseTimeDeps(buildTarget.getTargetConfiguration()))));
}
 
Example #2
Source File: JavaLibraryDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    JavaLibraryDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, constructorArg, buildTarget.getTargetConfiguration());

  unresolvedInferPlatform(toolchainProvider, buildTarget.getTargetConfiguration())
      .ifPresent(
          p ->
              UnresolvedInferPlatform.addParseTimeDepsToInferFlavored(
                  targetGraphOnlyDepsBuilder, buildTarget, p));
}
 
Example #3
Source File: GoLibraryDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    GoLibraryDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  GoToolchain toolchain = getGoToolchain(buildTarget.getTargetConfiguration());
  toolchain
      .getPlatformFlavorDomain()
      .getValue(buildTarget)
      .ifPresent(
          platform ->
              targetGraphOnlyDepsBuilder.addAll(
                  CxxPlatforms.getParseTimeDeps(
                      buildTarget.getTargetConfiguration(), platform.getCxxPlatform())));
}
 
Example #4
Source File: GroovyLibraryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractGroovyLibraryDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  compilerFactory.addTargetDeps(
      buildTarget.getTargetConfiguration(), extraDepsBuilder, targetGraphOnlyDepsBuilder);
}
 
Example #5
Source File: AndroidInstrumentationApkDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AndroidInstrumentationApkDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, null, buildTarget.getTargetConfiguration());
  AndroidTools.addParseTimeDepsToAndroidTools(
      toolchainProvider, buildTarget, targetGraphOnlyDepsBuilder);
}
 
Example #6
Source File: AndroidPrebuiltAarDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AndroidPrebuiltAarDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, null, buildTarget.getTargetConfiguration());
  AndroidTools.addParseTimeDepsToAndroidTools(
      toolchainProvider, buildTarget, targetGraphOnlyDepsBuilder);
}
 
Example #7
Source File: AndroidInstrumentationTestDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AndroidInstrumentationTestDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javaOptions
      .apply(buildTarget.getTargetConfiguration())
      .addParseTimeDeps(targetGraphOnlyDepsBuilder, buildTarget.getTargetConfiguration());
}
 
Example #8
Source File: AndroidAarDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AndroidAarDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, null, buildTarget.getTargetConfiguration());
}
 
Example #9
Source File: NdkLibraryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected ImmutableSortedSet<SourcePath> findSources(
    ProjectFilesystem filesystem, Path buildRulePath) {
  ImmutableSortedSet.Builder<SourcePath> srcs = ImmutableSortedSet.naturalOrder();

  try {
    Path rootDirectory = filesystem.resolve(buildRulePath);
    Files.walkFileTree(
        rootDirectory,
        EnumSet.of(FileVisitOption.FOLLOW_LINKS),
        /* maxDepth */ Integer.MAX_VALUE,
        new SimpleFileVisitor<Path>() {
          @Override
          public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
              throws IOException {
            if (EXTENSIONS_REGEX.matcher(file.toString()).matches()) {
              srcs.add(
                  PathSourcePath.of(
                      filesystem, buildRulePath.resolve(rootDirectory.relativize(file))));
            }

            return super.visitFile(file, attrs);
          }
        });
  } catch (IOException e) {
    throw new RuntimeException(e);
  }

  return srcs.build();
}
 
Example #10
Source File: NdkLibraryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
private Iterable<String> escapeForMakefile(
    ProjectFilesystem filesystem, boolean escapeInQuotes, Iterable<String> args) {
  ImmutableList.Builder<String> escapedArgs = ImmutableList.builder();

  for (String arg : args) {
    String escapedArg = arg;

    // The ndk-build makefiles make heavy use of the "eval" function to propagate variables,
    // which means we need to perform additional makefile escaping for *every* "eval" that
    // gets used.  Turns out there are three "evals", so we escape a total of four times
    // including the initial escaping.  Since the makefiles eventually hand-off these values
    // to the shell, we first perform bash escaping.
    //
    // Additionally to that Android NDK 16 has a fix that changes the escaping logic for some of
    // the flags, but not for all of them. This means some flags needs to be escaped with the old
    // logic (4 escapes) while other flags must be escaped using a simpler approach.
    // Github issue with the fix: https://github.com/android-ndk/ndk/issues/161

    escapedArg = Escaper.escapeAsShellString(escapedArg);

    if (escapeInQuotes) {
      escapedArg = Escaper.escapeWithQuotesAsMakefileValueString(escapedArg);
    } else {
      for (int i = 0; i < 4; i++) {
        escapedArg = Escaper.escapeAsMakefileValueString(escapedArg);
      }
    }

    // We run ndk-build from the root of the NDK, so fixup paths that use the relative path to
    // the buck out directory.
    if (arg.startsWith(filesystem.getBuckPaths().getBuckOut().toString())) {
      escapedArg = "$(BUCK_PROJECT_DIR)/" + escapedArg;
    }

    escapedArgs.add(escapedArg);
  }

  return escapedArgs.build();
}
 
Example #11
Source File: GwtBinaryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    GwtBinaryDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javaOptions
      .apply(buildTarget.getTargetConfiguration())
      .addParseTimeDeps(targetGraphOnlyDepsBuilder, buildTarget.getTargetConfiguration());
}
 
Example #12
Source File: GoLibraryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public BuildRule createBuildRule(
    BuildRuleCreationContextWithTargetGraph context,
    BuildTarget buildTarget,
    BuildRuleParams params,
    GoLibraryDescriptionArg args) {
  GoToolchain goToolchain = getGoToolchain(buildTarget.getTargetConfiguration());
  Optional<GoPlatform> platform = goToolchain.getPlatformFlavorDomain().getValue(buildTarget);
  ProjectFilesystem projectFilesystem = context.getProjectFilesystem();

  if (platform.isPresent()) {
    return GoDescriptors.createGoCompileRule(
        buildTarget,
        projectFilesystem,
        params,
        context.getActionGraphBuilder(),
        goBuckConfig,
        args.getPackageName()
            .map(Paths::get)
            .orElse(goBuckConfig.getDefaultPackageName(buildTarget)),
        args.getSrcs(),
        args.getCompilerFlags(),
        args.getAssemblerFlags(),
        platform.get(),
        new ImmutableList.Builder<BuildTarget>()
            .addAll(
                params.getDeclaredDeps().get().stream().map(BuildRule::getBuildTarget).iterator())
            .addAll(args.getExportedDeps())
            .build(),
        ImmutableList.of(),
        Collections.singletonList(ListType.GoFiles));
  }

  return new GoLibrary(buildTarget, projectFilesystem, params, args.getSrcs());
}
 
Example #13
Source File: CollectionUtils.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static <T> Collection<Tuple2<T, T>> crossProduct(List<T> list) {
	Builder<Tuple2<T, T>> result = ImmutableList.builder();
	int size = list.size();
	for (int i = 0; i < size; i++) {
		T left = list.get(i);
		Iterable<T> remaining = list.subList(i, size);
		Seq.of(left)
			.crossJoin(remaining)
			.forEach(result::add);
	}
	return result.build();
}
 
Example #14
Source File: GroovyLibraryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public BuildRule createBuildRule(
    BuildRuleCreationContextWithTargetGraph context,
    BuildTarget buildTarget,
    BuildRuleParams params,
    GroovyLibraryDescriptionArg args) {
  ActionGraphBuilder graphBuilder = context.getActionGraphBuilder();
  ProjectFilesystem projectFilesystem = context.getProjectFilesystem();
  JavacOptions javacOptions =
      JavacOptionsFactory.create(
          toolchainProvider
              .getByName(
                  JavacOptionsProvider.DEFAULT_NAME,
                  buildTarget.getTargetConfiguration(),
                  JavacOptionsProvider.class)
              .getJavacOptions(),
          buildTarget,
          graphBuilder,
          args);
  DefaultJavaLibraryRules defaultJavaLibraryRules =
      new DefaultJavaLibraryRules.Builder(
              buildTarget,
              projectFilesystem,
              context.getToolchainProvider(),
              params,
              graphBuilder,
              compilerFactory,
              javaBuckConfig,
              args)
          .setJavacOptions(javacOptions)
          .build();

  return JavaAbis.isAbiTarget(buildTarget)
      ? defaultJavaLibraryRules.buildAbi()
      : graphBuilder.addToIndex(defaultJavaLibraryRules.buildLibrary());
}
 
Example #15
Source File: JarGenruleDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    JarGenruleDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javaOptions
      .apply(buildTarget.getTargetConfiguration())
      .addParseTimeDeps(targetGraphOnlyDepsBuilder, buildTarget.getTargetConfiguration());
}
 
Example #16
Source File: JavaTestRunnerDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    JavaTestRunnerDescriptionArg constructorArg,
    Builder<BuildTarget> extraDepsBuilder,
    Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, constructorArg, buildTarget.getTargetConfiguration());
}
 
Example #17
Source File: StateSystem.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public List<@NonNull Integer> getQuarks(int startingNodeQuark, String... pattern) {
    Builder<@NonNull Integer> builder = ImmutableSet.builder();
    if (pattern.length > 0) {
        getQuarks(builder, startingNodeQuark, Arrays.asList(pattern));
    } else {
        builder.add(startingNodeQuark);
    }
    return builder.build().asList();
}
 
Example #18
Source File: ImmutableSortedSetDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected Builder<Object> createBuilder() {
    /* Not quite sure what to do with sorting/ordering; may require better support either
     * via annotations, or via custom serialization (bean style that includes ordering
     * aspects)
     */
    @SuppressWarnings("rawtypes")
    ImmutableSortedSet.Builder<?> builderComp = ImmutableSortedSet.<Comparable> naturalOrder();
    ImmutableSortedSet.Builder<Object> builder = (ImmutableSortedSet.Builder<Object>) builderComp;
    return builder;
}
 
Example #19
Source File: ImmutableSortedMultisetDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 5 votes vote down vote up
@Override
protected Builder<Object> createBuilder() {
    /* This is suboptimal. See the considerations in ImmutableSortedSetDeserializer. */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    Builder<Object> builder =  (Builder) ImmutableSortedMultiset.naturalOrder();
    return builder;
}
 
Example #20
Source File: GwtBinaryDescription.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public BuildRule createBuildRule(
    BuildRuleCreationContextWithTargetGraph context,
    BuildTarget buildTarget,
    BuildRuleParams params,
    GwtBinaryDescriptionArg args) {

  ActionGraphBuilder graphBuilder = context.getActionGraphBuilder();

  ImmutableSortedSet.Builder<BuildRule> extraDeps = ImmutableSortedSet.naturalOrder();

  // Find all of the reachable JavaLibrary rules and grab their associated GwtModules.
  ImmutableSortedSet.Builder<SourcePath> gwtModuleJarsBuilder = ImmutableSortedSet.naturalOrder();
  ImmutableSortedSet<BuildRule> moduleDependencies =
      graphBuilder.getAllRules(args.getModuleDeps());
  new AbstractBreadthFirstTraversal<BuildRule>(moduleDependencies) {
    @Override
    public Iterable<BuildRule> visit(BuildRule rule) {
      if (!(rule instanceof JavaLibrary)) {
        return ImmutableSet.of();
      }

      JavaLibrary javaLibrary = (JavaLibrary) rule;
      Iterable<BuildRule> ruleDeps = javaLibrary.getDepsForTransitiveClasspathEntries();

      // If the java library doesn't generate any output, it doesn't contribute a GwtModule
      if (javaLibrary.getSourcePathToOutput() == null) {
        return ruleDeps;
      }

      BuildRule gwtModule =
          graphBuilder.computeIfAbsent(
              javaLibrary
                  .getBuildTarget()
                  .assertUnflavored()
                  .withFlavors(JavaLibrary.GWT_MODULE_FLAVOR),
              gwtModuleTarget -> {
                ImmutableSortedSet<SourcePath> filesForGwtModule =
                    ImmutableSortedSet.<SourcePath>naturalOrder()
                        .addAll(javaLibrary.getSources())
                        .addAll(javaLibrary.getResources())
                        .build();
                ImmutableSortedSet<BuildRule> deps =
                    ImmutableSortedSet.copyOf(
                        graphBuilder.filterBuildRuleInputs(filesForGwtModule));

                return new GwtModule(
                    gwtModuleTarget,
                    context.getProjectFilesystem(),
                    params.withDeclaredDeps(deps).withoutExtraDeps(),
                    graphBuilder,
                    filesForGwtModule,
                    javaLibrary.getResourcesRoot());
              });

      extraDeps.add(gwtModule);
      gwtModuleJarsBuilder.add(Objects.requireNonNull(gwtModule.getSourcePathToOutput()));

      Optional<SourcePath> generatedCode = javaLibrary.getGeneratedAnnotationSourcePath();
      if (generatedCode.isPresent()) {
        extraDeps.add(javaLibrary);
        gwtModuleJarsBuilder.add(generatedCode.get());
      }

      // Traverse all of the deps of this rule.
      return ruleDeps;
    }
  }.start();

  return new GwtBinary(
      buildTarget,
      context.getProjectFilesystem(),
      params.withExtraDeps(extraDeps.build()),
      args.getModules(),
      javaOptions
          .apply(buildTarget.getTargetConfiguration())
          .getJavaRuntimeLauncher(graphBuilder, buildTarget.getTargetConfiguration()),
      args.getVmArgs(),
      args.getStyle().orElse(DEFAULT_STYLE),
      args.getDraftCompile().orElse(DEFAULT_DRAFT_COMPILE),
      args.getOptimize().orElse(DEFAULT_OPTIMIZE),
      args.getLocalWorkers().orElse(DEFAULT_NUM_LOCAL_WORKERS),
      args.getStrict().orElse(DEFAULT_STRICT),
      args.getExperimentalArgs(),
      gwtModuleJarsBuilder.build());
}
 
Example #21
Source File: ExternalJavacProvider.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public void addParseTimeDeps(Builder<BuildTarget> depsConsumer) {
  if (javacPath instanceof BuildTargetSourcePath) {
    depsConsumer.add(((BuildTargetSourcePath) javacPath).getTarget());
  }
}
 
Example #22
Source File: ImmutableMultisetDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
@Override
protected Builder<Object> createBuilder() {
    return ImmutableMultiset.builder();
}
 
Example #23
Source File: ImmutableSetDeserializer.java    From jackson-datatypes-collections with Apache License 2.0 4 votes vote down vote up
@Override
protected Builder<Object> createBuilder() {
    return ImmutableSet.builder();
}