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

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

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:com.facebook.buck.rules.UberRDotJavaUtil.java

public static void createDummyRDotJavaFiles(ImmutableList<AndroidResourceRule> androidResourceDeps,
        BuildTarget buildTarget, ImmutableList.Builder<Step> commands) {
    // Clear out the folder for the .java files.
    String rDotJavaSrcFolder = getRDotJavaSrcFolder(buildTarget);
    commands.add(new MakeCleanDirectoryStep(rDotJavaSrcFolder));

    // Generate the .java files and record where they will be written in javaSourceFilePaths.
    Set<String> javaSourceFilePaths = Sets.newHashSet();
    if (androidResourceDeps.isEmpty()) {
        // In this case, the user is likely running a Robolectric test that does not happen to
        // depend on any resources. However, if Robolectric doesn't find an R.java file, it flips
        // out, so we have to create one, anyway.

        // TODO(mbolin): Stop hardcoding com.facebook. This should match the package in the
        // associated TestAndroidManifest.xml file.
        String rDotJavaPackage = "com.facebook";
        String javaCode = MergeAndroidResourcesStep.generateJavaCodeForPackageWithoutResources(rDotJavaPackage);
        commands.add(new MakeCleanDirectoryStep(rDotJavaSrcFolder + "/com/facebook"));
        String rDotJavaFile = rDotJavaSrcFolder + "/com/facebook/R.java";
        commands.add(new WriteFileStep(javaCode, rDotJavaFile));
        javaSourceFilePaths.add(rDotJavaFile);
    } else {//from   ww w .  j  av a2  s .  c  om
        Map<String, String> symbolsFileToRDotJavaPackage = Maps.newHashMap();
        for (AndroidResourceRule res : androidResourceDeps) {
            String rDotJavaPackage = res.getRDotJavaPackage();
            symbolsFileToRDotJavaPackage.put(res.getPathToTextSymbolsFile(), rDotJavaPackage);
            String rDotJavaFilePath = MergeAndroidResourcesStep.getOutputFilePath(rDotJavaSrcFolder,
                    rDotJavaPackage);
            javaSourceFilePaths.add(rDotJavaFilePath);
        }
        commands.add(new MergeAndroidResourcesStep(symbolsFileToRDotJavaPackage, rDotJavaSrcFolder));
    }

    // Clear out the directory where the .class files will be generated.
    String rDotJavaClassesDirectory = getRDotJavaBinFolder(buildTarget);
    commands.add(new MakeCleanDirectoryStep(rDotJavaClassesDirectory));

    // Compile the .java files.
    JavacInMemoryStep javac = createJavacInMemoryCommandForRDotJavaFiles(javaSourceFilePaths,
            rDotJavaClassesDirectory);
    commands.add(javac);
}

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

/**
 * Creates an action to run Proguard over the given {@code programJar} with various other given
 * inputs to produce {@code proguardOutputJar}.  If requested explicitly, or implicitly with
 * --java_optimization_mode, the action also produces a mapping file (which shows what methods and
 * classes in the output Jar correspond to which methods and classes in the input).  The "pair"
 * returned by this method indicates whether a mapping is being produced.
 *
 * <p>See the Proguard manual for the meaning of the various artifacts in play.
 *
 * @param proguard Proguard executable to use
 * @param proguardSpecs Proguard specification files to pass to Proguard
 * @param proguardMapping optional mapping file for Proguard to apply
 * @param libraryJars any other Jar files that the {@code programJar} will run against
 * @param mappingRequested whether to ask Proguard to output a mapping file (a mapping will be
 *        produced anyway if --java_optimization_mode includes obfuscation)
 * @param filesBuilder all artifacts produced by this rule will be added to this builder
 */// w ww  .j  a v  a 2  s  . c o  m
