Example usage for com.google.common.collect ImmutableSet isEmpty

List of usage examples for com.google.common.collect ImmutableSet isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this set contains no elements.

Usage

From source file:com.facebook.buck.features.project.intellij.BaseIjModuleRule.java

private void addDepsAndFolder(IJFolderFactory folderFactory, DependencyType dependencyType,
        TargetNode<T> targetNode, boolean wantsPackagePrefix, ModuleBuildContext context,
        ImmutableSet<Path> resourcePaths) {
    ImmutableMultimap<Path, Path> foldersToInputsIndex = getSourceFoldersToInputsIndex(targetNode.getInputs()
            .stream().map(path -> projectFilesystem.relativize(targetNode.getFilesystem().resolve(path)))
            .collect(ImmutableList.toImmutableList()));

    if (!resourcePaths.isEmpty()) {
        foldersToInputsIndex = foldersToInputsIndex.entries().stream()
                .filter(entry -> !resourcePaths.contains(entry.getValue()))
                .collect(ImmutableListMultimap.toImmutableListMultimap(Map.Entry::getKey, Map.Entry::getValue));
    }/*w  w  w.  j av a 2  s.co  m*/

    addSourceFolders(folderFactory, foldersToInputsIndex, wantsPackagePrefix, context);
    addDeps(foldersToInputsIndex, targetNode, dependencyType, context);

    addGeneratedOutputIfNeeded(folderFactory, targetNode, context);

    if (targetNode.getConstructorArg() instanceof JvmLibraryArg) {
        addAnnotationOutputIfNeeded(folderFactory, targetNode, context);
    }
}

From source file:com.google.devtools.build.lib.rules.android.ZipFilterBuilder.java

/** Builds the action as configured. */
public void build() {
    ImmutableSet<Artifact> filterZips = filterZipsBuilder.build();
    ImmutableSet<String> filterFileTypes = filterFileTypesBuilder.build();
    ImmutableSet<String> explicitFilters = explicitFilterBuilder.build();

    CustomCommandLine.Builder args = CustomCommandLine.builder();
    args.addExecPath("--inputZip", inputZip);
    args.addExecPath("--outputZip", outputZip);
    if (!filterZips.isEmpty()) {
        args.addExecPaths("--filterZips", VectorArg.join(",").each(filterZips));
    }/*from w  w w . j a  va  2  s .  c o m*/
    if (!filterFileTypes.isEmpty()) {
        args.addAll("--filterTypes", VectorArg.join(",").each(filterFileTypes));
    }
    if (!explicitFilters.isEmpty()) {
        args.addAll("--explicitFilters", VectorArg.join(",").each(explicitFilters));
    }
    switch (checkHashMismatch) {
    case WARN:
        args.add("--checkHashMismatch").add("WARN");
        break;
    case ERROR:
        args.add("--checkHashMismatch").add("ERROR");
        break;
    case NONE:
        args.add("--checkHashMismatch").add("IGNORE");
        break;
    }
    args.add("--outputMode");
    switch (outputMode) {
    case COMPRESSED:
        args.add("FORCE_DEFLATE");
        break;
    case UNCOMPRESSED:
        args.add("FORCE_STORED");
        break;
    case DONT_CHANGE:
    default:
        args.add("DONT_CARE");
        break;
    }

    ruleContext.registerAction(new SpawnAction.Builder().addInput(inputZip).addInputs(filterZips)
            .addOutput(outputZip).setExecutable(ruleContext.getExecutablePrerequisite("$zip_filter", Mode.HOST))
            .addCommandLine(args.build()).setProgressMessage("Filtering Zip %s", inputZip.prettyPrint())
            .setMnemonic("ZipFilter").build(ruleContext));
}

From source file:com.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java

private void addAndroidResourcePaths(Map<String, Object> androidProperties, IjModule module,
        IjModuleAndroidFacet androidFacet) {
    ImmutableSet<Path> resourcePaths = androidFacet.getResourcePaths();
    if (resourcePaths.isEmpty()) {
        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER, EMPTY_STRING);
    } else {/*w w  w.  j  av  a2 s.c  o m*/
        Set<String> relativeResourcePaths = new HashSet<>(resourcePaths.size());
        for (Path resourcePath : resourcePaths) {
            relativeResourcePaths
                    .add(IjProjectPaths.toRelativeString(resourcePath, module.getModuleBasePath()));
        }

        androidProperties.put(RESOURCES_RELATIVE_PATH_TEMPLATE_PARAMETER,
                Joiner.on(";").join(relativeResourcePaths));
    }
}

