com.google.common.collect.ImmutableCollection Java Examples

The following examples show how to use com.google.common.collect.ImmutableCollection. 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: NativeLibrariesCompressionSplitterTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
public void splittingByCompression_preM_instantModule() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter(
          ApkGenerationConfiguration.builder().setForInstantAppVariants(true).build());

  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule("testModule", "x86", "lib/x86/libnoname.so"),
              lPlusVariantTargeting()));

  assertThat(splits).hasSize(1);

  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting()).isEqualTo(lPlusVariantTargeting());
  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isTrue();
  assertThat(
          compareManifestMutators(
              moduleSplit.getMasterManifestMutators(), withExtractNativeLibs(false)))
      .isTrue();
}
 
Example #2
Source File: IjSourceRootSimplifierTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testDifferentTypesAreNotMergedIntoParent() {
  IjSourceRootSimplifier simplifier = new IjSourceRootSimplifier(fakePackageFinder());
  IjFolder aSource = buildSourceFolder("a");
  IjFolder aaaSource = buildSourceFolder("a/a/a");
  IjFolder aaaaSource = buildSourceFolder("a/a/a/a");
  IjFolder aabSource = buildSourceFolder("a/a/b");
  IjFolder abSource = buildSourceFolder("a/b");
  IjFolder acTest = buildTestFolder("a/c");
  IjFolder adaTest = buildTestFolder("a/d/a");

  ImmutableCollection<IjFolder> mergedFolders =
      simplifier
          .simplify(
              0,
              ImmutableSet.of(
                  aSource, aaaSource, aaaaSource, aabSource, abSource, acTest, adaTest),
              Paths.get(""),
              ImmutableSet.of())
          .values();

  IjFolder adTest = buildTestFolder("a/d");
  assertThat(mergedFolders, Matchers.containsInAnyOrder(aSource, acTest, adTest));
}
 
Example #3
Source File: IcannReportingStager.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/** Creates and stores activity reports on GCS, returns a list of files stored. */
private ImmutableList<String> stageActivityReports(
    YearMonth yearMonth,
    String subdir,
    String headerRow,
    ImmutableCollection<Map<TableFieldSchema, Object>> rows)
    throws IOException {
  ImmutableList.Builder<String> manifestBuilder = new ImmutableList.Builder<>();
  // Create a report csv for each tld from query table, and upload to GCS
  for (Map<TableFieldSchema, Object> row : rows) {
    // Get the tld (first cell in each row)
    String tld = row.values().iterator().next().toString();
    if (isNullOrEmpty(tld)) {
      throw new RuntimeException("Found an empty row in the activity report table!");
    }
    ImmutableList<String> rowStrings = ImmutableList.of(constructRow(row.values()));
    // Create and upload the activity report with a single row
    manifestBuilder.add(
        saveReportToGcs(
            tld, yearMonth, subdir, createReport(headerRow, rowStrings), ReportType.ACTIVITY));
  }
  return manifestBuilder.build();
}
 
Example #4
Source File: GoTestDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractGoTestDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Add the C/C++ platform parse time deps.
  GoPlatform platform =
      GoDescriptors.getPlatformForRule(
          getGoToolchain(buildTarget.getTargetConfiguration()),
          this.goBuckConfig,
          buildTarget,
          constructorArg);
  targetGraphOnlyDepsBuilder.addAll(
      CxxPlatforms.getParseTimeDeps(
          buildTarget.getTargetConfiguration(), platform.getCxxPlatform()));
}
 
Example #5
Source File: LocationTemplateContext.java    From bazel with Apache License 2.0 6 votes vote down vote up
public LocationTemplateContext(
    TemplateContext delegate,
    RuleContext ruleContext,
    @Nullable ImmutableMap<Label, ImmutableCollection<Artifact>> labelMap,
    boolean execPaths,
    boolean allowData,
    boolean windowsPath) {
  this(
      delegate,
      ruleContext.getLabel(),
      // Use a memoizing supplier to avoid eagerly building the location map.
      Suppliers.memoize(
          () -> LocationExpander.buildLocationMap(ruleContext, labelMap, allowData)),
      execPaths,
      ruleContext.getRule().getPackage().getRepositoryMapping(),
      windowsPath);
}
 