public static ProguardOutput createProguardAction(RuleContext ruleContext, FilesToRunProvider proguard,
        Artifact programJar, ImmutableList<Artifact> proguardSpecs, @Nullable Artifact proguardMapping,
        NestedSet<Artifact> libraryJars, Artifact proguardOutputJar, boolean mappingRequested,
        NestedSetBuilder<Artifact> filesBuilder) throws InterruptedException {
    JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext);
    Preconditions.checkArgument(optMode != JavaOptimizationMode.NOOP);
    Preconditions.checkArgument(optMode != JavaOptimizationMode.LEGACY || !proguardSpecs.isEmpty());

    Builder builder = new SpawnAction.Builder().addInput(programJar).addInputs(libraryJars)
            .addInputs(proguardSpecs).addOutput(proguardOutputJar).setExecutable(proguard)
            .setProgressMessage("Trimming binary with Proguard").setMnemonic("Proguard").addArgument("-injars")
            .addArgument(programJar.getExecPathString());

    for (Artifact libraryJar : libraryJars) {
        builder.addArgument("-libraryjars").addArgument(libraryJar.getExecPathString());
    }

    filesBuilder.add(proguardOutputJar);

    if (proguardMapping != null) {
        builder.addInput(proguardMapping).addArgument("-applymapping")
                .addArgument(proguardMapping.getExecPathString());
    }

    builder.addArgument("-outjars").addArgument(proguardOutputJar.getExecPathString());

    for (Artifact proguardSpec : proguardSpecs) {
        builder.addArgument("@" + proguardSpec.getExecPathString());
    }

    Artifact proguardOutputMap = null;
    if (mappingRequested || optMode.alwaysGenerateOutputMapping()) {
        // TODO(bazel-team): Verify that proguard spec files don't contain -printmapping directions
        // which this -printmapping command line flag will override.
        proguardOutputMap = ruleContext
                .getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_BINARY_PROGUARD_MAP);

        builder.addOutput(proguardOutputMap).addArgument("-printmapping")
                .addArgument(proguardOutputMap.getExecPathString());
        filesBuilder.add(proguardOutputMap);
    }

    ruleContext.registerAction(builder.build(ruleContext));
    return new ProguardOutput(proguardOutputJar, proguardOutputMap);
}

From source file:com.google.javascript.jscomp.lint.CheckRequiresSorted.java

/**
 * Canonicalizes a list of import statements by deduplicating and merging imports for the same
 * namespace, and sorting the result.//from  w  ww  . ja v  a 2 s  .  com
 */
private static List<ImportStatement> canonicalizeImports(Multimap<String, ImportStatement> importsByNamespace) {
    List<ImportStatement> canonicalImports = new ArrayList<>();

    for (String namespace : importsByNamespace.keySet()) {
        Collection<ImportStatement> allImports = importsByNamespace.get(namespace);

        // Find the strongest primitive across all existing imports. Every emitted import for this
        // namespace will use this primitive. This makes the logic simpler and cannot change runtime
        // behavior, but may produce spurious changes when multiple aliasing imports of differing
        // strength exist (which are already in violation of the style guide).
        ImportPrimitive strongestPrimitive = allImports.stream().map(ImportStatement::primitive)
                .reduce(ImportPrimitive.WEAKEST, ImportPrimitive::stronger);

        // Emit each aliasing import separately, as deduplicating them would require code references
        // to be rewritten.
        boolean hasAliasing = false;
        for (ImportStatement stmt : Iterables.filter(allImports, ImportStatement::isAliasing)) {
            canonicalImports.add(stmt.upgrade(strongestPrimitive));
            hasAliasing = true;
        }

        // Emit a single destructuring import with a non-empty pattern, merged from the existing
        // destructuring imports.
        boolean hasDestructuring = false;
        ImmutableList<Node> destructuringNodes = allImports.stream().filter(ImportStatement::isDestructuring)
                .flatMap(i -> i.nodes().stream()).collect(toImmutableList());
        ImmutableList<DestructuringBinding> destructures = allImports.stream()
                .filter(ImportStatement::isDestructuring).flatMap(i -> i.destructures().stream()).distinct()
                .sorted().collect(toImmutableList());
        if (!destructures.isEmpty()) {
            canonicalImports.add(ImportStatement.of(destructuringNodes, strongestPrimitive, namespace,
                    /* alias= */ null, destructures));
            hasDestructuring = true;
        }

        // Emit a standalone import unless an aliasing or destructuring one already exists.
        if (!hasAliasing && !hasDestructuring) {
            ImmutableList<Node> standaloneNodes = allImports.stream().filter(ImportStatement::isStandalone)
                    .flatMap(i -> i.nodes().stream()).collect(toImmutableList());
            canonicalImports.add(ImportStatement.of(standaloneNodes, strongestPrimitive, namespace,
                    /* alias= */ null, /* destructures= */ null));
        }
    }

    // Sorting by natural order yields the correct result due to the implementation of
    // ImportStatement#compareTo.
    Collections.sort(canonicalImports);

    return canonicalImports;
}