From source file:cc.kune.kunecli.cmds.CustomDeltaMigrator.java

public void run() {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override//from  w ww. j  ava 2s.  c om
        public void run() {
            printStats();
        }
    });

    LOG.info("Starting Wave migration from " + sourceStore.getClass().getSimpleName() + " to "
            + targetStore.getClass().getSimpleName());

    final long startTime = System.currentTimeMillis();

    try {
        // We need the total number of waves to make a progress bar
        int waveCount = 0;
        final ExceptionalIterator<WaveId, PersistenceException> countIterator = sourceStore.getWaveIdIterator();
        while (countIterator.hasNext()) {
            waveCount++;
            countIterator.next();
        }

        final ExceptionalIterator<WaveId, PersistenceException> srcItr = sourceStore.getWaveIdIterator();
        final File stopFile = new File(System.getProperty("java.io.tmpdir") + "/wave-mongo-migration-stop");

        bar = new Progressbar(waveCount, "Migrating " + waveCount + " Waves");

        int currentWave = 0;
        // Waves
        while (srcItr.hasNext()) {
            currentWave++;

            if (stopFile.exists()) {
                LOG.info("Stopping Wave migration as requested. Partial migration.");
                break;
            }

            bar.setVal(currentWave);

            final WaveId waveId = srcItr.next();
            final ImmutableSet<WaveletId> sourceLookup = sourceStore.lookup(waveId);
            final ImmutableSet<WaveletId> targetLookup = targetStore.lookup(waveId);
            final ImmutableSet<WaveletId> waveletIds = sourceLookup;

            boolean wavesAreNotTheSame = false;

            if (!targetLookup.isEmpty()) {
                if (targetLookup.size() != sourceLookup.size()) {
                    wavesAreNotTheSame = true;
                } else {
                    // Comparing source and target deltas
                    for (final WaveletId waveletId : waveletIds) {
                        setStatus("comparing");
                        bar.setVal(currentWave);

                        final DeltasAccess sourceDeltas = sourceStore.open(WaveletName.of(waveId, waveletId));
                        final DeltasAccess targetDeltas = targetStore.open(WaveletName.of(waveId, waveletId));
                        final HashedVersion deltaResultingVersion = sourceDeltas.getEndVersion();
                        final HashedVersion deltaResultingTargetVersion = targetDeltas.getEndVersion();

                        if (!deltaResultingVersion.equals(deltaResultingTargetVersion)) {
                            wavesAreNotTheSame = true;
                            break;
                        }
                    }

                    if (wavesAreNotTheSame) {
                        for (final WaveletId targetWaveletId : targetLookup) {
                            // LOG.info(
                            // "Deleting and appending Wave in target because it's found and
                            // has not the same size: "
                            // + waveId.toString());
                            targetStore.delete(WaveletName.of(waveId, targetWaveletId));
                        }
                        // Continue migrating that wave
                    } else {
                        setStatus("skipping already migrated");
                        bar.setVal(currentWave);
                        countSkipped++;
                        continue;
                    }
                }
            }

            if (wavesAreNotTheSame) {
                setStatus("migrating partial wave");
                countMigratedBecausePartial++;
            } else {
                setStatus("migrating");
                countMigrated++;
            }
            setStatus(wavesAreNotTheSame ? "migrating partial wave" : "migrating");

            // LOG.info("--- Migrating Wave " + waveId.toString() + " with " +
            // waveletIds.size() + " wavelets");
            // final long waveStartTime = System.currentTimeMillis();
            //
            // Wavelets

            try {
                for (final WaveletId waveletId : waveletIds) {
                    bar.setVal(currentWave);

                    // LOG.info(
                    // "Migrating wavelet " + waveletsCount + "/" + waveletsTotal + " :
                    // "
                    // + waveletId.toString());

                    final DeltasAccess sourceDeltas = sourceStore.open(WaveletName.of(waveId, waveletId));
                    final DeltasAccess targetDeltas = targetStore.open(WaveletName.of(waveId, waveletId));

                    // Get all deltas from last version to initial version (0): reverse
                    // order
                    // int deltasCount = 0;

                    final ArrayList<WaveletDeltaRecord> deltas = new ArrayList<WaveletDeltaRecord>();
                    HashedVersion deltaResultingVersion = sourceDeltas.getEndVersion();

                    // Deltas
                    while (deltaResultingVersion != null && deltaResultingVersion.getVersion() != 0) {
                        // deltasCount++;
                        final WaveletDeltaRecord deltaRecord = sourceDeltas
                                .getDeltaByEndVersion(deltaResultingVersion.getVersion());
                        deltas.add(deltaRecord);
                        // get the previous delta, this is the appliedAt
                        deltaResultingVersion = deltaRecord.getAppliedAtVersion();
                    }
                    // LOG.info("Appending " + deltasCount + " deltas to target");
                    targetDeltas.append(deltas);
                }

            } catch (final EOFException e) {
                processCorruptedWave(waveId, e);
            } catch (final PersistenceException e) {
                processCorruptedWave(waveId, e);
            } catch (final IOException e) {
                processCorruptedWave(waveId, e);
            }

        } // While Waves

        bar.finish();
        final long endTime = System.currentTimeMillis();
        LOG.info("Migration completed. Total time = " + (endTime - startTime) + "ms");
        printStats();
    } catch (final PersistenceException e) {
        LOG.warning("Error iterating over waves");
        throw new RuntimeException(e);
    }
}