Example #6
Source File: CxxPythonExtensionDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractCxxPythonExtensionDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Get any parse time deps from the C/C++ platforms.
  getCxxPlatforms(buildTarget.getTargetConfiguration())
      .getValues(buildTarget)
      .forEach(
          p -> extraDepsBuilder.addAll(p.getParseTimeDeps(buildTarget.getTargetConfiguration())));

  for (PythonPlatform pythonPlatform :
      getPythonPlatforms(buildTarget.getTargetConfiguration()).getValues()) {
    Optionals.addIfPresent(pythonPlatform.getCxxLibrary(), extraDepsBuilder);
  }
}
 
Example #7
Source File: SearchPath.java    From vespa with Apache License 2.0 6 votes vote down vote up
private Group selectGroup(SearchCluster cluster) {
    if (group != null) {
        Optional<Group> specificGroup = cluster.group(group);
        if (specificGroup.isPresent()) {
            return specificGroup.get();
        } else {
            throw new InvalidSearchPathException("Invalid searchPath, cluster does not have " + (group + 1) + " groups");
        }
    }

    // pick "anything": try to find the first working
    ImmutableCollection<Group> groups = cluster.groups().values();
    for (Group g : groups) {
        if (g.hasSufficientCoverage()) {
            return g;
        }
    }

    // fallback: first
    return groups.iterator().next();
}
 
Example #8
Source File: CxxWriteArgsToFileStep.java    From buck with Apache License 2.0 6 votes vote down vote up
static ImmutableList<String> stringify(
    ImmutableCollection<Arg> args,
    CanonicalCellName currentCellName,
    SourcePathResolverAdapter pathResolver,
    boolean useUnixPathSeparator) {
  ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (Arg arg : args) {
    if (arg instanceof FileListableLinkerInputArg) {
      ((FileListableLinkerInputArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else if (arg instanceof SourcePathArg) {
      ((SourcePathArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else if (arg instanceof CompositeArg) {
      ((CompositeArg) arg)
          .appendToCommandLineRel(
              builder::add, currentCellName, pathResolver, useUnixPathSeparator);
    } else {
      arg.appendToCommandLine(builder::add, pathResolver);
    }
  }
  return builder.build();
}
 
Example #9
Source File: AggregateFuture.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@CanIgnoreReturnValue
@Override
public final boolean cancel(boolean mayInterruptIfRunning) {
  // Must get a reference to the futures before we cancel, as they'll be cleared out.
  RunningState localRunningState = runningState;
  ImmutableCollection<? extends ListenableFuture<? extends InputT>> futures =
      (localRunningState != null) ? localRunningState.futures : null;
  // Cancel all the component futures.
  boolean cancelled = super.cancel(mayInterruptIfRunning);
  // & is faster than the branch required for &&
  if (cancelled & futures != null) {
    for (ListenableFuture<?> future : futures) {
      future.cancel(mayInterruptIfRunning);
    }
  }
  return cancelled;
}
 
Example #10
Source File: CgoLibraryDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    CgoLibraryDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  // Add the C/C++ platform deps.
  GoToolchain toolchain = getGoToolchain(buildTarget.getTargetConfiguration());
  toolchain
      .getPlatformFlavorDomain()
      .getValue(buildTarget)
      .ifPresent(
          platform ->
              targetGraphOnlyDepsBuilder.addAll(
                  CxxPlatforms.getParseTimeDeps(
                      buildTarget.getTargetConfiguration(), platform.getCxxPlatform())));
}
 
Example #11
Source File: AndroidBinaryResourcesGraphEnhancer.java    From buck with Apache License 2.0 6 votes vote down vote up
private PackageStringAssets createPackageStringAssets(
    ImmutableSortedSet<BuildRule> resourceRules,
    ImmutableCollection<BuildRule> rulesWithResourceDirectories,
    FilteredResourcesProvider filteredResourcesProvider,
    AaptOutputInfo aaptOutputInfo) {
  return new PackageStringAssets(
      buildTarget.withAppendedFlavors(
          AndroidBinaryResourcesGraphEnhancer.PACKAGE_STRING_ASSETS_FLAVOR),
      projectFilesystem,
      graphBuilder,
      resourceRules,
      rulesWithResourceDirectories,
      filteredResourcesProvider,
      locales,
      aaptOutputInfo.getPathToRDotTxt());
}
 
Example #12
Source File: AbstractUserManager.java    From LuckPerms with MIT License 6 votes vote down vote up
/**
 * Check whether the user's state indicates that they should be persisted to storage.
 *
 * @param user the user to check
 * @return true if the user should be saved
 */
@Override
public boolean shouldSave(User user) {
    ImmutableCollection<Node> nodes = user.normalData().immutable().values();
    if (nodes.size() != 1) {
        return true;
    }

    Node onlyNode = nodes.iterator().next();
    if (!(onlyNode instanceof InheritanceNode)) {
        return true;
    }

    if (onlyNode.hasExpiry() || !onlyNode.getContexts().isEmpty()) {
        return true;
    }

    if (!((InheritanceNode) onlyNode).getGroupName().equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
        // The user's only node is not the default group one.
        return true;
    }


    // Not in the default primary group
    return !user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME);
}
 
Example #13
Source File: NativeLibsCompressionVariantGeneratorTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
public void variantsWithoutNativeLibs() throws Exception {
  NativeLibsCompressionVariantGenerator nativeLibsCompressionVariantGenerator =
      new NativeLibsCompressionVariantGenerator(
          ApkGenerationConfiguration.builder()
              .setEnableNativeLibraryCompressionSplitter(true)
              .build());

  BundleModule bundleModule =
      new BundleModuleBuilder("testModule")
          .addFile("assets/leftover.txt")
          .addFile("dex/classes.dex")
          .setManifest(androidManifest("com.test.app"))
          .build();

  ImmutableCollection<VariantTargeting> splits =
      nativeLibsCompressionVariantGenerator.generate(bundleModule).collect(toImmutableList());
  assertThat(splits).isEmpty();
}
 
Example #14
Source File: NativeLibrariesCompressionSplitterTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
public void nativeCompressionSplitter_withM_withLibsWithoutExternalStorage() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter();
  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule("testModule", "x86", "lib/x86/libnoname.so"),
              variantSdkTargeting(ANDROID_M_API_VERSION)));

  assertThat(splits).hasSize(1);
  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting())
      .isEqualTo(variantSdkTargeting(ANDROID_M_API_VERSION));

  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isTrue();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
  assertThat(
          compareManifestMutators(
              moduleSplit.getMasterManifestMutators(), withExtractNativeLibs(false)))
      .isTrue();
}
 