From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.CreateService.java

public static void createFolderPrompt(final Ds3Common ds3Common, final LoggingService loggingService,
        final ResourceBundle resourceBundle) {
    ImmutableList<TreeItem<Ds3TreeTableValue>> values = ds3Common.getDs3TreeTableView().getSelectionModel()
            .getSelectedItems().stream().collect(GuavaCollectors.immutableList());
    final TreeItem<Ds3TreeTableValue> root = ds3Common.getDs3TreeTableView().getRoot();
    final LazyAlert alert = new LazyAlert(resourceBundle);

    if (values.stream().map(TreeItem::getValue).anyMatch(Ds3TreeTableValue::isSearchOn)) {
        LOG.info("You can not create folder here. Please refresh your view");
        alert.info("cantCreateFolderHere");
        return;//from  w ww. j a  va  2 s .  c  o  m
    } else if (values.isEmpty() && root != null && root.getValue() != null) {
        final ImmutableList.Builder<TreeItem<Ds3TreeTableValue>> builder = ImmutableList.builder();
        values = builder.add(root).build();
    } else if (values.isEmpty()) {
        loggingService.logMessage(resourceBundle.getString("selectLocation"), LogType.ERROR);
        alert.info("locationNotSelected");
        return;
    } else if (values.size() > 1) {
        LOG.info("Only a single location can be selected to create empty folder");
        alert.info("selectSingleLocation");
        return;
    }

    final Optional<TreeItem<Ds3TreeTableValue>> first = values.stream().findFirst();
    if (first.isPresent()) {
        final TreeItem<Ds3TreeTableValue> ds3TreeTableValueTreeItem = first.get();

        final String destinationDirectory = ds3TreeTableValueTreeItem.getValue().getDirectoryName();

        final ImmutableList<String> buckets = values.stream().map(TreeItem::getValue)
                .map(Ds3TreeTableValue::getBucketName).distinct().collect(GuavaCollectors.immutableList());
        final Optional<String> bucketElement = buckets.stream().findFirst();
        bucketElement.ifPresent(bucket -> CreateFolderPopup.show(
                new CreateFolderModel(ds3Common.getCurrentSession().getClient(), destinationDirectory, bucket),
                resourceBundle));

        Ds3PanelService.refresh(ds3TreeTableValueTreeItem);
    }
}

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

/**
 * Retrieves the full set of proguard specs that should be applied to this binary, including the
 * specs passed in, if Proguard should run on the given rule.  {@link #createProguardAction}
 * relies on this method returning an empty list if the given rule doesn't declare specs in
 * --java_optimization_mode=legacy.//from   w  w w.  j a va  2  s. c om
 *
 * <p>If Proguard shouldn't be applied, or the legacy link mode is used and there are no
 * proguard_specs on this rule, an empty list will be returned, regardless of any given specs or
 * specs from dependencies.
 * {@link com.google.devtools.build.lib.rules.android.AndroidBinary#createAndroidBinary} relies on
 * that behavior.
 */
