Skip to content

Commit

Permalink
[Modernizer]Add Maven Modernizer plugin in pulsar-common module and f…
Browse files Browse the repository at this point in the history
…ix violation. (apache#12270)

Master Issue: apache#12271

### Motivation
Apply Maven Modernizer plugin to enforce we move away from legacy APIs.

### Modifications
Add Maven Modernizer plugin in pulsar-common module and fix violation.

### Verifying this change

This change is already covered by existing tests, such as *(please describe tests)*.
  • Loading branch information
MarvinCai authored Oct 30, 2021
1 parent 0b34e03 commit 56fee92
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 113 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ flexible messaging model and an intuitive client API.</description>
<surefire.version>3.0.0-M3</surefire.version>
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
<maven-dependency-plugin.version>3.1.2</maven-dependency-plugin.version>
<maven-modernizer-plugin.version>2.3.0</maven-modernizer-plugin.version>
<maven-shade-plugin>3.2.4</maven-shade-plugin>
<maven-antrun-plugin.version>3.0.0</maven-antrun-plugin.version>
<properties-maven-plugin.version>1.0.0</properties-maven-plugin.version>
Expand Down Expand Up @@ -1662,6 +1663,11 @@ flexible messaging model and an intuitive client API.</description>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<version>${maven-modernizer-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
17 changes: 17 additions & 0 deletions pulsar-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@

<build>
<plugins>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
<configuration>
<failOnViolations>true</failOnViolations>
<javaVersion>8</javaVersion>
</configuration>
<executions>
<execution>
<id>modernizer</id>
<goals>
<goal>modernizer</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>com.github.splunk.lightproto</groupId>
<artifactId>lightproto-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package org.apache.pulsar.client.impl.schema;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -134,7 +134,7 @@ public static SchemaInfo encodeKeyValueSchemaInfo(String schemaName,
SchemaInfo keySchemaInfo,
SchemaInfo valueSchemaInfo,
KeyValueEncodingType keyValueEncodingType) {
checkNotNull(keyValueEncodingType, "Null encoding type is provided");
requireNonNull(keyValueEncodingType, "Null encoding type is provided");

if (keySchemaInfo == null || valueSchemaInfo == null) {
// schema is not ready
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
package org.apache.pulsar.common.naming;

import com.google.common.base.Objects;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.UncheckedExecutionException;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -167,7 +168,7 @@ public String toString() {
public boolean equals(Object obj) {
if (obj instanceof NamespaceName) {
NamespaceName other = (NamespaceName) obj;
return Objects.equal(namespace, other.namespace);
return Objects.equals(namespace, other.namespace);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
*/
package org.apache.pulsar.common.naming;

import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.UncheckedExecutionException;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -361,7 +361,7 @@ public String toString() {
public boolean equals(Object obj) {
if (obj instanceof TopicName) {
TopicName other = (TopicName) obj;
return Objects.equal(completeTopicName, other.completeTopicName);
return Objects.equals(completeTopicName, other.completeTopicName);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@


import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
Expand Down Expand Up @@ -62,11 +63,11 @@ public class ServiceURI {
*
* @param uriStr service uri string
* @return a service uri instance
* @throws NullPointerException if {@code uriStr} is null
* @throws NullPointerExceptionFieldParser if {@code uriStr} is null
* @throws IllegalArgumentException if the given string violates RFC&nbsp;2396
*/
public static ServiceURI create(String uriStr) {
checkNotNull(uriStr, "service uri string is null");
requireNonNull(uriStr, "service uri string is null");

if (uriStr.contains("[") && uriStr.contains("]")) {
// deal with ipv6 address
Expand Down Expand Up @@ -116,7 +117,7 @@ public static ServiceURI create(String uriStr) {
* @throws IllegalArgumentException if the given string violates RFC&nbsp;2396
*/
public static ServiceURI create(URI uri) {
checkNotNull(uri, "service uri instance is null");
requireNonNull(uri, "service uri instance is null");

String serviceName;
final String[] serviceInfos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package org.apache.pulsar.common.policies.data;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Objects;
import org.apache.pulsar.common.util.ObjectMapperFactory;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;

public class EnsemblePlacementPolicyConfig {
public static final String ENSEMBLE_PLACEMENT_POLICY_CONFIG = "EnsemblePlacementPolicyConfig";
Expand Down Expand Up @@ -53,16 +53,16 @@ public Map<String, Object> getProperties() {

@Override
public int hashCode() {
return Objects.hashCode(policyClass != null ? policyClass.getName() : "", properties);
return Objects.hash(policyClass != null ? policyClass.getName() : "", properties);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof EnsemblePlacementPolicyConfig) {
EnsemblePlacementPolicyConfig other = (EnsemblePlacementPolicyConfig) obj;
return Objects.equal(this.policyClass == null ? null : this.policyClass.getName(),
return Objects.equals(this.policyClass == null ? null : this.policyClass.getName(),
other.policyClass == null ? null : other.policyClass.getName())
&& Objects.equal(this.properties, other.properties);
&& Objects.equals(this.properties, other.properties);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.apache.pulsar.common.policies.data;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -55,8 +55,8 @@ public class PersistentOfflineTopicStats {
public PersistentOfflineTopicStats(String topicName, String brokerName) {
this.brokerName = brokerName;
this.topicName = topicName;
this.dataLedgerDetails = Lists.newArrayList();
this.cursorDetails = Maps.newHashMap();
this.dataLedgerDetails = new ArrayList<>();
this.cursorDetails = new HashMap<>();
this.statGeneratedAt = new Date(System.currentTimeMillis());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/
package org.apache.pulsar.common.policies.data;

import com.google.common.collect.Maps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
Expand All @@ -46,7 +45,7 @@
public class TopicPolicies {

@Builder.Default
private Map<String, BacklogQuotaImpl> backLogQuotaMap = Maps.newHashMap();
private Map<String, BacklogQuotaImpl> backLogQuotaMap = new HashMap<>();
@Builder.Default
private List<SubType> subscriptionTypesEnabled = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@
*/
package org.apache.pulsar.common.policies.impl;

import com.google.common.base.Objects;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.pulsar.common.naming.NamespaceName;
import org.apache.pulsar.common.policies.AutoFailoverPolicy;
import org.apache.pulsar.common.policies.NamespaceIsolationPolicy;
import org.apache.pulsar.common.policies.data.BrokerStatus;
import org.apache.pulsar.common.policies.data.NamespaceIsolationData;
import org.apache.pulsar.common.policies.data.NamespaceIsolationDataImpl;

/**
* Implementation of the namespace isolation policy.
Expand Down Expand Up @@ -122,17 +121,17 @@ public boolean isSecondaryBroker(String broker) {

@Override
public int hashCode() {
return Objects.hashCode(namespaces, primary, secondary,
return Objects.hash(namespaces, primary, secondary,
autoFailoverPolicy);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof NamespaceIsolationPolicyImpl) {
NamespaceIsolationPolicyImpl other = (NamespaceIsolationPolicyImpl) obj;
return Objects.equal(this.namespaces, other.namespaces) && Objects.equal(this.primary, other.primary)
&& Objects.equal(this.secondary, other.secondary)
&& Objects.equal(this.autoFailoverPolicy, other.autoFailoverPolicy);
return Objects.equals(this.namespaces, other.namespaces) && Objects.equals(this.primary, other.primary)
&& Objects.equals(this.secondary, other.secondary)
&& Objects.equals(this.autoFailoverPolicy, other.autoFailoverPolicy);
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/
package org.apache.pulsar.common.stats;

import com.google.common.collect.Maps;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -44,7 +43,7 @@ public class JvmDefaultGCMetricsLogger implements JvmGCMetricsLogger {
private static Method getTotalSafepointTimeHandle;
private static Method getSafepointCountHandle;

private Map<String, GCMetrics> gcMetricsMap = Maps.newHashMap();
private Map<String, GCMetrics> gcMetricsMap = new HashMap<>();

static {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
package org.apache.pulsar.common.util;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.databind.util.EnumResolver;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -83,7 +84,7 @@ public final class FieldParser {
@SuppressWarnings("unchecked")
public static <T> T convert(Object from, Class<T> to) {

checkNotNull(to);
requireNonNull(to);
if (from == null) {
return null;
}
Expand Down Expand Up @@ -163,7 +164,7 @@ public static <T> void update(Map<String, String> properties, T obj) throws Ille
* @return
*/
public static Object value(String strValue, Field field) {
checkNotNull(field);
requireNonNull(field);
// if field is not primitive type
Type fieldType = field.getGenericType();
if (fieldType instanceof ParameterizedType) {
Expand Down Expand Up @@ -205,14 +206,14 @@ public static Object value(String strValue, Field field) {
*/
public static <T> void setEmptyValue(String strValue, Field field, T obj)
throws IllegalArgumentException, IllegalAccessException {
checkNotNull(field);
requireNonNull(field);
// if field is not primitive type
Type fieldType = field.getGenericType();
if (fieldType instanceof ParameterizedType) {
if (field.getType().equals(List.class)) {
field.set(obj, Lists.newArrayList());
field.set(obj, new ArrayList<>());
} else if (field.getType().equals(Set.class)) {
field.set(obj, Sets.newHashSet());
field.set(obj, new HashSet<>());
} else if (field.getType().equals(Optional.class)) {
field.set(obj, Optional.empty());
} else {
Expand Down Expand Up @@ -349,7 +350,7 @@ private static <K, V> Map<K, V> stringToMap(String strValue, Class<K> keyType, C
}

private static String trim(String val) {
checkNotNull(val);
requireNonNull(val);
return val.trim();
}

Expand Down Expand Up @@ -389,4 +390,4 @@ public static Boolean stringToBoolean(String value) {

// implement more converter methods here.

}
}
Loading

0 comments on commit 56fee92

Please sign in to comment.