use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class KnownBuildRuleTypesTest method createInstanceShouldReturnDifferentInstancesIfCalledWithDifferentParameters.
@Test
public void createInstanceShouldReturnDifferentInstancesIfCalledWithDifferentParameters() throws Exception {
ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
KnownBuildRuleTypes knownBuildRuleTypes1 = KnownBuildRuleTypes.createInstance(FakeBuckConfig.builder().build(), filesystem, createExecutor(), new FakeAndroidDirectoryResolver());
final Path javac = temporaryFolder.newExecutableFile();
ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("tools", ImmutableMap.of("javac", javac.toString()));
BuckConfig buckConfig = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(sections).build();
ProcessExecutor processExecutor = createExecutor(javac.toString(), "");
KnownBuildRuleTypes knownBuildRuleTypes2 = KnownBuildRuleTypes.createInstance(buckConfig, filesystem, processExecutor, new FakeAndroidDirectoryResolver());
assertNotEquals(knownBuildRuleTypes1, knownBuildRuleTypes2);
}
use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class TypeCoercerTest method traverseShouldVisitEveryObject.
/**
* Traverse visits every element of an input value without coercing to the output type.
*/
@Test
public void traverseShouldVisitEveryObject() throws NoSuchFieldException {
Type type = TestFields.class.getField("stringMapOfLists").getGenericType();
@SuppressWarnings("unchecked") TypeCoercer<ImmutableMap<String, ImmutableList<String>>> coercer = (TypeCoercer<ImmutableMap<String, ImmutableList<String>>>) typeCoercerFactory.typeCoercerForType(type);
final ImmutableMap<String, ImmutableList<String>> input = ImmutableMap.of("foo", ImmutableList.of("//foo:bar", "//foo:baz"), "bar", ImmutableList.of(":bar", "//foo:foo"));
TestTraversal traversal = new TestTraversal();
coercer.traverse(input, traversal);
Matcher<Iterable<?>> matcher = Matchers.contains(ImmutableList.of(sameInstance((Object) input), is((Object) "foo"), sameInstance((Object) input.get("foo")), is((Object) "//foo:bar"), is((Object) "//foo:baz"), is((Object) "bar"), sameInstance((Object) input.get("bar")), is((Object) ":bar"), is((Object) "//foo:foo")));
assertThat(traversal.getObjects(), matcher);
}
use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class GenruleTest method testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent.
@Test
public void testShouldIncludeAndroidSpecificEnvInEnvironmentIfPresent() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
AndroidPlatformTarget android = EasyMock.createNiceMock(AndroidPlatformTarget.class);
Path sdkDir = Paths.get("/opt/users/android_sdk");
Path ndkDir = Paths.get("/opt/users/android_ndk");
EasyMock.expect(android.getSdkDirectory()).andStubReturn(Optional.of(sdkDir));
EasyMock.expect(android.getNdkDirectory()).andStubReturn(Optional.of(ndkDir));
EasyMock.expect(android.getDxExecutable()).andStubReturn(Paths.get("."));
EasyMock.expect(android.getZipalignExecutable()).andStubReturn(Paths.get("zipalign"));
EasyMock.replay(android);
BuildTarget target = BuildTargetFactory.newInstance("//example:genrule");
Genrule genrule = GenruleBuilder.newGenruleBuilder(target).setBash("echo something > $OUT").setOut("file").build(resolver);
ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(android)).build();
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
genrule.addEnvironmentVariables(pathResolver, context, builder);
ImmutableMap<String, String> env = builder.build();
assertEquals(Paths.get(".").toString(), env.get("DX"));
assertEquals(Paths.get("zipalign").toString(), env.get("ZIPALIGN"));
assertEquals(sdkDir.toString(), env.get("ANDROID_HOME"));
assertEquals(ndkDir.toString(), env.get("NDK_HOME"));
EasyMock.verify(android);
}
use of com.google.common.collect.ImmutableMap in project killbill by killbill.
the class InvoiceResource method searchInvoices.
@TimedResource
@GET
@Path("/" + SEARCH + "/{searchKey:" + ANYTHING_PATTERN + "}")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Search invoices", response = InvoiceJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response searchInvoices(@PathParam("searchKey") final String searchKey, @QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final Boolean withItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws SubscriptionApiException {
final TenantContext tenantContext = context.createContext(request);
final Pagination<Invoice> invoices = invoiceApi.searchInvoices(searchKey, offset, limit, tenantContext);
final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "searchInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of("searchKey", searchKey, QUERY_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
return buildStreamingPaginationResponse(invoices, new Function<Invoice, InvoiceJson>() {
@Override
public InvoiceJson apply(final Invoice invoice) {
// Cache audit logs per account
if (accountsAuditLogs.get().get(invoice.getAccountId()) == null) {
accountsAuditLogs.get().put(invoice.getAccountId(), auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext));
}
return new InvoiceJson(invoice, withItems, null, accountsAuditLogs.get().get(invoice.getAccountId()));
}
}, nextPageUri);
}
use of com.google.common.collect.ImmutableMap in project killbill by killbill.
the class InvoiceResource method getInvoices.
@TimedResource
@GET
@Path("/" + PAGINATION)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "List invoices", response = InvoiceJson.class, responseContainer = "List")
@ApiResponses(value = {})
public Response getInvoices(@QueryParam(QUERY_SEARCH_OFFSET) @DefaultValue("0") final Long offset, @QueryParam(QUERY_SEARCH_LIMIT) @DefaultValue("100") final Long limit, @QueryParam(QUERY_INVOICE_WITH_ITEMS) @DefaultValue("false") final Boolean withItems, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws InvoiceApiException {
final TenantContext tenantContext = context.createContext(request);
final Pagination<Invoice> invoices = invoiceApi.getInvoices(offset, limit, tenantContext);
final URI nextPageUri = uriBuilder.nextPage(InvoiceResource.class, "getInvoices", invoices.getNextOffset(), limit, ImmutableMap.<String, String>of(QUERY_INVOICE_WITH_ITEMS, withItems.toString(), QUERY_AUDIT, auditMode.getLevel().toString()));
final AtomicReference<Map<UUID, AccountAuditLogs>> accountsAuditLogs = new AtomicReference<Map<UUID, AccountAuditLogs>>(new HashMap<UUID, AccountAuditLogs>());
return buildStreamingPaginationResponse(invoices, new Function<Invoice, InvoiceJson>() {
@Override
public InvoiceJson apply(final Invoice invoice) {
// Cache audit logs per account
if (accountsAuditLogs.get().get(invoice.getAccountId()) == null) {
accountsAuditLogs.get().put(invoice.getAccountId(), auditUserApi.getAccountAuditLogs(invoice.getAccountId(), auditMode.getLevel(), tenantContext));
}
return new InvoiceJson(invoice, withItems, null, accountsAuditLogs.get().get(invoice.getAccountId()));
}
}, nextPageUri);
}
Aggregations