Skip to content

Commit cea1f66

Browse files
committed
Tool to generate configuration reference docs
Having documentation about the configuration that is both "up-to-date" and "in-sync with the source code" with the actual code is good practice. The functionality added in this change allows generating markdown docs from smallrye-config based configuration types, starting at and grouped by types that are annotated with `@ConfigMapping`. The javadoc of the config interfaces and properties is emitted as markdown. On top there is functionality to generate reference docs for "static" types (currently unused in Polaris). The code is nearly a 1:1 port of the same functionality in Nessie. This change will become useful with/after apache#469. Gradle projects added in this change are: * `polaris-config-doc-annotations` adds an annotation used when generating docs to influence the generation of the configuration reference docs. * `polaris-config-doc-generator` is the reference doc generator implementation, as a "standalone" tool that uses javadoc _infrastructure_. See `ReferenceConfigDocsGenerator` why it needs to be a separate tool than "just" a doclet (class loader isolation issues). * `polaris-site-reference-docs` actually generates the markdown files from referenced Gradle projects. Currently there are no projects referenced, so generation yields nothing. The generated docs are not yet integrated into the website, which will happen in a follow-up PR.
1 parent eeab22e commit cea1f66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3651
-0
lines changed

gradle/libs.versions.toml

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
hadoop = "3.4.1"
2222
iceberg = "1.7.1"
2323
dropwizard = "4.0.11"
24+
picocli = "4.7.6"
2425
slf4j = "2.0.16"
2526
swagger = "1.6.14"
2627

@@ -40,6 +41,7 @@ bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk18on", version = "1
4041
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version = "3.1.8" }
4142
commons-codec1 = { module = "commons-codec:commons-codec", version = "1.17.2" }
4243
commons-lang3 = { module = "org.apache.commons:commons-lang3", version = "3.17.0" }
44+
commons-text = { module = "org.apache.commons:commons-text", version = "1.13.0" }
4345
dropwizard-bom = { module = "io.dropwizard:dropwizard-bom", version.ref = "dropwizard" }
4446
eclipselink = { module = "org.eclipse.persistence:eclipselink", version = "4.0.5" }
4547
errorprone = { module = "com.google.errorprone:error_prone_core", version = "2.36.0" }
@@ -67,10 +69,13 @@ micrometer-bom = { module = "io.micrometer:micrometer-bom", version = "1.14.3" }
6769
mockito-core = { module = "org.mockito:mockito-core", version = "5.15.2" }
6870
opentelemetry-bom = { module = "io.opentelemetry:opentelemetry-bom", version = "1.46.0" }
6971
opentelemetry-semconv = { module = "io.opentelemetry.semconv:opentelemetry-semconv", version = "1.25.0-alpha" }
72+
picocli = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
73+
picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "picocli" }
7074
prometheus-metrics-exporter-servlet-jakarta = { module = "io.prometheus:prometheus-metrics-exporter-servlet-jakarta", version = "1.3.5" }
7175
s3mock-testcontainers = { module = "com.adobe.testing:s3mock-testcontainers", version = "3.12.0" }
7276
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
7377
smallrye-common-annotation = { module = "io.smallrye.common:smallrye-common-annotation", version = "2.9.0" }
78+
smallrye-config-core = { module = "io.smallrye.config:smallrye-config-core", version = "3.10.2" }
7479
spotbugs-annotations = { module = "com.github.spotbugs:spotbugs-annotations", version = "4.8.6" }
7580
swagger-annotations = { module = "io.swagger:swagger-annotations", version.ref = "swagger" }
7681
swagger-jaxrs = { module = "io.swagger:swagger-jaxrs", version.ref = "swagger" }

gradle/projects.main.properties