public static ImmutableList<Artifact> collectTransitiveProguardSpecs(RuleContext ruleContext,
        Iterable<Artifact> specsToInclude) {
    JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext);
    if (optMode == JavaOptimizationMode.NOOP) {
        return ImmutableList.of();
    }

    ImmutableList<Artifact> proguardSpecs = ruleContext.attributes().has(PROGUARD_SPECS, BuildType.LABEL_LIST)
            ? ruleContext.getPrerequisiteArtifacts(PROGUARD_SPECS, Mode.TARGET).list()
            : ImmutableList.<Artifact>of();
    if (optMode == JavaOptimizationMode.LEGACY && proguardSpecs.isEmpty()) {
        return ImmutableList.of();
    }

    // TODO(bazel-team): In modes except LEGACY verify that proguard specs don't include -dont...
    // flags since those flags would override the desired optMode
    ImmutableSortedSet.Builder<Artifact> builder = ImmutableSortedSet.orderedBy(Artifact.EXEC_PATH_COMPARATOR)
            .addAll(proguardSpecs).addAll(specsToInclude)
            .addAll(ruleContext.getPrerequisiteArtifacts(":extra_proguard_specs", Mode.TARGET).list());
    for (ProguardSpecProvider dep : ruleContext.getPrerequisites("deps", Mode.TARGET,
            ProguardSpecProvider.class)) {
        builder.addAll(dep.getTransitiveProguardSpecs());
    }

    // Generate and include implicit Proguard spec for requested mode.
    if (!optMode.getImplicitProguardDirectives().isEmpty()) {
        Artifact implicitDirectives = getProguardConfigArtifact(ruleContext, optMode.name().toLowerCase());
        ruleContext.registerAction(FileWriteAction.create(ruleContext, implicitDirectives,
                optMode.getImplicitProguardDirectives(), /*makeExecutable=*/ false));
        builder.add(implicitDirectives);
    }

    return builder.build().asList();
}

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

private static boolean matchesConfigurationFilters(ImmutableList<FolderConfiguration> folderConfigs,
        FolderConfiguration config) {/*from   w w w . j a  v a2  s  .  c o m*/
    for (FolderConfiguration filter : folderConfigs) {
        if (config.isMatchFor(filter)) {
            return true;
        }
    }

    return folderConfigs.isEmpty();
}

From source file:com.facebook.buck.apple.AppleCxxPlatforms.java