Example #15
Source File: NativeLibrariesCompressionSplitterTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
public void nativeCompressionSplitter_withM_withNativeActivities() throws Exception {
  NativeLibrariesCompressionSplitter nativeLibrariesCompressionSplitter =
      new NativeLibrariesCompressionSplitter();
  ImmutableCollection<ModuleSplit> splits =
      nativeLibrariesCompressionSplitter.split(
          ModuleSplit.forNativeLibraries(
              createSingleLibraryModule(
                  "testModule", "x86", "lib/x86/libnoname.so", withNativeActivity("noname")),
              variantSdkTargeting(ANDROID_M_API_VERSION)));

  assertThat(splits).hasSize(1);
  ModuleSplit moduleSplit = Iterables.getOnlyElement(splits);

  assertThat(moduleSplit.getVariantTargeting())
      .isEqualTo(variantSdkTargeting(ANDROID_M_API_VERSION));

  assertThat(extractPaths(moduleSplit.getEntries())).containsExactly("lib/x86/libnoname.so");
  assertThat(moduleSplit.isMasterSplit()).isTrue();
  assertThat(getForceUncompressed(moduleSplit, "lib/x86/libnoname.so")).isFalse();
  assertThat(moduleSplit.getApkTargeting()).isEqualToDefaultInstance();
}
 
Example #16
Source File: ExecutableFinder.java    From buck with Apache License 2.0 6 votes vote down vote up
public Optional<Path> getOptionalExecutable(
    Path suggestedExecutable,
    ImmutableCollection<Path> path,
    ImmutableCollection<String> fileSuffixes) {

  // Fast path out of here.
  if (isExecutable(suggestedExecutable)) {
    return Optional.of(suggestedExecutable);
  }

  Optional<Path> executable =
      FileFinder.getOptionalFile(
          FileFinder.combine(
              /* prefixes */ null,
              suggestedExecutable.toString(),
              ImmutableSet.copyOf(fileSuffixes)),
          path,
          ExecutableFinder::isExecutable);
  LOG.debug("Executable '%s' mapped to '%s'", suggestedExecutable, executable);

  return executable;
}
 