+4
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ polaris-jpa-model=extension/persistence/jpa-model
2929
polaris-tests=integration-tests
3030
aggregated-license-report=aggregated-license-report
3131
polaris-version=tools/version
32+
33+
polaris-ref-config-annotations=tools/ref-config/annotations
34+
polaris-ref-config-generator=tools/ref-config/generator
35+
polaris-ref-config-site=tools/ref-config/site
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
plugins {
21+
id("polaris-client")
22+
`java-library`
23+
}
24+
25+
description = "Polaris reference docs annotations"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.docs;
20+
21+
import java.lang.annotation.ElementType;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
/** Contains annotations for {@code :polaris-config-doc-generator}. */
27+
public interface ConfigDocs {
28+
/**
29+
* For properties-configs, declares a class containing configuration constants for "properties"
30+
* and gives it a page name. The generated markdown files will start with this name.
31+
*/
32+
@Target(ElementType.TYPE)
33+
@Retention(RetentionPolicy.SOURCE)
34+
@interface ConfigPageGroup {
35+
String name();
36+
}
37+
38+
/**
39+
* Define the "section" in which the config option appears.
40+
*
41+
* <p>For properties-configs, this declares that a property constant field appears in the
42+
* generated markdown files.
43+
*
44+
* <p>For smallrye-configs, this declares that a property appears under a different "prefix".
45+
*/
46+
@Target({ElementType.FIELD, ElementType.METHOD})
47+
@Retention(RetentionPolicy.SOURCE)
48+
@interface ConfigItem {
49+
/**
50+
* The name of the "section" in which this constant field shall appear. The name of the
51+
* generated markdown file will "end" with this name.
52+
*/
53+
String section() default "";
54+
55+
/** For smallrye-configs only: the section docs are taken from property type's javadoc. */
56+
boolean sectionDocFromType() default false;
57+
}
58+
59+
/**
60+
* For smallrye-configs, gives map-keys a name that appears as a placeholder in the fully
61+
* qualified config name in the generated docs.
62+
*/
63+
@Target(ElementType.METHOD)
64+
@Retention(RetentionPolicy.SOURCE)
65+
@interface ConfigPropertyName {
66+
String value() default "";
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
plugins {
21+
id("polaris-server")
22+
`java-library`
23+
`java-test-fixtures`
24+
}
25+
26+
description = "Generates Polaris reference docs"
27+
28+
val genTesting by configurations.creating
29+
30+
dependencies {
31+
implementation(project(":polaris-ref-config-annotations"))
32+
33+
implementation(libs.commons.text)
34+
35+
implementation(libs.smallrye.config.core)
36+
implementation(libs.picocli)
37+
annotationProcessor(libs.picocli.codegen)
38+
39+
testFixturesApi(platform(libs.junit.bom))
40+
testFixturesApi("org.junit.jupiter:junit-jupiter")
41+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
42+
testFixturesApi(libs.assertj.core)
43+
testFixturesApi(libs.mockito.core)
44+
45+
genTesting(project(":polaris-ref-config-annotations"))
46+
genTesting(libs.smallrye.config.core)
47+
}
48+
49+
tasks.named<Test>("test") {
50+
// The test needs the classpath for the necessary dependencies (annotations + smallrye-config).
51+
// Resolving the dependencies must happen during task execution (not configuration).
52+
jvmArgumentProviders.add(
53+
CommandLineArgumentProvider {
54+
// So, in theory, all 'org.gradle.category' attributes should use the type
55+
// org.gradle.api.attributes.Category,
56+
// as Category.CATEGORY_ATTRIBUTE is defined. BUT! Some attributes have an attribute type ==
57+
// String.class!
58+
59+
val categoryAttributeAsString = Attribute.of("org.gradle.category", String::class.java)
60+
61+
val libraries =
62+
genTesting.incoming.artifacts
63+
.filter { a ->
64+
// dependencies:
65+
// org.gradle.category=library
66+
val category =
67+
a.variant.attributes.getAttribute(Category.CATEGORY_ATTRIBUTE)
68+
?: a.variant.attributes.getAttribute(categoryAttributeAsString)
69+
category != null && category.toString() == Category.LIBRARY
70+
}
71+
.map { a -> a.file }
72+
73+
listOf("-Dtesting.libraries=" + libraries.joinToString(":"))
74+
}
75+
)
76+
}

0 commit comments

Comments
 (0)