From source file:com.google.devtools.build.lib.rules.android.AndroidBinary.java

private static ImmutableSet<AndroidBinaryType> getEffectiveIncrementalDexing(RuleContext ruleContext,
        List<String> dexopts, boolean isBinaryProguarded) {
    TriState override = ruleContext.attributes().get("incremental_dexing", BuildType.TRISTATE);
    // Ignore --incremental_dexing_binary_types if the incremental_dexing attribute is set, but
    // raise an error if proguard is enabled (b/c incompatible with incremental dexing ATM).
    if (isBinaryProguarded && override == TriState.YES) {
        ruleContext.attributeError("incremental_dexing",
                "target cannot be incrementally dexed because it uses Proguard");
        return ImmutableSet.of();
    }//from  w w  w.  ja  va2 s .  c om
    if (isBinaryProguarded || override == TriState.NO) {
        return ImmutableSet.of();
    }
    ImmutableSet<AndroidBinaryType> result = override == TriState.YES
            ? ImmutableSet.copyOf(AndroidBinaryType.values())
            : AndroidCommon.getAndroidConfig(ruleContext).getIncrementalDexingBinaries();
    if (!result.isEmpty()) {
        Iterable<String> blacklistedDexopts = Iterables.filter(dexopts, new FlagMatcher(
                AndroidCommon.getAndroidConfig(ruleContext).getTargetDexoptsThatPreventIncrementalDexing()));
        if (!Iterables.isEmpty(blacklistedDexopts)) {
            // target's dexopts include flags blacklisted with --non_incremental_per_target_dexopts. If
            // incremental_dexing attribute is explicitly set for this target then we'll warn and
            // incrementally dex anyway.  Otherwise, just don't incrementally dex.
            if (override == TriState.YES) {
                Iterable<String> ignored = Iterables.filter(blacklistedDexopts, Predicates.not(Predicates.in(
                        AndroidCommon.getAndroidConfig(ruleContext).getDexoptsSupportedInIncrementalDexing())));
                ruleContext.attributeWarning("incremental_dexing",
                        String.format(
                                "Using incremental dexing even though dexopts %s indicate this target "
                                        + "may be unsuitable for incremental dexing for the moment.%s",
                                blacklistedDexopts,
                                Iterables.isEmpty(ignored) ? "" : " These will be ignored: " + ignored));
            } else {
                result = ImmutableSet.of();
            }
        }
    }
    return result;
}

From source file:de.monticore.mojo.GenerateMojo.java

/**
 * @return the value of the "grammars" configuration parameter.
 *///  w w  w .ja  v a2s  .  c  o  m
protected Set<File> getGrammars() {
    ImmutableSet.Builder<File> grammarFilesBuilder = ImmutableSet.builder();

    if (this.grammars != null) {
        this.grammars.forEach(g -> grammarFilesBuilder.add(fromBasePath(g)));
    }

    ImmutableSet<File> grammarFiles = grammarFilesBuilder.build();
    return grammarFiles.isEmpty() ? ImmutableSet.of(getDefaultGrammarDirectory()) : grammarFiles;
}

