List of usage examples for com.google.common.base Optional asSet
public abstract Set<T> asSet();
From source file:com.google.errorprone.dataflow.nullnesspropagation.NullnessPropagationTransferCases2.java
public void optionalMethodsReturnNonNullUnlessAnnotated() { // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(Optional.absent()); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(Optional.of("")); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(Optional.fromNullable(null)); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(Optional.of("Test")); Optional<String> myOptional = Optional.absent(); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(myOptional.get()); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(myOptional.or("")); // BUG: Diagnostic contains: (Non-null) triggerNullnessChecker(myOptional.asSet()); // BUG: Diagnostic contains: (Nullable) triggerNullnessChecker(myOptional.orNull()); }
From source file:com.google.devtools.build.lib.rules.objc.BinaryLinkingTargetFactory.java
@Override public final ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException { ProtobufSupport protoSupport = new ProtobufSupport(ruleContext).registerGenerationActions() .registerCompilationActions(); Optional<ObjcProvider> protosObjcProvider = protoSupport.getObjcProvider(); Optional<XcodeProvider> protosXcodeProvider = protoSupport.getXcodeProvider(); ObjcCommon common = common(ruleContext, protosObjcProvider); ObjcProvider objcProvider = common.getObjcProvider(); assertLibraryOrSources(objcProvider, ruleContext); XcodeProvider.Builder xcodeProviderBuilder = new XcodeProvider.Builder() .addPropagatedDependencies(protosXcodeProvider.asSet()); IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext); NestedSetBuilder<Artifact> filesToBuild = NestedSetBuilder.<Artifact>stableOrder() .add(intermediateArtifacts.strippedSingleArchitectureBinary()); new ResourceSupport(ruleContext).validateAttributes().addXcodeSettings(xcodeProviderBuilder); ruleContext.assertNoErrors();/*from www .j a va 2 s .co m*/ J2ObjcMappingFileProvider j2ObjcMappingFileProvider = J2ObjcMappingFileProvider .union(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcMappingFileProvider.class)); J2ObjcEntryClassProvider j2ObjcEntryClassProvider = new J2ObjcEntryClassProvider.Builder() .addTransitive(ruleContext.getPrerequisites("deps", Mode.TARGET, J2ObjcEntryClassProvider.class)) .build(); CompilationSupport compilationSupport = CompilationSupport.create(ruleContext).validateAttributes() .addXcodeSettings(xcodeProviderBuilder, common).registerCompileAndArchiveActions(common) .registerFullyLinkAction(common.getObjcProvider(), ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)) .registerLinkActions(objcProvider, j2ObjcMappingFileProvider, j2ObjcEntryClassProvider, getExtraLinkArgs(ruleContext), ImmutableList.<Artifact>of(), DsymOutputType.APP); Optional<XcTestAppProvider> xcTestAppProvider; Optional<RunfilesSupport> maybeRunfilesSupport = Optional.absent(); switch (hasReleaseBundlingSupport) { case YES: AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); // TODO(bazel-team): Remove once all bundle users are migrated to ios_application. ReleaseBundlingSupport releaseBundlingSupport = new ReleaseBundlingSupport(ruleContext, objcProvider, LinkedBinary.LOCAL_AND_DEPENDENCIES, ReleaseBundlingSupport.APP_BUNDLE_DIR_FORMAT, appleConfiguration.getMinimumOsForPlatformType(PlatformType.IOS), appleConfiguration.getSingleArchPlatform()); releaseBundlingSupport.registerActions(DsymOutputType.APP).addXcodeSettings(xcodeProviderBuilder) .addFilesToBuild(filesToBuild, Optional.of(DsymOutputType.APP)).validateResources() .validateAttributes(); xcTestAppProvider = Optional.of(releaseBundlingSupport.xcTestAppProvider()); if (appleConfiguration.getMultiArchPlatform(PlatformType.IOS) == Platform.IOS_SIMULATOR) { Artifact runnerScript = intermediateArtifacts.runnerScript(); Artifact ipaFile = ruleContext.getImplicitOutputArtifact(ReleaseBundlingSupport.IPA); releaseBundlingSupport.registerGenerateRunnerScriptAction(runnerScript, ipaFile); maybeRunfilesSupport = Optional.of(releaseBundlingSupport.runfilesSupport(runnerScript)); } break; case NO: xcTestAppProvider = Optional.absent(); break; default: throw new AssertionError(); } XcodeSupport xcodeSupport = new XcodeSupport(ruleContext) // TODO(bazel-team): Use LIBRARY_STATIC as parameter instead of APPLICATION once objc_binary // no longer creates an application bundle .addXcodeSettings(xcodeProviderBuilder, objcProvider, productType) .addDependencies(xcodeProviderBuilder, new Attribute("bundles", Mode.TARGET)) .addDependencies(xcodeProviderBuilder, new Attribute("deps", Mode.TARGET)) .addNonPropagatedDependencies(xcodeProviderBuilder, new Attribute("non_propagated_deps", Mode.TARGET)) .addFilesToBuild(filesToBuild); if (productType != XcodeProductType.LIBRARY_STATIC) { xcodeSupport.generateCompanionLibXcodeTarget(xcodeProviderBuilder); } XcodeProvider xcodeProvider = xcodeProviderBuilder.build(); xcodeSupport.registerActions(xcodeProvider); RuleConfiguredTargetBuilder targetBuilder = ObjcRuleClasses .ruleConfiguredTarget(ruleContext, filesToBuild.build()) .addProvider(XcodeProvider.class, xcodeProvider).addProvider(ObjcProvider.class, objcProvider) .addProvider(InstrumentedFilesProvider.class, compilationSupport.getInstrumentedFilesProvider(common)); if (xcTestAppProvider.isPresent()) { // TODO(bazel-team): Stop exporting an XcTestAppProvider once objc_binary no longer creates an // application bundle. targetBuilder.addProvider(XcTestAppProvider.class, xcTestAppProvider.get()); } if (maybeRunfilesSupport.isPresent()) { RunfilesSupport runfilesSupport = maybeRunfilesSupport.get(); targetBuilder.setRunfilesSupport(runfilesSupport, runfilesSupport.getExecutable()); } configureTarget(targetBuilder, ruleContext); return targetBuilder.build(); }
From source file:com.eucalyptus.auth.euare.persist.DatabasePrincipalProvider.java
@Override public UserPrincipal lookupPrincipalByAccessKeyId(final String keyId, final String nonce) throws AuthException { try (final TransactionResource tx = Entities.readOnlyDistinctTransactionFor(AccessKeyEntity.class)) { final UserEntity user; try {/*from w w w .j a va2 s .com*/ user = (UserEntity) Entities.createCriteria(UserEntity.class).createCriteria("keys") .add(Restrictions.eq("accessKey", keyId)).setFlushMode(FlushMode.MANUAL).setReadOnly(true) .uniqueResult(); } catch (Exception e) { throw new InvalidAccessKeyAuthException("Failed to find access key", e); } if (user == null) { throw new InvalidAccessKeyAuthException("Failed to find access key"); } final UserPrincipal principal = new UserPrincipalImpl(user); final Optional<AccessKey> accessKey = Iterables.tryFind(principal.getKeys(), CollectionUtils.propertyPredicate(keyId, AccessKeys.accessKeyIdentifier())); if (!Iterables.any(accessKey.asSet(), AccessKeys.isActive())) { throw new InvalidAccessKeyAuthException("Invalid access key or token"); } return decorateCredentials(principal, nonce, accessKey.get().getSecretKey()); } }
From source file:com.qcadoo.mes.productionPerShift.dates.OrderRealizationDaysResolver.java
private Optional<OrderRealizationDay> tryResolveFirstDay(final OrderRealizationDay firstWorkingDay, final DateTime orderStartDateTime) { LocalDate orderStartDate = orderStartDateTime.toLocalDate(); LocalTime orderStartTime = orderStartDateTime.toLocalTime(); Optional<Shift> shiftStartingOrder = firstWorkingDay.findShiftWorkingAt(orderStartTime); Optional<TimeRange> workTimeRange = FluentOptional.wrap(shiftStartingOrder).flatMap(shift -> { int prevDayOfWeek = firstWorkingDay.getDate().minusDays(1).getDayOfWeek(); return shift.findWorkTimeAt(prevDayOfWeek, orderStartTime); }).toOpt();/*from www . j ava 2 s . c o m*/ if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, startsDayBefore(orderStartTime))) { return Optional.of(new OrderRealizationDay(orderStartDate, firstWorkingDay.getRealizationDayNumber() - 1, Lists.newArrayList(shiftStartingOrder.asSet()))); } if (shiftWorkTimeMatchPredicate(shiftStartingOrder, workTimeRange, endsNextDay(orderStartTime))) { return Optional.of(new OrderRealizationDay(firstWorkingDay.getDate(), firstWorkingDay.getRealizationDayNumber(), Lists.newArrayList(shiftStartingOrder.asSet()))); } return Optional.absent(); }
From source file:com.google.devtools.build.lib.rules.objc.AppleStaticLibrary.java
private ObjcCommon common(RuleContext ruleContext, BuildConfiguration buildConfiguration, IntermediateArtifacts intermediateArtifacts, List<TransitiveInfoCollection> propagatedDeps, Optional<ObjcProvider> protosObjcProvider) { CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext, intermediateArtifacts);/* w w w . j a v a2s. com*/ return new ObjcCommon.Builder(ruleContext, buildConfiguration) .setCompilationAttributes(CompilationAttributes.Builder.fromRuleContext(ruleContext).build()) .setCompilationArtifacts(compilationArtifacts) .setResourceAttributes(new ResourceAttributes(ruleContext)) .addDefines(ruleContext.getTokenizedStringListAttr("defines")).addDeps(propagatedDeps) .addDepObjcProviders(ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class)) .addDepObjcProviders(protosObjcProvider.asSet()).setIntermediateArtifacts(intermediateArtifacts) .setAlwayslink(false).build(); }
From source file:com.google.devtools.build.lib.rules.objc.ObjcActionsBuilder.java
/** * Generates an action to link a binary. *//*from w w w. j ava 2s.co m*/ void registerLinkAction(Artifact linkedBinary, ObjcProvider objcProvider, ExtraLinkArgs extraLinkArgs, ExtraLinkInputs extraLinkInputs, Optional<Artifact> dsymBundle) { extraLinkArgs = new ExtraLinkArgs(Iterables.concat( Interspersing.beforeEach("-force_load", Artifact.toExecPaths(objcProvider.get(FORCE_LOAD_LIBRARY))), extraLinkArgs)); register(spawnOnDarwinActionBuilder().setMnemonic("ObjcLink") .setShellCommand(ImmutableList.of("/bin/bash", "-c")) .setCommandLine(new LinkCommandLine(objcConfiguration, extraLinkArgs, objcProvider, linkedBinary, dsymBundle)) .addOutput(linkedBinary).addOutputs(dsymBundle.asSet()) .addTransitiveInputs(objcProvider.get(LIBRARY)) .addTransitiveInputs(objcProvider.get(IMPORTED_LIBRARY)) .addTransitiveInputs(objcProvider.get(FRAMEWORK_FILE)).addInputs(extraLinkInputs).build(context)); }
From source file:clocker.docker.entity.microservice.MicroserviceDockerfileImpl.java
@Override protected void doStart(Collection<? extends Location> locations) { Optional<Location> dockerLocation = Iterables.tryFind(getLocations(), Predicates.instanceOf(DockerLocation.class)); if (!dockerLocation.isPresent()) { String locationName = DOCKER_LOCATION_PREFIX + getId(); DockerInfrastructure dockerInfrastructure = addChild(EntitySpec.create(DockerInfrastructure.class) .configure(DockerInfrastructure.DOCKER_HOST_CLUSTER_MIN_SIZE, 1) .configure(DockerInfrastructure.SDN_ENABLE, false) .configure(DockerInfrastructure.LOCATION_NAME, locationName) .displayName("Docker Infrastructure")); Entities.start(dockerInfrastructure, locations); dockerLocation = Optional.of(getManagementContext().getLocationRegistry().resolve(locationName)); }//from w w w .j a v a 2 s.co m Entities.start(vanillaDockerApplication, dockerLocation.asSet()); }
From source file:com.google.devtools.build.lib.rules.objc.MultiArchBinarySupport.java
/** * Returns a map from from dependency configuration to the {@link ObjcCommon} which comprises all * information about the dependencies in that configuration. This can be used both to register * actions in {@link #registerActions} and collect provider information to be propagated upstream. * * @param childConfigurations the set of configurations in which dependencies of the current rule * are built//www. j a v a 2 s .c o m * @param configToDepsCollectionMap a map from child configuration to providers that "deps" of the * current rule have propagated in that configuration * @param configurationToNonPropagatedObjcMap a map from child configuration to providers that * "non_propagated_deps" of the current rule have propagated in that configuration * @param dylibObjcProviders {@link ObjcProvider}s that dynamic library dependencies of the * current rule have propagated * @param dylibProtoProviders {@link ObjcProtoProvider} providers that dynamic library * dependencies of the current rule have propagated * @param bundleLoaderObjcProvider Optional ObjcProvider containing artifacts and paths to be * included in this binary's compilation actions * @throws RuleErrorException if there are attribute errors in the current rule context */ public Map<BuildConfiguration, ObjcProvider> objcProviderByDepConfiguration( Set<BuildConfiguration> childConfigurations, ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection> configToDepsCollectionMap, ImmutableListMultimap<BuildConfiguration, ObjcProvider> configurationToNonPropagatedObjcMap, Iterable<ObjcProvider> dylibObjcProviders, Iterable<ObjcProtoProvider> dylibProtoProviders) throws RuleErrorException, InterruptedException { ImmutableMap.Builder<BuildConfiguration, ObjcProvider> configurationToObjcProviderBuilder = ImmutableMap .builder(); for (BuildConfiguration childConfig : childConfigurations) { Optional<ObjcProvider> protosObjcProvider; if (ObjcRuleClasses.objcConfiguration(ruleContext).enableAppleBinaryNativeProtos()) { ProtobufSupport protoSupport = new ProtobufSupport(ruleContext, childConfig, protoArtifactsToAvoid(dylibProtoProviders)).registerGenerationActions() .registerCompilationActions(); protosObjcProvider = protoSupport.getObjcProvider(); } else { protosObjcProvider = Optional.absent(); } IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext, childConfig); Iterable<ObjcProvider> additionalDepProviders = Iterables.concat(dylibObjcProviders, ruleContext.getPrerequisites("bundles", Mode.TARGET, ObjcProvider.class), protosObjcProvider.asSet()); ObjcCommon common = common(ruleContext, childConfig, intermediateArtifacts, nullToEmptyList(configToDepsCollectionMap.get(childConfig)), nullToEmptyList(configurationToNonPropagatedObjcMap.get(childConfig)), additionalDepProviders); ObjcProvider objcProvider = common.getObjcProvider().subtractSubtrees(dylibObjcProviders); configurationToObjcProviderBuilder.put(childConfig, objcProvider); } return configurationToObjcProviderBuilder.build(); }
From source file:com.google.devtools.build.lib.rules.objc.BinaryLinkingTargetFactory.java
private ObjcCommon common(RuleContext ruleContext, Optional<ObjcProvider> protosObjcProvider) { IntermediateArtifacts intermediateArtifacts = ObjcRuleClasses.intermediateArtifacts(ruleContext); CompilationArtifacts compilationArtifacts = CompilationSupport.compilationArtifacts(ruleContext); ObjcCommon.Builder builder = new ObjcCommon.Builder(ruleContext) .setCompilationAttributes(CompilationAttributes.Builder.fromRuleContext(ruleContext).build()) .setCompilationArtifacts(compilationArtifacts) .setResourceAttributes(new ResourceAttributes(ruleContext)) .addDefines(ruleContext.getTokenizedStringListAttr("defines")) .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)) .addRuntimeDeps(ruleContext.getPrerequisites("runtime_deps", Mode.TARGET)) .addDeps(ruleContext.getPrerequisites("bundles", Mode.TARGET)) .addDepObjcProviders(protosObjcProvider.asSet()) .addNonPropagatedDepObjcProviders( ruleContext.getPrerequisites("non_propagated_deps", Mode.TARGET, ObjcProvider.class)) .setIntermediateArtifacts(intermediateArtifacts).setAlwayslink(false).setHasModuleMap() .setLinkedBinary(intermediateArtifacts.strippedSingleArchitectureBinary()); if (ObjcRuleClasses.objcConfiguration(ruleContext).generateDsym()) { builder.addDebugArtifacts(DsymOutputType.APP); }// www. j a va 2 s . c o m if (ObjcRuleClasses.objcConfiguration(ruleContext).generateLinkmap()) { builder.setLinkmapFile(intermediateArtifacts.linkmap()); } return builder.build(); }
From source file:com.facebook.buck.parser.ParallelDaemonicParserState.java
/** * Finds the build file responsible for the given {@link Path} and invalidates * all of the cached rules dependent on it. * @param path A {@link Path}, relative to the project root and "contained" * within the build file to find and invalidate. *//* w w w .j a v a 2 s.com*/ private synchronized void invalidateContainingBuildFile(Cell cell, BuildFileTree buildFiles, Path path) { Set<Path> packageBuildFiles = new HashSet<>(); // Find the closest ancestor package for the input path. We'll definitely need to invalidate // that. Optional<Path> packageBuildFile = buildFiles.getBasePathOfAncestorTarget(path); packageBuildFiles.addAll(packageBuildFile.transform(cell.getFilesystem().getAbsolutifier()).asSet()); // If we're *not* enforcing package boundary checks, it's possible for multiple ancestor // packages to reference the same file if (!cell.isEnforcingBuckPackageBoundaries()) { while (packageBuildFile.isPresent() && packageBuildFile.get().getParent() != null) { packageBuildFile = buildFiles.getBasePathOfAncestorTarget(packageBuildFile.get().getParent()); packageBuildFiles.addAll(packageBuildFile.asSet()); } } // Invalidate all the packages we found. for (Path buildFile : packageBuildFiles) { invalidatePath(cell, buildFile.resolve(cell.getBuildFileName())); } }