Example #17
Source File: HaskellHaddockDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractHaskellHaddockDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {

  HaskellDescriptionUtils.getParseTimeDeps(
      buildTarget.getTargetConfiguration(),
      ImmutableList.of(getPlatform(buildTarget, constructorArg)),
      targetGraphOnlyDepsBuilder);

  constructorArg
      .getDepsQuery()
      .ifPresent(
          depsQuery ->
              QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery)
                  .forEach(targetGraphOnlyDepsBuilder::add));
}
 
Example #18
Source File: AndroidBinaryResourcesGraphEnhancer.java    From buck with Apache License 2.0 6 votes vote down vote up
private ResourcesFilter createResourcesFilter(
    InternalFlavor flavor,
    AndroidPackageableCollection.ResourceDetails resourceDetails,
    ImmutableSortedSet<BuildRule> resourceRules,
    ImmutableCollection<BuildRule> rulesWithResourceDirectories) {
  return new ResourcesFilter(
      buildTarget.withAppendedFlavors(RESOURCES_FILTER_FLAVOR, flavor),
      projectFilesystem,
      resourceRules,
      rulesWithResourceDirectories,
      graphBuilder,
      resourceDetails.getResourceDirectories(),
      ImmutableSet.copyOf(resourceDetails.getWhitelistedStringDirectories()),
      locales,
      localizedStringFileName,
      resourceCompressionMode,
      resourceFilter,
      postFilterResourcesCmd);
}
 
Example #19
Source File: HaskellGhciDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractHaskellGhciDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {

  HaskellDescriptionUtils.getParseTimeDeps(
      buildTarget.getTargetConfiguration(),
      ImmutableList.of(getPlatform(buildTarget, constructorArg)),
      targetGraphOnlyDepsBuilder);

  constructorArg
      .getDepsQuery()
      .ifPresent(
          depsQuery ->
              QueryUtils.extractParseTimeTargets(buildTarget, cellRoots, depsQuery)
                  .forEach(targetGraphOnlyDepsBuilder::add));
}
 
Example #20
Source File: ScalaTestDescription.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractScalaTestDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  extraDepsBuilder.add(config.getScalaLibraryTarget(buildTarget.getTargetConfiguration()));
  Optionals.addIfPresent(
      config.getScalacTarget(buildTarget.getTargetConfiguration()), extraDepsBuilder);
  javaOptionsForTests
      .apply(buildTarget.getTargetConfiguration())
      .addParseTimeDeps(targetGraphOnlyDepsBuilder, buildTarget.getTargetConfiguration());
  javacFactory.addParseTimeDeps(
      targetGraphOnlyDepsBuilder, constructorArg, buildTarget.getTargetConfiguration());
}
 
Example #21
Source File: LuaBinaryDescription.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void findDepsForTargetFromConstructorArgs(
    BuildTarget buildTarget,
    CellNameResolver cellRoots,
    AbstractLuaBinaryDescriptionArg constructorArg,
    ImmutableCollection.Builder<BuildTarget> extraDepsBuilder,
    ImmutableCollection.Builder<BuildTarget> targetGraphOnlyDepsBuilder) {
  LuaPlatform luaPlatform = getPlatform(buildTarget, constructorArg);
  if (luaPlatform.getPackageStyle() == LuaPlatform.PackageStyle.STANDALONE) {
    extraDepsBuilder.addAll(
        luaPlatform.getPackager().getParseTimeDeps(buildTarget.getTargetConfiguration()));
  }
  extraDepsBuilder.addAll(getNativeStarterDepTargets(luaPlatform));
}
 
Example #22
Source File: QueryResponse.java    From Velocity with MIT License 5 votes vote down vote up
@VisibleForTesting
QueryResponse(String hostname, String gameVersion, String map, int currentPlayers,
    int maxPlayers, String proxyHost, int proxyPort, ImmutableCollection<String> players,
    String proxyVersion, ImmutableCollection<PluginInformation> plugins) {
  this.hostname = hostname;
  this.gameVersion = gameVersion;
  this.map = map;
  this.currentPlayers = currentPlayers;
  this.maxPlayers = maxPlayers;
  this.proxyHost = proxyHost;
  this.proxyPort = proxyPort;
  this.players = players;
  this.proxyVersion = proxyVersion;
  this.plugins = plugins;
}
 
