From 247a3ad737524c9961d33994b7d2b7f4b6897a3a Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 11:48:39 +0800 Subject: [PATCH 1/6] [fix][cli] Dedicated docs tools Signed-off-by: tison --- distribution/server/pom.xml | 6 ++ pom.xml | 4 +- pulsar-broker/pom.xml | 2 + .../org/apache/pulsar/utils/CmdUtility.java | 86 ------------------- pulsar-client-tools/pom.xml | 1 + pulsar-client/pom.xml | 1 + .../impl/conf/CmdGenerateDocumentation.java | 51 ----------- pulsar-common/pom.xml | 1 + pulsar-docs-tools/pom.xml | 62 +++++++++++++ .../tools}/BaseGenerateDocumentation.java | 4 +- .../docs/tools}/CmdGenerateDocumentation.java | 20 +++-- .../pulsar/docs/tools}/package-info.java | 2 +- .../tools/CmdGenerateDocumentationTest.java | 18 ++-- pulsar-functions/worker/pom.xml | 1 + pulsar-proxy/pom.xml | 6 ++ .../apache/pulsar/proxy/stats/ProxyStats.java | 2 - .../proxy/util/CmdGenerateDocumentation.java | 45 ---------- .../org/apache/pulsar/proxy/util/CmdTest.java | 58 ------------- pulsar-websocket/pom.xml | 1 + 19 files changed, 112 insertions(+), 259 deletions(-) delete mode 100644 pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdUtility.java delete mode 100644 pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/CmdGenerateDocumentation.java create mode 100644 pulsar-docs-tools/pom.xml rename {pulsar-common/src/main/java/org/apache/pulsar/common/util => pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools}/BaseGenerateDocumentation.java (99%) rename {pulsar-broker/src/main/java/org/apache/pulsar/utils => pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools}/CmdGenerateDocumentation.java (67%) rename {pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util => pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools}/package-info.java (95%) rename pulsar-broker/src/test/java/org/apache/pulsar/utils/CmdTest.java => pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java (83%) delete mode 100644 pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java delete mode 100644 pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdTest.java diff --git a/distribution/server/pom.xml b/distribution/server/pom.xml index 5f946f888aec8..2702bace54e6a 100644 --- a/distribution/server/pom.xml +++ b/distribution/server/pom.xml @@ -40,6 +40,12 @@ ${project.version} + + ${project.groupId} + pulsar-docs-tools + ${project.version} + + ${project.groupId} pulsar-proxy diff --git a/pom.xml b/pom.xml index 254609a6f07cb..586576710f5b7 100644 --- a/pom.xml +++ b/pom.xml @@ -869,14 +869,12 @@ flexible messaging model and an intuitive client API. io.swagger swagger-core ${swagger.version} - provided io.swagger swagger-annotations ${swagger.version} - provided @@ -2221,6 +2219,7 @@ flexible messaging model and an intuitive client API. pulsar-client-tools-customcommand-example pulsar-client-tools-test pulsar-client-all + pulsar-docs-tools pulsar-websocket pulsar-proxy pulsar-testclient @@ -2283,6 +2282,7 @@ flexible messaging model and an intuitive client API. pulsar-client-tools pulsar-client-tools-customcommand-example pulsar-client-tools-test + pulsar-docs-tools pulsar-websocket pulsar-proxy pulsar-testclient diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml index e084d70c79ad6..7bb778037dee6 100644 --- a/pulsar-broker/pom.xml +++ b/pulsar-broker/pom.xml @@ -291,6 +291,7 @@ io.swagger swagger-annotations + provided @@ -316,6 +317,7 @@ io.swagger swagger-core + provided diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdUtility.java b/pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdUtility.java deleted file mode 100644 index f0f88562953e5..0000000000000 --- a/pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdUtility.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.pulsar.utils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Writer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CmdUtility { - private static final Logger LOG = LoggerFactory.getLogger(CmdUtility.class); - private static final Charset UTF_8 = StandardCharsets.UTF_8; - - /** - * Executes the specified string command in a separate process. STDOUT and STDERR output will be buffered to the - * given writer ( {@link Writer}) argument. - * - * @param writer - * stdout and stderr output - * @param command - * a specified system command - * @return exitValue 0: success, Non-zero: failure - * @throws IOException - */ - public static int exec(Writer writer, String... command) throws IOException { - if (LOG.isDebugEnabled()) { - StringBuilder sb = new StringBuilder(); - for (String str : command) { - sb.append(str).append(' '); - } - LOG.debug("command={}", sb); - } - - ProcessBuilder pb = new ProcessBuilder(command); - pb.redirectErrorStream(true); - Process proc = null; - BufferedReader reader = null; - try { - proc = pb.start(); - reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), UTF_8)); - String line = null; - while ((line = reader.readLine()) != null) { - if (writer != null) { - writer.write(line); - writer.write('\n'); - } - } - LOG.debug("sending the command to the host"); - int exitValue = proc.waitFor(); - if (LOG.isDebugEnabled()) { - LOG.debug("command exit value={}", exitValue); - } - return exitValue; - } catch (InterruptedException e) { - throw new RuntimeException(e); - } finally { - if (reader != null) { - reader.close(); - } - if (proc != null) { - proc.destroy(); - } - } - } - -} diff --git a/pulsar-client-tools/pom.xml b/pulsar-client-tools/pom.xml index 025189b7bbfa5..16a30f8d63040 100644 --- a/pulsar-client-tools/pom.xml +++ b/pulsar-client-tools/pom.xml @@ -107,6 +107,7 @@ io.swagger swagger-core + provided diff --git a/pulsar-client/pom.xml b/pulsar-client/pom.xml index db2297100eeb2..0e45e73636612 100644 --- a/pulsar-client/pom.xml +++ b/pulsar-client/pom.xml @@ -76,6 +76,7 @@ io.swagger swagger-annotations + provided diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/CmdGenerateDocumentation.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/CmdGenerateDocumentation.java deleted file mode 100644 index ae6210b978edc..0000000000000 --- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/CmdGenerateDocumentation.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.pulsar.client.impl.conf; - -import com.beust.jcommander.Parameters; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.pulsar.common.util.BaseGenerateDocumentation; - -@Data -@Parameters(commandDescription = "Generate documentation automatically.") -@Slf4j -public class CmdGenerateDocumentation extends BaseGenerateDocumentation { - - @Override - public String generateDocumentByClassName(String className) throws Exception { - StringBuilder sb = new StringBuilder(); - if (ClientConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Client", sb); - } else if (ProducerConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Producer", sb); - } else if (ConsumerConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Consumer", sb); - } else if (ReaderConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Reader", sb); - } - - return "Class [" + className + "] not found"; - } - - public static void main(String[] args) throws Exception { - CmdGenerateDocumentation generateDocumentation = new CmdGenerateDocumentation(); - generateDocumentation.run(args); - } -} diff --git a/pulsar-common/pom.xml b/pulsar-common/pom.xml index cfc9cba7ede7f..6ffaeb0220f31 100644 --- a/pulsar-common/pom.xml +++ b/pulsar-common/pom.xml @@ -50,6 +50,7 @@ io.swagger swagger-annotations + provided diff --git a/pulsar-docs-tools/pom.xml b/pulsar-docs-tools/pom.xml new file mode 100644 index 0000000000000..db9bf1bb3cbd3 --- /dev/null +++ b/pulsar-docs-tools/pom.xml @@ -0,0 +1,62 @@ + + + + 4.0.0 + + + org.apache.pulsar + pulsar + 3.1.0-SNAPSHOT + + + pulsar-docs-tools + Pulsar Documentation Generators + + + + ${project.groupId} + pulsar-broker + ${project.version} + + + ${project.groupId} + pulsar-client-original + ${project.version} + + + ${project.groupId} + pulsar-proxy + ${project.version} + + + io.swagger + swagger-annotations + + + io.swagger + swagger-core + + + + diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/util/BaseGenerateDocumentation.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java similarity index 99% rename from pulsar-common/src/main/java/org/apache/pulsar/common/util/BaseGenerateDocumentation.java rename to pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java index b88ed197e8f2e..4a3c07fbe3b70 100644 --- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/BaseGenerateDocumentation.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.common.util; +package org.apache.pulsar.docs.tools; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; @@ -31,14 +31,12 @@ 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.lang3.StringUtils; import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.lang3.tuple.Pair; -@Data @Parameters(commandDescription = "Generate documentation automatically.") @Slf4j public abstract class BaseGenerateDocumentation { diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdGenerateDocumentation.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java similarity index 67% rename from pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdGenerateDocumentation.java rename to pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java index 4a8639c060603..c8ec8432c9a27 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/utils/CmdGenerateDocumentation.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java @@ -16,17 +16,19 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.utils; + +package org.apache.pulsar.docs.tools; import com.beust.jcommander.Parameters; -import lombok.Data; import lombok.extern.slf4j.Slf4j; 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.client.impl.conf.ConsumerConfigurationData; +import org.apache.pulsar.client.impl.conf.ProducerConfigurationData; +import org.apache.pulsar.client.impl.conf.ReaderConfigurationData; +import org.apache.pulsar.proxy.server.ProxyConfiguration; import org.apache.pulsar.websocket.service.WebSocketProxyConfiguration; -@Data @Parameters(commandDescription = "Generate documentation automatically.") @Slf4j public class CmdGenerateDocumentation extends BaseGenerateDocumentation { @@ -34,12 +36,20 @@ public class CmdGenerateDocumentation extends BaseGenerateDocumentation { @Override public String generateDocumentByClassName(String className) throws Exception { StringBuilder sb = new StringBuilder(); - if (ServiceConfiguration.class.getName().equals(className)) { + if (ProxyConfiguration.class.getName().equals(className)) { + return generateDocByFieldContext(className, "Pulsar proxy", sb); + } else if (ServiceConfiguration.class.getName().equals(className)) { return generateDocByFieldContext(className, "Broker", sb); } else if (ClientConfigurationData.class.getName().equals(className)) { return generateDocByApiModelProperty(className, "Client", sb); } else if (WebSocketProxyConfiguration.class.getName().equals(className)) { return generateDocByFieldContext(className, "WebSocket", sb); + } else if (ProducerConfigurationData.class.getName().equals(className)) { + return generateDocByApiModelProperty(className, "Producer", sb); + } else if (ConsumerConfigurationData.class.getName().equals(className)) { + return generateDocByApiModelProperty(className, "Consumer", sb); + } else if (ReaderConfigurationData.class.getName().equals(className)) { + return generateDocByApiModelProperty(className, "Reader", sb); } return "Class [" + className + "] not found"; diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java similarity index 95% rename from pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java rename to pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java index 1501a16f55813..ca5afd4d67fa2 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java @@ -16,4 +16,4 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.proxy.util; \ No newline at end of file +package org.apache.pulsar.docs.tools; \ No newline at end of file diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/utils/CmdTest.java b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java similarity index 83% rename from pulsar-broker/src/test/java/org/apache/pulsar/utils/CmdTest.java rename to pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java index a571a1cd0c92d..fc4c8b015219d 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/utils/CmdTest.java +++ b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java @@ -16,17 +16,22 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.utils; -import static org.testng.Assert.assertTrue; +package org.apache.pulsar.docs.tools; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.lang.reflect.Field; import org.apache.pulsar.common.configuration.FieldContext; import org.testng.annotations.Test; +import static org.testng.Assert.assertTrue; -@Test(groups = "utils") -public class CmdTest { +public class CmdGenerateDocumentationTest { + @Test + public void cmdParserProxyConfigurationTest() throws Exception { + String value = generateDoc("org.apache.pulsar.proxy.server.ProxyConfiguration"); + assertTrue(value.contains("Pulsar proxy")); + } @Test public void cmdParserTest() throws Exception { @@ -43,14 +48,14 @@ public void cmdParserClientTest() throws Exception { generateDoc("org.apache.pulsar.client.impl.conf.ClientConfigurationData"); } - private void generateDoc(String clazz) throws Exception { + private String generateDoc(String clazz) throws Exception { PrintStream oldStream = System.out; try (ByteArrayOutputStream baoStream = new ByteArrayOutputStream(2048); PrintStream cacheStream = new PrintStream(baoStream);) { System.setOut(cacheStream); CmdGenerateDocumentation.main(("-c " + clazz).split(" ")); String message = baoStream.toString(); - Class cls = Class.forName(clazz); + Class cls = Class.forName(clazz); Field[] fields = cls.getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); @@ -60,6 +65,7 @@ private void generateDoc(String clazz) throws Exception { } assertTrue(message.indexOf(field.getName()) > 0); } + return message; } finally { System.setOut(oldStream); } diff --git a/pulsar-functions/worker/pom.xml b/pulsar-functions/worker/pom.xml index da7c83689c1c9..c99fb1871da5e 100644 --- a/pulsar-functions/worker/pom.xml +++ b/pulsar-functions/worker/pom.xml @@ -132,6 +132,7 @@ io.swagger swagger-core + provided com.fasterxml.jackson.core diff --git a/pulsar-proxy/pom.xml b/pulsar-proxy/pom.xml index a607b9e835f8e..0bfee6da5e6c7 100644 --- a/pulsar-proxy/pom.xml +++ b/pulsar-proxy/pom.xml @@ -60,6 +60,12 @@ commons-lang3 + + io.swagger + swagger-annotations + provided + + org.eclipse.jetty jetty-server diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/stats/ProxyStats.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/stats/ProxyStats.java index 27e61c90e9e26..afa2e12dabb4f 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/stats/ProxyStats.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/stats/ProxyStats.java @@ -38,8 +38,6 @@ import javax.ws.rs.core.Response.Status; import org.apache.pulsar.proxy.server.ProxyService; - - @Path("/") @Api(value = "/proxy-stats", description = "Stats for proxy", tags = "proxy-stats", hidden = true) @Produces(MediaType.APPLICATION_JSON) diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java deleted file mode 100644 index a1c7e30a25ed6..0000000000000 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.pulsar.proxy.util; - -import com.beust.jcommander.Parameters; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.pulsar.common.util.BaseGenerateDocumentation; -import org.apache.pulsar.proxy.server.ProxyConfiguration; - -@Data -@Parameters(commandDescription = "Generate documentation automatically.") -@Slf4j -public class CmdGenerateDocumentation extends BaseGenerateDocumentation { - - @Override - public String generateDocumentByClassName(String className) throws Exception { - StringBuilder sb = new StringBuilder(); - if (ProxyConfiguration.class.getName().equals(className)) { - return generateDocByFieldContext(className, "Pulsar proxy", sb); - } - return "Class [" + className + "] not found"; - } - - public static void main(String[] args) throws Exception { - CmdGenerateDocumentation generateDocumentation = new CmdGenerateDocumentation(); - generateDocumentation.run(args); - } -} diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdTest.java deleted file mode 100644 index 59e1a43310d67..0000000000000 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.pulsar.proxy.util; - -import static org.testng.Assert.assertTrue; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.lang.reflect.Field; -import org.apache.pulsar.common.configuration.FieldContext; -import org.testng.annotations.Test; - -public class CmdTest { - - @Test - public void cmdParserProxyConfigurationTest() throws Exception { - String value = generateDoc("org.apache.pulsar.proxy.server.ProxyConfiguration"); - assertTrue(value.contains("Pulsar proxy")); - } - - private String generateDoc(String clazz) throws Exception { - PrintStream oldStream = System.out; - try (ByteArrayOutputStream baoStream = new ByteArrayOutputStream(2048); - PrintStream cacheStream = new PrintStream(baoStream);) { - System.setOut(cacheStream); - CmdGenerateDocumentation.main(("-c " + clazz).split(" ")); - String message = baoStream.toString(); - Class cls = Class.forName(clazz); - Field[] fields = cls.getDeclaredFields(); - for (Field field : fields) { - field.setAccessible(true); - FieldContext fieldContext = field.getAnnotation(FieldContext.class); - if (fieldContext == null) { - continue; - } - assertTrue(message.indexOf(field.getName()) > 0); - } - return message; - } finally { - System.setOut(oldStream); - } - } -} diff --git a/pulsar-websocket/pom.xml b/pulsar-websocket/pom.xml index f742c286f0b68..134a071347223 100644 --- a/pulsar-websocket/pom.xml +++ b/pulsar-websocket/pom.xml @@ -80,6 +80,7 @@ io.swagger swagger-core + provided From d955d64f469d787b631a48cb2ff8f7bc056ce235 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 13:46:01 +0800 Subject: [PATCH 2/6] restore licenses Signed-off-by: tison --- distribution/server/src/assemble/LICENSE.bin.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/distribution/server/src/assemble/LICENSE.bin.txt b/distribution/server/src/assemble/LICENSE.bin.txt index be97087edb75a..a541175f044d2 100644 --- a/distribution/server/src/assemble/LICENSE.bin.txt +++ b/distribution/server/src/assemble/LICENSE.bin.txt @@ -272,6 +272,8 @@ The Apache Software License, Version 2.0 * Netty Reactive Streams -- com.typesafe.netty-netty-reactive-streams-2.0.6.jar * Swagger - io.swagger-swagger-annotations-1.6.2.jar + - io.swagger-swagger-core-1.6.2.jar + - io.swagger-swagger-models-1.6.2.jar * DataSketches - com.yahoo.datasketches-memory-0.8.3.jar - com.yahoo.datasketches-sketches-core-0.8.3.jar From a31909618dd273a1cc2a314c823615ef1a5faad8 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 14:48:03 +0800 Subject: [PATCH 3/6] move CmdGenerateDocumentation to pulsar-proxy for break cycle deps Signed-off-by: tison --- pulsar-docs-tools/pom.xml | 19 ++++----------- .../docs/tools/BaseGenerateDocumentation.java | 10 ++++---- pulsar-proxy/pom.xml | 12 ++++++++++ .../proxy/util}/CmdGenerateDocumentation.java | 24 +++++++++---------- .../util}/CmdGenerateDocumentationTest.java | 2 +- 5 files changed, 34 insertions(+), 33 deletions(-) rename {pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools => pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util}/CmdGenerateDocumentation.java (89%) rename {pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools => pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util}/CmdGenerateDocumentationTest.java (98%) diff --git a/pulsar-docs-tools/pom.xml b/pulsar-docs-tools/pom.xml index db9bf1bb3cbd3..9074ad0d6c591 100644 --- a/pulsar-docs-tools/pom.xml +++ b/pulsar-docs-tools/pom.xml @@ -34,21 +34,6 @@ Pulsar Documentation Generators - - ${project.groupId} - pulsar-broker - ${project.version} - - - ${project.groupId} - pulsar-client-original - ${project.version} - - - ${project.groupId} - pulsar-proxy - ${project.version} - io.swagger swagger-annotations @@ -57,6 +42,10 @@ io.swagger swagger-core + + com.beust + jcommander + diff --git a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java index 4a3c07fbe3b70..db6178a7fda4d 100644 --- a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/BaseGenerateDocumentation.java @@ -20,7 +20,6 @@ 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; @@ -37,7 +36,6 @@ import org.apache.commons.lang3.reflect.MethodUtils; import org.apache.commons.lang3.tuple.Pair; -@Parameters(commandDescription = "Generate documentation automatically.") @Slf4j public abstract class BaseGenerateDocumentation { @@ -184,7 +182,9 @@ public int compare(Pair o1, Pair clazz = Class.forName(className); Object obj = clazz.getDeclaredConstructor().newInstance(); Field[] fields = clazz.getDeclaredFields(); @@ -216,7 +216,9 @@ protected String generateDocByFieldContext(String className, String type, String return sb.toString(); } - protected String generateDocByApiModelProperty(String className, String type, StringBuilder sb) throws Exception { + protected String generateDocByApiModelProperty(String className, String type) throws Exception { + final StringBuilder sb = new StringBuilder(); + Class clazz = Class.forName(className); Object obj = clazz.getDeclaredConstructor().newInstance(); Field[] fields = clazz.getDeclaredFields(); diff --git a/pulsar-proxy/pom.xml b/pulsar-proxy/pom.xml index 0bfee6da5e6c7..c1512c58dedb6 100644 --- a/pulsar-proxy/pom.xml +++ b/pulsar-proxy/pom.xml @@ -47,6 +47,18 @@ ${project.groupId} pulsar-common ${project.version} + + + io.swagger + * + + + + + + ${project.groupId} + pulsar-docs-tools + ${project.version} diff --git a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java similarity index 89% rename from pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java rename to pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java index c8ec8432c9a27..a9164b6d95393 100644 --- a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentation.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java @@ -17,42 +17,40 @@ * under the License. */ -package org.apache.pulsar.docs.tools; +package org.apache.pulsar.proxy.util; -import com.beust.jcommander.Parameters; import lombok.extern.slf4j.Slf4j; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.client.impl.conf.ClientConfigurationData; import org.apache.pulsar.client.impl.conf.ConsumerConfigurationData; import org.apache.pulsar.client.impl.conf.ProducerConfigurationData; import org.apache.pulsar.client.impl.conf.ReaderConfigurationData; +import org.apache.pulsar.docs.tools.BaseGenerateDocumentation; import org.apache.pulsar.proxy.server.ProxyConfiguration; import org.apache.pulsar.websocket.service.WebSocketProxyConfiguration; -@Parameters(commandDescription = "Generate documentation automatically.") @Slf4j public class CmdGenerateDocumentation extends BaseGenerateDocumentation { @Override public String generateDocumentByClassName(String className) throws Exception { - StringBuilder sb = new StringBuilder(); if (ProxyConfiguration.class.getName().equals(className)) { - return generateDocByFieldContext(className, "Pulsar proxy", sb); + return generateDocByFieldContext(className, "Pulsar proxy"); } else if (ServiceConfiguration.class.getName().equals(className)) { - return generateDocByFieldContext(className, "Broker", sb); + return generateDocByFieldContext(className, "Broker"); } else if (ClientConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Client", sb); + return generateDocByApiModelProperty(className, "Client"); } else if (WebSocketProxyConfiguration.class.getName().equals(className)) { - return generateDocByFieldContext(className, "WebSocket", sb); + return generateDocByFieldContext(className, "WebSocket"); } else if (ProducerConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Producer", sb); + return generateDocByApiModelProperty(className, "Producer"); } else if (ConsumerConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Consumer", sb); + return generateDocByApiModelProperty(className, "Consumer"); } else if (ReaderConfigurationData.class.getName().equals(className)) { - return generateDocByApiModelProperty(className, "Reader", sb); + return generateDocByApiModelProperty(className, "Reader"); + } else { + return "Class [" + className + "] not found"; } - - return "Class [" + className + "] not found"; } public static void main(String[] args) throws Exception { diff --git a/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentationTest.java similarity index 98% rename from pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java rename to pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentationTest.java index fc4c8b015219d..b76463e862f50 100644 --- a/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocumentationTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentationTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.pulsar.docs.tools; +package org.apache.pulsar.proxy.util; import java.io.ByteArrayOutputStream; import java.io.PrintStream; From b85827f12e6472e0ac754464e2faea2e9ea252f2 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 14:57:28 +0800 Subject: [PATCH 4/6] move CmdGenerateDocs to docs tools Signed-off-by: tison --- pulsar-broker/pom.xml | 12 ++++++++++++ .../java/org/apache/pulsar/PulsarBrokerStarter.java | 2 +- .../apache/pulsar/PulsarClusterMetadataSetup.java | 2 +- .../apache/pulsar/PulsarClusterMetadataTeardown.java | 2 +- .../apache/pulsar/PulsarInitialNamespaceSetup.java | 2 +- .../org/apache/pulsar/PulsarStandaloneStarter.java | 2 +- .../PulsarTransactionCoordinatorMetadataSetup.java | 4 ++-- .../java/org/apache/pulsar/PulsarVersionStarter.java | 2 +- .../pulsar/broker/tools/GenerateDocsCommand.java | 2 +- .../org/apache/pulsar/compaction/CompactorTool.java | 2 +- .../pulsar/utils/auth/tokens/TokensCliUtils.java | 2 +- .../org/apache/pulsar/PulsarBrokerStarterTest.java | 2 +- .../apache/pulsar/compaction/CompactorToolTest.java | 2 +- pulsar-common/pom.xml | 6 +----- .../apache/pulsar/docs/tools}/CmdGenerateDocs.java | 2 +- .../pulsar/docs/tools}/CmdGenerateDocsTest.java | 2 +- pulsar-functions/worker/pom.xml | 12 ++++++++++++ .../functions/worker/FunctionWorkerStarter.java | 2 +- pulsar-proxy/pom.xml | 6 ------ .../pulsar/proxy/server/ProxyServiceStarter.java | 2 +- pulsar-websocket/pom.xml | 12 ++++++++++++ .../websocket/service/WebSocketServiceStarter.java | 2 +- 22 files changed, 55 insertions(+), 29 deletions(-) rename {pulsar-common/src/main/java/org/apache/pulsar/common/util => pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools}/CmdGenerateDocs.java (99%) rename {pulsar-common/src/test/java/org/apache/pulsar/common/util => pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools}/CmdGenerateDocsTest.java (98%) diff --git a/pulsar-broker/pom.xml b/pulsar-broker/pom.xml index 7bb778037dee6..4c39d7c4b79d0 100644 --- a/pulsar-broker/pom.xml +++ b/pulsar-broker/pom.xml @@ -283,6 +283,18 @@ guava + + ${project.groupId} + pulsar-docs-tools + ${project.version} + + + io.swagger + * + + + + com.beust jcommander diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java index 92fc8c5c9acfa..1b24c806e62cb 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarBrokerStarter.java @@ -55,9 +55,9 @@ import org.apache.pulsar.common.allocator.PulsarByteBufAllocator; import org.apache.pulsar.common.naming.NamespaceBundleSplitAlgorithm; import org.apache.pulsar.common.protocol.Commands; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.DirectMemoryUtils; import org.apache.pulsar.common.util.ShutdownUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.functions.worker.WorkerConfig; import org.apache.pulsar.functions.worker.WorkerService; import org.apache.pulsar.functions.worker.service.WorkerServiceLoader; diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java index 9b757c55ccd1d..96ebadb1ff4aa 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataSetup.java @@ -44,8 +44,8 @@ import org.apache.pulsar.common.policies.data.ClusterData; import org.apache.pulsar.common.policies.data.Policies; import org.apache.pulsar.common.policies.data.TenantInfoImpl; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.ShutdownUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.functions.worker.WorkerUtils; import org.apache.pulsar.metadata.api.MetadataStore; import org.apache.pulsar.metadata.api.MetadataStoreConfig; diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java index cbbf909cdf7fa..01a9eedcca357 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarClusterMetadataTeardown.java @@ -33,8 +33,8 @@ import org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl; import org.apache.pulsar.broker.service.schema.SchemaStorageFormat.SchemaLocator; import org.apache.pulsar.common.naming.TopicName; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.FutureUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.metadata.api.MetadataStore; import org.apache.pulsar.metadata.api.MetadataStoreConfig; import org.apache.pulsar.metadata.api.MetadataStoreFactory; diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarInitialNamespaceSetup.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarInitialNamespaceSetup.java index c4020546d1c6c..22b38e59676ec 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarInitialNamespaceSetup.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarInitialNamespaceSetup.java @@ -23,7 +23,7 @@ import java.util.List; import org.apache.pulsar.broker.resources.PulsarResources; import org.apache.pulsar.common.naming.NamespaceName; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.metadata.api.MetadataStore; /** diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandaloneStarter.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandaloneStarter.java index 33dd58deac095..25320964fd62b 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandaloneStarter.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarStandaloneStarter.java @@ -29,7 +29,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.pulsar.broker.ServiceConfiguration; import org.apache.pulsar.common.configuration.PulsarConfigurationLoader; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; @Slf4j public class PulsarStandaloneStarter extends PulsarStandalone { diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarTransactionCoordinatorMetadataSetup.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarTransactionCoordinatorMetadataSetup.java index 78ce55f1b2ce2..6aedfe13a5b50 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarTransactionCoordinatorMetadataSetup.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarTransactionCoordinatorMetadataSetup.java @@ -23,11 +23,11 @@ import org.apache.pulsar.broker.resources.PulsarResources; import org.apache.pulsar.common.naming.NamespaceName; import org.apache.pulsar.common.naming.SystemTopicNames; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended; /** - * Setup the transaction coordinator metadata for a cluster, the setup will create pulsar/system namespace and create + * Set up the transaction coordinator metadata for a cluster, the setup will create pulsar/system namespace and create * partitioned topic for transaction coordinator assign. */ public class PulsarTransactionCoordinatorMetadataSetup { diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarVersionStarter.java b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarVersionStarter.java index 7eee9d083fc29..85a6c4156dbe4 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/PulsarVersionStarter.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/PulsarVersionStarter.java @@ -20,7 +20,7 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; /** * Pulsar version entry point. diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/tools/GenerateDocsCommand.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/tools/GenerateDocsCommand.java index 1819a56baa12a..b020b4bfd8bd1 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/tools/GenerateDocsCommand.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/tools/GenerateDocsCommand.java @@ -26,7 +26,7 @@ import org.apache.bookkeeper.tools.framework.CliCommand; import org.apache.bookkeeper.tools.framework.CliFlags; import org.apache.bookkeeper.tools.framework.CliSpec; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; /** * The command to generate documents of broker-tool. diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java index 2539c306500a2..83ff790228108 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/compaction/CompactorTool.java @@ -41,8 +41,8 @@ import org.apache.pulsar.client.api.SizeUnit; import org.apache.pulsar.client.internal.PropertiesUtils; import org.apache.pulsar.common.configuration.PulsarConfigurationLoader; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.netty.EventLoopUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.metadata.api.MetadataStoreConfig; import org.apache.pulsar.metadata.api.extended.MetadataStoreExtended; import org.apache.pulsar.policies.data.loadbalancer.AdvertisedListener; diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java b/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java index 2477e1ad2bb1b..fa91ef79d4067 100644 --- a/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java +++ b/pulsar-broker/src/main/java/org/apache/pulsar/utils/auth/tokens/TokensCliUtils.java @@ -45,8 +45,8 @@ import javax.crypto.SecretKey; import lombok.Cleanup; import org.apache.pulsar.broker.authentication.utils.AuthTokenUtils; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.RelativeTimeUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; public class TokensCliUtils { diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarBrokerStarterTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarBrokerStarterTest.java index c6945169512b5..1bc3bd26f1294 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/PulsarBrokerStarterTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/PulsarBrokerStarterTest.java @@ -38,7 +38,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import org.apache.pulsar.broker.ServiceConfiguration; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.testng.annotations.Test; @Test(groups = "broker") diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactorToolTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactorToolTest.java index b1f653fae012a..fb8d6566d9a0d 100644 --- a/pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactorToolTest.java +++ b/pulsar-broker/src/test/java/org/apache/pulsar/compaction/CompactorToolTest.java @@ -35,7 +35,7 @@ import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest; import org.apache.pulsar.client.api.PulsarClient; import org.apache.pulsar.client.api.PulsarClientException; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.testng.annotations.Test; /** diff --git a/pulsar-common/pom.xml b/pulsar-common/pom.xml index 6ffaeb0220f31..8c99638878f53 100644 --- a/pulsar-common/pom.xml +++ b/pulsar-common/pom.xml @@ -227,16 +227,12 @@ snappy-java test + com.google.code.gson gson - - com.beust - jcommander - - org.awaitility awaitility diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/util/CmdGenerateDocs.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java similarity index 99% rename from pulsar-common/src/main/java/org/apache/pulsar/common/util/CmdGenerateDocs.java rename to pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java index f41e53a80e7f3..c0c6e3c7d6e20 100644 --- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/CmdGenerateDocs.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.common.util; +package org.apache.pulsar.docs.tools; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; diff --git a/pulsar-common/src/test/java/org/apache/pulsar/common/util/CmdGenerateDocsTest.java b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java similarity index 98% rename from pulsar-common/src/test/java/org/apache/pulsar/common/util/CmdGenerateDocsTest.java rename to pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java index 68d8a02f48673..f219277b51735 100644 --- a/pulsar-common/src/test/java/org/apache/pulsar/common/util/CmdGenerateDocsTest.java +++ b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.common.util; +package org.apache.pulsar.docs.tools; import static org.testng.Assert.assertEquals; import com.beust.jcommander.Parameter; diff --git a/pulsar-functions/worker/pom.xml b/pulsar-functions/worker/pom.xml index c99fb1871da5e..c6db572f57d7e 100644 --- a/pulsar-functions/worker/pom.xml +++ b/pulsar-functions/worker/pom.xml @@ -129,6 +129,18 @@ commons-io + + ${project.groupId} + pulsar-docs-tools + ${project.version} + + + io.swagger + * + + + + io.swagger swagger-core diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java index fa988a0927bd6..679ce1db70d97 100644 --- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java +++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionWorkerStarter.java @@ -22,8 +22,8 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import lombok.extern.slf4j.Slf4j; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.ShutdownUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; /** * A starter to start function worker. diff --git a/pulsar-proxy/pom.xml b/pulsar-proxy/pom.xml index c1512c58dedb6..de1eb9a16c05b 100644 --- a/pulsar-proxy/pom.xml +++ b/pulsar-proxy/pom.xml @@ -47,12 +47,6 @@ ${project.groupId} pulsar-common ${project.version} - - - io.swagger - * - - diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java index beee9f1a4f763..fc4f58b887ca1 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java @@ -46,7 +46,7 @@ import org.apache.pulsar.common.configuration.PulsarConfigurationLoader; import org.apache.pulsar.common.configuration.VipStatus; import org.apache.pulsar.common.policies.data.ClusterData; -import org.apache.pulsar.common.util.CmdGenerateDocs; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.common.util.DirectMemoryUtils; import org.apache.pulsar.common.util.ShutdownUtil; import org.apache.pulsar.proxy.stats.ProxyStats; diff --git a/pulsar-websocket/pom.xml b/pulsar-websocket/pom.xml index 134a071347223..bf8f38f2da1af 100644 --- a/pulsar-websocket/pom.xml +++ b/pulsar-websocket/pom.xml @@ -52,6 +52,18 @@ test + + ${project.groupId} + pulsar-docs-tools + ${project.version} + + + io.swagger + * + + + + org.apache.commons commons-lang3 diff --git a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketServiceStarter.java b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketServiceStarter.java index fbcecc0642e34..530f0796d488d 100644 --- a/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketServiceStarter.java +++ b/pulsar-websocket/src/main/java/org/apache/pulsar/websocket/service/WebSocketServiceStarter.java @@ -26,8 +26,8 @@ import com.beust.jcommander.Parameter; import org.apache.pulsar.common.configuration.PulsarConfigurationLoader; import org.apache.pulsar.common.configuration.VipStatus; -import org.apache.pulsar.common.util.CmdGenerateDocs; import org.apache.pulsar.common.util.ShutdownUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.websocket.WebSocketConsumerServlet; import org.apache.pulsar.websocket.WebSocketPingPongServlet; import org.apache.pulsar.websocket.WebSocketProducerServlet; From f80fadb385c6d5acf9dfee202c9b1c9fa34c4c85 Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 15:25:01 +0800 Subject: [PATCH 5/6] style Signed-off-by: tison --- .../pulsar/docs/tools/package-info.java | 3 ++- .../proxy/server/ProxyServiceStarter.java | 4 +--- .../pulsar/proxy/util/package-info.java | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java diff --git a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java index ca5afd4d67fa2..d971fc8ee6b11 100644 --- a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/package-info.java @@ -16,4 +16,5 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.pulsar.docs.tools; \ No newline at end of file + +package org.apache.pulsar.docs.tools; diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java index fc4f58b887ca1..d8bb048710770 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java @@ -46,9 +46,9 @@ import org.apache.pulsar.common.configuration.PulsarConfigurationLoader; import org.apache.pulsar.common.configuration.VipStatus; import org.apache.pulsar.common.policies.data.ClusterData; -import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.common.util.DirectMemoryUtils; import org.apache.pulsar.common.util.ShutdownUtil; +import org.apache.pulsar.docs.tools.CmdGenerateDocs; import org.apache.pulsar.proxy.stats.ProxyStats; import org.apache.pulsar.websocket.WebSocketConsumerServlet; import org.apache.pulsar.websocket.WebSocketPingPongServlet; @@ -61,10 +61,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Starts an instance of the Pulsar ProxyService. - * */ public class ProxyServiceStarter { diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java new file mode 100644 index 0000000000000..85284c0dd229a --- /dev/null +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/package-info.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.pulsar.proxy.util; From 15774363f6d5d12a26fda80c195d47ade7493efe Mon Sep 17 00:00:00 2001 From: tison Date: Sat, 1 Jul 2023 16:17:44 +0800 Subject: [PATCH 6/6] stable options order Signed-off-by: tison --- .../apache/pulsar/docs/tools/CmdGenerateDocs.java | 15 ++++++++++----- .../pulsar/docs/tools/CmdGenerateDocsTest.java | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java index c0c6e3c7d6e20..8f784c1eca1fa 100644 --- a/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java +++ b/pulsar-docs-tools/src/main/java/org/apache/pulsar/docs/tools/CmdGenerateDocs.java @@ -23,6 +23,7 @@ import com.beust.jcommander.ParameterDescription; import com.beust.jcommander.Parameters; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import lombok.Getter; @@ -145,11 +146,15 @@ private String generateDocument(String module, JCommander commander) { sb.append("|Flag|Description|Default|\n"); sb.append("|---|---|---|\n"); List options = cmd.getParameters(); - options.forEach((option) -> - sb.append("| `").append(option.getNames()) - .append("` | ").append(option.getDescription().replace("\n", " ")) - .append("|").append(option.getDefault()).append("|\n") - ); + options.stream().sorted(Comparator.comparing(ParameterDescription::getLongestName)) + .forEach((option) -> + sb.append("| `") + .append(option.getNames()) + .append("` | ") + .append(option.getDescription().replace("\n", " ")) + .append("|") + .append(option.getDefault()).append("|\n") + ); } return sb.toString(); } diff --git a/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java index f219277b51735..3f96ddaef591a 100644 --- a/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java +++ b/pulsar-docs-tools/src/test/java/org/apache/pulsar/docs/tools/CmdGenerateDocsTest.java @@ -86,8 +86,8 @@ public void testGenerateDocs() { + "\n" + "|Flag|Description|Default|\n" + "|---|---|---|\n" - + "| `-n, --name` | Name|null|\n" + "| `-h, --help` | Show this help message|false|\n" + + "| `-n, --name` | Name|null|\n" + System.lineSeparator(); assertEquals(rightMsg, message); } finally {