Search in sources :

Example 1 with ImmutableCollection

use of com.google.common.collect.ImmutableCollection in project android by JetBrains.

the class LibraryDependencyNode method setUp.

private void setUp(@NotNull PsLibraryAndroidDependency dependency) {
    myName = getText(dependency);
    ImmutableCollection<PsDependency> transitiveDependencies = dependency.getTransitiveDependencies();
    transitiveDependencies.stream().filter(transitive -> transitive instanceof PsLibraryAndroidDependency).forEach(transitive -> {
        PsLibraryAndroidDependency transitiveLibrary = (PsLibraryAndroidDependency) transitive;
        LibraryDependencyNode child = new LibraryDependencyNode(this, transitiveLibrary);
        myChildren.add(child);
    });
    Collections.sort(myChildren, DependencyNodeComparator.INSTANCE);
}
Also used : StringUtil.isNotEmpty(com.intellij.openapi.util.text.StringUtil.isNotEmpty) GRADLE_PATH_SEPARATOR(com.android.SdkConstants.GRADLE_PATH_SEPARATOR) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) ImmutableCollection(com.google.common.collect.ImmutableCollection) AbstractPsNode(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsNode) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) Nullable(org.jetbrains.annotations.Nullable) PsUISettings(com.android.tools.idea.gradle.structure.configurables.ui.PsUISettings) List(java.util.List) Lists(com.google.common.collect.Lists) PsModel(com.android.tools.idea.gradle.structure.model.PsModel) SimpleNode(com.intellij.ui.treeStructure.SimpleNode) PsArtifactDependencySpec(com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) PsLibraryAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency)

Example 2 with ImmutableCollection

use of com.google.common.collect.ImmutableCollection in project buck by facebook.

the class DalvikAwareZipSplitter method execute.

@Override
public ImmutableMultimap<APKModule, Path> execute() throws IOException {
    ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
    final Set<String> secondaryTail = new HashSet<String>();
    // Start out by writing the primary zip and recording which entries were added to it.
    primaryOut = newZipOutput(outPrimary);
    secondaryDexWriter.reset();
    final ImmutableMap.Builder<String, FileLike> entriesBuilder = ImmutableMap.builder();
    final List<String> additionalDexStoreEntries = new ArrayList<>();
    // Iterate over all of the inFiles and add all entries that match the requiredInPrimaryZip
    // predicate.
    LOG.debug("Traversing classpath for primary zip");
    classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {

        @Override
        public void visit(FileLike entry) throws IOException {
            LOG.debug("Visiting " + entry.getRelativePath());
            String relativePath = entry.getRelativePath();
            if (!relativePath.endsWith(".class")) {
                // We don't need resources in dex jars, so just drop them.
                return;
            }
            Preconditions.checkNotNull(primaryOut);
            Preconditions.checkNotNull(classPathToDexStore);
            if (requiredInPrimaryZip.apply(relativePath)) {
                primaryOut.putEntry(entry);
            } else if (wantedInPrimaryZip.contains(relativePath) || (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath))) {
                entriesBuilder.put(relativePath, new BufferedFileLike(entry));
            } else if (secondaryTailSet != null && secondaryTailSet.contains(relativePath)) {
                entriesBuilder.put(relativePath, new BufferedFileLike(entry));
                secondaryTail.add(relativePath);
            } else {
                ImmutableCollection<APKModule> containingModule = classPathToDexStore.get(relativePath);
                if (!containingModule.isEmpty()) {
                    if (containingModule.size() > 1) {
                        throw new IllegalStateException(String.format("classpath %s is contained in multiple dex stores: %s", relativePath, classPathToDexStore.get(relativePath).asList().toString()));
                    }
                    APKModule dexStore = containingModule.iterator().next();
                    if (!dexStore.equals(apkModuleGraph.getRootAPKModule())) {
                        MySecondaryDexHelper dexHelper = additionalDexWriters.get(dexStore);
                        Preconditions.checkNotNull(dexHelper);
                        dexHelper.getOutputToWriteTo(entry).putEntry(entry);
                        additionalDexStoreEntries.add(relativePath);
                    }
                }
            }
        }
    });
    // Put as many of the items wanted in the primary dex as we can into the primary dex.
    ImmutableMap<String, FileLike> entries = entriesBuilder.build();
    for (String wanted : wantedInPrimaryZip) {
        FileLike entry = entries.get(wanted);
        if ((entry != null) && !primaryOut.containsEntry(entry) && primaryOut.canPutEntry(entry)) {
            primaryOut.putEntry(entry);
        }
    }
    if (secondaryHeadSet != null) {
        for (String head : secondaryHeadSet) {
            FileLike headEntry = entries.get(head);
            if ((headEntry != null) && !primaryOut.containsEntry(headEntry)) {
                secondaryDexWriter.getOutputToWriteTo(headEntry).putEntry(headEntry);
            }
        }
    }
    LOG.debug("Traversing classpath for secondary zip");
    // Now that all of the required entries have been added to the primary zip, fill the rest of
    // the zip up with the remaining entries.
    classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {

        @Override
        public void visit(FileLike entry) throws IOException {
            Preconditions.checkNotNull(primaryOut);
            String relativePath = entry.getRelativePath();
            // skip if it is the primary dex, is part of a modular dex store, or is not a class file
            if (primaryOut.containsEntry(entry) || additionalDexStoreEntries.contains(relativePath)) {
                return;
            }
            LOG.debug("Visiting " + entry.getRelativePath());
            // room in the primary dex for the current entry in the traversal.
            if (dexSplitStrategy == DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE && primaryOut.canPutEntry(entry)) {
                primaryOut.putEntry(entry);
            } else {
                if (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath)) {
                    return;
                }
                if (secondaryTail.contains(relativePath)) {
                    return;
                }
                secondaryDexWriter.getOutputToWriteTo(entry).putEntry(entry);
            }
        }
    });
    if (secondaryTailSet != null) {
        for (String tail : secondaryTailSet) {
            FileLike tailEntry = entries.get(tail);
            if ((tailEntry != null) && !primaryOut.containsEntry(tailEntry) && secondaryTail.contains(tail)) {
                secondaryDexWriter.getOutputToWriteTo(tailEntry).putEntry(tailEntry);
            }
        }
    }
    primaryOut.close();
    secondaryDexWriter.close();
    ImmutableMultimap.Builder<APKModule, Path> outputFilesBuilder = ImmutableMultimap.builder();
    APKModule secondaryDexStore = apkModuleGraph.getRootAPKModule();
    outputFilesBuilder.putAll(secondaryDexStore, secondaryDexWriter.getFiles());
    for (Map.Entry<APKModule, MySecondaryDexHelper> entry : additionalDexWriters.entrySet()) {
        if (!entry.getKey().equals(secondaryDexStore)) {
            entry.getValue().close();
            outputFilesBuilder.putAll(entry.getKey(), entry.getValue().getFiles());
        }
    }
    return outputFilesBuilder.build();
}
Also used : Path(java.nio.file.Path) ClasspathTraversal(com.facebook.buck.jvm.java.classes.ClasspathTraversal) ImmutableCollection(com.google.common.collect.ImmutableCollection) DefaultClasspathTraverser(com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser) ClasspathTraverser(com.facebook.buck.jvm.java.classes.ClasspathTraverser) DefaultClasspathTraverser(com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser) ArrayList(java.util.ArrayList) APKModule(com.facebook.buck.android.APKModule) IOException(java.io.IOException) AbstractFileLike(com.facebook.buck.jvm.java.classes.AbstractFileLike) FileLike(com.facebook.buck.jvm.java.classes.FileLike) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 3 with ImmutableCollection

