Example usage for com.google.common.collect ImmutableSortedSet of

List of usage examples for com.google.common.collect ImmutableSortedSet of

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet of.

Prototype

public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element) 

Source Link

Usage

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

private Optional<SourcePath> getXctool(BuildRuleParams params, BuildRuleResolver resolver,
        final SourcePathResolver sourcePathResolver) {
    // If xctool is specified as a build target in the buck config, it's wrapping ZIP file which
    // we need to unpack to get at the actual binary.  Otherwise, if it's specified as a path, we
    // can use that directly.
    if (appleConfig.getXctoolZipTarget().isPresent()) {
        final BuildRule xctoolZipBuildRule = resolver.getRule(appleConfig.getXctoolZipTarget().get());
        BuildTarget unzipXctoolTarget = BuildTarget.builder(xctoolZipBuildRule.getBuildTarget())
                .addFlavors(UNZIP_XCTOOL_FLAVOR).build();
        final Path outputDirectory = BuildTargets.getGenPath(params.getProjectFilesystem(), unzipXctoolTarget,
                "%s/unzipped");
        if (!resolver.getRuleOptional(unzipXctoolTarget).isPresent()) {
            BuildRuleParams unzipXctoolParams = params.copyWithChanges(unzipXctoolTarget,
                    Suppliers.ofInstance(ImmutableSortedSet.of(xctoolZipBuildRule)),
                    Suppliers.ofInstance(ImmutableSortedSet.of()));
            resolver.addToIndex(new AbstractBuildRuleWithResolver(unzipXctoolParams, sourcePathResolver) {
                @Override/*from w ww .j a  va  2 s  .c  om*/
                public ImmutableList<Step> getBuildSteps(BuildContext context,
                        BuildableContext buildableContext) {
                    buildableContext.recordArtifact(outputDirectory);
                    return ImmutableList.of(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory),
                            new UnzipStep(getProjectFilesystem(),
                                    Preconditions.checkNotNull(xctoolZipBuildRule.getPathToOutput()),
                                    outputDirectory));
                }

                @Override
                public Path getPathToOutput() {
                    return outputDirectory;
                }
            });
        }
        return Optional.of(new BuildTargetSourcePath(unzipXctoolTarget, outputDirectory.resolve("bin/xctool")));
    } else if (appleConfig.getXctoolPath().isPresent()) {
        return Optional
                .of(new PathSourcePath(params.getProjectFilesystem(), appleConfig.getXctoolPath().get()));
    } else {
        return Optional.empty();
    }
}

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

@SuppressWarnings("unchecked")
private void addAnnotationOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<?, ?> targetNode,
        ModuleBuildContext context) {/*from   www.j ava  2 s.c o  m*/
    TargetNode<? extends JvmLibraryArg, ?> jvmLibraryTargetNode = (TargetNode<? extends JvmLibraryArg, ?>) targetNode;

    Optional<Path> annotationOutput = moduleFactoryResolver.getAnnotationOutputPath(jvmLibraryTargetNode);
    if (!annotationOutput.isPresent()) {
        return;
    }

    Path annotationOutputPath = annotationOutput.get();
    context.addGeneratedSourceCodeFolder(
            folderFactory.create(annotationOutputPath, false, ImmutableSortedSet.of(annotationOutputPath)));
}

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

private void addGeneratedOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<?, ?> targetNode,
        ModuleBuildContext context) {//from  w  w  w  . ja  va 2s  .  c om

    Set<Path> generatedSourcePaths = findConfiguredGeneratedSourcePaths(targetNode);

    if (generatedSourcePaths == null) {
        return;
    }

    for (Path generatedSourcePath : generatedSourcePaths) {
        context.addGeneratedSourceCodeFolder(
                folderFactory.create(generatedSourcePath, false, ImmutableSortedSet.of(generatedSourcePath)));
    }
}

From source file:com.facebook.buck.cxx.CxxBinaryDescription.java

