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.python.PythonInPlaceBinary.java

private static Supplier<String> getScript(final BuildRuleResolver resolver, final PythonPlatform pythonPlatform,
        final CxxPlatform cxxPlatform, final String mainModule, final PythonPackageComponents components,
        final Path relativeLinkTreeRoot, final ImmutableSet<String> preloadLibraries) {
    final String relativeLinkTreeRootStr = Escaper.escapeAsPythonString(relativeLinkTreeRoot.toString());
    final Linker ld = cxxPlatform.getLd().resolve(resolver);
    return () -> {
        ST st = new ST(getRunInplaceResource()).add("PYTHON", pythonPlatform.getEnvironment().getPythonPath())
                .add("MAIN_MODULE", Escaper.escapeAsPythonString(mainModule))
                .add("MODULES_DIR", relativeLinkTreeRootStr);

        // Only add platform-specific values when the binary includes native libraries.
        if (components.getNativeLibraries().isEmpty()) {
            st.add("NATIVE_LIBS_ENV_VAR", "None");
            st.add("NATIVE_LIBS_DIR", "None");
        } else {//w  w  w . j a v a2 s. c o  m
            st.add("NATIVE_LIBS_ENV_VAR", Escaper.escapeAsPythonString(ld.searchPathEnvVar()));
            st.add("NATIVE_LIBS_DIR", relativeLinkTreeRootStr);
        }

        if (preloadLibraries.isEmpty()) {
            st.add("NATIVE_LIBS_PRELOAD_ENV_VAR", "None");
            st.add("NATIVE_LIBS_PRELOAD", "None");
        } else {
            st.add("NATIVE_LIBS_PRELOAD_ENV_VAR", Escaper.escapeAsPythonString(ld.preloadEnvVar()));
            st.add("NATIVE_LIBS_PRELOAD", Escaper.escapeAsPythonString(Joiner.on(':').join(preloadLibraries)));
        }
        return st.render();
    };
}

From source file:org.gradle.platform.base.internal.VariantAspectExtractionStrategy.java

@Nullable
@Override//from w w  w .  j  a  v a 2s  .  c o  m
public ModelSchemaAspectExtractionResult extract(ModelSchemaExtractionContext<?> extractionContext,
        final List<ModelPropertyExtractionResult<?>> propertyResults) {
    ImmutableSet.Builder<ModelProperty<?>> dimensionsBuilder = ImmutableSet.builder();
    for (ModelPropertyExtractionResult<?> propertyResult : propertyResults) {
        ModelProperty<?> property = propertyResult.getProperty();
        if (propertyResult.getGetter().isAnnotationPresent(Variant.class)) {
            Class<?> propertyType = property.getType().getRawClass();
            if (!String.class.equals(propertyType) && !Named.class.isAssignableFrom(propertyType)) {
                throw invalidProperty(extractionContext, property, String.format(
                        "@Variant annotation only allowed for properties of type String and %s, but property has type %s",
                        Named.class.getName(), propertyType.getName()));
            }
            dimensionsBuilder.add(property);
        }
        if (propertyResult.getSetter() != null
                && propertyResult.getSetter().isAnnotationPresent(Variant.class)) {
            throw invalidProperty(extractionContext, property,
                    "@Variant annotation is only allowed on getter methods");
        }
    }
    ImmutableSet<ModelProperty<?>> dimensions = dimensionsBuilder.build();
    if (dimensions.isEmpty()) {
        return null;
    }
    return new ModelSchemaAspectExtractionResult(new VariantAspect(dimensions));
}

From source file:com.facebook.buck.android.AndroidBinary.java

