Skip to content

Commit d779e4a

Browse files
authored
Merge pull request #91 from xsalefter/base_plugin_84-remove_guava_dependencies
Base plugin 84 remove guava dependencies
2 parents 27335ea + c9ac1c6 commit d779e4a

35 files changed

Lines changed: 422 additions & 369 deletions

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
5.1.0
2+
Make java.net.http.HttpClient.Builder overridable
3+
Remove all Guava classes and dependency
4+
15
4.2.15
26
Update killbill-oss-parent to 0.144.68
37

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Convenience library to help write Kill Bill plugins.
1414
| 4.1.y | 0.22.z |
1515
| 4.2.y | 0.22.z |
1616
| 5.0.y | 0.24.z |
17+
| 5.1.y | 0.24.z |
1718

1819
We've upgraded numerous dependencies in 4.2.x (required for Java 11 support).
1920

pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
<parent>
2222
<groupId>org.kill-bill.billing</groupId>
2323
<artifactId>killbill-oss-parent</artifactId>
24-
<version>0.146.10</version>
24+
<version>0.146.11</version>
2525
</parent>
2626
<groupId>org.kill-bill.billing.plugin.java</groupId>
2727
<artifactId>killbill-base-plugin</artifactId>
28-
<version>5.0.2-SNAPSHOT</version>
28+
<version>5.1.0-SNAPSHOT</version>
2929
<packaging>jar</packaging>
3030
<name>Kill Bill base OSGI plugin</name>
3131
<description>Kill Bill base OSGI plugin</description>
@@ -79,10 +79,6 @@
7979
<groupId>com.google.code.findbugs</groupId>
8080
<artifactId>jsr305</artifactId>
8181
</dependency>
82-
<dependency>
83-
<groupId>com.google.guava</groupId>
84-
<artifactId>guava</artifactId>
85-
</dependency>
8682
<dependency>
8783
<groupId>com.typesafe</groupId>
8884
<artifactId>config</artifactId>
@@ -240,6 +236,11 @@
240236
<artifactId>killbill-embeddeddb-postgresql</artifactId>
241237
<scope>test</scope>
242238
</dependency>
239+
<dependency>
240+
<groupId>org.kill-bill.commons</groupId>
241+
<artifactId>killbill-utils</artifactId>
242+
<scope>provided</scope>
243+
</dependency>
243244
<dependency>
244245
<groupId>org.kill-bill.testing</groupId>
245246
<artifactId>testing-mysql-server</artifactId>

src/main/java/org/killbill/billing/plugin/api/PluginApi.java

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
import java.math.BigDecimal;
2222
import java.util.Collection;
23+
import java.util.Collections;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
27+
import java.util.Objects;
2628
import java.util.UUID;
29+
import java.util.stream.Collectors;
2730

2831
import org.joda.time.DateTime;
2932
import org.joda.time.LocalDate;
@@ -70,12 +73,6 @@
7073
import org.slf4j.Logger;
7174
import org.slf4j.LoggerFactory;
7275