public ImmutableSortedSet<Flavor> addImplicitFlavorsForRuleTypes(ImmutableSortedSet<Flavor> argDefaultFlavors,
        BuildRuleType... types) {//from   w ww.  j  a v a 2s . c o  m
    Optional<Flavor> platformFlavor = getCxxPlatforms().getFlavor(argDefaultFlavors);

    for (BuildRuleType type : types) {
        ImmutableMap<String, Flavor> libraryDefaults = cxxBuckConfig.getDefaultFlavorsForRuleType(type);

        if (!platformFlavor.isPresent()) {
            platformFlavor = Optional.ofNullable(libraryDefaults.get(CxxBuckConfig.DEFAULT_FLAVOR_PLATFORM));
        }
    }

    if (platformFlavor.isPresent()) {
        return ImmutableSortedSet.of(platformFlavor.get());
    } else {
        // To avoid changing the output path of binaries built without a flavor,
        // we'll default to no flavor, which implicitly builds the default platform.
        return ImmutableSortedSet.of();
    }
}

From source file:com.facebook.buck.features.python.PythonTestDescription.java

@Override
public PythonTest createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget,
        BuildRuleParams params, PythonTestDescriptionArg args) {

    FlavorDomain<PythonPlatform> pythonPlatforms = toolchainProvider
            .getByName(PythonPlatformsProvider.DEFAULT_NAME, PythonPlatformsProvider.class)
            .getPythonPlatforms();// ww w.j  a  va  2  s .  c o  m

    ActionGraphBuilder graphBuilder = context.getActionGraphBuilder();
    PythonPlatform pythonPlatform = pythonPlatforms.getValue(buildTarget)
            .orElse(pythonPlatforms.getValue(args.getPlatform().<Flavor>map(InternalFlavor::of)
                    .orElse(pythonPlatforms.getFlavors().iterator().next())));
    CxxPlatform cxxPlatform = getCxxPlatform(buildTarget, args).resolve(graphBuilder);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
    SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
    Path baseModule = PythonUtil.getBasePath(buildTarget, args.getBaseModule());
    Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = context.getTargetGraph().get(buildTarget)
            .getSelectedVersions();

    ImmutableMap<Path, SourcePath> srcs = PythonUtil.getModules(buildTarget, graphBuilder, ruleFinder,
            pathResolver, pythonPlatform, cxxPlatform, "srcs", baseModule, args.getSrcs(),
            args.getPlatformSrcs(), args.getVersionedSrcs(), selectedVersions);

    ImmutableMap<Path, SourcePath> resources = PythonUtil.getModules(buildTarget, graphBuilder, ruleFinder,
            pathResolver, pythonPlatform, cxxPlatform, "resources", baseModule, args.getResources(),
            args.getPlatformResources(), args.getVersionedResources(), selectedVersions);

    // Convert the passed in module paths into test module names.
    ImmutableSet.Builder<String> testModulesBuilder = ImmutableSet.builder();
    for (Path name : srcs.keySet()) {
        testModulesBuilder.add(PythonUtil.toModuleName(buildTarget, name.toString()));
    }
    ImmutableSet<String> testModules = testModulesBuilder.build();

    ProjectFilesystem projectFilesystem = context.getProjectFilesystem();

    // Construct a build rule to generate the test modules list source file and
    // add it to the build.
    BuildRule testModulesBuildRule = createTestModulesSourceBuildRule(buildTarget, projectFilesystem,
            getTestModulesListPath(buildTarget, projectFilesystem), testModules);
    graphBuilder.addToIndex(testModulesBuildRule);

    String mainModule;
    if (args.getMainModule().isPresent()) {
        mainModule = args.getMainModule().get();
    } else {
        mainModule = PythonUtil.toModuleName(buildTarget, getTestMainName().toString());
    }

    // Build up the list of everything going into the python test.
    PythonPackageComponents testComponents = PythonPackageComponents.of(
            ImmutableMap.<Path, SourcePath>builder()
                    .put(getTestModulesListName(), testModulesBuildRule.getSourcePathToOutput())
                    .put(getTestMainName(), requireTestMain(buildTarget, projectFilesystem, graphBuilder))
                    .putAll(srcs).build(),
            resources, ImmutableMap.of(), ImmutableMultimap.of(), args.getZipSafe());
    ImmutableList<BuildRule> deps = RichStream
            .from(PythonUtil.getDeps(pythonPlatform, cxxPlatform, args.getDeps(), args.getPlatformDeps()))
            .concat(args.getNeededCoverage().stream().map(NeededCoverageSpec::getBuildTarget))
            .map(graphBuilder::getRule).collect(ImmutableList.toImmutableList());

    CellPathResolver cellRoots = context.getCellPathResolver();
    StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.builder().setBuildTarget(buildTarget)
            .setCellPathResolver(cellRoots).setExpanders(PythonUtil.MACRO_EXPANDERS).build();
    PythonPackageComponents allComponents = PythonUtil.getAllComponents(cellRoots, buildTarget,
            projectFilesystem, params, graphBuilder, ruleFinder, deps, testComponents, pythonPlatform,
            cxxBuckConfig, cxxPlatform,
            args.getLinkerFlags().stream().map(x -> macrosConverter.convert(x, graphBuilder))
                    .collect(ImmutableList.toImmutableList()),
            pythonBuckConfig.getNativeLinkStrategy(), args.getPreloadDeps());

    // Build the PEX using a python binary rule with the minimum dependencies.
    buildTarget.assertUnflavored();
    PythonBinary binary = binaryDescription.createPackageRule(buildTarget.withAppendedFlavors(BINARY_FLAVOR),
            projectFilesystem, params, graphBuilder, ruleFinder, pythonPlatform, cxxPlatform, mainModule,
            args.getExtension(), allComponents, args.getBuildArgs(),
            args.getPackageStyle().orElse(pythonBuckConfig.getPackageStyle()),
            PythonUtil.getPreloadNames(graphBuilder, cxxPlatform, args.getPreloadDeps()));
    graphBuilder.addToIndex(binary);

    ImmutableList.Builder<Pair<Float, ImmutableSet<Path>>> neededCoverageBuilder = ImmutableList.builder();
    for (NeededCoverageSpec coverageSpec : args.getNeededCoverage()) {
        BuildRule buildRule = graphBuilder.getRule(coverageSpec.getBuildTarget());
        if (deps.contains(buildRule) && buildRule instanceof PythonLibrary) {
            PythonLibrary pythonLibrary = (PythonLibrary) buildRule;
            ImmutableSortedSet<Path> paths;
            if (coverageSpec.getPathName().isPresent()) {
                Path path = coverageSpec.getBuildTarget().getBasePath()
                        .resolve(coverageSpec.getPathName().get());
                if (!pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder)
                        .getModules().keySet().contains(path)) {
                    throw new HumanReadableException(
                            "%s: path %s specified in needed_coverage not found in target %s", buildTarget,
                            path, buildRule.getBuildTarget());
                }
                paths = ImmutableSortedSet.of(path);
            } else {
                paths = ImmutableSortedSet.copyOf(
                        pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder)
                                .getModules().keySet());
            }
            neededCoverageBuilder
                    .add(new Pair<>(coverageSpec.getNeededCoverageRatioPercentage() / 100.f, paths));
        } else {
            throw new HumanReadableException(
                    "%s: needed_coverage requires a python library dependency. Found %s instead", buildTarget,
                    buildRule);
        }
    }

    Function<BuildRuleResolver, ImmutableMap<String, Arg>> testEnv = (ruleResolverInner) -> ImmutableMap
            .copyOf(Maps.transformValues(args.getEnv(), x -> macrosConverter.convert(x, graphBuilder)));

    // Additional CXX Targets used to generate CXX coverage.
    ImmutableSet<UnflavoredBuildTarget> additionalCoverageTargets = RichStream
            .from(args.getAdditionalCoverageTargets()).map(target -> target.getUnflavoredBuildTarget())
            .collect(ImmutableSet.toImmutableSet());
    ImmutableSortedSet<SourcePath> additionalCoverageSourcePaths = additionalCoverageTargets.isEmpty()
            ? ImmutableSortedSet.of()
            : binary.getRuntimeDeps(ruleFinder)
                    .filter(target -> additionalCoverageTargets.contains(target.getUnflavoredBuildTarget()))
                    .map(target -> DefaultBuildTargetSourcePath.of(target))
                    .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural()));

    // Generate and return the python test rule, which depends on the python binary rule above.
    return PythonTest.from(buildTarget, projectFilesystem, params, graphBuilder, testEnv, binary,
            args.getLabels(), neededCoverageBuilder.build(), additionalCoverageSourcePaths,
            args.getTestRuleTimeoutMs().map(Optional::of).orElse(
                    cxxBuckConfig.getDelegate().getView(TestBuckConfig.class).getDefaultTestRuleTimeoutMs()),
            args.getContacts());
}

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

