11/*
2- * Copyright 2012-2024 the original author or authors.
2+ * Copyright 2012-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2222import java .io .IOException ;
2323import java .io .PrintWriter ;
2424import java .io .Reader ;
25+ import java .io .UncheckedIOException ;
26+ import java .util .List ;
2527import java .util .Properties ;
2628import java .util .Set ;
2729import java .util .SortedSet ;
@@ -61,22 +63,39 @@ public void setAutoConfiguration(FileCollection autoConfiguration) {
6163
6264 @ TaskAction
6365 void documentAutoConfigurationClasses () throws IOException {
66+ List <AutoConfiguration > autoConfigurations = load ();
67+ autoConfigurations .forEach (this ::writeModuleAdoc );
6468 for (File metadataFile : this .autoConfiguration ) {
6569 Properties metadata = new Properties ();
6670 try (Reader reader = new FileReader (metadataFile )) {
6771 metadata .load (reader );
6872 }
6973 AutoConfiguration autoConfiguration = new AutoConfiguration (metadata .getProperty ("module" ), new TreeSet <>(
7074 StringUtils .commaDelimitedListToSet (metadata .getProperty ("autoConfigurationClassNames" ))));
71- writeTable (autoConfiguration );
75+ writeModuleAdoc (autoConfiguration );
7276 }
77+ writeNavAdoc (autoConfigurations );
7378 }
7479
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 ) {
7689 File outputDir = getOutputDir ().getAsFile ().get ();
7790 outputDir .mkdirs ();
7891 try (PrintWriter writer = new PrintWriter (
7992 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 ();
8099 writer .println ("[cols=\" 4,1\" ]" );
81100 writer .println ("|===" );
82101 writer .println ("| Configuration Class | Links" );
@@ -88,6 +107,22 @@ private void writeTable(AutoConfiguration autoConfigurationClasses) throws IOExc
88107 }
89108 writer .println ("|===" );
90109 }
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+ }
91126 }
92127
93128 private static final class AutoConfiguration {
@@ -105,6 +140,18 @@ private AutoConfiguration(String module, Set<String> classNames) {
105140 }).collect (Collectors .toCollection (TreeSet ::new ));
106141 }
107142
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+
108155 }
109156
110157 private static final class AutoConfigurationClass implements Comparable <AutoConfigurationClass > {
0 commit comments