73-
import com.google.common.base.Function;
74-
import com.google.common.base.MoreObjects;
75-
import com.google.common.base.Predicate;
76-
import com.google.common.collect.ImmutableList;
77-
import com.google.common.collect.Iterables;
78-
7976
public abstract class PluginApi {
8077

8178
private static final Logger logger = LoggerFactory.getLogger(PluginApi.class);
@@ -89,7 +86,7 @@ public abstract class PluginApi {
8986
// See convention in InternalCallContextFactory
9087
protected static final long INTERNAL_TENANT_RECORD_ID = 0L;
9188

92-
protected static final Iterable<PluginProperty> PLUGIN_PROPERTIES = ImmutableList.<PluginProperty>of();
89+
protected static final Iterable<PluginProperty> PLUGIN_PROPERTIES = Collections.emptyList();
9390

9491
protected final OSGIKillbillAPI killbillAPI;
9592
protected final OSGIConfigPropertiesService configProperties;
@@ -221,31 +218,20 @@ protected Long getSubscriptionEventRecordId(final UUID subscriptionEventId, fina
221218

222219
protected Iterable<SubscriptionEvent> getBlockingHistory(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable {
223220
final List<SubscriptionBundle> bundles = getSubscriptionBundlesForAccount(accountId, context);
224-
225-
// Find all subscription events for that account
226-
final Iterable<SubscriptionEvent> subscriptionEvents = Iterables.<SubscriptionEvent>concat(Iterables.<SubscriptionBundle, List<SubscriptionEvent>>transform(bundles,
227-
new Function<SubscriptionBundle, List<SubscriptionEvent>>() {
228-
@Override
229-
public List<SubscriptionEvent> apply(final SubscriptionBundle bundle) {
230-
return bundle == null ? ImmutableList.<SubscriptionEvent>of() : bundle.getTimeline().getSubscriptionEvents();
231-
}
232-
}
233-
));
234-
235-
// Filter all service state changes
236-
return Iterables.<SubscriptionEvent>filter(subscriptionEvents,
237-
new Predicate<SubscriptionEvent>() {
238-
@Override
239-
public boolean apply(final SubscriptionEvent event) {
240-
return event != null &&
241-
event.getSubscriptionEventType() != null &&
242-
// We want events coming from the blocking states table...
243-
ObjectType.BLOCKING_STATES.equals(event.getSubscriptionEventType().getObjectType()) &&
244-
// ...that are for any service but entitlement
245-
!ENTITLEMENT_SERVICE_NAME.equals(event.getServiceName());
246-
}
247-
}
248-
);
221+
if (bundles != null) {
222+
// Find all subscription events for that account
223+
return bundles.stream()
224+
.map(subscriptionBundle -> subscriptionBundle.getTimeline().getSubscriptionEvents())
225+
.flatMap(Collection::stream)
226+
.filter(event -> event != null &&
227+
event.getSubscriptionEventType() != null &&
228+
// We want events coming from the blocking states table...
229+
ObjectType.BLOCKING_STATES.equals(event.getSubscriptionEventType().getObjectType()) &&
230+
// ...that are for any service but entitlement
231+
!ENTITLEMENT_SERVICE_NAME.equals(event.getServiceName()))
232+
.collect(Collectors.toUnmodifiableList());
233+
}
234+
return Collections.emptyList();
249235
}
250236

251237
//
@@ -321,7 +307,7 @@ protected Plan getPlanFromInvoiceItem(final InvoiceItem invoiceItem, final Tenan
321307
try {
322308
final VersionedCatalog catalog = getCatalog(context);
323309
// getCatalogEffectiveDate was introduced in 0.21.x
324-
final DateTime catalogEffectiveDate = MoreObjects.firstNonNull(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
310+
final DateTime catalogEffectiveDate = Objects.requireNonNullElse(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
325311
return catalog.getVersion(catalogEffectiveDate.toDate()).findPlan(invoiceItem.getPlanName());
326312
} catch (final CatalogApiException e) {
327313
logger.info("Unable to retrieve plan for invoice item {}", invoiceItem.getId(), e);
@@ -333,7 +319,7 @@ protected PlanPhase getPlanPhaseFromInvoiceItem(final InvoiceItem invoiceItem, f
333319
try {
334320
final VersionedCatalog catalog = getCatalog(context);
335321
// getCatalogEffectiveDate was introduced in 0.21.x
336-
final DateTime catalogEffectiveDate = MoreObjects.firstNonNull(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
322+
final DateTime catalogEffectiveDate = Objects.requireNonNullElse(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
337323
return catalog.getVersion(catalogEffectiveDate.toDate()).findPhase(invoiceItem.getPhaseName());
338324
} catch (final CatalogApiException e) {
339325
logger.info("Unable to retrieve phase for invoice item {}", invoiceItem.getId(), e);
@@ -451,13 +437,9 @@ protected PaymentTransaction getPaymentTransaction(final UUID kbPaymentId, final
451437
}
452438

453439
protected PaymentTransaction getPaymentTransaction(final UUID kbTransactionId, final Payment payment) throws OSGIServiceNotAvailable {
454-
return Iterables.<PaymentTransaction>find(payment.getTransactions(),
455-
new Predicate<PaymentTransaction>() {
456-
@Override
457-
public boolean apply(final PaymentTransaction input) {
458-
return input != null && kbTransactionId.equals(input.getId());
459-
}
460-
});
440+
return payment.getTransactions().stream()
441+
.filter(input -> input != null && kbTransactionId.equals(input.getId()))
442+
.findFirst().get();
461443
}
462444

463445
protected Long getPaymentRecordId(final UUID paymentId, final TenantContext context) throws OSGIServiceNotAvailable {

src/main/java/org/killbill/billing/plugin/api/PluginProperties.java

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,41 @@
1818

1919
package org.killbill.billing.plugin.api;
2020

21+
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.Map.Entry;
2426
import java.util.regex.Pattern;
27+
import java.util.stream.Collectors;
2528

2629
import javax.annotation.Nullable;
2730

2831
import org.killbill.billing.payment.api.PluginProperty;
2932
import org.killbill.billing.plugin.util.http.UTF8UrlDecoder;
33+
import org.killbill.commons.utils.Strings;
34+
import org.killbill.commons.utils.collect.Iterables;
3035

31-
import com.google.common.base.Function;
32-
import com.google.common.base.Predicate;
33-
import com.google.common.base.Strings;
34-
import com.google.common.collect.ImmutableList;
35-
import com.google.common.collect.Iterables;
36-
import com.google.common.collect.Maps;
3736
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3837

3938
public abstract class PluginProperties {
4039

4140
// Last one has precedence
41+
@SafeVarargs
4242
public static Iterable<PluginProperty> merge(final Iterable<PluginProperty>... propertiesLists) {
4343
return buildPluginProperties(toMap(propertiesLists));
4444
}
4545

4646
// Last one has precedence
47-
public static Iterable<PluginProperty> merge(@Nullable final Map data, final Iterable<PluginProperty>... propertiesLists) {
47+
@SafeVarargs
48+
public static <K, V> Iterable<PluginProperty> merge(@Nullable final Map<K, V> data, final Iterable<PluginProperty>... propertiesLists) {
4849
return merge(buildPluginProperties(data), merge(propertiesLists));
4950
}
5051

5152
// Last one has precedence
53+
@SafeVarargs
5254
public static Map<String, Object> toMap(final Iterable<PluginProperty>... propertiesLists) {
53-
final Map<String, Object> mergedProperties = new HashMap<String, Object>();
55+
final Map<String, Object> mergedProperties = new HashMap<>();
5456
for (final Iterable<PluginProperty> propertiesList : propertiesLists) {
5557
if (propertiesList == null) {
5658
continue;
@@ -65,14 +67,12 @@ public static Map<String, Object> toMap(final Iterable<PluginProperty>... proper
6567
}
6668

6769
// Last one has precedence
70+
@SafeVarargs
6871
public static Map<String, String> toStringMap(final Iterable<PluginProperty>... propertiesLists) {
69-
return Maps.transformValues(toMap(propertiesLists),
70-
new Function<Object, String>() {
71-
@Override
72-
public String apply(final Object input) {
73-
return input == null ? null : input.toString();
74-
}
75-
});
72+
return toMap(propertiesLists)
73+
.entrySet()
74+
.stream()
75+
.collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue() == null ? null : entry.getValue().toString()));
7676
}
7777

7878
// Return the value from the plugin properties if it exists, or the fallback otherwise
@@ -86,13 +86,9 @@ public static String findPluginPropertyValue(final String pluginPropertyName, @N
8686
return null;
8787
}
8888

89-
final PluginProperty pluginProperty = Iterables.tryFind(properties,
90-
new Predicate<PluginProperty>() {
91-
@Override
92-
public boolean apply(final PluginProperty input) {
93-
return input != null && pluginPropertyName.equals(input.getKey());
94-
}
95-
}).orNull();
89+
final PluginProperty pluginProperty = Iterables.toStream(properties)
90+
.filter(input -> input != null && pluginPropertyName.equals(input.getKey()))
91+
.findFirst().orElse(null);
9692

9793
if (pluginProperty == null || pluginProperty.getValue() == null) {
9894
return null;
@@ -111,40 +107,28 @@ public static Iterable<PluginProperty> findPluginProperties(final String key, @N
111107
return null;
112108
}
113109

114-
return Iterables.filter(properties,
115-
new Predicate<PluginProperty>() {
116-
@Override
117-
public boolean apply(final PluginProperty input) {
118-
return key != null && key.equals(input.getKey());
119-
}
120-
});
110+
return Iterables.toStream(properties)
111+
.filter(input -> key != null && input != null && key.equals(input.getKey()))
112+
.collect(Collectors.toUnmodifiableSet());
121113
}
122114

123115
public static Iterable<PluginProperty> findPluginProperties(final Pattern keyPattern, @Nullable final Iterable<PluginProperty> properties) {
124116
if (properties == null) {
125117
return null;
126118
}
127119

128-
return Iterables.filter(properties,
129-
new Predicate<PluginProperty>() {
130-
@Override
131-
public boolean apply(final PluginProperty input) {
132-
return input != null && keyPattern.matcher(input.getKey()).matches();
133-
}
134-
});
120+
return Iterables.toStream(properties)
121+
.filter(input -> keyPattern != null && input != null && keyPattern.matcher(input.getKey()).matches())
122+
.collect(Collectors.toUnmodifiableSet());
135123
}
136124

137125
@SuppressFBWarnings("WMI_WRONG_MAP_ITERATOR")
138-
public static List<PluginProperty> buildPluginProperties(@Nullable final Map data) {
139-
final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.builder();
140-
if (data != null) {
141-
for (final Object key : data.keySet()) {
142-
if (key != null) {
143-
final PluginProperty property = new PluginProperty(key.toString(), data.get(key), false);
144-
propertiesBuilder.add(property);
145-
}
146-
}
126+
public static <K, V> List<PluginProperty> buildPluginProperties(@Nullable final Map<K, V> data) {
127+
if (data == null || data.isEmpty()) {
128+
return Collections.emptyList();
147129
}
148-
return propertiesBuilder.build();
130+
return data.entrySet().stream()
131+
.map(entry -> new PluginProperty(entry.getKey().toString(), entry.getValue(), false))
132+
.collect(Collectors.toUnmodifiableList());
149133
}
150134
}

src/main/java/org/killbill/billing/plugin/api/core/PaymentApiWrapper.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.killbill.billing.plugin.api.core;
2020

2121
import java.math.BigDecimal;
22+
import java.util.Collections;
2223
import java.util.List;
2324
import java.util.UUID;
2425

@@ -38,12 +39,10 @@
3839
import org.killbill.billing.payment.plugin.api.PaymentPluginStatus;
3940
import org.killbill.billing.util.callcontext.CallContext;
4041
import org.killbill.billing.util.callcontext.TenantContext;
42+
import org.killbill.commons.utils.Strings;
4143
import org.slf4j.Logger;
4244
import org.slf4j.LoggerFactory;
4345

44-
import com.google.common.base.Splitter;
45-
import com.google.common.collect.ImmutableList;
46-
4746
public class PaymentApiWrapper {
4847

4948
private static final Logger logger = LoggerFactory.getLogger(PaymentApiWrapper.class);
@@ -64,11 +63,11 @@ public List<String> getPaymentControlPluginNames(final UUID kbPaymentId, final T
6463
return null;
6564
}
6665

67-
final Payment payment = osgiKillbillAPI.getPaymentApi().getPayment(kbPaymentId, false, true, ImmutableList.<PluginProperty>of(), context);
66+
final Payment payment = osgiKillbillAPI.getPaymentApi().getPayment(kbPaymentId, false, true, Collections.emptyList(), context);
6867
if (payment.getPaymentAttempts() != null && !payment.getPaymentAttempts().isEmpty()) {
69-
return ImmutableList.<String>copyOf(Splitter.on(",").split(payment.getPaymentAttempts().get(0).getPluginName()));
68+
return Strings.split(payment.getPaymentAttempts().get(0).getPluginName(), ",");
7069
} else {
71-
return ImmutableList.<String>of();
70+
return Collections.emptyList();
7271
}
7372
}
7473

@@ -125,8 +124,8 @@ public PaymentTransaction fixPaymentTransactionState(final Payment payment,
125124
updatedPaymentTransaction.getPaymentInfoPlugin().getStatus(),
126125
paymentPluginStatus);
127126

128-
osgiKillbillAPI.getAdminPaymentApi().fixPaymentTransactionState(payment, updatedPaymentTransaction, transactionStatus, lastSuccessfulPaymentStateName, currentPaymentStateName, ImmutableList.<PluginProperty>of(), context);
129-
final Payment fixedPayment = osgiKillbillAPI.getPaymentApi().getPayment(payment.getId(), true, false, ImmutableList.<PluginProperty>of(), context);
127+
osgiKillbillAPI.getAdminPaymentApi().fixPaymentTransactionState(payment, updatedPaymentTransaction, transactionStatus, lastSuccessfulPaymentStateName, currentPaymentStateName, Collections.emptyList(), context);
128+
final Payment fixedPayment = osgiKillbillAPI.getPaymentApi().getPayment(payment.getId(), true, false, Collections.emptyList(), context);
130129
return filterForTransaction(fixedPayment, updatedPaymentTransaction.getId());
131130
}
132131

0 commit comments

Comments
 (0)