@VisibleForTesting
static void copyNativeLibrary(Path sourceDir, final Path destinationDir, ImmutableSet<TargetCpuType> cpuFilters,
        ImmutableList.Builder<Step> steps) {

    if (cpuFilters.isEmpty()) {
        steps.add(CopyStep.forDirectory(sourceDir, destinationDir, CopyStep.DirectoryMode.CONTENTS_ONLY));
    } else {//from w  w  w.ja va2s  . c o  m
        for (TargetCpuType cpuType : cpuFilters) {
            Optional<String> abiDirectoryComponent = getAbiDirectoryComponent(cpuType);
            Preconditions.checkState(abiDirectoryComponent.isPresent());

            final Path libSourceDir = sourceDir.resolve(abiDirectoryComponent.get());
            Path libDestinationDir = destinationDir.resolve(abiDirectoryComponent.get());

            final MkdirStep mkDirStep = new MkdirStep(libDestinationDir);
            final CopyStep copyStep = CopyStep.forDirectory(libSourceDir, libDestinationDir,
                    CopyStep.DirectoryMode.CONTENTS_ONLY);
            steps.add(new Step() {
                @Override
                public int execute(ExecutionContext context) {
                    if (!context.getProjectFilesystem().exists(libSourceDir)) {
                        return 0;
                    }
                    if (mkDirStep.execute(context) == 0 && copyStep.execute(context) == 0) {
                        return 0;
                    }
                    return 1;
                }

                @Override
                public String getShortName() {
                    return "copy_native_libraries";
                }

                @Override
                public String getDescription(ExecutionContext context) {
                    ImmutableList.Builder<String> stringBuilder = ImmutableList.builder();
                    stringBuilder.add(String.format("[ -d %s ]", libSourceDir.toString()));
                    stringBuilder.add(mkDirStep.getDescription(context));
                    stringBuilder.add(copyStep.getDescription(context));
                    return Joiner.on(" && ").join(stringBuilder.build());
                }
            });
        }
    }

    // Rename native files named like "*-disguised-exe" to "lib*.so" so they will be unpacked
    // by the Android package installer.  Then they can be executed like normal binaries
    // on the device.
    steps.add(new AbstractExecutionStep("rename_native_executables") {

        @Override
        public int execute(ExecutionContext context) {

            ProjectFilesystem filesystem = context.getProjectFilesystem();
            final ImmutableSet.Builder<Path> executablesBuilder = ImmutableSet.builder();
            try {
                filesystem.walkRelativeFileTree(destinationDir, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (file.toString().endsWith("-disguised-exe")) {
                            executablesBuilder.add(file);
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
                for (Path exePath : executablesBuilder.build()) {
                    Path fakeSoPath = Paths
                            .get(exePath.toString().replaceAll("/([^/]+)-disguised-exe$", "/lib$1.so"));
                    filesystem.move(exePath, fakeSoPath);
                }
            } catch (IOException e) {
                context.logError(e, "Renaming native executables failed.");
                return 1;
            }
            return 0;
        }
    });
}

From source file:com.facebook.buck.jvm.java.JvmLibraryArg.java

public AnnotationProcessingParams buildAnnotationProcessingParams(BuildTarget owner,
        ProjectFilesystem filesystem, BuildRuleResolver resolver) {
    ImmutableSet<String> annotationProcessors = this.annotationProcessors;

    if (annotationProcessors.isEmpty()) {
        return AnnotationProcessingParams.EMPTY;
    }//from   w  w w .j ava  2  s .c  o m

    AnnotationProcessingParams.Builder builder = new AnnotationProcessingParams.Builder();
    builder.setOwnerTarget(owner);
    builder.addAllProcessors(annotationProcessors);
    builder.setProjectFilesystem(filesystem);
    ImmutableSortedSet<BuildRule> processorDeps = resolver.getAllRules(annotationProcessorDeps);
    for (BuildRule processorDep : processorDeps) {
        builder.addProcessorBuildTarget(processorDep);
    }
    for (String processorParam : annotationProcessorParams) {
        builder.addParameter(processorParam);
    }
    builder.setProcessOnly(annotationProcessorOnly.orElse(Boolean.FALSE));

    return builder.build();
}

From source file:com.facebook.buck.ide.intellij.lang.java.JavaBinaryModuleRule.java

private void saveMetaInfDirectoryForIntellijPlugin(TargetNode<JavaBinaryDescription.Args, ?> target,
        ModuleBuildContext context) {//  ww  w .  j  av a  2  s. c om
    ImmutableSet<String> intellijPluginLabels = projectConfig.getIntellijPluginLabels();
    if (intellijPluginLabels.isEmpty()) {
        return;
    }
    Optional<Path> metaInfDirectory = target.getConstructorArg().metaInfDirectory;
    if (metaInfDirectory.isPresent() && target.getConstructorArg().labelsContainsAnyOf(intellijPluginLabels)) {
        context.setMetaInfDirectory(metaInfDirectory.get());
    }
}

From source file:com.facebook.buck.ide.intellij.lang.java.JavaBinaryModuleRule.java

@Override
public IjModuleType detectModuleType(TargetNode<JavaBinaryDescription.Args, ?> target) {
    ImmutableSet<String> intellijPluginLabels = projectConfig.getIntellijPluginLabels();
    if (intellijPluginLabels.isEmpty()) {
        return IjModuleType.JAVA_MODULE;
    }//from  w  w w  .  j  a  v  a  2s  .c  o m
    Optional<Path> metaInfDirectory = target.getConstructorArg().metaInfDirectory;
    if (metaInfDirectory.isPresent() && target.getConstructorArg().labelsContainsAnyOf(intellijPluginLabels)) {
        return IjModuleType.INTELLIJ_PLUGIN_MODULE;
    }
    return IjModuleType.JAVA_MODULE;
}

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

private void saveMetaInfDirectoryForIntellijPlugin(TargetNode<JavaBinaryDescriptionArg> target,
        ModuleBuildContext context) {//from w w  w.j  av  a 2  s . co m
    ImmutableSet<String> intellijPluginLabels = projectConfig.getIntellijPluginLabels();
    if (intellijPluginLabels.isEmpty()) {
        return;
    }
    Optional<Path> metaInfDirectory = target.getConstructorArg().getMetaInfDirectory();
    if (metaInfDirectory.isPresent() && target.getConstructorArg().labelsContainsAnyOf(intellijPluginLabels)) {
        context.setMetaInfDirectory(metaInfDirectory.get());
    }
}

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

@Override
public IjModuleType detectModuleType(TargetNode<JavaBinaryDescriptionArg> target) {
    ImmutableSet<String> intellijPluginLabels = projectConfig.getIntellijPluginLabels();
    if (intellijPluginLabels.isEmpty()) {
        return IjModuleType.JAVA_MODULE;
    }//from w w w.jav a 2  s .  com
    Optional<Path> metaInfDirectory = target.getConstructorArg().getMetaInfDirectory();
    if (metaInfDirectory.isPresent() && target.getConstructorArg().labelsContainsAnyOf(intellijPluginLabels)) {
        return IjModuleType.INTELLIJ_PLUGIN_MODULE;
    }
    return IjModuleType.JAVA_MODULE;
}

From source file:com.google.idea.blaze.base.run.smrunner.BlazeCompositeTestEventsHandler.java

@Override
protected EnumSet<Kind> handledKinds() {
    ImmutableSet<Kind> handledKinds = getHandlers().keySet();
    return !handledKinds.isEmpty() ? EnumSet.copyOf(handledKinds) : EnumSet.noneOf(Kind.class);
}

From source file:com.facebook.buck.query.AttrFilterFunction.java

@Override
public Set<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args,
        ListeningExecutorService executor) throws QueryException, InterruptedException {
    QueryExpression argument = args.get(args.size() - 1).getExpression();
    String attr = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord());

    final String attrValue = args.get(1).getWord();
    final Predicate<Object> predicate = input -> attrValue.equals(input.toString());

    Set<QueryTarget> result = new LinkedHashSet<>();
    for (QueryTarget target : argument.eval(env, executor)) {
        ImmutableSet<Object> matchingObjects = env.filterAttributeContents(target, attr, predicate);
        if (!matchingObjects.isEmpty()) {
            result.add(target);//  w w w .ja  va2  s  .com
        }
    }
    return result;
}