Search in sources :

Example 11 with Either

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);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) WorkerTool(com.facebook.buck.shell.WorkerTool) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Flavor(com.facebook.buck.model.Flavor)

Example 12 with Either

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();
}
Also used : Type(java.lang.reflect.Type) Either(com.facebook.buck.model.Either) Test(org.junit.Test)

Example 13 with Either

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();
}
Also used : Type(java.lang.reflect.Type) Either(com.facebook.buck.model.Either) Test(org.junit.Test)

Aggregations

Either (com.facebook.buck.model.Either)13 SourcePath (com.facebook.buck.rules.SourcePath)7 BuildRule (com.facebook.buck.rules.BuildRule)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 ImmutableList (com.google.common.collect.ImmutableList)5 Path (java.nio.file.Path)5 BuildTarget (com.facebook.buck.model.BuildTarget)4 Flavor (com.facebook.buck.model.Flavor)4 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)4 Optional (java.util.Optional)4 Pair (com.facebook.buck.model.Pair)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)3 MorePaths (com.facebook.buck.io.MorePaths)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 JavacOptions (com.facebook.buck.jvm.java.JavacOptions)2 Flavored (com.facebook.buck.model.Flavored)2