use of com.google.common.base.Predicate in project druid by druid-io.
the class ConvertSegmentTask method run.
@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
final Iterable<DataSegment> segmentsToUpdate;
if (segment == null) {
final List<DataSegment> segments = toolbox.getTaskActionClient().submit(new SegmentListUsedAction(getDataSource(), getInterval(), null));
segmentsToUpdate = FunctionalIterable.create(segments).filter(new Predicate<DataSegment>() {
@Override
public boolean apply(DataSegment segment) {
final Integer segmentVersion = segment.getBinaryVersion();
if (!CURR_VERSION_INTEGER.equals(segmentVersion)) {
return true;
} else if (force) {
log.info("Segment[%s] already at version[%s], forcing conversion", segment.getIdentifier(), segmentVersion);
return true;
} else {
log.info("Skipping[%s], already version[%s]", segment.getIdentifier(), segmentVersion);
return false;
}
}
});
} else {
log.info("I'm in a subless mood.");
segmentsToUpdate = Collections.singleton(segment);
}
// Vestigial from a past time when this task spawned subtasks.
for (final Task subTask : generateSubTasks(getGroupId(), segmentsToUpdate, indexSpec, force, validate, getContext())) {
final TaskStatus status = subTask.run(toolbox);
if (!status.isSuccess()) {
return TaskStatus.fromCode(getId(), status.getStatusCode());
}
}
return success();
}
use of com.google.common.base.Predicate in project buck by facebook.
the class OwnersReport method generateOwnersReport.
@VisibleForTesting
static OwnersReport generateOwnersReport(Cell rootCell, TargetNode<?, ?> targetNode, Iterable<String> filePaths) {
// Process arguments assuming they are all relative file paths.
Set<Path> inputs = Sets.newHashSet();
Set<String> nonExistentInputs = Sets.newHashSet();
Set<String> nonFileInputs = Sets.newHashSet();
for (String filePath : filePaths) {
Path file = rootCell.getFilesystem().getPathForRelativePath(filePath);
if (!Files.exists(file)) {
nonExistentInputs.add(filePath);
} else if (!Files.isRegularFile(file)) {
nonFileInputs.add(filePath);
} else {
inputs.add(rootCell.getFilesystem().getPath(filePath));
}
}
// Try to find owners for each valid and existing file.
Set<Path> inputsWithNoOwners = Sets.newHashSet(inputs);
SetMultimap<TargetNode<?, ?>, Path> owners = TreeMultimap.create();
for (final Path commandInput : inputs) {
Predicate<Path> startsWith = input -> !commandInput.equals(input) && commandInput.startsWith(input);
Set<Path> ruleInputs = targetNode.getInputs();
if (ruleInputs.contains(commandInput) || FluentIterable.from(ruleInputs).anyMatch(startsWith)) {
inputsWithNoOwners.remove(commandInput);
owners.put(targetNode, commandInput);
}
}
return new OwnersReport(owners, inputsWithNoOwners, nonExistentInputs, nonFileInputs);
}
use of com.google.common.base.Predicate in project buck by facebook.
the class AuditRulesCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
try (ProjectBuildFileParser parser = params.getCell().createBuildFileParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(params.getObjectMapper())), params.getConsole(), params.getBuckEventBus(), /* ignoreBuckAutodepsFiles */
false)) {
PrintStream out = params.getConsole().getStdOut();
for (String pathToBuildFile : getArguments()) {
if (!json) {
// Print a comment with the path to the build file.
out.printf("# %s\n\n", pathToBuildFile);
}
// Resolve the path specified by the user.
Path path = Paths.get(pathToBuildFile);
if (!path.isAbsolute()) {
Path root = projectFilesystem.getRootPath();
path = root.resolve(path);
}
// Parse the rules from the build file.
List<Map<String, Object>> rawRules;
try {
rawRules = parser.getAll(path);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Format and print the rules from the raw data, filtered by type.
final ImmutableSet<String> types = getTypes();
Predicate<String> includeType = type -> types.isEmpty() || types.contains(type);
printRulesToStdout(params, rawRules, includeType);
}
} catch (BuildFileParseException e) {
throw new HumanReadableException("Unable to create parser");
}
return 0;
}
use of com.google.common.base.Predicate in project buck by facebook.
the class AuditRulesCommand method printRulesToStdout.
private void printRulesToStdout(CommandRunnerParams params, List<Map<String, Object>> rawRules, final Predicate<String> includeType) throws IOException {
Iterable<Map<String, Object>> filteredRules = FluentIterable.from(rawRules).filter(rawRule -> {
String type = (String) rawRule.get(BuckPyFunction.TYPE_PROPERTY_NAME);
return includeType.apply(type);
});
PrintStream stdOut = params.getConsole().getStdOut();
if (json) {
Map<String, Object> rulesKeyedByName = new HashMap<>();
for (Map<String, Object> rawRule : filteredRules) {
String name = (String) rawRule.get("name");
Preconditions.checkNotNull(name);
rulesKeyedByName.put(name, Maps.filterValues(rawRule, v -> shouldInclude(v)));
}
// We create a new JsonGenerator that does not close the stream.
ObjectMapper mapper = params.getObjectMapper();
JsonFactory factory = mapper.getFactory();
try (JsonGenerator generator = factory.createGenerator(stdOut).disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET).useDefaultPrettyPrinter()) {
mapper.writeValue(generator, rulesKeyedByName);
}
stdOut.print('\n');
} else {
for (Map<String, Object> rawRule : filteredRules) {
printRuleAsPythonToStdout(stdOut, rawRule);
}
}
}
use of com.google.common.base.Predicate in project MinecraftForge by MinecraftForge.
the class ModelLoader method loadItemModels.
@Override
protected void loadItemModels() {
// register model for the universal bucket, if it exists
if (FluidRegistry.isUniversalBucketEnabled()) {
setBucketModelDefinition(ForgeModContainer.getInstance().universalBucket);
}
registerVariantNames();
List<Item> items = Lists.newArrayList(Iterables.filter(Item.REGISTRY, new Predicate<Item>() {
public boolean apply(Item item) {
return item.getRegistryName() != null;
}
}));
Collections.sort(items, new Comparator<Item>() {
public int compare(Item i1, Item i2) {
return i1.getRegistryName().toString().compareTo(i2.getRegistryName().toString());
}
});
ProgressBar itemBar = ProgressManager.push("ModelLoader: items", items.size());
for (Item item : items) {
itemBar.step(item.getRegistryName().toString());
for (String s : getVariantNames(item)) {
ResourceLocation file = getItemLocation(s);
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getMissingModel();
Exception exception = null;
try {
model = ModelLoaderRegistry.getModel(file);
} catch (Exception normalException) {
// try blockstate json if the item model is missing
FMLLog.fine("Item json isn't found for '" + memory + "', trying to load the variant from the blockstate json");
try {
model = ModelLoaderRegistry.getModel(memory);
} catch (Exception blockstateException) {
exception = new ItemLoadingException("Could not load item model either from the normal location " + file + " or from the blockstate", normalException, blockstateException);
}
}
if (exception != null) {
storeException(memory, exception);
model = ModelLoaderRegistry.getMissingModel(memory, exception);
}
stateModels.put(memory, model);
}
}
ProgressManager.pop(itemBar);
// replace vanilla bucket models if desired. done afterwards for performance reasons
if (ForgeModContainer.replaceVanillaBucketModel) {
// ensure the bucket model is loaded
if (!stateModels.containsKey(ModelDynBucket.LOCATION)) {
// load forges blockstate json for it
try {
registerVariant(getModelBlockDefinition(ModelDynBucket.LOCATION), ModelDynBucket.LOCATION);
} catch (Exception exception) {
FMLLog.getLogger().error("Could not load the forge bucket model from the blockstate", exception);
return;
}
}
// empty bucket
for (String s : getVariantNames(Items.BUCKET)) {
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket"));
// only on successful load, otherwise continue using the old model
if (model != getMissingModel()) {
stateModels.put(memory, model);
}
}
setBucketModel(Items.WATER_BUCKET);
setBucketModel(Items.LAVA_BUCKET);
// milk bucket only replaced if some mod adds milk
if (FluidRegistry.isFluidRegistered("milk")) {
// can the milk be put into a bucket?
Fluid milk = FluidRegistry.getFluid("milk");
FluidStack milkStack = new FluidStack(milk, Fluid.BUCKET_VOLUME);
IFluidHandler bucketHandler = FluidUtil.getFluidHandler(new ItemStack(Items.BUCKET));
if (bucketHandler != null && bucketHandler.fill(milkStack, false) == Fluid.BUCKET_VOLUME) {
setBucketModel(Items.MILK_BUCKET);
}
} else {
// milk bucket if no milk fluid is present
for (String s : getVariantNames(Items.MILK_BUCKET)) {
ModelResourceLocation memory = getInventoryVariant(s);
IModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(ForgeVersion.MOD_ID, "item/bucket_milk"));
// only on successful load, otherwise continue using the old model
if (model != getMissingModel()) {
stateModels.put(memory, model);
}
}
}
}
}
Aggregations