private Optional<JarParameters> getJarParameters(BuildContext context, ProjectFilesystem filesystem,
        BuildTarget buildTarget, CompilerParameters compilerParameters) {
    return getOutputJarPath(buildTarget, filesystem).map(output -> JarParameters.builder()
            .setEntriesToJar(ImmutableSortedSet.of(compilerParameters.getOutputPaths().getClassesDir()))
            .setManifestFile(manifestFile.map(context.getSourcePathResolver()::getAbsolutePath))
            .setJarPath(output).setRemoveEntryPredicate(classesToRemoveFromJar).build());
}

From source file:com.facebook.buck.features.go.GoDescriptors.java

static Tool getTestMainGenerator(GoBuckConfig goBuckConfig, GoPlatform platform, BuildTarget sourceBuildTarget,
        ProjectFilesystem projectFilesystem, BuildRuleParams sourceParams, ActionGraphBuilder graphBuilder) {

    Optional<Tool> configTool = platform.getTestMainGen();
    if (configTool.isPresent()) {
        return configTool.get();
    }/*from   w  ww. j  a v  a  2 s.c o  m*/

    // TODO(mikekap): Make a single test main gen, rather than one per test. The generator itself
    // doesn't vary per test.
    BuildRule generator = graphBuilder.computeIfAbsent(
            sourceBuildTarget.withFlavors(InternalFlavor.of("make-test-main-gen")), generatorTarget -> {
                WriteFile writeFile = (WriteFile) graphBuilder.computeIfAbsent(
                        sourceBuildTarget.withAppendedFlavors(InternalFlavor.of("test-main-gen-source")),
                        generatorSourceTarget -> new WriteFile(generatorSourceTarget, projectFilesystem,
                                extractTestMainGenerator(), BuildTargetPaths.getGenPath(projectFilesystem,
                                        generatorSourceTarget, "%s/main.go"),
                                /* executable */ false));

                return createGoBinaryRule(generatorTarget, projectFilesystem,
                        sourceParams.withoutDeclaredDeps().withExtraDeps(ImmutableSortedSet.of(writeFile)),
                        graphBuilder, goBuckConfig, Linker.LinkableDepType.STATIC_PIC, Optional.empty(),
                        ImmutableSet.of(writeFile.getSourcePathToOutput()), ImmutableSortedSet.of(),
                        ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
                        platform);
            });

    return ((BinaryBuildRule) generator).getExecutableCommand();
}

