use of com.facebook.buck.model.Either in project buck by facebook.
the class JsLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
params.getBuildTarget().getBasePath();
// this params object is used as base for the JsLibrary build rule, but also for all dynamically
// created JsFile rules.
// For the JsLibrary case, we want to propagate flavors to library dependencies
// For the JsFile case, we only want to depend on the worker, not on any libraries
params = JsUtil.withWorkerDependencyOnly(params, resolver, args.worker);
final WorkerTool worker = resolver.getRuleWithType(args.worker, WorkerTool.class);
final SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
final SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
final ImmutableBiMap<Either<SourcePath, Pair<SourcePath, String>>, Flavor> sourcesToFlavors = mapSourcesToFlavors(sourcePathResolver, args.srcs);
final Optional<Either<SourcePath, Pair<SourcePath, String>>> file = JsFlavors.extractSourcePath(sourcesToFlavors.inverse(), params.getBuildTarget().getFlavors().stream());
if (file.isPresent()) {
return params.getBuildTarget().getFlavors().contains(JsFlavors.RELEASE) ? createReleaseFileRule(params, resolver, args, worker) : createDevFileRule(params, ruleFinder, sourcePathResolver, args, file.get(), worker);
} else {
return new LibraryBuilder(targetGraph, resolver, params, sourcesToFlavors).setSources(args.srcs).setLibraryDependencies(args.libs).build(worker);
}
}
use of com.facebook.buck.model.Either in project buck by facebook.
the class TypeCoercerTest method coercedEitherThrowsOnAccessingMissingLeft.
@Test
public void coercedEitherThrowsOnAccessingMissingLeft() throws NoSuchFieldException, CoerceFailedException {
Type type = TestFields.class.getField("eitherStringSetOrStringToStringMap").getGenericType();
TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
Map<String, String> inputMap = ImmutableMap.of("key1", "One", "key2", "Two");
Either<?, ?> either = (Either<?, ?>) coercer.coerce(cellRoots, filesystem, Paths.get(""), inputMap);
assertEquals(inputMap, either.getRight());
exception.expect(RuntimeException.class);
either.getLeft();
}
use of com.facebook.buck.model.Either in project buck by facebook.
the class TypeCoercerTest method coercedEitherThrowsOnAccessingMissingRight.
@Test
public void coercedEitherThrowsOnAccessingMissingRight() throws NoSuchFieldException, CoerceFailedException {
Type type = TestFields.class.getField("eitherStringSetOrStringToStringMap").getGenericType();
TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
Set<String> inputSet = ImmutableSet.of("a", "b", "x");
Either<?, ?> either = (Either<?, ?>) coercer.coerce(cellRoots, filesystem, Paths.get(""), inputSet);
assertEquals(inputSet, either.getLeft());
exception.expect(RuntimeException.class);
either.getRight();
}
Aggregations