Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base plugin 84 remove guava dependencies #91

Merged
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
5.1.0
Make java.net.http.HttpClient.Builder overridable
Remove all Guava classes and dependency

4.2.15
Update killbill-oss-parent to 0.144.68

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Convenience library to help write Kill Bill plugins.
| 4.1.y | 0.22.z |
| 4.2.y | 0.22.z |
| 5.0.y | 0.24.z |
| 5.1.y | 0.24.z |

We've upgraded numerous dependencies in 4.2.x (required for Java 11 support).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a note like (or something along these lines):

Guava has been removed as a dependency in 5.1.x, native JDK alternatives should be used instead

Otherwise, if a user upgrades without looking at the code changes, they might get confused why the compilation errors if they implicitly rely on Guava in their plugins 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this in NEWS commit.


Expand Down
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<parent>
<groupId>org.kill-bill.billing</groupId>
<artifactId>killbill-oss-parent</artifactId>
<version>0.146.10</version>
<version>0.146.11</version>
</parent>
<groupId>org.kill-bill.billing.plugin.java</groupId>
<artifactId>killbill-base-plugin</artifactId>
<version>5.0.2-SNAPSHOT</version>
<version>5.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Kill Bill base OSGI plugin</name>
<description>Kill Bill base OSGI plugin</description>
Expand Down Expand Up @@ -79,10 +79,6 @@
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
Expand Down Expand Up @@ -240,6 +236,11 @@
<artifactId>killbill-embeddeddb-postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kill-bill.commons</groupId>
<artifactId>killbill-utils</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.kill-bill.testing</groupId>
<artifactId>testing-mysql-server</artifactId>
Expand Down
64 changes: 23 additions & 41 deletions src/main/java/org/killbill/billing/plugin/api/PluginApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.stream.Collectors;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
Expand Down Expand Up @@ -70,12 +73,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