@VisibleForTesting
static AppleCxxPlatform buildWithExecutableChecker(ProjectFilesystem filesystem, AppleSdk targetSdk,
        String minVersion, String targetArchitecture, final AppleSdkPaths sdkPaths, BuckConfig buckConfig,
        AppleConfig appleConfig, ExecutableFinder executableFinder, Optional<ProcessExecutor> processExecutor,
        Optional<AppleToolchain> swiftToolChain) {
    AppleCxxPlatform.Builder platformBuilder = AppleCxxPlatform.builder();

    ImmutableList.Builder<Path> toolSearchPathsBuilder = ImmutableList.builder();
    // Search for tools from most specific to least specific.
    toolSearchPathsBuilder.add(sdkPaths.getSdkPath().resolve(USR_BIN))
            .add(sdkPaths.getSdkPath().resolve("Developer").resolve(USR_BIN))
            .add(sdkPaths.getPlatformPath().resolve("Developer").resolve(USR_BIN));
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        toolSearchPathsBuilder.add(toolchainPath.resolve(USR_BIN));
    }/*from  w  w  w. ja  va2  s. c  om*/
    if (sdkPaths.getDeveloperPath().isPresent()) {
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve(USR_BIN));
        toolSearchPathsBuilder.add(sdkPaths.getDeveloperPath().get().resolve("Tools"));
    }

    // TODO(bhamiltoncx): Add more and better cflags.
    ImmutableList.Builder<String> cflagsBuilder = ImmutableList.builder();
    cflagsBuilder.add("-isysroot", sdkPaths.getSdkPath().toString());
    cflagsBuilder.add("-arch", targetArchitecture);
    cflagsBuilder.add(targetSdk.getApplePlatform().getMinVersionFlagPrefix() + minVersion);

    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        cflagsBuilder.add("-fembed-bitcode");
    }

    ImmutableList.Builder<String> ldflagsBuilder = ImmutableList.builder();
    ldflagsBuilder.addAll(Linkers.iXlinker("-sdk_version", targetSdk.getVersion(), "-ObjC"));
    if (targetSdk.getApplePlatform().equals(ApplePlatform.WATCHOS)) {
        ldflagsBuilder
                .addAll(Linkers.iXlinker("-bitcode_verify", "-bitcode_hide_symbols", "-bitcode_symbol_map"));
    }

    // Populate Xcode version keys from Xcode's own Info.plist if available.
    Optional<String> xcodeBuildVersion = Optional.empty();
    Optional<Path> developerPath = sdkPaths.getDeveloperPath();
    if (developerPath.isPresent()) {
        Path xcodeBundlePath = developerPath.get().getParent();
        if (xcodeBundlePath != null) {
            File xcodeInfoPlistPath = xcodeBundlePath.resolve("Info.plist").toFile();
            try {
                NSDictionary parsedXcodeInfoPlist = (NSDictionary) PropertyListParser.parse(xcodeInfoPlistPath);

                NSObject xcodeVersionObject = parsedXcodeInfoPlist.objectForKey("DTXcode");
                if (xcodeVersionObject != null) {
                    Optional<String> xcodeVersion = Optional.of(xcodeVersionObject.toString());
                    platformBuilder.setXcodeVersion(xcodeVersion);
                }
            } catch (IOException e) {
                LOG.debug("Error reading Xcode's info plist %s; ignoring Xcode versions", xcodeInfoPlistPath);
            } catch (PropertyListFormatException | ParseException | ParserConfigurationException
                    | SAXException e) {
                LOG.debug("Error in parsing %s; ignoring Xcode versions", xcodeInfoPlistPath);
            }
        }

        // Get the Xcode build version as reported by `xcodebuild -version`.  This is
        // different than the build number in the Info.plist, sigh.
        if (processExecutor.isPresent()) {
            xcodeBuildVersion = appleConfig
                    .getXcodeBuildVersionSupplier(developerPath.get(), processExecutor.get()).get();
            platformBuilder.setXcodeBuildVersion(xcodeBuildVersion);
            LOG.debug("Xcode build version is: " + xcodeBuildVersion.orElse("<absent>"));
        }
    }

    ImmutableList.Builder<String> versions = ImmutableList.builder();
    versions.add(targetSdk.getVersion());

    ImmutableList<String> toolchainVersions = targetSdk.getToolchains().stream().map(AppleToolchain::getVersion)
            .flatMap(Optionals::toStream).collect(MoreCollectors.toImmutableList());
    if (toolchainVersions.isEmpty()) {
        if (!xcodeBuildVersion.isPresent()) {
            throw new HumanReadableException("Failed to read toolchain versions and Xcode version.");
        }
        versions.add(xcodeBuildVersion.get());
    } else {
        versions.addAll(toolchainVersions);
    }

    String version = Joiner.on(':').join(versions.build());

    ImmutableList<Path> toolSearchPaths = toolSearchPathsBuilder.build();

    Tool clangPath = VersionedTool.of(getToolPath("clang", toolSearchPaths, executableFinder), "apple-clang",
            version);

    Tool clangXxPath = VersionedTool.of(getToolPath("clang++", toolSearchPaths, executableFinder),
            "apple-clang++", version);

    Tool ar = VersionedTool.of(getToolPath("ar", toolSearchPaths, executableFinder), "apple-ar", version);

    Tool ranlib = VersionedTool.builder().setPath(getToolPath("ranlib", toolSearchPaths, executableFinder))
            .setName("apple-ranlib").setVersion(version).build();

    Tool strip = VersionedTool.of(getToolPath("strip", toolSearchPaths, executableFinder), "apple-strip",
            version);

    Tool nm = VersionedTool.of(getToolPath("nm", toolSearchPaths, executableFinder), "apple-nm", version);

    Tool actool = VersionedTool.of(getToolPath("actool", toolSearchPaths, executableFinder), "apple-actool",
            version);

    Tool ibtool = VersionedTool.of(getToolPath("ibtool", toolSearchPaths, executableFinder), "apple-ibtool",
            version);

    Tool momc = VersionedTool.of(getToolPath("momc", toolSearchPaths, executableFinder), "apple-momc", version);

    Tool xctest = VersionedTool.of(getToolPath("xctest", toolSearchPaths, executableFinder), "apple-xctest",
            version);

    Tool dsymutil = VersionedTool.of(getToolPath("dsymutil", toolSearchPaths, executableFinder),
            "apple-dsymutil", version);

    Tool lipo = VersionedTool.of(getToolPath("lipo", toolSearchPaths, executableFinder), "apple-lipo", version);

    Tool lldb = VersionedTool.of(getToolPath("lldb", toolSearchPaths, executableFinder), "lldb", version);

    Optional<Path> stubBinaryPath = targetSdk.getApplePlatform().getStubBinaryPath()
            .map(input -> sdkPaths.getSdkPath().resolve(input));

    CxxBuckConfig config = new CxxBuckConfig(buckConfig);

    ImmutableFlavor targetFlavor = ImmutableFlavor
            .of(ImmutableFlavor.replaceInvalidCharacters(targetSdk.getName() + "-" + targetArchitecture));

    ImmutableBiMap.Builder<Path, Path> sanitizerPaths = ImmutableBiMap.builder();
    sanitizerPaths.put(sdkPaths.getSdkPath(), Paths.get("APPLE_SDKROOT"));
    sanitizerPaths.put(sdkPaths.getPlatformPath(), Paths.get("APPLE_PLATFORM_DIR"));
    if (sdkPaths.getDeveloperPath().isPresent()) {
        sanitizerPaths.put(sdkPaths.getDeveloperPath().get(), Paths.get("APPLE_DEVELOPER_DIR"));
    }

    DebugPathSanitizer compilerDebugPathSanitizer = new PrefixMapDebugPathSanitizer(
            config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build(),
            filesystem.getRootPath().toAbsolutePath(), CxxToolProvider.Type.CLANG);
    DebugPathSanitizer assemblerDebugPathSanitizer = new MungingDebugPathSanitizer(
            config.getDebugPathSanitizerLimit(), File.separatorChar, Paths.get("."), sanitizerPaths.build());

    ImmutableList<String> cflags = cflagsBuilder.build();

    ImmutableMap.Builder<String, String> macrosBuilder = ImmutableMap.builder();
    macrosBuilder.put("SDKROOT", sdkPaths.getSdkPath().toString());
    macrosBuilder.put("PLATFORM_DIR", sdkPaths.getPlatformPath().toString());
    macrosBuilder.put("CURRENT_ARCH", targetArchitecture);
    if (sdkPaths.getDeveloperPath().isPresent()) {
        macrosBuilder.put("DEVELOPER_DIR", sdkPaths.getDeveloperPath().get().toString());
    }
    ImmutableMap<String, String> macros = macrosBuilder.build();

    Optional<String> buildVersion = Optional.empty();
    Path platformVersionPlistPath = sdkPaths.getPlatformPath().resolve("version.plist");
    try (InputStream versionPlist = Files.newInputStream(platformVersionPlistPath)) {
        NSDictionary versionInfo = (NSDictionary) PropertyListParser.parse(versionPlist);
        if (versionInfo != null) {
            NSObject productBuildVersion = versionInfo.objectForKey("ProductBuildVersion");
            if (productBuildVersion != null) {
                buildVersion = Optional.of(productBuildVersion.toString());
            } else {
                LOG.warn("In %s, missing ProductBuildVersion. Build version will be unset for this platform.",
                        platformVersionPlistPath);
            }
        } else {
            LOG.warn("Empty version plist in %s. Build version will be unset for this platform.",
                    platformVersionPlistPath);
        }
    } catch (NoSuchFileException e) {
        LOG.warn("%s does not exist. Build version will be unset for this platform.", platformVersionPlistPath);
    } catch (PropertyListFormatException | SAXException | ParserConfigurationException | ParseException
            | IOException e) {
        // Some other error occurred, print the exception since it may contain error details.
        LOG.warn(e, "Failed to parse %s. Build version will be unset for this platform.",
                platformVersionPlistPath);
    }

    PreprocessorProvider aspp = new PreprocessorProvider(new ConstantToolProvider(clangPath),
            CxxToolProvider.Type.CLANG);
    CompilerProvider as = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cpp = new PreprocessorProvider(new ConstantToolProvider(clangPath),
            CxxToolProvider.Type.CLANG);
    CompilerProvider cc = new CompilerProvider(new ConstantToolProvider(clangPath), CxxToolProvider.Type.CLANG);
    PreprocessorProvider cxxpp = new PreprocessorProvider(new ConstantToolProvider(clangXxPath),
            CxxToolProvider.Type.CLANG);
    CompilerProvider cxx = new CompilerProvider(new ConstantToolProvider(clangXxPath),
            CxxToolProvider.Type.CLANG);
    ImmutableList.Builder<String> whitelistBuilder = ImmutableList.builder();
    whitelistBuilder.add("^" + Pattern.quote(sdkPaths.getSdkPath().toString()) + "\\/.*");
    for (Path toolchainPath : sdkPaths.getToolchainPaths()) {
        whitelistBuilder.add("^" + Pattern.quote(toolchainPath.toString()) + "\\/.*");
    }
    HeaderVerification headerVerification = config.getHeaderVerification()
            .withAdditionalWhitelist(whitelistBuilder.build());

    CxxPlatform cxxPlatform = CxxPlatforms.build(targetFlavor, Platform.MACOS, config, as, aspp, cc, cxx, cpp,
            cxxpp, new DefaultLinkerProvider(LinkerProvider.Type.DARWIN, new ConstantToolProvider(clangXxPath)),
            ImmutableList.<String>builder().addAll(cflags).addAll(ldflagsBuilder.build()).build(), strip,
            new BsdArchiver(ar), ranlib, new PosixNmSymbolNameTool(nm), cflagsBuilder.build(),
            ImmutableList.of(), cflags, ImmutableList.of(), "dylib", "%s.dylib", "a", "o",
            compilerDebugPathSanitizer, assemblerDebugPathSanitizer, macros, Optional.empty(),
            headerVerification);

    ApplePlatform applePlatform = targetSdk.getApplePlatform();
    ImmutableList.Builder<Path> swiftOverrideSearchPathBuilder = ImmutableList.builder();
    AppleSdkPaths.Builder swiftSdkPathsBuilder = AppleSdkPaths.builder().from(sdkPaths);
    if (swiftToolChain.isPresent()) {
        swiftOverrideSearchPathBuilder.add(swiftToolChain.get().getPath().resolve(USR_BIN));
        swiftSdkPathsBuilder.setToolchainPaths(ImmutableList.of(swiftToolChain.get().getPath()));
    }
    Optional<SwiftPlatform> swiftPlatform = getSwiftPlatform(applePlatform.getName(),
            targetArchitecture + "-apple-" + applePlatform.getSwiftName().orElse(applePlatform.getName())
                    + minVersion,
            version, swiftSdkPathsBuilder.build(),
            swiftOverrideSearchPathBuilder.addAll(toolSearchPaths).build(), executableFinder);

    platformBuilder.setCxxPlatform(cxxPlatform).setSwiftPlatform(swiftPlatform).setAppleSdk(targetSdk)
            .setAppleSdkPaths(sdkPaths).setMinVersion(minVersion).setBuildVersion(buildVersion)
            .setActool(actool).setIbtool(ibtool).setMomc(momc)
            .setCopySceneKitAssets(
                    getOptionalTool("copySceneKitAssets", toolSearchPaths, executableFinder, version))
            .setXctest(xctest).setDsymutil(dsymutil).setLipo(lipo).setStubBinary(stubBinaryPath).setLldb(lldb)
            .setCodesignAllocate(
                    getOptionalTool("codesign_allocate", toolSearchPaths, executableFinder, version));

    return platformBuilder.build();
}