use of com.google.common.collect.ImmutableCollection in project incubator-atlas by apache.

the class ReplaceIdWithInstance method convertToInstances.

ImmutableCollection<?> convertToInstances(ImmutableCollection<?> val, Multiplicity m, DataTypes.ArrayType arrType) throws AtlasException {
    if (val == null || arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) {
        return val;
    }
    ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder();
    for (Object elem : val) {
        if (elem instanceof Id) {
            Id id = (Id) elem;
            elem = getInstance(id);
        }
        b.add(elem);
    }
    return b.build();
}
Also used : ImmutableCollection(com.google.common.collect.ImmutableCollection) Id(org.apache.atlas.typesystem.persistence.Id)

Aggregations

ImmutableCollection (com.google.common.collect.ImmutableCollection)3 GRADLE_PATH_SEPARATOR (com.android.SdkConstants.GRADLE_PATH_SEPARATOR)1 PsUISettings (com.android.tools.idea.gradle.structure.configurables.ui.PsUISettings)1 AbstractPsNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsNode)1 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)1 PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)1 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)1 PsLibraryAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsLibraryAndroidDependency)1 APKModule (com.facebook.buck.android.APKModule)1 AbstractFileLike (com.facebook.buck.jvm.java.classes.AbstractFileLike)1 ClasspathTraversal (com.facebook.buck.jvm.java.classes.ClasspathTraversal)1 ClasspathTraverser (com.facebook.buck.jvm.java.classes.ClasspathTraverser)1 DefaultClasspathTraverser (com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser)1 FileLike (com.facebook.buck.jvm.java.classes.FileLike)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Lists (com.google.common.collect.Lists)1 StringUtil.isNotEmpty (com.intellij.openapi.util.text.StringUtil.isNotEmpty)1 SimpleNode (com.intellij.ui.treeStructure.SimpleNode)1 IOException (java.io.IOException)1