From source file:org.jahia.services.shindig.JahiaShindigService.java

/**
 * Get the set of user id's from a user and group
 *//*w  w  w . j  a  va  2s  .co m*/
private Set<String> getIdSet(UserId user, GroupId group, SecurityToken token) throws RepositoryException {
    final String userId = user.getUserId(token);

    if (group == null) {
        return ImmutableSortedSet.of(userId);
    }

    final Set<String> returnVal = Sets.newLinkedHashSet();
    switch (group.getType()) {
    case all:
    case friends:
        jcrTemplate.doExecuteWithSystemSession(new JCRCallback<Object>() {
            public Object doInJCR(JCRSessionWrapper session) throws RepositoryException {
                String userName = getUserNameFromKey(userId);

                Node userNode = null;
                try {
                    userNode = session.getNode(
                            jahiaUserManagerService.getUserSplittingRule().getPathForUsername(userName));
                } catch (PathNotFoundException pnfe) {
                    return returnVal;
                }
                Query myConnectionsQuery = session.getWorkspace().getQueryManager()
                        .createQuery("select * from [jnt:socialConnection] as uC where isdescendantnode(uC,['"
                                + userNode.getPath() + "'])", Query.JCR_SQL2);
                QueryResult myConnectionsResult = myConnectionsQuery.execute();

                NodeIterator myConnectionsIterator = myConnectionsResult.getNodes();
                while (myConnectionsIterator.hasNext()) {
                    JCRNodeWrapper myConnectionNode = (JCRNodeWrapper) myConnectionsIterator.nextNode();
                    JCRNodeWrapper connectedToNode = (JCRNodeWrapper) myConnectionNode
                            .getProperty("j:connectedTo").getNode();
                    JahiaUser jahiaUser = jahiaUserManagerService.lookupUser(connectedToNode.getName());
                    if (jahiaUser != null) {
                        returnVal.add(jahiaUser.getUserKey());
                    }
                }
                return returnVal;
            }
        });
        break;
    case groupId:
        break;
    case self:
        returnVal.add(userId);
        break;
    }
    return returnVal;
}

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