From source file:net.conquiris.lucene.search.Queries.java

/**
 * Adds clauses to a boolean query./* ww  w  .  ja va  2  s .  com*/
 * @param query Boolean query to which the clauses are added.
 * @param occur Specifies how clauses are to occur in matching documents.
 * @param queries Queries to use to build the clauses.
 * @return The provided boolean query.
 * @throws IllegalArgumentException if the queries argument is empty.
 */
public static BooleanQuery addClauses(BooleanQuery query, Occur occur, Iterable<? extends Query> queries) {
    checkNotNull(query, "The destination boolean query must be provided");
    checkNotNull(occur, "The occurrence specification must be provided");
    ImmutableList<Query> list = ImmutableList.copyOf(queries);
    checkArgument(!list.isEmpty(), "At least one query must be provided");
    for (Query q : queries) {
        query.add(q, occur);
    }
    return query;
}

From source file:org.glowroot.weaving.WeavingClassVisitor.java

private static String /*@Nullable*/[] getInterfacesIncludingShimsAndMixins(String /*@Nullable*/[] interfaces,
        ImmutableList<ShimType> matchedShimTypes, ImmutableList<MixinType> matchedMixinTypes) {
    if (matchedMixinTypes.isEmpty() && matchedShimTypes.isEmpty()) {
        return interfaces;
    }/*w ww  .java2  s . com*/
    Set<String> interfacesIncludingShimsAndMixins = Sets.newHashSet();
    if (interfaces != null) {
        interfacesIncludingShimsAndMixins.addAll(Arrays.asList(interfaces));
    }
    for (ShimType matchedShimType : matchedShimTypes) {
        interfacesIncludingShimsAndMixins.add(matchedShimType.iface().getInternalName());
    }
    for (MixinType matchedMixinType : matchedMixinTypes) {
        for (Type mixinInterface : matchedMixinType.interfaces()) {
            interfacesIncludingShimsAndMixins.add(mixinInterface.getInternalName());
        }
    }
    return Iterables.toArray(interfacesIncludingShimsAndMixins, String.class);
}

