1
1
/*
2
- * Copyright 2019-2020 the original author or authors.
2
+ * Copyright 2019-2021 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.
26
26
import org .asciidoctor .gradle .jvm .AsciidoctorJExtension ;
27
27
import org .asciidoctor .gradle .jvm .AsciidoctorJPlugin ;
28
28
import org .asciidoctor .gradle .jvm .AsciidoctorTask ;
29
- import org .gradle .api .Action ;
30
- import org .gradle .api .DefaultTask ;
31
29
import org .gradle .api .Project ;
32
- import org .gradle .api .Task ;
33
30
import org .gradle .api .artifacts .Configuration ;
34
- import org .gradle .api .file .FileCollection ;
35
- import org .gradle .api .tasks .InputFiles ;
36
- import org .gradle .api .tasks .OutputDirectory ;
31
+ import org .gradle .api .artifacts .ConfigurationContainer ;
37
32
import org .gradle .api .tasks .Sync ;
38
- import org .gradle .api .tasks .TaskAction ;
39
33
40
34
import org .springframework .boot .build .artifactory .ArtifactoryRepository ;
41
35
import org .springframework .util .StringUtils ;
46
40
*
47
41
* <ul>
48
42
* <li>All warnings are made fatal.
49
- * <li>The version of AsciidoctorJ is upgraded to 2.4.1.
50
- * <li>A task is created to resolve and unzip our documentation resources (CSS and
51
- * Javascript).
43
+ * <li>The version of AsciidoctorJ is upgraded to 2.4.3.
44
+ * <li>A {@code asciidoctorExtensions} configuration is created.
52
45
* <li>For each {@link AsciidoctorTask} (HTML only):
53
46
* <ul>
54
47
* <li>A task is created to sync the documentation resources to its output directory.
55
48
* <li>{@code doctype} {@link AsciidoctorTask#options(Map) option} is configured.
56
- * <li>{@link AsciidoctorTask#attributes(Map) Attributes} are configured for syntax
57
- * highlighting, CSS styling, docinfo, etc.
49
+ * <li>The {@code backend} is configured.
58
50
* </ul>
59
51
* <li>For each {@link AbstractAsciidoctorTask} (HTML and PDF):
60
52
* <ul>
70
62
*/
71
63
class AsciidoctorConventions {
72
64
73
- private static final String ASCIIDOCTORJ_VERSION = "2.4.1" ;
65
+ private static final String EXTENSIONS_CONFIGURATION = "asciidoctorExtensions" ;
66
+
67
+ private static final String ASCIIDOCTORJ_VERSION = "2.4.3" ;
74
68
75
69
void apply (Project project ) {
76
70
project .getPlugins ().withType (AsciidoctorJPlugin .class , (asciidoctorPlugin ) -> {
77
71
configureDocResourcesRepository (project );
78
72
makeAllWarningsFatal (project );
79
73
upgradeAsciidoctorJVersion (project );
80
- UnzipDocumentationResources unzipResources = createUnzipDocumentationResourcesTask (project );
81
- project .getTasks ().withType (AbstractAsciidoctorTask .class , (asciidoctorTask ) -> {
82
- configureCommonAttributes (project , asciidoctorTask );
83
- configureOptions (asciidoctorTask );
84
- asciidoctorTask .baseDirFollowsSourceDir ();
85
- Sync syncSource = createSyncDocumentationSourceTask (project , asciidoctorTask );
86
- if (asciidoctorTask instanceof AsciidoctorTask ) {
87
- configureHtmlOnlyAttributes (asciidoctorTask );
88
- syncSource .from (unzipResources , (resources ) -> resources .into ("asciidoc" ));
89
- asciidoctorTask .doFirst (new Action <Task >() {
90
-
91
- @ Override
92
- public void execute (Task task ) {
93
- project .copy ((spec ) -> {
94
- spec .from (asciidoctorTask .getSourceDir ());
95
- spec .into (asciidoctorTask .getOutputDir ());
96
- spec .include ("css/**" , "js/**" );
97
- });
98
- }
99
-
100
- });
101
- }
102
- });
74
+ createAsciidoctorExtensionsConfiguration (project );
75
+ project .getTasks ().withType (AbstractAsciidoctorTask .class ,
76
+ (asciidoctorTask ) -> configureAsciidoctorTask (project , asciidoctorTask ));
103
77
});
104
78
}
105
79
106
80
private void configureDocResourcesRepository (Project project ) {
107
81
project .getRepositories ().maven ((mavenRepo ) -> {
108
- mavenRepo .setUrl (URI .create ("https://repo.spring.io/release " ));
109
- mavenRepo .mavenContent ((mavenContent ) -> mavenContent .includeGroup ("io.spring.docresources " ));
82
+ mavenRepo .setUrl (URI .create ("https://repo.spring.io/snapshot " ));
83
+ mavenRepo .mavenContent ((mavenContent ) -> mavenContent .includeGroup ("io.spring.asciidoctor.backends " ));
110
84
});
111
85
}
112
86
@@ -118,41 +92,26 @@ private void upgradeAsciidoctorJVersion(Project project) {
118
92
project .getExtensions ().getByType (AsciidoctorJExtension .class ).setVersion (ASCIIDOCTORJ_VERSION );
119
93
}
120
94
121
- private UnzipDocumentationResources createUnzipDocumentationResourcesTask (Project project ) {
122
- Configuration documentationResources = project .getConfigurations ().maybeCreate ("documentationResources" );
123
- documentationResources .getDependencies ()
124
- .add (project .getDependencies ().create ("io.spring.docresources:spring-doc-resources:0.2.5" ));
125
- UnzipDocumentationResources unzipResources = project .getTasks ().create ("unzipDocumentationResources" ,
126
- UnzipDocumentationResources .class );
127
- unzipResources .setResources (documentationResources );
128
- unzipResources .setOutputDir (new File (project .getBuildDir (), "docs/resources" ));
129
- return unzipResources ;
130
- }
131
-
132
- private Sync createSyncDocumentationSourceTask (Project project , AbstractAsciidoctorTask asciidoctorTask ) {
133
- Sync syncDocumentationSource = project .getTasks ()
134
- .create ("syncDocumentationSourceFor" + StringUtils .capitalize (asciidoctorTask .getName ()), Sync .class );
135
- File syncedSource = new File (project .getBuildDir (), "docs/src/" + asciidoctorTask .getName ());
136
- syncDocumentationSource .setDestinationDir (syncedSource );
137
- syncDocumentationSource .from ("src/docs/" );
138
- asciidoctorTask .dependsOn (syncDocumentationSource );
139
- asciidoctorTask .setSourceDir (project .relativePath (new File (syncedSource , "asciidoc/" )));
140
- return syncDocumentationSource ;
141
- }
142
-
143
- private void configureOptions (AbstractAsciidoctorTask asciidoctorTask ) {
144
- asciidoctorTask .options (Collections .singletonMap ("doctype" , "book" ));
95
+ private void createAsciidoctorExtensionsConfiguration (Project project ) {
96
+ ConfigurationContainer configurations = project .getConfigurations ();
97
+ Configuration asciidoctorExtensions = configurations .maybeCreate (EXTENSIONS_CONFIGURATION );
98
+ asciidoctorExtensions .getDependencies ().add (project .getDependencies ()
99
+ .create ("io.spring.asciidoctor.backends:asciidoctor-spring-backends:0.0.1-SNAPSHOT" ));
100
+ Configuration dependencyManagement = configurations .findByName ("dependencyManagement" );
101
+ if (dependencyManagement != null ) {
102
+ asciidoctorExtensions .extendsFrom (dependencyManagement );
103
+ }
145
104
}
146
105
147
- private void configureHtmlOnlyAttributes ( AbstractAsciidoctorTask asciidoctorTask ) {
148
- Map < String , Object > attributes = new HashMap <>( );
149
- attributes . put ( "source-highlighter" , "highlightjs" );
150
- attributes . put ( "highlightjsdir" , "js/highlight" );
151
- attributes . put ( "highlightjs-theme" , "github" );
152
- attributes . put ( "linkcss" , true );
153
- attributes . put ( "icons" , "font" );
154
- attributes . put ( "stylesheet" , "css/spring.css" );
155
- asciidoctorTask . attributes ( attributes );
106
+ private void configureAsciidoctorTask ( Project project , AbstractAsciidoctorTask asciidoctorTask ) {
107
+ asciidoctorTask . configurations ( EXTENSIONS_CONFIGURATION );
108
+ configureCommonAttributes ( project , asciidoctorTask );
109
+ configureOptions ( asciidoctorTask );
110
+ asciidoctorTask . baseDirFollowsSourceDir ( );
111
+ createSyncDocumentationSourceTask ( project , asciidoctorTask );
112
+ if ( asciidoctorTask instanceof AsciidoctorTask ) {
113
+ configureAsciidoctorHtmlTask ( project , ( AsciidoctorTask ) asciidoctorTask );
114
+ }
156
115
}
157
116
158
117
private void configureCommonAttributes (Project project , AbstractAsciidoctorTask asciidoctorTask ) {
@@ -169,43 +128,23 @@ private String determineGitHubTag(Project project) {
169
128
return (version .endsWith ("-SNAPSHOT" )) ? "master" : version ;
170
129
}
171
130
172
- /**
173
- * {@link Task} for unzipping the documentation resources.
174
- */
175
- public static class UnzipDocumentationResources extends DefaultTask {
176
-
177
- private FileCollection resources ;
178
-
179
- private File outputDir ;
180
-
181
- @ InputFiles
182
- public FileCollection getResources () {
183
- return this .resources ;
184
- }
185
-
186
- public void setResources (FileCollection resources ) {
187
- this .resources = resources ;
188
- }
189
-
190
- @ OutputDirectory
191
- public File getOutputDir () {
192
- return this .outputDir ;
193
- }
194
-
195
- public void setOutputDir (File outputDir ) {
196
- this .outputDir = outputDir ;
197
- }
131
+ private void configureOptions (AbstractAsciidoctorTask asciidoctorTask ) {
132
+ asciidoctorTask .options (Collections .singletonMap ("doctype" , "book" ));
133
+ }
198
134
199
- @ TaskAction
200
- void syncDocumentationResources () {
201
- getProject ().sync ((copySpec ) -> {
202
- copySpec .into (this .outputDir );
203
- for (File resource : this .resources ) {
204
- copySpec .from (getProject ().zipTree (resource ));
205
- }
206
- });
207
- }
135
+ private Sync createSyncDocumentationSourceTask (Project project , AbstractAsciidoctorTask asciidoctorTask ) {
136
+ Sync syncDocumentationSource = project .getTasks ()
137
+ .create ("syncDocumentationSourceFor" + StringUtils .capitalize (asciidoctorTask .getName ()), Sync .class );
138
+ File syncedSource = new File (project .getBuildDir (), "docs/src/" + asciidoctorTask .getName ());
139
+ syncDocumentationSource .setDestinationDir (syncedSource );
140
+ syncDocumentationSource .from ("src/docs/" );
141
+ asciidoctorTask .dependsOn (syncDocumentationSource );
142
+ asciidoctorTask .setSourceDir (project .relativePath (new File (syncedSource , "asciidoc/" )));
143
+ return syncDocumentationSource ;
144
+ }
208
145
146
+ private void configureAsciidoctorHtmlTask (Project project , AsciidoctorTask asciidoctorTask ) {
147
+ asciidoctorTask .outputOptions ((outputOptions ) -> outputOptions .backends ("spring-html" ));
209
148
}
210
149
211
150
}
0 commit comments