public abstract class PluginApi {

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

protected static final Iterable<PluginProperty> PLUGIN_PROPERTIES = ImmutableList.<PluginProperty>of();
protected static final Iterable<PluginProperty> PLUGIN_PROPERTIES = Collections.emptyList();

protected final OSGIKillbillAPI killbillAPI;
protected final OSGIConfigPropertiesService configProperties;
Expand Down Expand Up @@ -221,31 +218,20 @@ protected Long getSubscriptionEventRecordId(final UUID subscriptionEventId, fina

protected Iterable<SubscriptionEvent> getBlockingHistory(final UUID accountId, final TenantContext context) throws OSGIServiceNotAvailable {
final List<SubscriptionBundle> bundles = getSubscriptionBundlesForAccount(accountId, context);

// Find all subscription events for that account
final Iterable<SubscriptionEvent> subscriptionEvents = Iterables.<SubscriptionEvent>concat(Iterables.<SubscriptionBundle, List<SubscriptionEvent>>transform(bundles,
new Function<SubscriptionBundle, List<SubscriptionEvent>>() {
@Override
public List<SubscriptionEvent> apply(final SubscriptionBundle bundle) {
return bundle == null ? ImmutableList.<SubscriptionEvent>of() : bundle.getTimeline().getSubscriptionEvents();
}
}
));

// Filter all service state changes
return Iterables.<SubscriptionEvent>filter(subscriptionEvents,
new Predicate<SubscriptionEvent>() {
@Override
public boolean apply(final SubscriptionEvent event) {
return event != null &&
event.getSubscriptionEventType() != null &&
// We want events coming from the blocking states table...
ObjectType.BLOCKING_STATES.equals(event.getSubscriptionEventType().getObjectType()) &&
// ...that are for any service but entitlement
!ENTITLEMENT_SERVICE_NAME.equals(event.getServiceName());
}
}
);
if (bundles != null) {
// Find all subscription events for that account
return bundles.stream()
.map(subscriptionBundle -> subscriptionBundle.getTimeline().getSubscriptionEvents())
.flatMap(Collection::stream)
.filter(event -> event != null &&
event.getSubscriptionEventType() != null &&
// We want events coming from the blocking states table...
ObjectType.BLOCKING_STATES.equals(event.getSubscriptionEventType().getObjectType()) &&
// ...that are for any service but entitlement
!ENTITLEMENT_SERVICE_NAME.equals(event.getServiceName()))
.collect(Collectors.toUnmodifiableList());
}
return Collections.emptyList();
}

//
Expand Down Expand Up @@ -321,7 +307,7 @@ protected Plan getPlanFromInvoiceItem(final InvoiceItem invoiceItem, final Tenan
try {
final VersionedCatalog catalog = getCatalog(context);
// getCatalogEffectiveDate was introduced in 0.21.x
final DateTime catalogEffectiveDate = MoreObjects.firstNonNull(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
final DateTime catalogEffectiveDate = Objects.requireNonNullElse(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
return catalog.getVersion(catalogEffectiveDate.toDate()).findPlan(invoiceItem.getPlanName());
} catch (final CatalogApiException e) {
logger.info("Unable to retrieve plan for invoice item {}", invoiceItem.getId(), e);
Expand All @@ -333,7 +319,7 @@ protected PlanPhase getPlanPhaseFromInvoiceItem(final InvoiceItem invoiceItem, f
try {
final VersionedCatalog catalog = getCatalog(context);
// getCatalogEffectiveDate was introduced in 0.21.x
final DateTime catalogEffectiveDate = MoreObjects.firstNonNull(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
final DateTime catalogEffectiveDate = Objects.requireNonNullElse(invoiceItem.getCatalogEffectiveDate(), invoiceItem.getCreatedDate());
return catalog.getVersion(catalogEffectiveDate.toDate()).findPhase(invoiceItem.getPhaseName());
} catch (final CatalogApiException e) {
logger.info("Unable to retrieve phase for invoice item {}", invoiceItem.getId(), e);
Expand Down Expand Up @@ -451,13 +437,9 @@ protected PaymentTransaction getPaymentTransaction(final UUID kbPaymentId, final
}

protected PaymentTransaction getPaymentTransaction(final UUID kbTransactionId, final Payment payment) throws OSGIServiceNotAvailable {
return Iterables.<PaymentTransaction>find(payment.getTransactions(),
new Predicate<PaymentTransaction>() {
@Override
public boolean apply(final PaymentTransaction input) {
return input != null && kbTransactionId.equals(input.getId());
}
});
return payment.getTransactions().stream()
.filter(input -> input != null && kbTransactionId.equals(input.getId()))
.findFirst().get();
}

protected Long getPaymentRecordId(final UUID paymentId, final TenantContext context) throws OSGIServiceNotAvailable {
Expand Down
76 changes: 30 additions & 46 deletions src/main/java/org/killbill/billing/plugin/api/PluginProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,41 @@

package org.killbill.billing.plugin.api;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

import org.killbill.billing.payment.api.PluginProperty;
import org.killbill.billing.plugin.util.http.UTF8UrlDecoder;
import org.killbill.commons.utils.Strings;
import org.killbill.commons.utils.collect.Iterables;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public abstract class PluginProperties {

// Last one has precedence
@SafeVarargs
public static Iterable<PluginProperty> merge(final Iterable<PluginProperty>... propertiesLists) {
return buildPluginProperties(toMap(propertiesLists));
}

// Last one has precedence
public static Iterable<PluginProperty> merge(@Nullable final Map data, final Iterable<PluginProperty>... propertiesLists) {
@SafeVarargs
public static <K, V> Iterable<PluginProperty> merge(@Nullable final Map<K, V> data, final Iterable<PluginProperty>... propertiesLists) {
return merge(buildPluginProperties(data), merge(propertiesLists));
}

// Last one has precedence
@SafeVarargs
public static Map<String, Object> toMap(final Iterable<PluginProperty>... propertiesLists) {
final Map<String, Object> mergedProperties = new HashMap<String, Object>();
final Map<String, Object> mergedProperties = new HashMap<>();
for (final Iterable<PluginProperty> propertiesList : propertiesLists) {
if (propertiesList == null) {
continue;
Expand All @@ -65,14 +67,12 @@ public static Map<String, Object> toMap(final Iterable<PluginProperty>... proper
}

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

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

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

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

return Iterables.filter(properties,
new Predicate<PluginProperty>() {
@Override
public boolean apply(final PluginProperty input) {
return key != null && key.equals(input.getKey());
}
});
return Iterables.toStream(properties)
.filter(input -> key != null && input != null && key.equals(input.getKey()))
.collect(Collectors.toUnmodifiableSet());
}

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

return Iterables.filter(properties,
new Predicate<PluginProperty>() {
@Override
public boolean apply(final PluginProperty input) {
return input != null && keyPattern.matcher(input.getKey()).matches();
}
});
return Iterables.toStream(properties)
.filter(input -> keyPattern != null && input != null && keyPattern.matcher(input.getKey()).matches())
.collect(Collectors.toUnmodifiableSet());
}

@SuppressFBWarnings("WMI_WRONG_MAP_ITERATOR")
public static List<PluginProperty> buildPluginProperties(@Nullable final Map data) {
final ImmutableList.Builder<PluginProperty> propertiesBuilder = ImmutableList.builder();
if (data != null) {
for (final Object key : data.keySet()) {
if (key != null) {
final PluginProperty property = new PluginProperty(key.toString(), data.get(key), false);
propertiesBuilder.add(property);
}
}
public static <K, V> List<PluginProperty> buildPluginProperties(@Nullable final Map<K, V> data) {
if (data == null || data.isEmpty()) {
return Collections.emptyList();
}
return propertiesBuilder.build();
return data.entrySet().stream()
.map(entry -> new PluginProperty(entry.getKey().toString(), entry.getValue(), false))
.collect(Collectors.toUnmodifiableList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.killbill.billing.plugin.api.core;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

Expand All @@ -38,12 +39,10 @@
import org.killbill.billing.payment.plugin.api.PaymentPluginStatus;
import org.killbill.billing.util.callcontext.CallContext;
import org.killbill.billing.util.callcontext.TenantContext;
import org.killbill.commons.utils.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;

public class PaymentApiWrapper {

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

final Payment payment = osgiKillbillAPI.getPaymentApi().getPayment(kbPaymentId, false, true, ImmutableList.<PluginProperty>of(), context);
final Payment payment = osgiKillbillAPI.getPaymentApi().getPayment(kbPaymentId, false, true, Collections.emptyList(), context);
if (payment.getPaymentAttempts() != null && !payment.getPaymentAttempts().isEmpty()) {
return ImmutableList.<String>copyOf(Splitter.on(",").split(payment.getPaymentAttempts().get(0).getPluginName()));
return Strings.split(payment.getPaymentAttempts().get(0).getPluginName(), ",");
} else {
return ImmutableList.<String>of();
return Collections.emptyList();
}
}

Expand Down Expand Up @@ -125,8 +124,8 @@ public PaymentTransaction fixPaymentTransactionState(final Payment payment,
updatedPaymentTransaction.getPaymentInfoPlugin().getStatus(),
paymentPluginStatus);

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

Expand Down
Loading