Search in sources :

Example 86 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project intellij-community by JetBrains.

the class GithubTagListProvider method toGithubTagList.

@NotNull
private static ImmutableSet<GithubTagInfo> toGithubTagList(@NotNull JsonElement jsonElement) throws GeneratorException {
    if (jsonElement instanceof JsonArray) {
        JsonArray array = (JsonArray) jsonElement;
        ImmutableSet.Builder<GithubTagInfo> tags = ImmutableSet.builder();
        for (JsonElement element : array) {
            if (element instanceof JsonObject) {
                JsonObject obj = (JsonObject) element;
                JsonElement nameElement = obj.get("name");
                String name = null;
                if (nameElement != null) {
                    name = nameElement.getAsString();
                }
                String zipball = null;
                JsonElement zipballElement = obj.get("zipball_url");
                if (zipballElement != null) {
                    zipball = zipballElement.getAsString();
                }
                if (name != null && zipball != null) {
                    tags.add(new GithubTagInfo(name, zipball));
                }
            } else {
                throw new GeneratorException("Unexpected child element " + element.getClass().getName());
            }
        }
        return tags.build();
    } else {
        throw new GeneratorException("jsonElement is expected be instance of " + JsonArray.class.getName());
    }
}
Also used : JsonArray(com.google.gson.JsonArray) GithubTagInfo(com.intellij.platform.templates.github.GithubTagInfo) ImmutableSet(com.google.common.collect.ImmutableSet) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) GeneratorException(com.intellij.platform.templates.github.GeneratorException) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project cdap by caskdata.

the class ArtifactStoreTest method testConcurrentSnapshotWrite.

@Category(SlowTests.class)
@Test
public void testConcurrentSnapshotWrite() throws Exception {
    // write parent
    Id.Artifact parentArtifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "parent", "1.0.0");
    ArtifactMeta parentMeta = new ArtifactMeta(ArtifactClasses.builder().build());
    writeArtifact(parentArtifactId, parentMeta, "content");
    final ArtifactRange parentArtifacts = new ArtifactRange(NamespaceId.DEFAULT.getNamespace(), "parent", new ArtifactVersion("1.0.0"), new ArtifactVersion("2.0.0"));
    // start up a bunch of threads that will try and write the same artifact at the same time
    // only one of them should be able to write it
    int numThreads = 20;
    final Id.Artifact artifactId = Id.Artifact.from(Id.Namespace.DEFAULT, "abc", "1.0.0-SNAPSHOT");
    // use a barrier so they all try and write at the same time
    final CyclicBarrier barrier = new CyclicBarrier(numThreads);
    final CountDownLatch latch = new CountDownLatch(numThreads);
    ExecutorService executorService = Executors.newFixedThreadPool(numThreads);
    for (int i = 0; i < numThreads; i++) {
        final String writer = String.valueOf(i);
        executorService.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    barrier.await();
                    ArtifactMeta meta = new ArtifactMeta(ArtifactClasses.builder().addPlugin(new PluginClass("plugin-type", "plugin" + writer, "", "classname", "cfg", ImmutableMap.<String, PluginPropertyField>of())).build(), ImmutableSet.of(parentArtifacts));
                    writeArtifact(artifactId, meta, writer);
                } catch (InterruptedException | BrokenBarrierException | ArtifactAlreadyExistsException | IOException e) {
                    // something went wrong, fail the test
                    throw new RuntimeException(e);
                } catch (WriteConflictException e) {
                // these are ok though unexpected (means couldn't write after a bunch of retries too)
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    // wait for all writers to finish
    latch.await();
    // figure out which was the last writer by reading our data. all the writers should have been able to write,
    // and they should have all overwritten each other in a consistent manner
    ArtifactDetail detail = artifactStore.getArtifact(artifactId);
    // figure out the winning writer from the plugin name, which is 'plugin<writer>'
    String pluginName = detail.getMeta().getClasses().getPlugins().iterator().next().getName();
    String winnerWriter = pluginName.substring("plugin".length());
    ArtifactMeta expectedMeta = new ArtifactMeta(ArtifactClasses.builder().addPlugin(new PluginClass("plugin-type", "plugin" + winnerWriter, "", "classname", "cfg", ImmutableMap.<String, PluginPropertyField>of())).build(), ImmutableSet.of(parentArtifacts));
    assertEqual(artifactId, expectedMeta, winnerWriter, detail);
    // check only 1 plugin remains and that its the correct one
    Map<ArtifactDescriptor, Set<PluginClass>> pluginMap = artifactStore.getPluginClasses(NamespaceId.DEFAULT, parentArtifactId, "plugin-type");
    Map<ArtifactDescriptor, Set<PluginClass>> expected = Maps.newHashMap();
    expected.put(detail.getDescriptor(), ImmutableSet.<PluginClass>of(new PluginClass("plugin-type", "plugin" + winnerWriter, "", "classname", "cfg", ImmutableMap.<String, PluginPropertyField>of())));
    Assert.assertEquals(expected, pluginMap);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) ArtifactRange(co.cask.cdap.api.artifact.ArtifactRange) CountDownLatch(java.util.concurrent.CountDownLatch) PluginPropertyField(co.cask.cdap.api.plugin.PluginPropertyField) CyclicBarrier(java.util.concurrent.CyclicBarrier) ArtifactVersion(co.cask.cdap.api.artifact.ArtifactVersion) ExecutorService(java.util.concurrent.ExecutorService) Id(co.cask.cdap.proto.Id) ArtifactId(co.cask.cdap.proto.id.ArtifactId) NamespaceId(co.cask.cdap.proto.id.NamespaceId) PluginClass(co.cask.cdap.api.plugin.PluginClass) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 88 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project GeoGig by boundlessgeo.

