Search in sources :

Example 86 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class TargetsCommandIntegrationTest method testValidateBuildTargetForNonAliasTarget.

@Test
public void testValidateBuildTargetForNonAliasTarget() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "target_validation", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--resolve-alias", "//:test-library");
    assertTrue(result.getStdout(), result.getStdout().contains("//:test-library"));
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//:");
    } catch (HumanReadableException e) {
        assertEquals("//: cannot end with a colon", e.getMessage());
    }
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//:test-libarry");
    } catch (HumanReadableException e) {
        assertEquals("//:test-libarry is not a valid target.", e.getMessage());
    }
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//blah/foo");
    } catch (HumanReadableException e) {
        assertEquals("//blah/foo must contain exactly one colon (found 0)", e.getMessage());
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 87 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class IntraCellIntegrationTest method shouldTreatCellBoundariesAsVisibilityBoundariesToo.

@SuppressWarnings("PMD.EmptyCatchBlock")
@Test
public void shouldTreatCellBoundariesAsVisibilityBoundariesToo() throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "intracell/visibility", tmp);
    workspace.setUp();
    // We don't need to do a build. It's enough to just parse these things.
    Cell cell = workspace.asCell();
    TypeCoercerFactory coercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), coercerFactory, new ConstructorArgMarshaller(coercerFactory));
    // This parses cleanly
    parser.buildTargetGraph(BuckEventBusFactory.newInstance(), cell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(cell.getFilesystem(), "//just-a-directory:rule")));
    Cell childCell = cell.getCell(BuildTargetFactory.newInstance(workspace.getDestPath().resolve("child-repo"), "//:child-target"));
    try {
        // Whereas, because visibility is limited to the same cell, this won't.
        parser.buildTargetGraph(BuckEventBusFactory.newInstance(), childCell, false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(childCell.getFilesystem(), "//:child-target")));
        fail("Didn't expect parsing to work because of visibility");
    } catch (HumanReadableException e) {
    // This is expected
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) HumanReadableException(com.facebook.buck.util.HumanReadableException) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) Cell(com.facebook.buck.rules.Cell) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ParserConfig(com.facebook.buck.parser.ParserConfig) Parser(com.facebook.buck.parser.Parser) Test(org.junit.Test)

Example 88 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class GoAssumptions method assumeGoCompilerAvailable.

public static void assumeGoCompilerAvailable() throws InterruptedException, IOException {
    Throwable exception = null;
    try {
        ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
        FakeBuckConfig.Builder baseConfig = FakeBuckConfig.builder();
        String goRoot = System.getenv("GOROOT");
        if (goRoot != null) {
            baseConfig.setSections("[go]", "  root = " + goRoot);
            // This should really act like some kind of readonly bind-mount onto the real filesystem.
            // But this is currently enough to check whether Go seems to be installed, so we'll live...
            FakeProjectFilesystem fs = new FakeProjectFilesystem();
            fs.mkdirs(fs.getPath(goRoot));
            baseConfig.setFilesystem(fs);
        }
        new GoBuckConfig(baseConfig.build(), executor, FlavorDomain.from("Cxx", ImmutableSet.of())).getCompiler();
    } catch (HumanReadableException e) {
        exception = e;
    }
    assumeNoException(exception);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig)

Example 89 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class MavenUrlDecoderTest method optionalServerUrlMustBeHttpOrHttps.

@Test
@SuppressWarnings("PMD.EmptyCatchBlock")
public void optionalServerUrlMustBeHttpOrHttps() throws URISyntaxException {
    Optional<String> repo = Optional.of("http://foo.bar");
    MavenUrlDecoder.toHttpUrl(repo, new URI("mvn:http://example.org/:org.seleniumhq.selenium:selenium-java:jar:2.42.2"));
    MavenUrlDecoder.toHttpUrl(repo, new URI("mvn:https://example.org/:org.seleniumhq.selenium:selenium-java:jar:2.42.2"));
    try {
        MavenUrlDecoder.toHttpUrl(repo, new URI("mvn:mvn://custom.org/:org.seleniumhq.selenium:selenium-java:jar:2.42.2"));
        fail();
    } catch (HumanReadableException expected) {
    // Ignored
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) URI(java.net.URI) Test(org.junit.Test)

Example 90 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class JavaBuckConfigTest method whenJavacIsNotExecutableThenHumanReadableExeceptionIsThrown.

@Test
public void whenJavacIsNotExecutableThenHumanReadableExeceptionIsThrown() throws IOException {
    assumeThat("Files on Windows are executable by default.", Platform.detect(), is(not(Platform.WINDOWS)));
    Path javac = temporaryFolder.newFile();
    Reader reader = new StringReader(Joiner.on('\n').join("[tools]", "    javac = " + javac.toString()));
    JavaBuckConfig config = createWithDefaultFilesystem(reader);
    try {
        config.getJavacPath();
        fail("Should throw exception as javac file is not executable.");
    } catch (HumanReadableException e) {
        assertEquals(e.getHumanReadableErrorMessage(), "javac is not executable: " + javac);
    }
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15