5050 * Task to generate a local Antora playbook.
5151 *
5252 * @author Phillip Webb
53+ * @author Yanming Zhou
5354 */
5455public abstract class GenerateAntoraPlaybook extends DefaultTask {
5556
5657 private static final String ANTORA_SOURCE_DIR = "src/docs/antora" ;
5758
5859 private static final String GENERATED_DOCS = "build/generated/docs/" ;
5960
61+ private final Project project ;
62+
6063 @ OutputFile
6164 public abstract RegularFileProperty getOutputFile ();
6265
@@ -76,9 +79,10 @@ public abstract class GenerateAntoraPlaybook extends DefaultTask {
7679 public abstract Property <Boolean > getExcludeJavadocExtension ();
7780
7881 public GenerateAntoraPlaybook () {
82+ this .project = getProject ();
7983 setGroup ("Documentation" );
8084 setDescription ("Generates an Antora playbook.yml file for local use" );
81- getOutputFile ().convention (getProject () .getLayout ()
85+ getOutputFile ().convention (this . project .getLayout ()
8286 .getBuildDirectory ()
8387 .file ("generated/docs/antora-playbook/antora-playbook.yml" ));
8488 getContentSourceConfiguration ().convention ("antoraContent" );
@@ -127,7 +131,7 @@ private void addExtensions(Map<String, Object> data) {
127131 extensions .xref ((xref ) -> xref .stub (getXrefStubs ().getOrElse (Collections .emptyList ())));
128132 extensions .zipContentsCollector ((zipContentsCollector ) -> {
129133 zipContentsCollector .versionFile ("gradle.properties" );
130- String locationName = getProject () .getName () + "-${version}-${name}-${classifier}.zip" ;
134+ String locationName = this . project .getName () + "-${version}-${name}-${classifier}.zip" ;
131135 Path antoraContent = getRelativeProjectPath ()
132136 .resolve (GENERATED_DOCS + "antora-content/" + locationName );
133137 Path antoraDependencies = getRelativeProjectPath ()
@@ -149,12 +153,12 @@ private void addSources(Map<String, Object> data) {
149153 private Map <String , Object > createContentSource () {
150154 Map <String , Object > source = new LinkedHashMap <>();
151155 Path playbookPath = getOutputFile ().get ().getAsFile ().toPath ().getParent ();
152- Path antoraSrc = getProjectPath (getProject () ).resolve (ANTORA_SOURCE_DIR );
156+ Path antoraSrc = getProjectPath (this . project ).resolve (ANTORA_SOURCE_DIR );
153157 StringBuilder url = new StringBuilder ("." );
154158 relativizeFromRootProject (playbookPath ).normalize ().forEach ((path ) -> url .append (File .separator ).append (".." ));
155159 source .put ("url" , url .toString ());
156160 source .put ("branches" , "HEAD" );
157- source .put ("version" , getProject () .getVersion ().toString ());
161+ source .put ("version" , this . project .getVersion ().toString ());
158162 Set <String > startPaths = new LinkedHashSet <>();
159163 addAntoraContentStartPaths (startPaths );
160164 startPaths .add (relativizeFromRootProject (antoraSrc ).toString ());
@@ -163,7 +167,7 @@ private Map<String, Object> createContentSource() {
163167 }
164168
165169 private void addAntoraContentStartPaths (Set <String > startPaths ) {
166- Configuration configuration = getProject () .getConfigurations ().findByName ("antoraContent" );
170+ Configuration configuration = this . project .getConfigurations ().findByName ("antoraContent" );
167171 if (configuration != null ) {
168172 for (ProjectDependency dependency : configuration .getAllDependencies ().withType (ProjectDependency .class )) {
169173 Path path = dependency .getDependencyProject ().getProjectDir ().toPath ();
@@ -175,7 +179,7 @@ private void addAntoraContentStartPaths(Set<String> startPaths) {
175179 private void addDir (Map <String , Object > data ) {
176180 Path playbookDir = toRealPath (getOutputFile ().get ().getAsFile ().toPath ()).getParent ();
177181 Path outputDir = toRealPath (
178- getProject () .getLayout ().getBuildDirectory ().dir ("site" ).get ().getAsFile ().toPath ());
182+ this . project .getLayout ().getBuildDirectory ().dir ("site" ).get ().getAsFile ().toPath ());
179183 data .put ("output" , Map .of ("dir" , "." + File .separator + playbookDir .relativize (outputDir )));
180184 }
181185
@@ -202,11 +206,11 @@ private Yaml createYaml() {
202206 }
203207
204208 private Path getRelativeProjectPath () {
205- return relativizeFromRootProject (getProjectPath (getProject () ));
209+ return relativizeFromRootProject (getProjectPath (this . project ));
206210 }
207211
208212 private Path relativizeFromRootProject (Path subPath ) {
209- Path rootProjectPath = getProjectPath (getProject () .getRootProject ());
213+ Path rootProjectPath = getProjectPath (this . project .getRootProject ());
210214 return rootProjectPath .relativize (subPath ).normalize ();
211215 }
212216
0 commit comments