Search in sources :

Example 16 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class BuildCommandTest method testGenerateJsonBuildReport.

@Test
public void testGenerateJsonBuildReport() throws IOException {
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    String rule1TxtPath = mapper.valueToTree(MorePaths.pathWithPlatformSeparators("buck-out/gen/fake/rule1.txt")).toString();
    String expectedReport = Joiner.on(System.lineSeparator()).join("{", "  \"success\" : false,", "  \"results\" : {", "    \"//fake:rule1\" : {", "      \"success\" : true,", "      \"type\" : \"BUILT_LOCALLY\",", "      \"output\" : " + rule1TxtPath, "    },", "    \"//fake:rule2\" : {", "      \"success\" : false", "    },", "    \"//fake:rule3\" : {", "      \"success\" : true,", "      \"type\" : \"FETCHED_FROM_CACHE\",", "      \"output\" : null", "    },", "    \"//fake:rule4\" : {", "      \"success\" : false", "    }", "  },", "  \"failures\" : {", "    \"//fake:rule2\" : \"some\"", "  }", "}");
    String observedReport = new BuildReport(buildExecutionResult, resolver).generateJsonBuildReport();
    assertEquals(expectedReport, observedReport);
}
Also used : BuildReport(com.facebook.buck.command.BuildReport) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 17 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class AuditClasspathCommandTest method testJsonClassPathWithVersions.

@Test
public void testJsonClassPathWithVersions() throws Exception {
    // Build the test target graph.
    TargetNode<?, ?> javaLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-java-library")).addSrc(Paths.get("src/com/facebook/TestJavaLibrary.java")).build();
    TargetNode<?, ?> androidLibrary = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:test-android-library")).addSrc(Paths.get("src/com/facebook/TestAndroidLibrary.java")).addDep(javaLibrary.getBuildTarget()).build();
    TargetNode<?, ?> version = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:version")).setVersions("1.0", "//:test-android-library").build();
    TargetNode<?, ?> binary = new JavaBinaryRuleBuilder(BuildTargetFactory.newInstance("//:rule")).setDeps(ImmutableSortedSet.of(version.getBuildTarget())).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(javaLibrary, androidLibrary, version, binary);
    // Run the command.
    auditClasspathCommand.printJsonClasspath(params.withBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("build", ImmutableMap.of("versions", "true"))).build()), targetGraph, ImmutableSet.of(androidLibrary.getBuildTarget(), javaLibrary.getBuildTarget()));
    // Verify output.
    Path root = javaLibrary.getBuildTarget().getCellPath();
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    String expected = String.format(EXPECTED_JSON, mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), androidLibrary.getBuildTarget(), "lib__%s__output").resolve(androidLibrary.getBuildTarget().getShortName() + ".jar"))), mapper.valueToTree(root.resolve(BuildTargets.getGenPath(params.getCell().getFilesystem(), javaLibrary.getBuildTarget(), "lib__%s__output").resolve(javaLibrary.getBuildTarget().getShortName() + ".jar"))));
    assertEquals(expected, console.getTextWrittenToStdOut());
    assertEquals("", console.getTextWrittenToStdErr());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) Test(org.junit.Test)

Example 18 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class AuditInputCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    console = new TestConsole();
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    projectFilesystem.touch(Paths.get("src/com/facebook/AndroidLibraryTwo.java"));
    projectFilesystem.touch(Paths.get("src/com/facebook/TestAndroidLibrary.java"));
    projectFilesystem.touch(Paths.get("src/com/facebook/TestJavaLibrary.java"));
    Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
    ArtifactCache artifactCache = new NoopArtifactCache();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    auditInputCommand = new AuditInputCommand();
    params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, new FakeAndroidDirectoryResolver(), artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 19 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class QueryCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    TestConsole console = new TestConsole();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
    workspace.setUp();
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
    ArtifactCache artifactCache = new NoopArtifactCache();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    queryCommand = new QueryCommand();
    queryCommand.outputAttributes = Suppliers.ofInstance(ImmutableSet.<String>of());
    params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
    executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 20 with ObjectMapper

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project buck by facebook.

the class TargetsCommandIntegrationTest method testJsonOutputWithShowCellPath.

@Test
public void testJsonOutputWithShowCellPath() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-cell-path", "//:test");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    // Parse the observed JSON.
    JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
    assertTrue(observed.isArray());
    JsonNode targetNode = observed.get(0);
    assertTrue(targetNode.isObject());
    JsonNode cellPath = targetNode.get("buck.cell_path");
    assertNotNull(cellPath);
    assertEquals(cellPath.asText(), MorePaths.pathWithPlatformSeparators(tmp.getRoot().toRealPath()));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5262 Test (org.junit.Test)1989 IOException (java.io.IOException)837 JsonNode (com.fasterxml.jackson.databind.JsonNode)724 HashMap (java.util.HashMap)375 Map (java.util.Map)367 ArrayList (java.util.ArrayList)346 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)318 File (java.io.File)282 List (java.util.List)222 Test (org.junit.jupiter.api.Test)205 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)202 Before (org.junit.Before)202 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)197 InputStream (java.io.InputStream)143 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)137 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)127 Matchers.containsString (org.hamcrest.Matchers.containsString)127 TypeReference (com.fasterxml.jackson.core.type.TypeReference)108 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)99