Search in sources :

Example 76 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project GeoGig by boundlessgeo.

the class HttpRemoteRepo method listRefs.

/**
     * List the remote's {@link Ref refs}.
     * 
     * @param getHeads whether to return refs in the {@code refs/heads} namespace
     * @param getTags whether to return refs in the {@code refs/tags} namespace
     * @return an immutable set of refs from the remote
     */
@Override
public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
    HttpURLConnection connection = null;
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    try {
        String expanded = repositoryURL.toString() + "/repo/manifest";
        connection = HttpUtils.connect(expanded);
        // Get Response
        InputStream is = HttpUtils.getResponseStream(connection);
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));
        String line;
        try {
            while ((line = rd.readLine()) != null) {
                if ((getHeads && line.startsWith("refs/heads")) || (getTags && line.startsWith("refs/tags"))) {
                    builder.add(HttpUtils.parseRef(line));
                }
            }
        } finally {
            rd.close();
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        HttpUtils.consumeErrStreamAndCloseConnection(connection);
    }
    return builder.build();
}
Also used : Ref(org.locationtech.geogig.api.Ref) HttpURLConnection(java.net.HttpURLConnection) ImmutableSet(com.google.common.collect.ImmutableSet) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) SynchronizationException(org.locationtech.geogig.api.porcelain.SynchronizationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 77 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project GeoGig by boundlessgeo.

the class LocalMappedRemoteRepo method listRefs.

/**
     * List the remote's {@link Ref refs}.
     * 
     * @param getHeads whether to return refs in the {@code refs/heads} namespace
     * @param getTags whether to return refs in the {@code refs/tags} namespace
     * @return an immutable set of refs from the remote
     */
@Override
public ImmutableSet<Ref> listRefs(final boolean getHeads, final boolean getTags) {
    Predicate<Ref> filter = new Predicate<Ref>() {

        @Override
        public boolean apply(Ref input) {
            boolean keep = false;
            if (getHeads) {
                keep = input.getName().startsWith(Ref.HEADS_PREFIX);
            }
            if (getTags) {
                keep = keep || input.getName().startsWith(Ref.TAGS_PREFIX);
            }
            return keep;
        }
    };
    ImmutableSet<Ref> remoteRefs = remoteGeoGig.command(ForEachRef.class).setFilter(filter).call();
    // Translate the refs to their mapped values.
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    for (Ref remoteRef : remoteRefs) {
        Ref newRef = remoteRef;
        if (!(newRef instanceof SymRef) && localRepository.graphDatabase().exists(remoteRef.getObjectId())) {
            ObjectId mappedCommit = localRepository.graphDatabase().getMapping(remoteRef.getObjectId());
            if (mappedCommit != null) {
                newRef = new Ref(remoteRef.getName(), mappedCommit);
            }
        }
        builder.add(newRef);
    }
    return builder.build();
}
Also used : UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) UpdateSymRef(org.locationtech.geogig.api.plumbing.UpdateSymRef) SymRef(org.locationtech.geogig.api.SymRef) ImmutableSet(com.google.common.collect.ImmutableSet) ObjectId(org.locationtech.geogig.api.ObjectId) CommitBuilder(org.locationtech.geogig.api.CommitBuilder) Predicate(com.google.common.base.Predicate)

Example 78 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project GeoGig by boundlessgeo.

the class ForEachRef method _call.

/**
     * @return the new value of the ref
     */
@Override
protected ImmutableSet<Ref> _call() {
    @SuppressWarnings("unchecked") final Predicate<Ref> filter = (Predicate<Ref>) (this.filter == null ? Predicates.alwaysTrue() : this.filter);
    ImmutableSet.Builder<Ref> refs = new ImmutableSet.Builder<Ref>();
    for (String refName : refDatabase().getAll().keySet()) {
        Optional<Ref> ref = command(RefParse.class).setName(refName).call();
        if (ref.isPresent() && filter.apply(ref.get())) {
            Ref accepted = ref.get();
            refs.add(accepted);
        }
    }
    return refs.build();
}
Also used : Ref(org.locationtech.geogig.api.Ref) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(com.google.common.base.Predicate)

Example 79 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project gradle by gradle.

the class DefaultTaskExecutionPlan method canonicalizedPaths.

private static ImmutableSet<String> canonicalizedPaths(final Map<File, String> cache, Iterable<File> files) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (File file : files) {
        String path;
        try {
            path = cache.get(file);
            if (path == null) {
                path = file.getCanonicalPath();
                cache.put(file, path);
            }
            builder.add(path);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) File(java.io.File)

Example 80 with ImmutableSet

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project gradle by gradle.

the class FileToArchiveEntrySetTransformer method walk.

private ImmutableSet<ArchiveEntry> walk(InputStream archiveInputStream, ImmutableSet.Builder<ArchiveEntry> allEntries, ImmutableList<String> parentPaths) {
    ImmutableSet.Builder<ArchiveEntry> entries = ImmutableSet.builder();
    ZipInputStream zipStream = new ZipInputStream(archiveInputStream);
    try {
        ZipEntry entry = zipStream.getNextEntry();
        while (entry != null) {
            ArchiveEntry.Builder builder = new ArchiveEntry.Builder();
            builder.setParentPaths(parentPaths);
            builder.setPath(entry.getName());
            builder.setCrc(entry.getCrc());
            builder.setDirectory(entry.isDirectory());
            builder.setSize(entry.getSize());
            if (!builder.isDirectory() && (zipStream.available() == 1)) {
                boolean zipEntry;
                final BufferedInputStream bis = new BufferedInputStream(zipStream) {

                    @Override
                    public void close() throws IOException {
                    }
                };
                bis.mark(Integer.MAX_VALUE);
                zipEntry = new ZipInputStream(bis).getNextEntry() != null;
                bis.reset();
                if (zipEntry) {
                    ImmutableList<String> nextParentPaths = ImmutableList.<String>builder().addAll(parentPaths).add(entry.getName()).build();
                    ImmutableSet<ArchiveEntry> subEntries = walk(bis, allEntries, nextParentPaths);
                    builder.setSubEntries(subEntries);
                }
            }
            ArchiveEntry archiveEntry = builder.build();
            entries.add(archiveEntry);
            allEntries.add(archiveEntry);
            zipStream.closeEntry();
            entry = zipStream.getNextEntry();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        IOUtils.closeQuietly(zipStream);
    }
    return entries.build();
}
Also used : ZipEntry(java.util.zip.ZipEntry) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ZipInputStream(java.util.zip.ZipInputStream) ImmutableSet(com.google.common.collect.ImmutableSet)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)348 Set (java.util.Set)86 ImmutableList (com.google.common.collect.ImmutableList)73 Path (java.nio.file.Path)71 ImmutableMap (com.google.common.collect.ImmutableMap)69 IOException (java.io.IOException)67 Optional (java.util.Optional)65 Map (java.util.Map)63 List (java.util.List)60 BuildTarget (com.facebook.buck.model.BuildTarget)58 Test (org.junit.Test)55 HashMap (java.util.HashMap)42 Collection (java.util.Collection)34 HashSet (java.util.HashSet)33 SourcePath (com.facebook.buck.rules.SourcePath)31 ArrayList (java.util.ArrayList)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 VisibleForTesting (com.google.common.annotations.VisibleForTesting)25 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)25