From source file:org.locationtech.geogig.storage.datastream.FormatCommonV2.java

public static RevTree readTree(ObjectId id, DataInput in) throws IOException {
    final long size = readUnsignedVarLong(in);
    final int treeCount = readUnsignedVarInt(in);

    final ImmutableList.Builder<Node> featuresBuilder = new ImmutableList.Builder<Node>();
    final ImmutableList.Builder<Node> treesBuilder = new ImmutableList.Builder<Node>();
    final SortedMap<Integer, Bucket> buckets = new TreeMap<Integer, Bucket>();

    final int nFeatures = readUnsignedVarInt(in);
    for (int i = 0; i < nFeatures; i++) {
        Node n = readNode(in);//w w w  .  java2  s.co m
        checkState(RevObject.TYPE.FEATURE.equals(n.getType()), "Non-feature node in tree's feature list.");
        featuresBuilder.add(n);
    }

    final int nTrees = readUnsignedVarInt(in);
    for (int i = 0; i < nTrees; i++) {
        Node n = readNode(in);
        checkState(RevObject.TYPE.TREE.equals(n.getType()), "Non-tree node in tree's subtree list.");

        treesBuilder.add(n);
    }

    final int nBuckets = readUnsignedVarInt(in);
    for (int i = 0; i < nBuckets; i++) {
        int bucketIndex = readUnsignedVarInt(in);
        {
            Integer idx = Integer.valueOf(bucketIndex);
            checkState(!buckets.containsKey(idx), "duplicate bucket index: %s", idx);
            // checkState(bucketIndex < RevTree.MAX_BUCKETS, "Illegal bucket index: %s", idx);
        }
        Bucket bucket = readBucketBody(in);
        buckets.put(Integer.valueOf(bucketIndex), bucket);
    }
    checkState(nBuckets == buckets.size(), "expected %s buckets, got %s", nBuckets, buckets.size());
    ImmutableList<Node> trees = treesBuilder.build();
    ImmutableList<Node> features = featuresBuilder.build();
    checkArgument(buckets.isEmpty() || (trees.isEmpty() && features.isEmpty()),
            "Tree has mixed buckets and nodes; this is not supported.");

    if (trees.isEmpty() && features.isEmpty()) {
        return RevTreeImpl.createNodeTree(id, size, treeCount, buckets);
    }
    return RevTreeImpl.createLeafTree(id, size, features, trees);
}