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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations