List of usage examples for com.google.common.collect ImmutableSortedSet isEmpty
boolean isEmpty();
From source file:com.facebook.buck.features.project.intellij.DefaultIjModuleFactory.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private IjModule createModuleUsingSortedTargetNodes(Path moduleBasePath, ImmutableSortedSet<TargetNode> targetNodes, Set<Path> excludes) { Preconditions.checkArgument(!targetNodes.isEmpty()); ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(TargetNode::getBuildTarget) .collect(ImmutableSet.toImmutableSet()); ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets); Set<Class<?>> seenTypes = new HashSet<>(); for (TargetNode<?> targetNode : targetNodes) { Class<?> nodeType = targetNode.getDescription().getClass(); seenTypes.add(nodeType);//from w ww . ja v a 2s . co m IjModuleRule<?> rule = Objects.requireNonNull(typeRegistry.getModuleRuleByTargetNodeType(nodeType)); rule.apply((TargetNode) targetNode, context); context.setModuleType(rule.detectModuleType((TargetNode) targetNode)); } if (seenTypes.size() > 1) { LOG.debug("Multiple types at the same path. Path: %s, types: %s", moduleBasePath, seenTypes); } if (context.isAndroidFacetBuilderPresent()) { context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath( IjAndroidHelper.createAndroidGenPath(projectFilesystem, moduleBasePath)); } excludes.stream().map(moduleBasePath::resolve).map(ExcludeFolder::new).forEach(context::addSourceFolder); return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(moduleBuildTargets) .setNonSourceBuildTargets(context.getNonSourceBuildTargets()) .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies()) .setAndroidFacet(context.getAndroidFacet()) .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies()) .addAllExtraModuleDependencies(context.getExtraModuleDependencies()) .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders()) .setLanguageLevel(context.getJavaLanguageLevel()).setModuleType(context.getModuleType()) .setMetaInfDirectory(context.getMetaInfDirectory()) .setCompilerOutputPath(context.getCompilerOutputPath()).build(); }
From source file:com.facebook.buck.python.PythonLibraryRule.java
protected PythonLibraryRule(BuildRuleParams buildRuleParams, ImmutableSortedSet<String> srcs) { super(buildRuleParams); this.srcs = ImmutableSortedSet.copyOf(srcs); if (srcs.isEmpty()) { this.pythonPathDirectory = Optional.absent(); } else {/*www. j a v a2 s .c om*/ this.pythonPathDirectory = Optional.of(getPathToPythonPathDirectory()); } }
From source file:com.facebook.buck.python.PythonLibrary.java
protected PythonLibrary(BuildRuleParams buildRuleParams, ImmutableSortedSet<SourcePath> srcs) { this.buildTarget = buildRuleParams.getBuildTarget(); Preconditions.checkNotNull(srcs);/* w w w . j a v a 2 s.c om*/ Preconditions.checkArgument(!srcs.isEmpty(), "Must specify srcs for %s.", buildRuleParams.getBuildTarget()); this.srcs = srcs; this.pythonPathDirectory = getPathToPythonPathDirectory(); }
From source file:com.zulily.omicron.sla.TimeSinceLastSuccess.java
@Override protected Alert generateAlert(final Job job) { // The task has never been evaluated to run because it's new or it's not considered to be runnable to begin with // We cannot logically evaluate this alert if (!job.isRunnable() || !job.isActive()) { return createNotApplicableAlert(job); }//from www . j a va 2 s . co m final ImmutableSortedSet<TaskLogEntry> logView = job.filterLog(STATUS_FILTER); // No observable status changes in the task log - still nothing to do if (logView.isEmpty()) { return createNotApplicableAlert(job); } // Just succeed if the last log status is complete // This also avoids false alerts during schedule gaps if (logView.last().getTaskStatus() == TaskStatus.Complete) { return createAlert(job, logView.last(), AlertStatus.Success); } // Avoid spamming alerts during gaps in the schedule if (alertedOnceSinceLastActive(logView.last().getTimestamp(), job.getJobId())) { return createNotApplicableAlert(job); } // The last status is either error or failed start // so find that last time there was a complete, if any final Optional<TaskLogEntry> latestComplete = logView.descendingSet().stream() .filter(entry -> entry.getTaskStatus() == TaskStatus.Complete).findFirst(); // If we've seen at least one success in recent history and a task is running, // do not alert until a final status is achieved to avoid noise before potential recovery if (logView.last().getTaskStatus() == TaskStatus.Started && latestComplete.isPresent()) { return createNotApplicableAlert(job); } final int minutesBetweenSuccessThreshold = job.getConfiguration().getInt(ConfigKey.SLAMinutesSinceSuccess); final long currentTimestamp = Clock.systemUTC().millis(); final TaskLogEntry baselineTaskLogEntry = latestComplete.isPresent() ? latestComplete.get() : logView.first(); final long minutesIncomplete = TimeUnit.MILLISECONDS .toMinutes(currentTimestamp - baselineTaskLogEntry.getTimestamp()); if (minutesIncomplete <= minutesBetweenSuccessThreshold) { return createAlert(job, baselineTaskLogEntry, AlertStatus.Success); } else { return createAlert(job, baselineTaskLogEntry, AlertStatus.Failure); } }
From source file:com.facebook.buck.jvm.java.JavacStep.java
public static ImmutableList<String> getOptions(JavacOptions javacOptions, ProjectFilesystem filesystem, Path outputDirectory, ExecutionContext context, ImmutableSortedSet<Path> buildClasspathEntries) { final ImmutableList.Builder<String> builder = ImmutableList.builder(); javacOptions.appendOptionsTo(new OptionsConsumer() { @Override// ww w . j av a2 s . co m public void addOptionValue(String option, String value) { builder.add("-" + option).add(value); } @Override public void addFlag(String flagName) { builder.add("-" + flagName); } @Override public void addExtras(Collection<String> extras) { builder.addAll(extras); } }, filesystem::resolve); // verbose flag, if appropriate. if (context.getVerbosity().shouldUseVerbosityFlagIfAvailable()) { builder.add("-verbose"); } // Specify the output directory. builder.add("-d").add(filesystem.resolve(outputDirectory).toString()); // Build up and set the classpath. if (!buildClasspathEntries.isEmpty()) { String classpath = Joiner.on(File.pathSeparator).join(buildClasspathEntries); builder.add("-classpath", classpath); } else { builder.add("-classpath", "''"); } return builder.build(); }
From source file:com.facebook.buck.jvm.java.JavacStep.java
private void processBuildFailureWithFailedImports(ExecutionContext context, String firstOrderStderr, ImmutableList.Builder<String> errorMessage) { ImmutableSet<String> failedImports = findFailedImports(firstOrderStderr); ImmutableSortedSet<String> suggestions = ImmutableSortedSet .copyOf(suggestBuildRules.get().suggest(failedImports)); if (!suggestions.isEmpty()) { appendSuggestionMessage(errorMessage, failedImports, suggestions); }/*from ww w .ja v a2 s.com*/ CompilerErrorEvent evt = CompilerErrorEvent.create(invokingRule, firstOrderStderr, CompilerErrorEvent.CompilerType.Java, suggestions); context.postEvent(evt); }
From source file:edu.mit.streamjit.impl.compiler2.Storage.java
/** * Returns a range spanning the indices written in this storage during an * execution of the given schedule. (Note that, as a span, not every * contained index will be written.) The returned range will be * {@link Range#canonical(com.google.common.collect.DiscreteDomain) canonical}. * The range is not cached so as to be responsive to changes in output index * functions.//ww w .j a va2s.c o m * @param externalSchedule the schedule * @return a range spanning the indices written during the given schedule * under the current index functions * @see #writeIndices(java.util.Map) */ public Range<Integer> writeIndexSpan(Map<ActorGroup, Integer> externalSchedule) { Range<Integer> range = null; for (Actor a : upstream()) { //just the first and last iteration int maxIteration = a.group().schedule().get(a) * externalSchedule.get(a.group()) - 1; if (maxIteration >= 0) for (int iteration : new int[] { 0, maxIteration }) { ImmutableSortedSet<Integer> writes = a.writes(this, iteration); Range<Integer> writeRange = writes.isEmpty() ? range : Range.closed(writes.first(), writes.last()); range = range == null ? writeRange : range.span(writeRange); } } range = (range != null ? range : Range.closedOpen(0, 0)); return range.canonical(DiscreteDomain.integers()); }
From source file:com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryFunction.java
@Override public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws SkyFunctionException, InterruptedException { prepareLocalRepositorySymlinkTree(rule, outputDirectory); WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule); FileSystem fs = directories.getOutputBase().getFileSystem(); Path androidSdkPath;// w w w.ja v a 2 s . co m if (attributes.isAttributeValueExplicitlySpecified("path")) { androidSdkPath = fs.getPath(getTargetPath(rule, directories.getWorkspace())); } else if (clientEnvironment.containsKey(PATH_ENV_VAR)) { androidSdkPath = fs .getPath(getAndroidHomeEnvironmentVar(directories.getWorkspace(), clientEnvironment)); } else { throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "Either the path attribute of android_sdk_repository or the ANDROID_HOME environment " + " variable must be set."), Transience.PERSISTENT); } if (!symlinkLocalRepositoryContents(outputDirectory, androidSdkPath)) { return null; } DirectoryListingValue platformsDirectoryValue = getDirectoryListing(fs, androidSdkPath.getChild(PLATFORMS_DIR_NAME), env); if (platformsDirectoryValue == null) { return null; } ImmutableSortedSet<Integer> apiLevels = getApiLevels(platformsDirectoryValue.getDirents()); if (apiLevels.isEmpty()) { throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "android_sdk_repository requires that at least one Android SDK Platform is installed " + "in the Android SDK. Please install an Android SDK Platform through the " + "Android SDK manager."), Transience.PERSISTENT); } String defaultApiLevel; if (attributes.isAttributeValueExplicitlySpecified("api_level")) { try { defaultApiLevel = attributes.get("api_level", Type.INTEGER).toString(); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } } else { // If the api_level attribute is not explicitly set, we select the highest api level that is // available in the SDK. defaultApiLevel = String.valueOf(apiLevels.first()); } String buildToolsDirectory; if (attributes.isAttributeValueExplicitlySpecified("build_tools_version")) { try { buildToolsDirectory = attributes.get("build_tools_version", Type.STRING); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } } else { // If the build_tools_version attribute is not explicitly set, we select the highest version // installed in the SDK. DirectoryListingValue directoryValue = getDirectoryListing(fs, androidSdkPath.getChild(BUILD_TOOLS_DIR_NAME), env); if (directoryValue == null) { return null; } buildToolsDirectory = getNewestBuildToolsDirectory(rule, directoryValue.getDirents()); } // android_sdk_repository.build_tools_version is technically actually the name of the // directory in $sdk/build-tools. Most of the time this is just the actual build tools // version, but for preview build tools, the directory is something like 24.0.0-preview, and // the actual version is something like "24 rc3". The android_sdk rule in the template needs // the real version. String buildToolsVersion; if (buildToolsDirectory.contains("-preview")) { Properties sourceProperties = getBuildToolsSourceProperties(outputDirectory, buildToolsDirectory, env); if (env.valuesMissing()) { return null; } buildToolsVersion = sourceProperties.getProperty("Pkg.Revision"); } else { buildToolsVersion = buildToolsDirectory; } try { assertValidBuildToolsVersion(rule, buildToolsVersion); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } String template = getStringResource("android_sdk_repository_template.txt"); String buildFile = template.replace("%repository_name%", rule.getName()) .replace("%build_tools_version%", buildToolsVersion) .replace("%build_tools_directory%", buildToolsDirectory) .replace("%api_levels%", Iterables.toString(apiLevels)) .replace("%default_api_level%", defaultApiLevel); // All local maven repositories that are shipped in the Android SDK. // TODO(ajmichael): Create SkyKeys so that if the SDK changes, this function will get rerun. Iterable<Path> localMavenRepositories = ImmutableList.of( outputDirectory.getRelative("extras/android/m2repository"), outputDirectory.getRelative("extras/google/m2repository")); try { SdkMavenRepository sdkExtrasRepository = SdkMavenRepository .create(Iterables.filter(localMavenRepositories, new Predicate<Path>() { @Override public boolean apply(@Nullable Path path) { return path.isDirectory(); } })); sdkExtrasRepository.writeBuildFiles(outputDirectory); buildFile = buildFile.replace("%exported_files%", sdkExtrasRepository.getExportsFiles(outputDirectory)); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } writeBuildFile(outputDirectory, buildFile); return RepositoryDirectoryValue.builder().setPath(outputDirectory); }
From source file:com.google.googlejavaformat.java.ImportOrderer.java
private String reorderedImportsString(ImmutableSortedSet<Import> imports) { Preconditions.checkArgument(!imports.isEmpty(), "imports"); // Pretend that the first import was preceded by another import of the same kind, so we don't // insert a newline there. Import prevImport = imports.iterator().next(); StringBuilder sb = new StringBuilder(); for (Import currImport : imports) { if (shouldInsertBlankLineFn.apply(prevImport, currImport)) { // Blank line between static and non-static imports. sb.append(lineSeparator);/*from w ww . j a va 2s .c o m*/ } sb.append(currImport); prevImport = currImport; } return sb.toString(); }
From source file:org.apache.james.imap.processor.GetAnnotationProcessor.java
private Optional<Integer> getMaxSizeOfOversizedItems(List<MailboxAnnotation> mailboxAnnotations, final Integer maxsize) { Predicate<MailboxAnnotation> filterOverSizedAnnotation = new Predicate<MailboxAnnotation>() { @Override/* w ww . j a va2 s . c om*/ public boolean apply(MailboxAnnotation input) { return (input.size() > maxsize); } }; Function<MailboxAnnotation, Integer> transformToSize = new Function<MailboxAnnotation, Integer>() { public Integer apply(MailboxAnnotation input) { return input.size(); } }; ImmutableSortedSet<Integer> overLimitSizes = FluentIterable.from(mailboxAnnotations) .filter(filterOverSizedAnnotation).transform(transformToSize) .toSortedSet(new Comparator<Integer>() { @Override public int compare(Integer annotationSize1, Integer annotationSize2) { return annotationSize2.compareTo(annotationSize1); } }); if (overLimitSizes.isEmpty()) { return Optional.absent(); } return Optional.of(overLimitSizes.first()); }