List of usage examples for com.google.common.collect ImmutableSet stream
default Stream<E> stream()
From source file:com.facebook.buck.jvm.java.intellij.IjModuleFactory.java
/** * Create an {@link IjModule} form the supplied parameters. * * @param moduleBasePath the top-most directory the module is responsible for. * @param targetNodes set of nodes the module is to be created from. * @return nice shiny new module./*from w ww. j a v a2 s . c o m*/ */ @SuppressWarnings({ "unchecked", "rawtypes" }) public IjModule createModule(Path moduleBasePath, ImmutableSet<TargetNode<?, ?>> targetNodes) { Preconditions.checkArgument(!targetNodes.isEmpty()); ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(HasBuildTarget::getBuildTarget) .collect(MoreCollectors.toImmutableSet()); ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets); for (TargetNode<?, ?> targetNode : targetNodes) { IjModuleRule<?> rule = Preconditions .checkNotNull(moduleRuleIndex.get(targetNode.getDescription().getClass())); rule.apply((TargetNode) targetNode, context); } Optional<String> sourceLevel = getSourceLevel(targetNodes); String sdkType; Optional<String> sdkName; if (context.isAndroidFacetBuilderPresent()) { context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath(createAndroidGenPath(moduleBasePath)); sdkType = projectConfig.getAndroidModuleSdkType().orElse(SDK_TYPE_ANDROID); sdkName = projectConfig.getAndroidModuleSdkName(); } else { sdkType = projectConfig.getJavaModuleSdkType().orElse(SDK_TYPE_JAVA); sdkName = projectConfig.getJavaModuleSdkName(); } return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(targetNodes) .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies()) .setAndroidFacet(context.getAndroidFacet()) .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies()) .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders()).setSdkName(sdkName) .setSdkType(sdkType).setLanguageLevel(sourceLevel).build(); }
From source file:com.facebook.buck.jvm.java.intellij.ExportedDepsClosureResolver.java
/** * @param buildTarget target to process. * @return the set of {@link BuildTarget}s that must be appended to the * dependencies of a node Y if node Y depends on X. *///from w w w. ja va2 s. c om public ImmutableSet<BuildTarget> getExportedDepsClosure(BuildTarget buildTarget) { if (index.containsKey(buildTarget)) { return index.get(buildTarget); } ImmutableSet<BuildTarget> exportedDeps = ImmutableSet.of(); TargetNode<?, ?> targetNode = targetGraph.get(buildTarget); if (targetNode.getDescription() instanceof JavaLibraryDescription) { JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) targetNode.getConstructorArg(); exportedDeps = arg.exportedDeps; } else if (targetNode.getDescription() instanceof AndroidLibraryDescription) { AndroidLibraryDescription.Arg arg = (AndroidLibraryDescription.Arg) targetNode.getConstructorArg(); exportedDeps = arg.exportedDeps; } ImmutableSet<BuildTarget> exportedDepsClosure = exportedDeps.stream() .flatMap(target -> Stream.concat(Stream.of(target), getExportedDepsClosure(target).stream())) .collect(MoreCollectors.toImmutableSet()); index.put(buildTarget, exportedDepsClosure); return exportedDepsClosure; }
From source file:com.facebook.buck.ide.intellij.ExportedDepsClosureResolver.java
/** * @param buildTarget target to process. * @return the set of {@link BuildTarget}s that must be appended to the dependencies of a node Y * if node Y depends on X.// w w w .j av a 2 s .c om */ public ImmutableSet<BuildTarget> getExportedDepsClosure(BuildTarget buildTarget) { if (index.containsKey(buildTarget)) { return index.get(buildTarget); } ImmutableSet<BuildTarget> exportedDeps = ImmutableSet.of(); TargetNode<?, ?> targetNode = targetGraph.get(buildTarget); if (targetNode.getDescription() instanceof JavaLibraryDescription) { JavaLibraryDescription.Arg arg = (JavaLibraryDescription.Arg) targetNode.getConstructorArg(); exportedDeps = arg.exportedDeps; } else if (targetNode.getDescription() instanceof AndroidLibraryDescription) { AndroidLibraryDescription.Arg arg = (AndroidLibraryDescription.Arg) targetNode.getConstructorArg(); exportedDeps = arg.exportedDeps; } ImmutableSet<BuildTarget> exportedDepsClosure = exportedDeps.stream().filter(target -> { AbstractDescriptionArg arg = (AbstractDescriptionArg) targetGraph.get(target).getConstructorArg(); return !arg.labelsContainsAnyOf(ignoredTargetLabels); }).flatMap(target -> Stream.concat(Stream.of(target), getExportedDepsClosure(target).stream())) .collect(MoreCollectors.toImmutableSet()); index.put(buildTarget, exportedDepsClosure); return exportedDepsClosure; }
From source file:com.facebook.buck.ide.intellij.IjProjectTemplateDataPreparer.java
private ContentRoot createContentRoot(final IjModule module, Path contentRootPath, ImmutableSet<IjFolder> folders, final Path moduleLocationBasePath) { String url = IjProjectPaths.toModuleDirRelativeString(contentRootPath, moduleLocationBasePath); ImmutableSet<IjFolder> simplifiedFolders = sourceRootSimplifier .simplify(SimplificationLimit.of(contentRootPath.getNameCount()), folders); IjFolderToIjSourceFolderTransform transformToFolder = new IjFolderToIjSourceFolderTransform(module); ImmutableSortedSet<IjSourceFolder> sourceFolders = simplifiedFolders.stream().map(transformToFolder::apply) .collect(MoreCollectors.toImmutableSortedSet(Ordering.natural())); return ContentRoot.builder().setUrl(url).setFolders(sourceFolders).build(); }
From source file:com.facebook.buck.features.project.intellij.ExportedDepsClosureResolver.java
/** * @param buildTarget target to process. * @return the set of {@link BuildTarget}s that must be appended to the dependencies of a node Y * if node Y depends on X./*from w ww .j av a 2 s . c o m*/ */ public ImmutableSet<BuildTarget> getExportedDepsClosure(BuildTarget buildTarget) { if (index.containsKey(buildTarget)) { return index.get(buildTarget); } ImmutableSet<BuildTarget> exportedDeps = ImmutableSet.of(); TargetNode<?> targetNode = targetGraph.get(buildTarget); if (targetNode.getConstructorArg() instanceof JavaLibraryDescription.CoreArg) { JavaLibraryDescription.CoreArg arg = (JavaLibraryDescription.CoreArg) targetNode.getConstructorArg(); exportedDeps = arg.getExportedDeps(); } else if (targetNode.getConstructorArg() instanceof PrebuiltJarDescriptionArg) { PrebuiltJarDescriptionArg arg = (PrebuiltJarDescriptionArg) targetNode.getConstructorArg(); exportedDeps = arg.getDeps(); } ImmutableSet<BuildTarget> exportedDepsClosure = exportedDeps.stream().filter(target -> { CommonDescriptionArg arg = (CommonDescriptionArg) targetGraph.get(target).getConstructorArg(); return !arg.labelsContainsAnyOf(ignoredTargetLabels); }).flatMap(target -> Stream.concat(Stream.of(target), getExportedDepsClosure(target).stream())) .collect(ImmutableSet.toImmutableSet()); index.put(buildTarget, exportedDepsClosure); return exportedDepsClosure; }
From source file:org.dcache.webdav.macaroons.MacaroonRequestHandler.java
private MacaroonContext buildContext(String target, Request request) throws ErrorResponseException { MacaroonContext context = new MacaroonContext(); FsPath userRoot = FsPath.ROOT;// www. ja v a 2 s.co m for (LoginAttribute attr : AuthenticationHandler.getLoginAttributes(request)) { if (attr instanceof HomeDirectory) { context.setHome(FsPath.ROOT.resolve(((HomeDirectory) attr).getHome())); } else if (attr instanceof RootDirectory) { userRoot = FsPath.ROOT.resolve(((RootDirectory) attr).getRoot()); } else if (attr instanceof Expiry) { context.updateExpiry(((Expiry) attr).getExpiry()); } else if (attr instanceof DenyActivityRestriction) { context.removeActivities(((DenyActivityRestriction) attr).getDenied()); } else if (attr instanceof PrefixRestriction) { ImmutableSet<FsPath> paths = ((PrefixRestriction) attr).getPrefixes(); if (target.equals("/")) { checkArgument(paths.size() == 1, "Cannot serialise with multiple path restrictions"); context.setPath(paths.iterator().next()); } else { FsPath desiredPath = _pathMapper.asDcachePath(request, target); if (!paths.stream().anyMatch(desiredPath::hasPrefix)) { throw new ErrorResponseException(SC_BAD_REQUEST, "Bad request path: Desired path not within existing path"); } context.setPath(desiredPath); } } else if (attr instanceof Restriction) { throw new ErrorResponseException(SC_BAD_REQUEST, "Cannot serialise restriction " + attr.getClass().getSimpleName()); } else if (attr instanceof MaxUploadSize) { try { context.updateMaxUpload(((MaxUploadSize) attr).getMaximumSize()); } catch (InvalidCaveatException e) { throw new ErrorResponseException(SC_BAD_REQUEST, "Cannot add max-upload: " + e.getMessage()); } } } Subject subject = getSubject(); context.setUid(Subjects.getUid(subject)); context.setGids(Subjects.getGids(subject)); context.setUsername(Subjects.getUserName(subject)); context.setRoot(_pathMapper.effectiveRoot(userRoot, m -> new ErrorResponseException(SC_BAD_REQUEST, m))); if (!target.equals("/") && !context.getPath().isPresent()) { context.setPath(_pathMapper.asDcachePath(request, target)); } return context; }
From source file:com.facebook.buck.jvm.java.intellij.IjProjectTemplateDataPreparer.java
private ContentRoot createContentRoot(final IjModule module, Path contentRootPath, ImmutableSet<IjFolder> folders, final Path moduleLocationBasePath) { String url = toModuleDirRelativeString(contentRootPath, moduleLocationBasePath); ImmutableSet<IjFolder> simplifiedFolders = sourceRootSimplifier .simplify(SimplificationLimit.of(contentRootPath.getNameCount()), folders); IjFolderToIjSourceFolderTransform transformToFolder = new IjFolderToIjSourceFolderTransform(module); ImmutableSortedSet<IjSourceFolder> sourceFolders = simplifiedFolders.stream().map(transformToFolder::apply) .collect(MoreCollectors.toImmutableSortedSet(Ordering.natural())); return ContentRoot.builder().setUrl(url).setFolders(sourceFolders).build(); }
From source file:com.facebook.buck.features.project.intellij.IjProjectWriter.java
/** Update the modules.xml file with any new modules from the given set */ private void updateModulesIndex(ImmutableSet<IjModule> modulesEdited) throws IOException { final Set<ModuleIndexEntry> existingModules = modulesParser .getAllModules(projectFilesystem.newFileInputStream(getIdeaConfigDir().resolve("modules.xml"))); final Set<Path> existingModuleFilepaths = existingModules.stream().map(ModuleIndexEntry::getFilePath) .map(MorePaths::pathWithUnixSeparators).map(Paths::get).collect(ImmutableSet.toImmutableSet()); ImmutableSet<Path> remainingModuleFilepaths = modulesEdited.stream().map(projectPaths::getModuleImlFilePath) .map(MorePaths::pathWithUnixSeparators).map(Paths::get) .filter(modulePath -> !existingModuleFilepaths.contains(modulePath)) .collect(ImmutableSet.toImmutableSet()); // Merge the existing and new modules into a single sorted set ImmutableSortedSet.Builder<ModuleIndexEntry> finalModulesBuilder = ImmutableSortedSet .orderedBy(Comparator.<ModuleIndexEntry>naturalOrder()); // Add the existing definitions finalModulesBuilder.addAll(existingModules); // Add any new module definitions that we haven't seen yet remainingModuleFilepaths.forEach(modulePath -> finalModulesBuilder .add(ModuleIndexEntry.builder().setFilePath(projectPaths.getProjectRelativePath(modulePath)) .setFileUrl(getUrl(projectPaths.getProjectQualifiedPath(modulePath))) .setGroup(projectConfig.getModuleGroupName()).build())); // Write out the merged set to disk writeModulesIndex(finalModulesBuilder.build()); }
From source file:vazkii.quark.vanity.feature.PanoramaMaker.java
@SubscribeEvent public void loadMainMenu(GuiOpenEvent event) { if (overrideMainMenu && !overridenOnce && event.getGui() instanceof GuiMainMenu) { File mcDir = ModuleLoader.configFile.getParentFile().getParentFile(); File panoramasDir = new File(mcDir, "/screenshots/panoramas"); List<File[]> validFiles = new ArrayList(); ImmutableSet<String> set = ImmutableSet.of("panorama_0.png", "panorama_1.png", "panorama_2.png", "panorama_3.png", "panorama_4.png", "panorama_5.png"); if (panoramasDir.exists()) { File[] subDirs;// w w w . j a v a2 s . c o m File mainMenu = new File(panoramasDir, "main_menu"); if (mainMenu.exists()) subDirs = new File[] { mainMenu }; else subDirs = panoramasDir.listFiles((File f) -> f.isDirectory()); for (File f : subDirs) if (set.stream().allMatch((String s) -> new File(f, s).exists())) validFiles.add(f.listFiles((File f1) -> set.contains(f1.getName()))); } if (!validFiles.isEmpty()) { File[] files = validFiles.get(new Random().nextInt(validFiles.size())); Arrays.sort(files); Minecraft mc = Minecraft.getMinecraft(); ResourceLocation[] resources = new ResourceLocation[6]; for (int i = 0; i < resources.length; i++) { File f = files[i]; try { DynamicTexture tex = new DynamicTexture(ImageIO.read(f)); String name = "quark:" + f.getName(); resources[i] = mc.getTextureManager().getDynamicTextureLocation(name, tex); } catch (IOException e) { e.printStackTrace(); return; } } try { Field field = ReflectionHelper.findField(GuiMainMenu.class, LibObfuscation.TITLE_PANORAMA_PATHS); field.setAccessible(true); if (Modifier.isFinal(field.getModifiers())) { Field modfield = Field.class.getDeclaredField("modifiers"); modfield.setAccessible(true); modfield.setInt(field, field.getModifiers() & ~Modifier.FINAL); } field.set(null, resources); } catch (Exception e) { e.printStackTrace(); } } overridenOnce = true; } }
From source file:com.facebook.buck.features.project.intellij.IjProjectTemplateDataPreparer.java
private ImmutableSet<IjModule> createModulesToBeWritten(IjModuleGraph graph) { Path rootModuleBasePath = Paths.get(projectConfig.getProjectRoot()); boolean hasRootModule = graph.getModules().stream() .anyMatch(module -> rootModuleBasePath.equals(module.getModuleBasePath())); ImmutableSet<IjModule> supplementalModules = ImmutableSet.of(); if (!hasRootModule) { supplementalModules = ImmutableSet.of(IjModule.builder().setModuleBasePath(rootModuleBasePath) .setTargets(ImmutableSet.of()).setModuleType(IjModuleType.UNKNOWN_MODULE).build()); }//from w w w . ja v a 2s . com return Stream.concat(graph.getModules().stream(), supplementalModules.stream()) .collect(ImmutableSet.toImmutableSet()); }