50
50
* Task to generate a local Antora playbook.
51
51
*
52
52
* @author Phillip Webb
53
+ * @author Yanming Zhou
53
54
*/
54
55
public abstract class GenerateAntoraPlaybook extends DefaultTask {
55
56
56
57
private static final String ANTORA_SOURCE_DIR = "src/docs/antora" ;
57
58
58
59
private static final String GENERATED_DOCS = "build/generated/docs/" ;
59
60
61
+ private final Project project ;
62
+
60
63
@ OutputFile
61
64
public abstract RegularFileProperty getOutputFile ();
62
65
@@ -76,9 +79,10 @@ public abstract class GenerateAntoraPlaybook extends DefaultTask {
76
79
public abstract Property <Boolean > getExcludeJavadocExtension ();
77
80
78
81
public GenerateAntoraPlaybook () {
82
+ this .project = getProject ();
79
83
setGroup ("Documentation" );
80
84
setDescription ("Generates an Antora playbook.yml file for local use" );
81
- getOutputFile ().convention (getProject () .getLayout ()
85
+ getOutputFile ().convention (this . project .getLayout ()
82
86
.getBuildDirectory ()
83
87
.file ("generated/docs/antora-playbook/antora-playbook.yml" ));
84
88
getContentSourceConfiguration ().convention ("antoraContent" );
@@ -127,7 +131,7 @@ private void addExtensions(Map<String, Object> data) {
127
131
extensions .xref ((xref ) -> xref .stub (getXrefStubs ().getOrElse (Collections .emptyList ())));
128
132
extensions .zipContentsCollector ((zipContentsCollector ) -> {
129
133
zipContentsCollector .versionFile ("gradle.properties" );
130
- String locationName = getProject () .getName () + "-${version}-${name}-${classifier}.zip" ;
134
+ String locationName = this . project .getName () + "-${version}-${name}-${classifier}.zip" ;
131
135
Path antoraContent = getRelativeProjectPath ()
132
136
.resolve (GENERATED_DOCS + "antora-content/" + locationName );
133
137
Path antoraDependencies = getRelativeProjectPath ()
@@ -149,12 +153,12 @@ private void addSources(Map<String, Object> data) {
149
153
private Map <String , Object > createContentSource () {
150
154
Map <String , Object > source = new LinkedHashMap <>();
151
155
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 );
153
157
StringBuilder url = new StringBuilder ("." );
154
158
relativizeFromRootProject (playbookPath ).normalize ().forEach ((path ) -> url .append (File .separator ).append (".." ));
155
159
source .put ("url" , url .toString ());
156
160
source .put ("branches" , "HEAD" );
157
- source .put ("version" , getProject () .getVersion ().toString ());
161
+ source .put ("version" , this . project .getVersion ().toString ());
158
162
Set <String > startPaths = new LinkedHashSet <>();
159
163
addAntoraContentStartPaths (startPaths );
160
164
startPaths .add (relativizeFromRootProject (antoraSrc ).toString ());
@@ -163,7 +167,7 @@ private Map<String, Object> createContentSource() {
163
167
}
164
168
165
169
private void addAntoraContentStartPaths (Set <String > startPaths ) {
166
- Configuration configuration = getProject () .getConfigurations ().findByName ("antoraContent" );
170
+ Configuration configuration = this . project .getConfigurations ().findByName ("antoraContent" );
167
171
if (configuration != null ) {
168
172
for (ProjectDependency dependency : configuration .getAllDependencies ().withType (ProjectDependency .class )) {
169
173
Path path = dependency .getDependencyProject ().getProjectDir ().toPath ();
@@ -175,7 +179,7 @@ private void addAntoraContentStartPaths(Set<String> startPaths) {
175
179
private void addDir (Map <String , Object > data ) {
176
180
Path playbookDir = toRealPath (getOutputFile ().get ().getAsFile ().toPath ()).getParent ();
177
181
Path outputDir = toRealPath (
178
- getProject () .getLayout ().getBuildDirectory ().dir ("site" ).get ().getAsFile ().toPath ());
182
+ this . project .getLayout ().getBuildDirectory ().dir ("site" ).get ().getAsFile ().toPath ());
179
183
data .put ("output" , Map .of ("dir" , "." + File .separator + playbookDir .relativize (outputDir )));
180
184
}
181
185
@@ -202,11 +206,11 @@ private Yaml createYaml() {
202
206
}
203
207
204
208
private Path getRelativeProjectPath () {
205
- return relativizeFromRootProject (getProjectPath (getProject () ));
209
+ return relativizeFromRootProject (getProjectPath (this . project ));
206
210
}
207
211
208
212
private Path relativizeFromRootProject (Path subPath ) {
209
- Path rootProjectPath = getProjectPath (getProject () .getRootProject ());
213
+ Path rootProjectPath = getProjectPath (this . project .getRootProject ());
210
214
return rootProjectPath .relativize (subPath ).normalize ();
211
215
}
212
216
0 commit comments