/**
 * Building a java_library() rule entails compiling the .java files specified in the srcs
 * attribute. They are compiled into a directory under {@link BuckPaths#getScratchDir()}.
 *//*w ww.j av  a2  s  . c om*/
@Override
public final ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();

    FluentIterable<JavaLibrary> declaredClasspathDeps = JavaLibraryClasspathProvider
            .getJavaLibraryDeps(getDepsForTransitiveClasspathEntries());

    // Always create the output directory, even if there are no .java files to compile because there
    // might be resources that need to be copied there.
    BuildTarget target = getBuildTarget();
    Path outputDirectory = getClassesDir(target, getProjectFilesystem());
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), outputDirectory));

    SuggestBuildRules suggestBuildRule = DefaultSuggestBuildRules.createSuggestBuildFunction(JAR_RESOLVER,
            declaredClasspathDeps.toSet(),
            ImmutableSet.<JavaLibrary>builder().addAll(getTransitiveClasspathDeps()).add(this).build(),
            context.getActionGraph().getNodes());

    // We don't want to add these to the declared or transitive deps, since they're only used at
    // compile time.
    Collection<Path> provided = JavaLibraryClasspathProvider.getJavaLibraryDeps(providedDeps)
            .transformAndConcat(JavaLibrary::getOutputClasspaths).filter(Objects::nonNull).toSet();

    ProjectFilesystem projectFilesystem = getProjectFilesystem(); // NOPMD confused by lambda
    Iterable<Path> declaredClasspaths = declaredClasspathDeps
            .transformAndConcat(JavaLibrary::getOutputClasspaths).transform(projectFilesystem::resolve);
    // Only override the bootclasspath if this rule is supposed to compile Android code.
    ImmutableSortedSet<Path> declared = ImmutableSortedSet.<Path>naturalOrder().addAll(declaredClasspaths)
            .addAll(additionalClasspathEntries).addAll(provided).build();

    // Make sure that this directory exists because ABI information will be written here.
    Step mkdir = new MakeCleanDirectoryStep(getProjectFilesystem(), getPathToAbiOutputDir());
    steps.add(mkdir);

    // If there are resources, then link them to the appropriate place in the classes directory.
    JavaPackageFinder finder = context.getJavaPackageFinder();
    if (resourcesRoot.isPresent()) {
        finder = new ResourcesRootPackageFinder(resourcesRoot.get(), finder);
    }

    steps.add(new CopyResourcesStep(getProjectFilesystem(), getResolver(), ruleFinder, target, resources,
            outputDirectory, finder));

    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(),
            getOutputJarDirPath(target, getProjectFilesystem())));

    // Only run javac if there are .java files to compile or we need to shovel the manifest file
    // into the built jar.
    if (!getJavaSrcs().isEmpty()) {
        ClassUsageFileWriter usedClassesFileWriter;
        if (trackClassUsage) {
            final Path usedClassesFilePath = getUsedClassesFilePath(getBuildTarget(), getProjectFilesystem());
            depFileOutputPath = getProjectFilesystem().getPathForRelativePath(usedClassesFilePath);
            usedClassesFileWriter = new DefaultClassUsageFileWriter(usedClassesFilePath);

            buildableContext.recordArtifact(usedClassesFilePath);
        } else {
            usedClassesFileWriter = NoOpClassUsageFileWriter.instance();
        }

        // This adds the javac command, along with any supporting commands.
        Path pathToSrcsList = BuildTargets.getGenPath(getProjectFilesystem(), getBuildTarget(), "__%s__srcs");
        steps.add(new MkdirStep(getProjectFilesystem(), pathToSrcsList.getParent()));

        Path scratchDir = BuildTargets.getGenPath(getProjectFilesystem(), target,
                "lib__%s____working_directory");
        steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), scratchDir));
        Optional<Path> workingDirectory = Optional.of(scratchDir);

        ImmutableSortedSet<Path> javaSrcs = getJavaSrcs().stream().map(getResolver()::getRelativePath)
                .collect(MoreCollectors.toImmutableSortedSet());

        compileStepFactory.createCompileToJarStep(context, javaSrcs, target, getResolver(), ruleFinder,
                getProjectFilesystem(), declared, outputDirectory, workingDirectory, pathToSrcsList,
                Optional.of(suggestBuildRule), postprocessClassesCommands,
                ImmutableSortedSet.of(outputDirectory), /* mainClass */ Optional.empty(),
                manifestFile.map(getResolver()::getAbsolutePath), outputJar.get(), usedClassesFileWriter,
                /* output params */
                steps, buildableContext, classesToRemoveFromJar);
    }

    if (outputJar.isPresent()) {
        Path output = outputJar.get();

        // No source files, only resources
        if (getJavaSrcs().isEmpty()) {
            steps.add(
                    new JarDirectoryStep(getProjectFilesystem(), output, ImmutableSortedSet.of(outputDirectory),
                            /* mainClass */ null, manifestFile.map(getResolver()::getAbsolutePath).orElse(null),
                            true, classesToRemoveFromJar));
        }
        buildableContext.recordArtifact(output);
    }

    JavaLibraryRules.addAccumulateClassNamesStep(this, buildableContext, steps);

    return steps.build();
}

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