Example #23
Source File: SingularGuavaCollection.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
protected SingularGuavaCollection(final SingularGuavaCollectionBuilder<T, ?, ?> b) {
  com.google.common.collect.ImmutableCollection<java.lang.Object> rawTypes = b.rawTypes == null ? com.google.common.collect.ImmutableList.<java.lang.Object>of() : b.rawTypes.build();
  this.rawTypes = rawTypes;
  com.google.common.collect.ImmutableCollection<Integer> integers = b.integers == null ? com.google.common.collect.ImmutableList.<Integer>of() : b.integers.build();
  this.integers = integers;
  com.google.common.collect.ImmutableCollection<T> generics = b.generics == null ? com.google.common.collect.ImmutableList.<T>of() : b.generics.build();
  this.generics = generics;
  com.google.common.collect.ImmutableCollection<Number> extendsGenerics = b.extendsGenerics == null ? com.google.common.collect.ImmutableList.<Number>of() : b.extendsGenerics.build();
  this.extendsGenerics = extendsGenerics;
}
 
Example #24
Source File: DexCompressionVariantGeneratorTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void variantsGeneration_withDexFile_generatesQVariant() throws Exception {
  DexCompressionVariantGenerator dexCompressionVariantGenerator =
      new DexCompressionVariantGenerator(
          ApkGenerationConfiguration.builder().setEnableDexCompressionSplitter(true).build());
  ImmutableCollection<VariantTargeting> splits =
      dexCompressionVariantGenerator
          .generate(createModuleWithDexFile())
          .collect(toImmutableList());
  assertThat(splits).containsExactly(variantMinSdkTargeting(ANDROID_Q_API_VERSION));
}
 
Example #25
Source File: ScreenDensityResourcesSplitterTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void lowestDensityStylesPinnedToMaster_enabled() throws Exception {
  BundleModule testModule =
      new BundleModuleBuilder("testModule")
          .setResourceTable(
              new ResourceTableBuilder()
                  .addPackage("com.test.app")
                  .addResource(
                      "style",
                      "title_text_size",
                      configValueWithDensity("320dens", Optional.of(XHDPI)),
                      configValueWithDensity("default", Optional.empty()))
                  .build())
          .setManifest(androidManifest("com.test.app"))
          .build();

  ScreenDensityResourcesSplitter splitter =
      new ScreenDensityResourcesSplitter(
          BundleToolVersion.getCurrentVersion(),
          NO_RESOURCES_PINNED_TO_MASTER,
          NO_LOW_DENSITY_CONFIG_PINNED_TO_MASTER,
          /* pinLowestBucketOfStylesToMaster= */ true);

  ImmutableCollection<ModuleSplit> splits = splitter.split(ModuleSplit.forResources(testModule));

  ModuleSplit masterSplit =
      splits.stream().filter(ModuleSplit::isMasterSplit).collect(onlyElement());
  assertThat(extractStyleValues(masterSplit, "title_text_size")).containsExactly("default");

  ModuleSplit xhdpiSplit = extractDensityTargetingModule(splits, DensityAlias.XXHDPI).get();
  assertThat(extractStyleValues(xhdpiSplit, "title_text_size")).containsExactly("320dens");

  Optional<ModuleSplit> mdpiSplit = extractDensityTargetingModule(splits, DensityAlias.MDPI);
  assertThat(mdpiSplit).isEmpty();
}
 
Example #26
Source File: AssembleDirectories.java    From buck with Apache License 2.0 5 votes vote down vote up
public AssembleDirectories(
    BuildTarget buildTarget,
    ProjectFilesystem projectFilesystem,
    SourcePathRuleFinder ruleFinder,
    ImmutableCollection<SourcePath> directories) {
  super(buildTarget, projectFilesystem);
  this.originalDirectories = directories;
  this.destinationDirectory =
      BuildTargetPaths.getGenPath(getProjectFilesystem(), buildTarget, "__assembled_%s__");
  this.buildDepsSupplier =
      MoreSuppliers.memoize(
          () ->
              BuildableSupport.deriveDeps(this, ruleFinder)
                  .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())));
}
 
