/** * 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. */ 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())); } }
@Override public String nameForDeserialization(final BeanPropertyDefinition beanProperty) { DeserializationConfig deserializationConfig = objectMapper.getDeserializationConfig(); Optional<PropertyNamingStrategy> namingStrategy = Optional.fromNullable(deserializationConfig.getPropertyNamingStrategy()); String newName = namingStrategy .transform(overTheWireName(beanProperty, deserializationConfig)) .or(beanProperty.getName()); LOG.debug("Name '{}' renamed to '{}'", beanProperty.getName(), newName); return newName; }
private Jsr199Javac createJavac(boolean withSyntaxError, Optional<Path> javacJar) throws IOException { File exampleJava = tmp.newFile("Example.java"); Files.write( Joiner.on('\n') .join( "package com.example;", "", "public class Example {" + (withSyntaxError ? "" : "}")), exampleJava, Charsets.UTF_8); Path pathToOutputDirectory = Paths.get("out"); tmp.newFolder(pathToOutputDirectory.toString()); Optional<SourcePath> jar = javacJar.transform(SourcePaths.toSourcePath(new FakeProjectFilesystem())); if (jar.isPresent()) { return new JarBackedJavac("com.sun.tools.javac.api.JavacTool", ImmutableSet.of(jar.get())); } return new JdkProvidedInMemoryJavac(); }
@Override public <A extends Arg> BuildRule createBuildRule( TargetGraph targetGraph, BuildRuleParams originalBuildRuleParams, BuildRuleResolver resolver, A args) { UnflavoredBuildTarget originalBuildTarget = originalBuildRuleParams.getBuildTarget().checkUnflavored(); SourcePathResolver pathResolver = new SourcePathResolver(resolver); ImmutableList.Builder<BuildRule> aarExtraDepsBuilder = ImmutableList.<BuildRule>builder().addAll(originalBuildRuleParams.getExtraDeps().get()); /* android_manifest */ AndroidManifestDescription.Arg androidManifestArgs = androidManifestDescription.createUnpopulatedConstructorArg(); androidManifestArgs.skeleton = args.manifestSkeleton; androidManifestArgs.deps = args.deps; BuildRuleParams androidManifestParams = originalBuildRuleParams.copyWithChanges( BuildTargets.createFlavoredBuildTarget( originalBuildTarget, AAR_ANDROID_MANIFEST_FLAVOR), originalBuildRuleParams.getDeclaredDeps(), originalBuildRuleParams.getExtraDeps()); AndroidManifest manifest = androidManifestDescription.createBuildRule( targetGraph, androidManifestParams, resolver, androidManifestArgs); aarExtraDepsBuilder.add(resolver.addToIndex(manifest)); /* assemble dirs */ AndroidPackageableCollector collector = new AndroidPackageableCollector( originalBuildRuleParams.getBuildTarget(), /* buildTargetsToExcludeFromDex */ ImmutableSet.<BuildTarget>of(), /* resourcesToExclude */ ImmutableSet.<BuildTarget>of()); collector.addPackageables( AndroidPackageableCollector.getPackageableRules(originalBuildRuleParams.getDeps())); AndroidPackageableCollection packageableCollection = collector.build(); ImmutableSortedSet<BuildRule> androidResourceDeclaredDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getDeclaredDeps().get()); ImmutableSortedSet<BuildRule> androidResourceExtraDeps = AndroidResourceHelper.androidResOnly(originalBuildRuleParams.getExtraDeps().get()); BuildRuleParams assembleAssetsParams = originalBuildRuleParams.copyWithChanges( BuildTargets.createFlavoredBuildTarget(originalBuildTarget, AAR_ASSEMBLE_ASSETS_FLAVOR), Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps)); ImmutableCollection<SourcePath> assetsDirectories = packageableCollection.getAssetsDirectories(); AssembleDirectories assembleAssetsDirectories = new AssembleDirectories(assembleAssetsParams, pathResolver, assetsDirectories); aarExtraDepsBuilder.add(resolver.addToIndex(assembleAssetsDirectories)); BuildRuleParams assembleResourceParams = originalBuildRuleParams.copyWithChanges( BuildTargets.createFlavoredBuildTarget( originalBuildTarget, AAR_ASSEMBLE_RESOURCE_FLAVOR), Suppliers.ofInstance(androidResourceDeclaredDeps), Suppliers.ofInstance(androidResourceExtraDeps)); ImmutableCollection<SourcePath> resDirectories = packageableCollection.getResourceDetails().getResourceDirectories(); MergeAndroidResourceSources assembleResourceDirectories = new MergeAndroidResourceSources(assembleResourceParams, pathResolver, resDirectories); aarExtraDepsBuilder.add(resolver.addToIndex(assembleResourceDirectories)); /* android_resource */ BuildRuleParams androidResourceParams = originalBuildRuleParams.copyWithChanges( BuildTargets.createFlavoredBuildTarget( originalBuildTarget, AAR_ANDROID_RESOURCE_FLAVOR), Suppliers.ofInstance( ImmutableSortedSet.<BuildRule>of( manifest, assembleAssetsDirectories, assembleResourceDirectories)), Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>of())); AndroidResource androidResource = new AndroidResource( androidResourceParams, pathResolver, /* deps */ ImmutableSortedSet.<BuildRule>naturalOrder() .add(assembleAssetsDirectories) .add(assembleResourceDirectories) .addAll(originalBuildRuleParams.getDeclaredDeps().get()) .build(), new BuildTargetSourcePath(assembleResourceDirectories.getBuildTarget()), /* resSrcs */ ImmutableSortedSet.<SourcePath>of(), Optional.<SourcePath>absent(), /* rDotJavaPackage */ null, new BuildTargetSourcePath(assembleAssetsDirectories.getBuildTarget()), /* assetsSrcs */ ImmutableSortedSet.<SourcePath>of(), Optional.<SourcePath>absent(), new BuildTargetSourcePath(manifest.getBuildTarget()), /* hasWhitelistedStrings */ false); aarExtraDepsBuilder.add(resolver.addToIndex(androidResource)); /* native_libraries */ AndroidNativeLibsPackageableGraphEnhancer packageableGraphEnhancer = new AndroidNativeLibsPackageableGraphEnhancer( resolver, originalBuildRuleParams, nativePlatforms, ImmutableSet.<NdkCxxPlatforms.TargetCpuType>of()); Optional<CopyNativeLibraries> nativeLibrariesOptional = packageableGraphEnhancer.getCopyNativeLibraries(targetGraph, packageableCollection); if (nativeLibrariesOptional.isPresent()) { aarExtraDepsBuilder.add(resolver.addToIndex(nativeLibrariesOptional.get())); } Optional<Path> assembledNativeLibsDir = nativeLibrariesOptional.transform( new Function<CopyNativeLibraries, Path>() { @Override public Path apply(CopyNativeLibraries input) { return input.getPathToNativeLibsDir(); } }); BuildRuleParams androidAarParams = originalBuildRuleParams.copyWithExtraDeps( Suppliers.ofInstance(ImmutableSortedSet.copyOf(aarExtraDepsBuilder.build()))); return new AndroidAar( androidAarParams, pathResolver, manifest, androidResource, assembleResourceDirectories.getPathToOutput(), assembleAssetsDirectories.getPathToOutput(), assembledNativeLibsDir, packageableCollection.getNativeLibAssetsDirectories()); }
@Override public void onBindViewHolder(CommentView view, int position) { CommentEntry entry = comments.get(position); Comment comment = entry.comment; view.setCommentDepth(entry.depth); view.senderInfo.setSenderName(comment.getName(), comment.getMark()); view.senderInfo.setOnSenderClickedListener(v -> doOnAuthorClicked(comment)); AndroidUtility.linkify(view.comment, comment.getContent()); // show the points if (equalsIgnoreCase(comment.getName(), selfName) || comment.getCreated().isBefore(scoreVisibleThreshold)) { view.senderInfo.setPoints(getCommentScore(entry)); } else { view.senderInfo.setPointsUnknown(); } // and the date of the post view.senderInfo.setDate(comment.getCreated()); // enable or disable the badge boolean badge = op.transform(op -> op.equalsIgnoreCase(comment.getName())).or(false); view.senderInfo.setBadgeOpVisible(badge); // and register a vote handler view.vote.setVote(entry.vote, true); view.vote.setOnVoteListener( v -> { boolean changed = doVote(entry, v); notifyItemChanged(position); return changed; }); // set alpha for the sub views. sadly, setting alpha on view.itemView is not working view.comment.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f); view.senderInfo.setAlpha(entry.vote == Vote.DOWN ? 0.5f : 1f); view.senderInfo.setOnAnswerClickedListener(v -> doAnswer(comment)); Context context = view.itemView.getContext(); view.itemView.setBackgroundColor( ContextCompat.getColor( context, comment.getId() == selectedCommentId ? R.color.selected_comment_background : R.color.feed_background)); if (view.kFav != null) { if (showFavCommentButton) { boolean isFavorite = favedComments.contains(comment.getId()); view.kFav.setTextColor( isFavorite ? ContextCompat.getColor(context, R.color.primary) : ContextCompat.getColor(context, R.color.grey_700)); view.kFav.setVisibility(View.VISIBLE); view.kFav.setOnClickListener( v -> { commentActionListener.onCommentMarkAsFavoriteClicked(comment, !isFavorite); }); } else { view.kFav.setVisibility(View.GONE); } } }