final Set<UUID> getPlayers() { ImmutableSet.Builder<UUID> setBuilder = ImmutableSet.builder(); if (pool != null) { try (Jedis rsc = pool.getResource()) { List<String> keys = new ArrayList<>(); for (String i : getServerIds()) { keys.add("proxy:" + i + ":usersOnline"); } if (!keys.isEmpty()) { Set<String> users = rsc.sunion(keys.toArray(new String[keys.size()])); if (users != null && !users.isEmpty()) { for (String user : users) { try { setBuilder = setBuilder.add(UUID.fromString(user)); } catch (IllegalArgumentException ignored) { } } } } } catch (JedisConnectionException e) { // Redis server has disappeared! getLogger() .log( Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e); throw new RuntimeException("Unable to get all players online", e); } } return setBuilder.build(); }
private void logManagedObjects() { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (Object bean : lifeCycle.getBeans()) { builder.add(bean.getClass().getCanonicalName()); } LOG.debug("managed objects = {}", builder.build()); }
static { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (TrackerFilterEnum eventFilter : TrackerFilterEnum.values()) { builder.add(eventFilter.getValue()); } valuesSet = builder.build(); }
private ImmutableSet<AspectWithParameters> requiredAspects( AspectDefinition aspectDefinition, AspectParameters aspectParameters, Attribute attribute, Target target, Rule originalRule) { if (!(target instanceof Rule)) { return ImmutableSet.of(); } Set<AspectWithParameters> aspectCandidates = extractAspectCandidates(aspectDefinition, aspectParameters, attribute, originalRule); RuleClass ruleClass = ((Rule) target).getRuleClassObject(); ImmutableSet.Builder<AspectWithParameters> result = ImmutableSet.builder(); for (AspectWithParameters candidateClass : aspectCandidates) { ConfiguredAspectFactory candidate = (ConfiguredAspectFactory) AspectFactory.Util.create(candidateClass.getAspectFactory()); if (Sets.difference( candidate.getDefinition().getRequiredProviders(), ruleClass.getAdvertisedProviders()) .isEmpty()) { result.add(candidateClass); } } return result.build(); }
/** * Returns the context for a LIPO compile action. This uses the include dirs and defines of the * library, but the declared inclusion dirs/srcs from both the library and the owner binary. * * <p>TODO(bazel-team): this might make every LIPO target have an unnecessary large set of * inclusion dirs/srcs. The correct behavior would be to merge only the contexts of actual * referred targets (as listed in .imports file). * * <p>Undeclared inclusion checking ({@link #getDeclaredIncludeDirs()}, {@link * #getDeclaredIncludeWarnDirs()}, and {@link #getDeclaredIncludeSrcs()}) needs to use the union * of the contexts of the involved source files. * * <p>For include and define command line flags ({@link #getIncludeDirs()} {@link * #getQuoteIncludeDirs()}, {@link #getSystemIncludeDirs()}, and {@link #getDefines()}) LIPO * compilations use the same values as non-LIPO compilation. * * <p>Include scanning is not handled by this method. See {@code * IncludeScannable#getAuxiliaryScannables()} instead. * * @param ownerContext the compilation context of the owner binary * @param libContext the compilation context of the library */ public static CppCompilationContext mergeForLipo( CppCompilationContext ownerContext, CppCompilationContext libContext) { ImmutableSet.Builder<Artifact> prerequisites = ImmutableSet.builder(); prerequisites.addAll(ownerContext.compilationPrerequisites); prerequisites.addAll(libContext.compilationPrerequisites); ModuleInfo.Builder moduleInfo = new ModuleInfo.Builder(); moduleInfo.merge(ownerContext.moduleInfo); moduleInfo.merge(libContext.moduleInfo); ModuleInfo.Builder picModuleInfo = new ModuleInfo.Builder(); picModuleInfo.merge(ownerContext.picModuleInfo); picModuleInfo.merge(libContext.picModuleInfo); return new CppCompilationContext( libContext.commandLineContext, prerequisites.build(), mergeSets(ownerContext.declaredIncludeDirs, libContext.declaredIncludeDirs), mergeSets(ownerContext.declaredIncludeWarnDirs, libContext.declaredIncludeWarnDirs), mergeSets(ownerContext.declaredIncludeSrcs, libContext.declaredIncludeSrcs), mergeSets(ownerContext.pregreppedHdrs, libContext.pregreppedHdrs), moduleInfo.build(), picModuleInfo.build(), mergeSets(ownerContext.transitiveModuleMaps, libContext.transitiveModuleMaps), mergeSets(ownerContext.directModuleMaps, libContext.directModuleMaps), libContext.cppModuleMap, libContext.provideTransitiveModuleMaps, libContext.useHeaderModules); }
public Collection<ITrait> getAllTraits() { ImmutableSet.Builder<ITrait> builder = ImmutableSet.builder(); for (List<ITrait> traitlist : traits.values()) { builder.addAll(traitlist); } return builder.build(); }
public static Set<Sort> of(Collection<org.kframework.kil.Sort> sorts) { ImmutableSet.Builder<Sort> builder = ImmutableSet.builder(); for (org.kframework.kil.Sort name : sorts) { builder.add(Sort.of(name.getName())); } return builder.build(); }
/** Generates the set of Java library rules under test. */ private static ImmutableSet<JavaLibrary> getRulesUnderTest(Iterable<TestRule> tests) { ImmutableSet.Builder<JavaLibrary> rulesUnderTest = ImmutableSet.builder(); // Gathering all rules whose source will be under test. for (TestRule test : tests) { if (test instanceof JavaTest) { JavaTest javaTest = (JavaTest) test; ImmutableSet<BuildRule> sourceUnderTest = javaTest.getSourceUnderTest(); for (BuildRule buildRule : sourceUnderTest) { if (buildRule instanceof JavaLibrary) { JavaLibrary javaLibrary = (JavaLibrary) buildRule; rulesUnderTest.add(javaLibrary); } else { throw new HumanReadableException( "Test '%s' is a java_test() " + "but it is testing module '%s' " + "which is not a java_library()!", test.getBuildTarget(), buildRule.getBuildTarget()); } } } } return rulesUnderTest.build(); }
static ImmutableSet<ObjectType> withLooseObjects(Set<ObjectType> objs) { ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder(); for (ObjectType obj : objs) { newObjs.add(obj.withLoose()); } return newObjs.build(); }
@Test public void fieldsWithIsDepEqualsFalseHintAreNotTreatedAsDeps() throws ConstructorArgMarshalException, NoSuchBuildTargetException { class Dto { @Hint(isDep = false) public Optional<Set<BuildTarget>> deps; } final String dep = "//should/be:ignored"; Dto dto = new Dto(); Map<String, Object> args = Maps.newHashMap(); args.put("deps", ImmutableList.of(dep)); ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); marshaller.populate( createCellRoots(filesystem), filesystem, buildRuleFactoryParams(), dto, declaredDeps, ImmutableSet.<BuildTargetPattern>builder(), args); assertEquals(ImmutableSet.of(), declaredDeps.build()); }
private ImmutableSet<ASTAnnotation> flatten(ImmutableSet<ASTAnnotation>... sets) { ImmutableSet.Builder<ASTAnnotation> combineBuilder = ImmutableSet.builder(); for (ImmutableSet<ASTAnnotation> set : sets) { combineBuilder.addAll(set); } return combineBuilder.build(); }
@Test public void onlyFieldNamedDepsAreConsideredDeclaredDeps() throws ConstructorArgMarshalException, NoSuchBuildTargetException { class Dto { public Optional<Set<BuildTarget>> deps; public Optional<Set<BuildTarget>> notdeps; } final String dep = "//is/a/declared:dep"; final String notDep = "//is/not/a/declared:dep"; BuildTarget declaredDep = BuildTargetFactory.newInstance(dep); Dto dto = new Dto(); Map<String, Object> args = Maps.newHashMap(); args.put("deps", ImmutableList.of(dep)); args.put("notdeps", ImmutableList.of(notDep)); ImmutableSet.Builder<BuildTarget> declaredDeps = ImmutableSet.builder(); marshaller.populate( createCellRoots(filesystem), filesystem, buildRuleFactoryParams(), dto, declaredDeps, ImmutableSet.<BuildTargetPattern>builder(), args); assertEquals(ImmutableSet.of(declaredDep), declaredDeps.build()); }
/** * 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 = remoteGeoGit.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.getGraphDatabase().exists(remoteRef.getObjectId())) { ObjectId mappedCommit = localRepository.getGraphDatabase().getMapping(remoteRef.getObjectId()); if (mappedCommit != null) { newRef = new Ref(remoteRef.getName(), mappedCommit, remoteRef.getType()); } } builder.add(newRef); } return builder.build(); }
private static Iterable<PathFragment> uniqueParentDirectories(Iterable<PathFragment> paths) { ImmutableSet.Builder<PathFragment> parents = new ImmutableSet.Builder<>(); for (PathFragment path : paths) { parents.add(path.getParentDirectory()); } return parents.build(); }
/** * Returns the configurable attribute conditions necessary to evaluate the given configured * target, or null if not all dependencies have yet been SkyFrame-evaluated. */ @Nullable private Set<ConfigMatchingProvider> getConfigurableAttributeConditions( TargetAndConfiguration ctg, Environment env) { if (!(ctg.getTarget() instanceof Rule)) { return ImmutableSet.of(); } Rule rule = (Rule) ctg.getTarget(); RawAttributeMapper mapper = RawAttributeMapper.of(rule); Set<SkyKey> depKeys = new LinkedHashSet<>(); for (Attribute attribute : rule.getAttributes()) { for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) { if (!BuildType.Selector.isReservedLabel(label)) { depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration())); } } } Map<SkyKey, SkyValue> cts = env.getValues(depKeys); if (env.valuesMissing()) { return null; } ImmutableSet.Builder<ConfigMatchingProvider> conditions = ImmutableSet.builder(); for (SkyValue ctValue : cts.values()) { ConfiguredTarget ct = ((ConfiguredTargetValue) ctValue).getConfiguredTarget(); conditions.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class))); } return conditions.build(); }
static ImmutableSet<ObjectType> withoutProperty(Set<ObjectType> objs, QualifiedName qname) { ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder(); for (ObjectType obj : objs) { newObjs.add(obj.withProperty(qname, null)); } return newObjs.build(); }
@VisibleForTesting List<Module> createModulesForProjectConfigs() throws IOException { DependencyGraph dependencyGraph = partialGraph.getDependencyGraph(); List<Module> modules = Lists.newArrayList(); // Convert the project_config() targets into modules and find the union of all jars passed to // no_dx. ImmutableSet.Builder<Path> noDxJarsBuilder = ImmutableSet.builder(); for (BuildTarget target : partialGraph.getTargets()) { BuildRule buildRule = dependencyGraph.findBuildRuleByTarget(target); ProjectConfig projectConfig = (ProjectConfig) buildRule.getBuildable(); BuildRule srcRule = projectConfig.getSrcRule(); if (srcRule != null) { Buildable buildable = srcRule.getBuildable(); if (buildable instanceof AndroidBinary) { AndroidBinary androidBinary = (AndroidBinary) buildable; AndroidDexTransitiveDependencies binaryDexTransitiveDependencies = androidBinary.findDexTransitiveDependencies(); noDxJarsBuilder.addAll(binaryDexTransitiveDependencies.noDxClasspathEntries); } } Module module = createModuleForProjectConfig(projectConfig); modules.add(module); } ImmutableSet<Path> noDxJars = noDxJarsBuilder.build(); // Update module dependencies to apply scope="PROVIDED", where appropriate. markNoDxJarsAsProvided(modules, noDxJars); return modules; }
static ImmutableSet<ObjectType> withPropertyRequired(Set<ObjectType> objs, String pname) { ImmutableSet.Builder<ObjectType> newObjs = ImmutableSet.builder(); for (ObjectType obj : objs) { newObjs.add(obj.withPropertyRequired(pname)); } return newObjs.build(); }
public ImmutableSet<CxxInferCapture> createInferCaptureBuildRules( ImmutableMap<String, CxxSource> sources, CxxInferTools inferTools, CxxInferSourceFilter sourceFilter) { ImmutableSet.Builder<CxxInferCapture> objects = ImmutableSet.builder(); for (Map.Entry<String, CxxSource> entry : sources.entrySet()) { String name = entry.getKey(); CxxSource source = entry.getValue(); Preconditions.checkState( CxxSourceTypes.isPreprocessableType(source.getType()), "Only preprocessable source types are currently supported"); if (sourceFilter.isBlacklisted(source)) { continue; } CxxInferCapture rule = requireInferCaptureBuildRule(name, source, inferTools); objects.add(rule); } return objects.build(); }
public static ImmutableSet<Path> createPackageLookupPathSet(IjModuleGraph moduleGraph) { ImmutableSet.Builder<Path> builder = ImmutableSet.builder(); for (IjModule module : moduleGraph.getModuleNodes()) { for (IjFolder folder : module.getFolders()) { if (!folder.getWantsPackagePrefix()) { continue; } Optional<Path> firstJavaFile = FluentIterable.from(folder.getInputs()) .filter( new Predicate<Path>() { @Override public boolean apply(Path input) { return input.getFileName().toString().endsWith(".java"); } }) .first(); if (firstJavaFile.isPresent()) { builder.add(firstJavaFile.get()); } } } return builder.build(); }
@Override public AnswerKey apply(AnswerKey input) { final Set<Response> existingResponses = Sets.newHashSet(input.allResponses()); final ImmutableSet.Builder<AssessedResponse> newAssessedResponses = ImmutableSet.builder(); newAssessedResponses.addAll(input.annotatedResponses()); for (final AssessedResponse assessedResponse : input.annotatedResponses()) { if (assessedResponse.assessment().realis().isPresent()) { final Response responseWithAssessedRealis = assessedResponse .response() .copyWithSwappedRealis(assessedResponse.assessment().realis().get()); if (!existingResponses.contains(responseWithAssessedRealis)) { newAssessedResponses.add( AssessedResponse.from(responseWithAssessedRealis, assessedResponse.assessment())); existingResponses.add(responseWithAssessedRealis); } } } return AnswerKey.from( input.docId(), newAssessedResponses.build(), input.unannotatedResponses(), input.corefAnnotation()); }
private void ensureTagCache() { if (tagCache == null) { synchronized (this) { if (tagCache == null) { tagCache = new Long2ObjectOpenHashMap<List<String>>(); ImmutableSet.Builder<String> vocabBuilder = ImmutableSet.builder(); Cursor<String[]> lines = null; try { lines = new DelimitedTextCursor(tagFile, ","); } catch (FileNotFoundException e) { throw new DataAccessException("cannot open file", e); } try { for (String[] line : lines) { long mid = Long.parseLong(line[0]); List<String> tags = tagCache.get(mid); if (tags == null) { tags = new ArrayList<String>(); tagCache.put(mid, tags); } tags.add(line[1]); vocabBuilder.add(line[1]); } } finally { lines.close(); } vocabCache = vocabBuilder.build(); } } } }
/** * 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(); }
private ImmutableSet<String> prepareDirectory( String dirname, Pattern filePattern, ImmutableSet<String> requiredHashes) throws Exception { try (TraceEventLogger ignored = TraceEventLogger.start(eventBus, "prepare_" + dirname)) { String dirPath = dataRoot.resolve(dirname).toString(); mkDirP(dirPath); String output = AdbHelper.executeCommandWithErrorChecking(device, "ls " + dirPath); ImmutableSet.Builder<String> foundHashes = ImmutableSet.builder(); ImmutableSet.Builder<String> filesToDelete = ImmutableSet.builder(); processLsOutput(output, filePattern, requiredHashes, foundHashes, filesToDelete); String commandPrefix = "cd " + dirPath + " && rm "; // Add a fudge factor for separators and error checking. final int overhead = commandPrefix.length() + 100; for (List<String> rmArgs : chunkArgs(filesToDelete.build(), MAX_ADB_COMMAND_SIZE - overhead)) { String command = commandPrefix + Joiner.on(' ').join(rmArgs); LOG.debug("Executing %s", command); AdbHelper.executeCommandWithErrorChecking(device, command); } return foundHashes.build(); } }
@Test public void testGetJobUpdateDiffWithUpdateRemove() throws Exception { TaskConfig task1 = defaultTask(false).setNumCpus(1.0); TaskConfig task2 = defaultTask(false).setNumCpus(2.0); TaskConfig task3 = defaultTask(false).setNumCpus(3.0); ImmutableSet.Builder<IScheduledTask> tasks = ImmutableSet.builder(); makeTasks(0, 10, task1, tasks); makeTasks(10, 20, task2, tasks); makeTasks(20, 30, task3, tasks); expect(storageUtil.jobStore.fetchJob(JOB_KEY)).andReturn(Optional.absent()); storageUtil.expectTaskFetch(Query.jobScoped(JOB_KEY).active(), tasks.build()); control.replay(); JobUpdateRequest request = new JobUpdateRequest() .setTaskConfig(defaultTask(false).setNumCpus(6.0)) .setInstanceCount(20) .setSettings(new JobUpdateSettings()); GetJobUpdateDiffResult expected = new GetJobUpdateDiffResult() .setRemove(ImmutableSet.of(group(task3, new Range(20, 29)))) .setUpdate( ImmutableSet.of(group(task1, new Range(0, 9)), group(task2, new Range(10, 19)))) .setAdd(ImmutableSet.of()) .setUnchanged(ImmutableSet.of()); Response response = assertOkResponse(thrift.getJobUpdateDiff(request)); assertEquals(expected, response.getResult().getGetJobUpdateDiffResult()); }
public ResponseLinking copyWithFilteredResponses(final Predicate<Response> toKeepCondition) { final Set<Response> newIncompletes = Sets.filter(incompleteResponses(), toKeepCondition); final ImmutableSet.Builder<ResponseSet> newResponseSetsB = ImmutableSet.builder(); final ImmutableBiMap.Builder<String, ResponseSet> responseSetsIdB = ImmutableBiMap.builder(); // to account for ResponseSets merging due to lost annotation final Set<ResponseSet> alreadyAdded = Sets.newHashSet(); for (final ResponseSet responseSet : responseSets()) { final ImmutableSet<Response> okResponses = FluentIterable.from(responseSet.asSet()).filter(toKeepCondition).toSet(); if (!okResponses.isEmpty()) { final ResponseSet newResponseSet = ResponseSet.from(okResponses); if (alreadyAdded.contains(newResponseSet)) { continue; } alreadyAdded.add(newResponseSet); newResponseSetsB.add(newResponseSet); if (responseSetIds().isPresent()) { responseSetsIdB.put(responseSetIds().get().inverse().get(responseSet), newResponseSet); } } } final ImmutableSet<ResponseSet> newResponseSets = newResponseSetsB.build(); final ResponseLinking.Builder ret = ResponseLinking.builder() .docID(docID()) .responseSets(newResponseSets) .incompleteResponses(newIncompletes); if (responseSetIds().isPresent()) { ret.responseSetIds(responseSetsIdB.build()); } return ret.build(); }
private void logHealthChecks() { final ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (HealthCheck healthCheck : healthChecks.build()) { builder.add(healthCheck.getClass().getCanonicalName()); } LOG.debug("health checks = {}", builder.build()); }
/** Get the safe path strings for a list of paths to use in the build variables. */ private Collection<String> getSafePathStrings(Collection<PathFragment> paths) { ImmutableSet.Builder<String> result = ImmutableSet.builder(); for (PathFragment path : paths) { result.add(path.getSafePathString()); } return result.build(); }
static Set<UUID> extractIndexes(List<ShardIndexInfo> inputShards, int... indexes) { ImmutableSet.Builder<UUID> builder = ImmutableSet.builder(); for (int index : indexes) { builder.add(inputShards.get(index).getShardUuid()); } return builder.build(); }
private Set<String> getLocalPlayersAsUuidStrings() { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); for (ProxiedPlayer player : getProxy().getPlayers()) { builder.add(player.getUniqueId().toString()); } return builder.build(); }