This is an automated email from the ASF dual-hosted git repository.
penghui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 3e34ef1 Generate documentation of PulsarProxy automatically (#11421)
3e34ef1 is described below
commit 3e34ef129af55231519be5d13f837d2e2fe452df
Author: feynmanlin <[email protected]>
AuthorDate: Thu Jul 22 22:41:27 2021 +0800
Generate documentation of PulsarProxy automatically (#11421)
Master Issue: #10041
### Motivation
The config object has already been annotated.
We just need to add it to the auto-generated list
---
.../proxy/util/CmdGenerateDocumentation.java | 45 +++++++++++++++++
.../java/org/apache/pulsar/proxy/util/CmdTest.java | 58 ++++++++++++++++++++++
2 files changed, 103 insertions(+)
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
new file mode 100644
index 0000000..8b77b38
--- /dev/null
+++
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/util/CmdGenerateDocumentation.java
@@ -0,0 +1,45 @@
+/**
+ * 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.broker.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
new file mode 100644
index 0000000..be05e6b
--- /dev/null
+++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/util/CmdTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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);
+ }
+ }
+}