From source file:de.metas.ui.web.handlingunits.process.WEBUI_M_HU_Transform.java

/**
 * @return true if at least one HU was removed
 *//* w  w  w  . j a v  a  2  s .c  o m*/
private boolean removeHUsIfDestroyed(final Collection<HuId> huIds) {
    final ImmutableSet<HuId> destroyedHUIds = huIds.stream().distinct().map(huId -> load(huId, I_M_HU.class))
            .filter(Services.get(IHandlingUnitsBL.class)::isDestroyed).map(I_M_HU::getM_HU_ID)
            .map(HuId::ofRepoId).collect(ImmutableSet.toImmutableSet());
    if (destroyedHUIds.isEmpty()) {
        return false;
    }

    final HUEditorView view = getView();
    final boolean changes = view.removeHUIds(destroyedHUIds);
    return changes;
}

From source file:de.monticore.mojo.GenerateMojo.java

/**
 * @return the value of the "targetPaths" configuration parameter.
 *//* w ww  .j  a v a2  s .com*/
protected Set<File> getHandcodedPaths() {
    ImmutableSet.Builder<File> handcodedPathsBuilder = ImmutableSet.builder();

    if (this.handcodedPaths != null) {
        this.handcodedPaths.forEach(t -> handcodedPathsBuilder.add(fromBasePath(t)));
    }

    ImmutableSet<File> handcodedPathFiles = handcodedPathsBuilder.build();
    return handcodedPathFiles.isEmpty() ? ImmutableSet.of(getDefaultHandcodedPath()) : handcodedPathFiles;
}

From source file:de.monticore.mojo.GenerateMojo.java

/**
 * @return the value of the "templatePaths" configuration parameter.
 *//*from   ww w . ja  va  2 s  .co m*/
protected Set<File> getTemplatePaths() {
    ImmutableSet.Builder<File> templatePathsBuilder = ImmutableSet.builder();

    if (this.templatePaths != null) {
        this.templatePaths.forEach(t -> templatePathsBuilder.add(fromBasePath(t)));
    }

    ImmutableSet<File> templatePathFiles = templatePathsBuilder.build();
    return templatePathFiles.isEmpty()
            ? getDefaultTemplatePath().map(ImmutableSet::of).orElse(ImmutableSet.of())
            : templatePathFiles;
}

From source file:com.facebook.buck.jvm.java.intellij.IjModuleFactory.java

/**
 * Create an {@link IjModule} form the supplied parameters.
 *
 * @param moduleBasePath the top-most directory the module is responsible for.
 * @param targetNodes set of nodes the module is to be created from.
 * @return nice shiny new module./*w  w  w. j a  v a2 s.c  o  m*/
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public IjModule createModule(Path moduleBasePath, ImmutableSet<TargetNode<?, ?>> targetNodes) {
    Preconditions.checkArgument(!targetNodes.isEmpty());

    ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(HasBuildTarget::getBuildTarget)
            .collect(MoreCollectors.toImmutableSet());

    ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets);

    for (TargetNode<?, ?> targetNode : targetNodes) {
        IjModuleRule<?> rule = Preconditions
                .checkNotNull(moduleRuleIndex.get(targetNode.getDescription().getClass()));
        rule.apply((TargetNode) targetNode, context);
    }

    Optional<String> sourceLevel = getSourceLevel(targetNodes);
    String sdkType;
    Optional<String> sdkName;

    if (context.isAndroidFacetBuilderPresent()) {
        context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath(createAndroidGenPath(moduleBasePath));

        sdkType = projectConfig.getAndroidModuleSdkType().orElse(SDK_TYPE_ANDROID);
        sdkName = projectConfig.getAndroidModuleSdkName();
    } else {
        sdkType = projectConfig.getJavaModuleSdkType().orElse(SDK_TYPE_JAVA);
        sdkName = projectConfig.getJavaModuleSdkName();
    }

    return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(targetNodes)
            .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies())
            .setAndroidFacet(context.getAndroidFacet())
            .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies())
            .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders()).setSdkName(sdkName)
            .setSdkType(sdkType).setLanguageLevel(sourceLevel).build();
}