Skip to content

Commit

Permalink
[fix] Remove pulsar-broker-common dependency from pulsar-client (apac…
Browse files Browse the repository at this point in the history
…he#17855)

* [fix] Remove pulsar-broker-common dependency from pulsar-client

* fix newline

* add enforcer rule

* Move packages-core to jdk8 bytecode

* checkstyle

* use variables

* style

* Fix annotation discovery

* Fix kafka module compile
  • Loading branch information
nicoloboschi authored Sep 30, 2022
1 parent 7b26260 commit 74d6305
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 51 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ flexible messaging model and an intuitive client API.</description>
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<license-maven-plugin.version>4.0.rc2</license-maven-plugin.version>
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
<maven-enforcer-plugin.version>3.0.0</maven-enforcer-plugin.version>
<maven-enforcer-plugin.version>3.1.0</maven-enforcer-plugin.version>
<!-- surefire.version is defined in apache parent pom -->
<!-- it is used for surefire, failsafe and surefire-report plugins -->
<!-- do not upgrade surefire.version to 3.0.0-M5 since it runs slowly and breaks tests. -->
Expand All @@ -281,6 +281,7 @@ flexible messaging model and an intuitive client API.</description>
<lightproto-maven-plugin.version>0.4</lightproto-maven-plugin.version>
<dependency-check-maven.version>7.1.0</dependency-check-maven.version>
<roaringbitmap.version>0.9.15</roaringbitmap.version>
<extra-enforcer-rules.version>1.6.1</extra-enforcer-rules.version>

<!-- Used to configure rename.netty.native. Libs -->
<rename.netty.native.libs>rename-netty-native-libs.sh</rename.netty.native.libs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import com.beust.jcommander.Parameters;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.BaseGenerateDocumentation;
import org.apache.pulsar.broker.ServiceConfiguration;
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;
import org.apache.pulsar.common.util.BaseGenerateDocumentation;
import org.apache.pulsar.websocket.service.WebSocketProxyConfiguration;

@Data
Expand Down
27 changes: 27 additions & 0 deletions pulsar-client-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,33 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<executions>
<execution>
<id>enforce-bytecode-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>${pulsar.client.compiler.release}</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>extra-enforcer-rules</artifactId>
<version>${extra-enforcer-rules.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
7 changes: 0 additions & 7 deletions pulsar-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@
<version>${project.parent.version}</version>
</dependency>

<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-broker-common</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bouncy-castle-bc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.beust.jcommander.Parameters;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.BaseGenerateDocumentation;
import org.apache.pulsar.common.util.BaseGenerateDocumentation;

@Data
@Parameters(commandDescription = "Generate documentation automatically.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.broker;
package org.apache.pulsar.common.util;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.Data;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.pulsar.common.configuration.FieldContext;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.lang3.tuple.Pair;

@Data
@Parameters(commandDescription = "Generate documentation automatically.")
Expand Down Expand Up @@ -72,7 +76,7 @@ public boolean run(String[] args) throws Exception {
jcommander.usage();
return false;
}
if (!CollectionUtils.isEmpty(classNames)) {
if (classNames != null) {
for (String className : classNames) {
System.out.println(generateDocumentByClassName(className));
}
Expand All @@ -82,21 +86,6 @@ public boolean run(String[] args) throws Exception {

protected abstract String generateDocumentByClassName(String className) throws Exception;

protected Predicate<Field> isRequired = field -> {
FieldContext fieldContext = field.getAnnotation(FieldContext.class);
return fieldContext.required();
};

protected Predicate<Field> isOptional = field -> {
FieldContext fieldContext = field.getAnnotation(FieldContext.class);
return !fieldContext.deprecated() && !fieldContext.required();
};

protected Predicate<Field> isDeprecated = field -> {
FieldContext fieldContext = field.getAnnotation(FieldContext.class);
return fieldContext.deprecated();
};

protected Predicate<Field> isRequiredApiModel = field -> {
ApiModelProperty modelProperty = field.getAnnotation(ApiModelProperty.class);
return modelProperty.required();
Expand All @@ -107,11 +96,62 @@ public boolean run(String[] args) throws Exception {
return !modelProperty.required();
};

protected void writeDocListByFieldContext(List<Field> fieldList, StringBuilder sb, Object obj) throws Exception {
for (Field field : fieldList) {
FieldContext fieldContext = field.getAnnotation(FieldContext.class);
private Annotation getFieldContextAnnotation(Field field) {
for (Annotation annotation : field.getAnnotations()) {
if (annotation.annotationType().getCanonicalName()
.equals("org.apache.pulsar.common.configuration.FieldContext")) {
return annotation;
}
}
return null;
}

private static class FieldContextWrapper {
private final Object fieldContext;

public FieldContextWrapper(Object fieldContext) {
this.fieldContext = fieldContext;
}

@SneakyThrows
String doc() {
return (String) MethodUtils.invokeMethod(fieldContext, "doc");
}

@SneakyThrows
Class type() {
return (Class) MethodUtils.invokeMethod(fieldContext, "type");
}

@SneakyThrows
boolean required() {
return (boolean) MethodUtils.invokeMethod(fieldContext, "required");
}

@SneakyThrows
boolean deprecated() {
return (boolean) MethodUtils.invokeMethod(fieldContext, "deprecated");
}

@SneakyThrows
boolean dynamic() {
return (boolean) MethodUtils.invokeMethod(fieldContext, "dynamic");
}

@SneakyThrows
String category() {
return (String) MethodUtils.invokeMethod(fieldContext, "category");
}
}

protected void writeDocListByFieldContext(List<Pair<Field, FieldContextWrapper>> fieldList,
StringBuilder sb, Object obj) throws Exception {
for (Pair<Field, FieldContextWrapper> fieldPair : fieldList) {
FieldContextWrapper fieldContext = fieldPair.getValue();
final Field field = fieldPair.getKey();
field.setAccessible(true);


sb.append("### ").append(field.getName()).append("\n");
sb.append(fieldContext.doc().replace(">", "\\>")).append("\n\n");
sb.append("**Type**: `").append(field.getType().getCanonicalName()).append("`\n\n");
Expand All @@ -134,37 +174,46 @@ protected void writeDocListByApiModel(List<Field> fieldList, StringBuilder sb, O
}
}

protected static class CategoryComparator implements Comparator<Field> {
protected static class CategoryComparator implements Comparator<Pair<Field, FieldContextWrapper>>, Serializable {
@Override
public int compare(Field o1, Field o2) {
FieldContext o1Context = o1.getAnnotation(FieldContext.class);
FieldContext o2Context = o2.getAnnotation(FieldContext.class);
public int compare(Pair<Field, FieldContextWrapper> o1, Pair<Field, FieldContextWrapper> o2) {
FieldContextWrapper o1Context = o1.getValue();
FieldContextWrapper o2Context = o2.getValue();

if (o1Context.category().equals(o2Context.category())) {
return o1.getName().compareTo(o2.getName());
return o1.getKey().getName().compareTo(o2.getKey().getName());
}
return o1Context.category().compareTo(o2Context.category());
}
}

protected String prefix = """
!> This page is automatically generated from code files.
If you find something inaccurate, feel free to update `""";
protected String suffix = """
`.
""";
protected String prefix = "\n"
+ "!> This page is automatically generated from code files.\n"
+ "If you find something inaccurate, feel free to update `";
protected String suffix = "\n`.\n";


protected String generateDocByFieldContext(String className, String type, StringBuilder sb) throws Exception {
Class<?> clazz = Class.forName(className);
Object obj = clazz.getDeclaredConstructor().newInstance();
Field[] fields = clazz.getDeclaredFields();
ArrayList<Field> fieldList = new ArrayList<>(Arrays.asList(fields));
List<Pair<Field, FieldContextWrapper>> fieldList = new ArrayList<>(fields.length);
for (Field field : fields) {
final Annotation fieldContextAnnotation = getFieldContextAnnotation(field);

fieldList.removeIf(f -> f.getAnnotation(FieldContext.class) == null);
if (fieldContextAnnotation != null) {
fieldList.add(Pair.of(field, new FieldContextWrapper(fieldContextAnnotation)));
}
}
fieldList.sort(new CategoryComparator());
List<Field> requiredFields = fieldList.stream().filter(isRequired).toList();
List<Field> optionalFields = fieldList.stream().filter(isOptional).toList();
List<Field> deprecatedFields = fieldList.stream().filter(isDeprecated).toList();
List<Pair<Field, FieldContextWrapper>> requiredFields =
fieldList.stream().filter(p -> p.getValue().required()).collect(Collectors.toList());
List<Pair<Field, FieldContextWrapper>> optionalFields =
fieldList.stream().filter(p -> !p.getValue().required() && !p.getValue().deprecated())
.collect(Collectors.toList());
List<Pair<Field, FieldContextWrapper>> deprecatedFields =
fieldList.stream().filter(p -> p.getValue().deprecated()).collect(Collectors.toList());


sb.append("# ").append(type).append("\n");

Expand All @@ -187,8 +236,8 @@ protected String generateDocByApiModelProperty(String className, String type, St

fieldList.removeIf(f -> f.getAnnotation(ApiModelProperty.class) == null);
fieldList.sort(Comparator.comparing(Field::getName));
List<Field> requiredFields = fieldList.stream().filter(isRequiredApiModel).toList();
List<Field> optionalFields = fieldList.stream().filter(isOptionalApiModel).toList();
List<Field> requiredFields = fieldList.stream().filter(isRequiredApiModel).collect(Collectors.toList());
List<Field> optionalFields = fieldList.stream().filter(isOptionalApiModel).collect(Collectors.toList());

sb.append("# ").append(type).append("\n");
sb.append(prefix).append(className).append(suffix);
Expand Down
10 changes: 10 additions & 0 deletions pulsar-io/kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
<version>${kafka.confluent.avroserializer.version}</version>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
</dependency>

</dependencies>

<build>
Expand Down
8 changes: 8 additions & 0 deletions pulsar-package-management/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- This module is distributed with the Pulsar Admin Client -->
<release>${pulsar.client.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.gaul</groupId>
<artifactId>modernizer-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.beust.jcommander.Parameters;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.BaseGenerateDocumentation;
import org.apache.pulsar.common.util.BaseGenerateDocumentation;
import org.apache.pulsar.proxy.server.ProxyConfiguration;

@Data
Expand Down

0 comments on commit 74d6305

Please sign in to comment.