List of usage examples for com.google.common.collect ImmutableMap values
public ImmutableCollection<V> values()
From source file:com.google.devtools.build.lib.rules.cpp.CppLinkActionBuilder.java
/** Builds the Action as configured and returns it. */ public CppLinkAction build() throws InterruptedException { // Executable links do not have library identifiers. boolean hasIdentifier = (libraryIdentifier != null); boolean isExecutable = linkType.isExecutable(); Preconditions.checkState(hasIdentifier != isExecutable); if (interfaceOutput != null && (fake || linkType != LinkTargetType.DYNAMIC_LIBRARY)) { throw new RuntimeException( "Interface output can only be used " + "with non-fake DYNAMIC_LIBRARY targets"); }//from w ww. ja v a2 s . c o m final ImmutableList<Artifact> buildInfoHeaderArtifacts = !linkstamps.isEmpty() ? analysisEnvironment.getBuildInfo(ruleContext, CppBuildInfo.KEY, configuration) : ImmutableList.<Artifact>of(); boolean needWholeArchive = wholeArchive || needWholeArchive(linkStaticness, linkType, linkopts, isNativeDeps, cppConfiguration); NestedSet<LibraryToLink> uniqueLibraries = libraries.build(); final Iterable<Artifact> objectArtifacts = LinkerInputs.toLibraryArtifacts(objectFiles); final Iterable<LinkerInput> linkerInputs = IterablesChain.<LinkerInput>builder() .add(ImmutableList.copyOf(objectFiles)) .add(ImmutableIterable.from( Link.mergeInputsCmdLine(uniqueLibraries, needWholeArchive, cppConfiguration.archiveType()))) .build(); // ruleContext can only be null during testing. This is kind of ugly. final ImmutableSet<String> features = (ruleContext == null) ? ImmutableSet.<String>of() : ruleContext.getFeatures(); // For backwards compatibility, and for tests, we permit the link action to be // instantiated without a feature configuration. if (featureConfiguration == null) { if (toolchain != null) { featureConfiguration = CcCommon.configureFeatures(ruleContext, toolchain, CcLibraryHelper.SourceCategory.CC); } else { featureConfiguration = CcCommon.configureFeatures(ruleContext); } } final LibraryToLink outputLibrary = linkType.isExecutable() ? null : LinkerInputs.newInputLibrary(output, linkType.getLinkerOutput(), libraryIdentifier, objectArtifacts, this.ltoBitcodeFiles); final LibraryToLink interfaceOutputLibrary = (interfaceOutput == null) ? null : LinkerInputs.newInputLibrary(interfaceOutput, ArtifactCategory.DYNAMIC_LIBRARY, libraryIdentifier, objectArtifacts, this.ltoBitcodeFiles); final ImmutableMap<Artifact, Artifact> linkstampMap = mapLinkstampsToOutputs(linkstamps, ruleContext, configuration, output, linkArtifactFactory); PathFragment ltoOutputRootPrefix = null; if (isLTOIndexing && allLTOArtifacts == null) { ltoOutputRootPrefix = FileSystemUtils.appendExtension(output.getRootRelativePath(), ".lto"); allLTOArtifacts = createLTOArtifacts(ltoOutputRootPrefix, uniqueLibraries); } PathFragment linkerParamFileRootPath = null; @Nullable Artifact thinltoParamFile = null; if (allLTOArtifacts != null) { // Create artifact for the file that the LTO indexing step will emit // object file names into for any that were included in the link as // determined by the linker's symbol resolution. It will be used to // provide the inputs for the subsequent final native object link. // Note that the paths emitted into this file will have their prefixes // replaced with the final output directory, so they will be the paths // of the native object files not the input bitcode files. linkerParamFileRootPath = ParameterFile.derivePath(output.getRootRelativePath(), "lto-final"); thinltoParamFile = linkArtifactFactory.create(ruleContext, configuration, linkerParamFileRootPath); } final ImmutableList<Artifact> actionOutputs; if (isLTOIndexing) { ImmutableList.Builder<Artifact> builder = ImmutableList.builder(); for (LTOBackendArtifacts ltoA : allLTOArtifacts) { ltoA.addIndexingOutputs(builder); } if (thinltoParamFile != null) { builder.add(thinltoParamFile); } actionOutputs = builder.build(); } else { actionOutputs = constructOutputs(output, linkstampMap.values(), interfaceOutputLibrary == null ? null : interfaceOutputLibrary.getArtifact(), symbolCounts); } ImmutableList<LinkerInput> runtimeLinkerInputs = ImmutableList .copyOf(LinkerInputs.simpleLinkerInputs(runtimeInputs, runtimeType)); PathFragment paramRootPath = ParameterFile.derivePath(output.getRootRelativePath(), (isLTOIndexing) ? "lto-index" : "2"); @Nullable final Artifact paramFile = canSplitCommandLine() ? linkArtifactFactory.create(ruleContext, configuration, paramRootPath) : null; // Add build variables necessary to template link args into the crosstool. Variables.Builder buildVariablesBuilder = new Variables.Builder(); CppLinkVariablesExtension variablesExtension = isLTOIndexing ? new CppLinkVariablesExtension(configuration, ImmutableMap.<Artifact, Artifact>of(), needWholeArchive, linkerInputs, runtimeLinkerInputs, null, paramFile, thinltoParamFile, ltoOutputRootPrefix, null, null) : new CppLinkVariablesExtension(configuration, linkstampMap, needWholeArchive, linkerInputs, runtimeLinkerInputs, output, paramFile, thinltoParamFile, PathFragment.EMPTY_FRAGMENT, getInterfaceSoBuilder(), interfaceOutput); variablesExtension.addVariables(buildVariablesBuilder); for (VariablesExtension extraVariablesExtension : variablesExtensions) { extraVariablesExtension.addVariables(buildVariablesBuilder); } Variables buildVariables = buildVariablesBuilder.build(); Preconditions.checkArgument(linkType != LinkTargetType.INTERFACE_DYNAMIC_LIBRARY, "you can't link an interface dynamic library directly"); if (linkType != LinkTargetType.DYNAMIC_LIBRARY) { Preconditions.checkArgument(interfaceOutput == null, "interface output may only be non-null for dynamic library links"); } if (linkType.staticness() == Staticness.STATIC) { // solib dir must be null for static links runtimeSolibDir = null; Preconditions.checkArgument(linkStaticness == LinkStaticness.FULLY_STATIC, "static library link must be static"); Preconditions.checkArgument(symbolCounts == null, "the symbol counts output must be null for static links"); Preconditions.checkArgument(!isNativeDeps, "the native deps flag must be false for static links"); Preconditions.checkArgument(!needWholeArchive, "the need whole archive flag must be false for static links"); } LinkCommandLine.Builder linkCommandLineBuilder = new LinkCommandLine.Builder(configuration, getOwner(), ruleContext).setLinkerInputs(linkerInputs).setRuntimeInputs(runtimeLinkerInputs) .setLinkTargetType(linkType).setLinkStaticness(linkStaticness).setFeatures(features) .setRuntimeSolibDir(linkType.staticness() == Staticness.STATIC ? null : runtimeSolibDir) .setNativeDeps(isNativeDeps).setUseTestOnlyFlags(useTestOnlyFlags).setParamFile(paramFile) .setToolchain(toolchain).setBuildVariables(buildVariables).setToolPath(getToolPath()) .setFeatureConfiguration(featureConfiguration); if (!isLTOIndexing) { linkCommandLineBuilder.setOutput(output).setBuildInfoHeaderArtifacts(buildInfoHeaderArtifacts) .setLinkstamps(linkstampMap).setLinkopts(ImmutableList.copyOf(linkopts)) .addLinkstampCompileOptions(linkstampOptions); } else { List<String> opts = new ArrayList<>(linkopts); opts.addAll(featureConfiguration.getCommandLine("lto-indexing", buildVariables)); opts.addAll(cppConfiguration.getLTOIndexOptions()); linkCommandLineBuilder.setLinkopts(ImmutableList.copyOf(opts)); } LinkCommandLine linkCommandLine = linkCommandLineBuilder.build(); // Compute the set of inputs - we only need stable order here. NestedSetBuilder<Artifact> dependencyInputsBuilder = NestedSetBuilder.stableOrder(); dependencyInputsBuilder.addTransitive(crosstoolInputs); dependencyInputsBuilder.add(toolchain.getLinkDynamicLibraryTool()); dependencyInputsBuilder.addTransitive(linkActionInputs.build()); if (runtimeMiddleman != null) { dependencyInputsBuilder.add(runtimeMiddleman); } if (!isLTOIndexing) { dependencyInputsBuilder.addAll(buildInfoHeaderArtifacts); dependencyInputsBuilder.addAll(linkstamps); dependencyInputsBuilder.addTransitive(compilationInputs.build()); } Iterable<Artifact> expandedInputs = LinkerInputs.toLibraryArtifacts( Link.mergeInputsDependencies(uniqueLibraries, needWholeArchive, cppConfiguration.archiveType())); Iterable<Artifact> expandedNonLibraryInputs = LinkerInputs.toLibraryArtifacts(objectFiles); if (!isLTOIndexing && allLTOArtifacts != null) { // We are doing LTO, and this is the real link, so substitute // the LTO bitcode files with the real object files they were translated into. Map<Artifact, Artifact> ltoMapping = new HashMap<>(); for (LTOBackendArtifacts a : allLTOArtifacts) { ltoMapping.put(a.getBitcodeFile(), a.getObjectFile()); } // Handle libraries. List<Artifact> renamedInputs = new ArrayList<>(); for (Artifact a : expandedInputs) { Artifact renamed = ltoMapping.get(a); renamedInputs.add(renamed == null ? a : renamed); } expandedInputs = renamedInputs; // Handle non-libraries. List<Artifact> renamedNonLibraryInputs = new ArrayList<>(); for (Artifact a : expandedNonLibraryInputs) { Artifact renamed = ltoMapping.get(a); renamedNonLibraryInputs.add(renamed == null ? a : renamed); } expandedNonLibraryInputs = renamedNonLibraryInputs; } else if (isLTOIndexing && allLTOArtifacts != null) { for (LTOBackendArtifacts a : allLTOArtifacts) { List<String> argv = new ArrayList<>(); argv.addAll(cppConfiguration.getLinkOptions()); argv.addAll(cppConfiguration.getCompilerOptions(features)); a.setCommandLine(argv); } } // getPrimaryInput returns the first element, and that is a public interface - therefore the // order here is important. IterablesChain.Builder<Artifact> inputsBuilder = IterablesChain.<Artifact>builder() .add(ImmutableList.copyOf(expandedNonLibraryInputs)).add(ImmutableList.copyOf(nonCodeInputs)) .add(dependencyInputsBuilder.build()).add(ImmutableIterable.from(expandedInputs)); if (thinltoParamFile != null && !isLTOIndexing) { inputsBuilder.add(ImmutableList.of(thinltoParamFile)); } if (linkCommandLine.getParamFile() != null) { inputsBuilder.add(ImmutableList.of(linkCommandLine.getParamFile())); Action parameterFileWriteAction = new ParameterFileWriteAction(getOwner(), paramFile, linkCommandLine.paramCmdLine(), ParameterFile.ParameterFileType.UNQUOTED, ISO_8859_1); analysisEnvironment.registerAction(parameterFileWriteAction); } ImmutableMap<String, String> toolchainEnv = featureConfiguration.getEnvironmentVariables(getActionName(), buildVariables); // If the crosstool uses action_configs to configure cc compilation, collect execution info // from there, otherwise, use no execution info. // TODO(b/27903698): Assert that the crosstool has an action_config for this action. ImmutableSet.Builder<String> executionRequirements = ImmutableSet.<String>builder(); if (featureConfiguration.actionIsConfigured(getActionName())) { executionRequirements .addAll(featureConfiguration.getToolForAction(getActionName()).getExecutionRequirements()); } return new CppLinkAction(getOwner(), mnemonic, inputsBuilder.deduplicate().build(), actionOutputs, cppConfiguration, outputLibrary, output, interfaceOutputLibrary, fake, isLTOIndexing, allLTOArtifacts, linkCommandLine, configuration.getVariableShellEnvironment(), configuration.getLocalShellEnvironment(), toolchainEnv, executionRequirements.build()); }
From source file:com.outerspacecat.icalendar.Schedule.java
/** * Parses a schedule./*from w ww.j a v a2 s.co m*/ * * @param startProperty the DTSTART property. Must be non {@code null}. * @param endProperty the DTEND property. May be {@code null}. * @param durationProperty the DURATION property. May be {@code null}. * @return a schedule. Never {@code null}. * @throws CalendarParseException if a valid schedule cannot be parsed */ public static Schedule parse(final Property startProperty, final Property endProperty, final Property durationProperty) throws CalendarParseException { Preconditions.checkNotNull(startProperty, "start required"); Preconditions.checkArgument(startProperty.getName().getName().equals("DTSTART"), "invalid start property name: " + startProperty.getName().getName()); if (endProperty != null) { Preconditions.checkArgument(endProperty.getName().getName().equals("DTEND"), "invalid end property name: " + endProperty.getName().getName()); } if (durationProperty != null) { Preconditions.checkArgument(durationProperty.getName().getName().equals("DURATION"), "invalid duration property name: " + durationProperty.getName().getName()); } LocalDate startDate = null; ParsedDateTime startDateTime = null; ZoneId startTimeZone = null; ImmutableMap<String, Parameter> startParameters = null; LocalDate endDate = null; ParsedDateTime endDateTime = null; ZoneId endTimeZone = null; ImmutableMap<String, Parameter> endParameters = null; DurationType duration = null; ImmutableMap<String, Parameter> durationParameters = null; String startValue = startProperty.getParameterValue("VALUE").getValue(); if (startValue.equals("DATE")) { startDate = startProperty.asDate(); } else if (startValue.equals("DATE-TIME")) { startDateTime = startProperty.asDateTime(); String startTzId = startProperty.getParameterValue("TZID").getValue(); if (startTzId != null) { try { startTimeZone = ZoneId.of(startTzId); } catch (ZoneRulesException e) { throw new CalendarParseException("no time zone for DTSTART TZID: " + startTzId, e); } } if (startTimeZone == null) { if (startDateTime.isUtc()) startTimeZone = ZoneOffset.UTC; } else { if (startDateTime.isUtc()) throw new CalendarParseException("DTSTART specified as UTC with TZID"); } } else { throw new CalendarParseException("invalid DSTART VALUE parameter: " + startValue); } startParameters = startProperty.getParametersExcept(ImmutableSet.of("VALUE", "TZID")); if (endProperty != null) { if (durationProperty != null) throw new CalendarParseException("both DTEND and DURATION specified"); String endValue = endProperty.getParameterValue("VALUE").getValue(); if (endValue.equals("DATE")) { if (startDate == null) { throw new CalendarParseException("DATE-TIME DSTART specified with DATE DTEND"); } endDate = endProperty.asDate(); } else if (endValue.equals("DATE-TIME")) { if (startDateTime == null) { throw new CalendarParseException("DATE DSTART specified with DATE-TIME DTEND"); } endDateTime = endProperty.asDateTime(); String endTzId = endProperty.getParameterValue("TZID").getValue(); if (endTzId != null) { try { endTimeZone = ZoneId.of(endTzId); } catch (ZoneRulesException e) { throw new CalendarParseException("no time zone for DTEND TZID: " + endTzId, e); } } if (endTimeZone == null) { if (endDateTime.isUtc()) endTimeZone = ZoneOffset.UTC; } else { if (endDateTime.isUtc()) throw new CalendarParseException("DTEND specified as UTC with TZID"); } if (endTimeZone == null) { if (startTimeZone != null) { throw new CalendarParseException("Floating DTEND paired with non-floating DTSTART"); } } else { if (startTimeZone == null) { throw new CalendarParseException("Non-float DTEND paired with floating DTSTART"); } } } endParameters = endProperty.getParametersExcept(ImmutableSet.of("VALUE", "TZID")); } if (durationProperty != null) { if (endProperty != null) throw new CalendarParseException("both DTEND and DURATION specified"); duration = durationProperty.asDuration(); if (startDate != null) { if (!duration.isDayOrWeekOnly()) { throw new CalendarParseException("DATE DTSTART can only be paired with a day or week DURATION"); } } durationParameters = durationProperty.getParametersExcept(ImmutableSet.of()); } if (startDate != null) { if (endDate != null) { return Schedule.fromDates(new TypedProperty<LocalDate>(startDate, startParameters.values()), new TypedProperty<LocalDate>(endDate, endParameters.values())); } else if (duration != null) { return Schedule.fromDateAndDuration( new TypedProperty<LocalDate>(startDate, startParameters.values()), new TypedProperty<DurationType>(duration, durationParameters.values())); } else { return Schedule.fromDate(new TypedProperty<LocalDate>(startDate, startParameters.values())); } } if (startDateTime != null) { if (endDateTime != null) { if (startTimeZone != null) { return Schedule.fromZonedDateTimes( new TypedProperty<ZonedDateTime>(startDateTime.getDateTime().atZone(startTimeZone), startParameters.values()), new TypedProperty<ZonedDateTime>(endDateTime.getDateTime().atZone(endTimeZone), endParameters.values())); } else { return Schedule.fromDateTimes( new TypedProperty<LocalDateTime>(startDateTime.getDateTime(), startParameters.values()), new TypedProperty<LocalDateTime>(endDateTime.getDateTime(), endParameters.values())); } } else if (duration != null) { if (startTimeZone != null) { return Schedule.fromZonedDateTimeAndDuration( new TypedProperty<ZonedDateTime>(startDateTime.getDateTime().atZone(startTimeZone), startParameters.values()), new TypedProperty<DurationType>(duration, durationParameters.values())); } else { return Schedule.fromDateTimeAndDuration( new TypedProperty<LocalDateTime>(startDateTime.getDateTime(), startParameters.values()), new TypedProperty<DurationType>(duration, durationParameters.values())); } } else { return Schedule.fromDateTime( new TypedProperty<LocalDateTime>(startDateTime.getDateTime(), startParameters.values())); } } throw new IllegalStateException("unexpected combination, startDate=" + startDate + ", startDateTime=" + startDateTime + ", startTimeZone=" + startTimeZone + ", endDate=" + endDate + ", endDateTime=" + endDateTime + ", endTimeZone=" + endTimeZone + ", duration=" + duration); }
From source file:com.facebook.presto.connector.jmx.JmxRecordSetProvider.java
@Override public RecordSet getRecordSet(ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) { JmxTableHandle tableHandle = checkType(split, JmxSplit.class, "split").getTableHandle(); requireNonNull(columns, "columns is null"); checkArgument(!columns.isEmpty(), "must provide at least one column"); ImmutableMap.Builder<String, Type> builder = ImmutableMap.builder(); for (ColumnHandle column : columns) { JmxColumnHandle jmxColumnHandle = checkType(column, JmxColumnHandle.class, "column"); builder.put(jmxColumnHandle.getColumnName(), jmxColumnHandle.getColumnType()); }/*from www .j a va 2 s. com*/ ImmutableMap<String, Type> columnTypes = builder.build(); List<List<Object>> rows; try { Map<String, Object> attributes = getAttributes(columnTypes.keySet(), tableHandle); List<Object> row = new ArrayList<>(); // NOTE: data must be produced in the order of the columns parameter. This code relies on the // fact that columnTypes is an ImmutableMap which is an order preserving LinkedHashMap under // the covers. for (Entry<String, Type> entry : columnTypes.entrySet()) { if (entry.getKey().equals("node")) { row.add(nodeId); } else { Object value = attributes.get(entry.getKey()); if (value == null) { row.add(null); } else { Class<?> javaType = entry.getValue().getJavaType(); if (javaType == boolean.class) { if (value instanceof Boolean) { row.add(value); } else { // mbeans can lie about types row.add(null); } } else if (javaType == long.class) { if (value instanceof Number) { row.add(((Number) value).longValue()); } else { // mbeans can lie about types row.add(null); } } else if (javaType == double.class) { if (value instanceof Number) { row.add(((Number) value).doubleValue()); } else { // mbeans can lie about types row.add(null); } } else if (javaType == Slice.class) { if (value.getClass().isArray()) { // return a string representation of the array if (value.getClass().getComponentType() == boolean.class) { row.add(Arrays.toString((boolean[]) value)); } else if (value.getClass().getComponentType() == byte.class) { row.add(Arrays.toString((byte[]) value)); } else if (value.getClass().getComponentType() == char.class) { row.add(Arrays.toString((char[]) value)); } else if (value.getClass().getComponentType() == double.class) { row.add(Arrays.toString((double[]) value)); } else if (value.getClass().getComponentType() == float.class) { row.add(Arrays.toString((float[]) value)); } else if (value.getClass().getComponentType() == int.class) { row.add(Arrays.toString((int[]) value)); } else if (value.getClass().getComponentType() == long.class) { row.add(Arrays.toString((long[]) value)); } else if (value.getClass().getComponentType() == short.class) { row.add(Arrays.toString((short[]) value)); } else { row.add(Arrays.toString((Object[]) value)); } } else { row.add(value.toString()); } } } } } rows = ImmutableList.of(row); } catch (JMException e) { rows = ImmutableList.of(); } return new InMemoryRecordSet(columnTypes.values(), rows); }