1
1
/*
2
- * Copyright 2012-2024 the original author or authors.
2
+ * Copyright 2012-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
22
22
import java .io .IOException ;
23
23
import java .io .PrintWriter ;
24
24
import java .io .Reader ;
25
+ import java .io .UncheckedIOException ;
26
+ import java .util .List ;
25
27
import java .util .Properties ;
26
28
import java .util .Set ;
27
29
import java .util .SortedSet ;
@@ -61,22 +63,39 @@ public void setAutoConfiguration(FileCollection autoConfiguration) {
61
63
62
64
@ TaskAction
63
65
void documentAutoConfigurationClasses () throws IOException {
66
+ List <AutoConfiguration > autoConfigurations = load ();
67
+ autoConfigurations .forEach (this ::writeModuleAdoc );
64
68
for (File metadataFile : this .autoConfiguration ) {
65
69
Properties metadata = new Properties ();
66
70
try (Reader reader = new FileReader (metadataFile )) {
67
71
metadata .load (reader );
68
72
}
69
73
AutoConfiguration autoConfiguration = new AutoConfiguration (metadata .getProperty ("module" ), new TreeSet <>(
70
74
StringUtils .commaDelimitedListToSet (metadata .getProperty ("autoConfigurationClassNames" ))));
71
- writeTable (autoConfiguration );
75
+ writeModuleAdoc (autoConfiguration );
72
76
}
77
+ writeNavAdoc (autoConfigurations );
73
78
}
74
79
75
- private void writeTable (AutoConfiguration autoConfigurationClasses ) throws IOException {
80
+ private List <AutoConfiguration > load () {
81
+ return this .autoConfiguration .getFiles ()
82
+ .stream ()
83
+ .map (AutoConfiguration ::of )
84
+ .sorted ((a1 , a2 ) -> a1 .module .compareTo (a2 .module ))
85
+ .toList ();
86
+ }
87
+
88
+ private void writeModuleAdoc (AutoConfiguration autoConfigurationClasses ) {
76
89
File outputDir = getOutputDir ().getAsFile ().get ();
77
90
outputDir .mkdirs ();
78
91
try (PrintWriter writer = new PrintWriter (
79
92
new FileWriter (new File (outputDir , autoConfigurationClasses .module + ".adoc" )))) {
93
+ writer .println ("[[appendix.auto-configuration-classes.%s]]" .formatted (autoConfigurationClasses .module ));
94
+ writer .println ("= %s" .formatted (autoConfigurationClasses .module ));
95
+ writer .println ();
96
+ writer .println ("The following auto-configuration classes are from the `%s` module:"
97
+ .formatted (autoConfigurationClasses .module ));
98
+ writer .println ();
80
99
writer .println ("[cols=\" 4,1\" ]" );
81
100
writer .println ("|===" );
82
101
writer .println ("| Configuration Class | Links" );
@@ -88,6 +107,22 @@ private void writeTable(AutoConfiguration autoConfigurationClasses) throws IOExc
88
107
}
89
108
writer .println ("|===" );
90
109
}
110
+ catch (IOException ex ) {
111
+ throw new UncheckedIOException (ex );
112
+ }
113
+ }
114
+
115
+ private void writeNavAdoc (List <AutoConfiguration > autoConfigurations ) {
116
+ File outputDir = getOutputDir ().getAsFile ().get ();
117
+ outputDir .mkdirs ();
118
+ try (PrintWriter writer = new PrintWriter (new FileWriter (new File (outputDir , "nav.adoc" )))) {
119
+ autoConfigurations .forEach ((autoConfigurationClasses ) -> writer
120
+ .println ("*** xref:appendix:auto-configuration-classes/%s.adoc[]"
121
+ .formatted (autoConfigurationClasses .module )));
122
+ }
123
+ catch (IOException ex ) {
124
+ throw new UncheckedIOException (ex );
125
+ }
91
126
}
92
127
93
128
private static final class AutoConfiguration {
@@ -105,6 +140,18 @@ private AutoConfiguration(String module, Set<String> classNames) {
105
140
}).collect (Collectors .toCollection (TreeSet ::new ));
106
141
}
107
142
143
+ private static AutoConfiguration of (File metadataFile ) {
144
+ Properties metadata = new Properties ();
145
+ try (Reader reader = new FileReader (metadataFile )) {
146
+ metadata .load (reader );
147
+ }
148
+ catch (IOException ex ) {
149
+ throw new UncheckedIOException (ex );
150
+ }
151
+ return new AutoConfiguration (metadata .getProperty ("module" ), new TreeSet <>(
152
+ StringUtils .commaDelimitedListToSet (metadata .getProperty ("autoConfigurationClassNames" ))));
153
+ }
154
+
108
155
}
109
156
110
157
private static final class AutoConfigurationClass implements Comparable <AutoConfigurationClass > {
0 commit comments