private Aapt2Link createAapt2Link(int packageId, InternalFlavor flavor, SourcePath realManifest,
        AndroidPackageableCollection.ResourceDetails resourceDetails,
        Optional<FilteredResourcesProvider> filteredResourcesProvider,
        ImmutableList<SourcePath> dependencyResourceApks, boolean isProtoFormat) {

    ImmutableList.Builder<Aapt2Compile> compileListBuilder = ImmutableList.builder();
    if (filteredResourcesProvider.isPresent()) {
        Optional<BuildRule> resourceFilterRule = filteredResourcesProvider.get().getResourceFilterRule();
        Preconditions.checkState(resourceFilterRule.isPresent(),
                "Expected ResourceFilterRule to be present when filtered resources are present.");

        ImmutableSortedSet<BuildRule> compileDeps = ImmutableSortedSet.of(resourceFilterRule.get());
        int index = 0;
        for (SourcePath resDir : filteredResourcesProvider.get().getResDirectories()) {
            Aapt2Compile compileRule = new Aapt2Compile(
                    buildTarget.withAppendedFlavors(InternalFlavor.of("aapt2_compile_" + index), flavor),
                    projectFilesystem, androidPlatformTarget, compileDeps, resDir);
            graphBuilder.addToIndex(compileRule);
            compileListBuilder.add(compileRule);
            index++;/*  w w  w  .  j  a  va  2 s  .co  m*/
        }
    } else {
        for (BuildTarget resTarget : resourceDetails.getResourcesWithNonEmptyResDir()) {
            compileListBuilder.add((Aapt2Compile) graphBuilder.requireRule(
                    resTarget.withAppendedFlavors(AndroidResourceDescription.AAPT2_COMPILE_FLAVOR)));
        }
    }
    return new Aapt2Link(
            buildTarget.withAppendedFlavors(AAPT2_LINK_FLAVOR, flavor,
                    InternalFlavor.of(isProtoFormat ? "proto" : "arsc")),
            projectFilesystem, ruleFinder, compileListBuilder.build(),
            getTargetsAsResourceDeps(resourceDetails.getResourcesWithNonEmptyResDir()), realManifest,
            manifestEntries, packageId, dependencyResourceApks, includesVectorDrawables, noAutoVersionResources,
            noVersionTransitionsResources, noAutoAddOverlayResources, isProtoFormat, androidPlatformTarget);
}