Example #27
Source File: SameTargetingMergerTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
public void sameSplitTargeting_oneGroup() throws Exception {
  ModuleSplit moduleSplit =
      createModuleSplitBuilder()
          .setEntries(
              ImmutableList.of(createModuleEntryForFile("assets/some_asset.txt", DUMMY_CONTENT)))
          .setApkTargeting(ApkTargeting.getDefaultInstance())
          .build();
  ModuleSplit moduleSplit2 =
      createModuleSplitBuilder()
          .setEntries(
              ImmutableList.of(
                  createModuleEntryForFile("assets/some_other_asset.txt", DUMMY_CONTENT)))
          .setApkTargeting(ApkTargeting.getDefaultInstance())
          .build();

  ImmutableCollection<ModuleSplit> splits =
      new SameTargetingMerger().merge(ImmutableList.of(moduleSplit, moduleSplit2));

  assertThat(splits).hasSize(1);
  ModuleSplit masterSplit = splits.iterator().next();
  assertThat(extractPaths(masterSplit.getEntries()))
      .containsExactly("assets/some_asset.txt", "assets/some_other_asset.txt");
  assertThat(masterSplit.getApkTargeting()).isEqualToDefaultInstance();
  assertThat(masterSplit.getVariantTargeting()).isEqualTo(lPlusVariantTargeting());
  assertThat(masterSplit.getAndroidManifest()).isEqualTo(DEFAULT_MANIFEST);
  assertThat(masterSplit.getResourceTable()).isEmpty();
}
 
Example #28
Source File: IjSourceRootSimplifier.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Merges either SourceFolders or TestFolders with matching packages. */
private Optional<IjFolder> tryCreateNewParentFolderFromChildrenWithPackage(
    FolderTypeWithPackageInfo typeForMerging,
    Path currentPath,
    ImmutableCollection<IjFolder> children) {
  Optional<Path> currentPackage = packagePathCache.lookup(currentPath);
  if (!currentPackage.isPresent()) {
    return Optional.empty();
  }

  Class<? extends IjFolder> folderClass = typeForMerging.getFolderTypeClass();
  ImmutableList<IjFolder> childrenToMerge =
      children.stream()
          .filter(folderClass::isInstance)
          .filter(IjFolder::getWantsPackagePrefix)
          .filter(
              child ->
                  canMergeWithKeepingPackage(
                      currentPath, currentPackage.get(), child, packagePathCache))
          .collect(ImmutableList.toImmutableList());

  if (childrenToMerge.isEmpty()) {
    return Optional.empty();
  }

  IjFolder mergedFolder =
      typeForMerging
          .getFolderFactory()
          .create(
              currentPath,
              true,
              childrenToMerge.stream()
                  .flatMap(folder -> folder.getInputs().stream())
                  .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural())));

  removeFolders(childrenToMerge);
  mergePathsMap.put(currentPath, mergedFolder);

  return Optional.of(mergedFolder);
}
 
Example #29
Source File: SingularGuavaCollection.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@java.lang.SuppressWarnings("all")
public SingularGuavaCollection<T> build() {
  com.google.common.collect.ImmutableCollection<java.lang.Object> rawTypes = this.rawTypes == null ? com.google.common.collect.ImmutableList.<java.lang.Object>of() : this.rawTypes.build();
  com.google.common.collect.ImmutableCollection<Integer> integers = this.integers == null ? com.google.common.collect.ImmutableList.<Integer>of() : this.integers.build();
  com.google.common.collect.ImmutableCollection<T> generics = this.generics == null ? com.google.common.collect.ImmutableList.<T>of() : this.generics.build();
  com.google.common.collect.ImmutableCollection<Number> extendsGenerics = this.extendsGenerics == null ? com.google.common.collect.ImmutableList.<Number>of() : this.extendsGenerics.build();
  return new SingularGuavaCollection<T>(rawTypes, integers, generics, extendsGenerics);
}
 
Example #30
Source File: ScreenDensityResourcesSplitterTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
private static ModuleSplit findModuleSplitWithScreenDensityTargeting(
    ImmutableCollection<ModuleSplit> moduleSplits, ScreenDensity density) {
  return moduleSplits.stream()
      .filter(
          split ->
              split.getApkTargeting().getScreenDensityTargeting().getValueCount() > 0
                  && density.equals(
                      split.getApkTargeting().getScreenDensityTargeting().getValue(0)))
      .collect(onlyElement());
}