the class HttpMappedRemoteRepo method listRefs.

/**
     * List the mapped versions of the remote's {@link Ref refs}. For example, if the remote ref
     * points to commit A, the returned ref will point to the commit that A is mapped to.
     * 
     * @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(boolean getHeads, boolean getTags) {
    HttpURLConnection connection = null;
    ImmutableSet.Builder<Ref> builder = new ImmutableSet.Builder<Ref>();
    try {
        String expanded = repositoryURL.toString() + "/repo/manifest";
        connection = (HttpURLConnection) new URL(expanded).openConnection();
        connection.setRequestMethod("GET");
        connection.setUseCaches(false);
        connection.setDoOutput(true);
        // Get Response
        InputStream is = connection.getInputStream();
        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"))) {
                    Ref remoteRef = HttpUtils.parseRef(line);
                    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);
                }
            }
        } finally {
            rd.close();
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    } finally {
        HttpUtils.consumeErrStreamAndCloseConnection(connection);
    }
    return builder.build();
}
Also used : InputStreamReader(java.io.InputStreamReader) ObjectId(org.locationtech.geogig.api.ObjectId) InputStream(java.io.InputStream) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) SymRef(org.locationtech.geogig.api.SymRef) HttpURLConnection(java.net.HttpURLConnection) ImmutableSet(com.google.common.collect.ImmutableSet) BufferedReader(java.io.BufferedReader)

Example 89 with ImmutableSet

use of 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 90 with ImmutableSet

use of 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)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)212 Path (java.nio.file.Path)66 BuildTarget (com.facebook.buck.model.BuildTarget)58 ImmutableList (com.google.common.collect.ImmutableList)48 ImmutableMap (com.google.common.collect.ImmutableMap)48 IOException (java.io.IOException)43 Optional (java.util.Optional)39 Test (org.junit.Test)35 SourcePath (com.facebook.buck.rules.SourcePath)31 Set (java.util.Set)31 Map (java.util.Map)30 TargetNode (com.facebook.buck.rules.TargetNode)28 List (java.util.List)28 BuildRule (com.facebook.buck.rules.BuildRule)26 HumanReadableException (com.facebook.buck.util.HumanReadableException)23 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)21 HashMap (java.util.HashMap)21 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)20