-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
executable file
·172 lines (157 loc) · 5.57 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import org.apache.tools.ant.filters.ReplaceTokens
import java.time.LocalDate
import java.time.format.DateTimeFormatter
plugins {
id 'com.github.ben-manes.versions' version '0.42.0' // adds the task 'dependencyUpdates'
id 'com.dorongold.task-tree' version '2.1.0' // adds the task 'taskTree [some task]'
id 'distribution'
id 'maven-publish'
id 'org.asciidoctor.jvm.convert' version '3.3.2'
}
repositories {
mavenCentral()
}
subprojects {
apply plugin: 'distribution'
apply plugin: 'maven-publish'
apply plugin: 'org.asciidoctor.jvm.convert'
group = 'ish.oncourse.docs'
version = 'SNAPSHOT' // this project doesn't have versioned releases
// bug https://github.com/asciidoctor/asciidoctor-gradle-plugin/issues/559
repositories {
mavenCentral()
}
asciidoctor {
logDocuments true
baseDir "src"
sourceDir baseDir
sources {
include 'index.adoc'
}
outputDir "${buildDir}/dist"
options doctype: 'book'
attributes 'source-highlighter': 'coderay',
'linkcss': '',
'toc': 'left',
'toc-title': "",
'sectnums': 'all',
'sectnumlevels': 2,
'partnums': true,
'icons': 'font',
'docinfo': 'shared',
'docinfodir': "${rootDir}/src",
'stylesheet': 'css/oncourse.css',
'revnumber': null,
'revdate': LocalDate.now().format(DateTimeFormatter.ofPattern("d MMM yyyy")),
'plantuml-config':"${rootDir}/src/plantuml.config"
resources {
from(sourceDir) {
include 'images/**'
}
from("${rootDir}/src") {
include "css/oncourse.css"
include "js/**"
include 'images/**'
}
}
asciidoctorj {
modules {
diagram.use()
}
}
doLast {
ant.replaceregexp(match: 'img src', replace: 'img src="images/placeholder.png" class="lazy" data-src', flags: 'g') {
fileset(dir: "${buildDir}/dist", includes: '*.html')
}
}
}
distributions {
main {
contents {
from asciidoctor
}
}
}
distZip {
archiveVersion = ''
}
publishing {
publications {
maven(MavenPublication) {
artifact distZip
pom {
description = "ish onCourse documentation"
licenses {
license {
name = "Creative Commons Attribution 4.0 International License"
url = "https://github.com/ishgroup/onCourseDocs/blob/master/LICENSE.txt"
}
}
scm {
url = "https://github.com/ishgroup/onCourseDocs"
}
}
}
}
repositories {
maven {
name "snapshots"
url "https://repo.ish.com.au/content/repositories/ish-snapshots"
credentials {
username nexusUsername
password nexusPassword
}
}
}
}
// this task should be periodically run manually to optimise files in the source folders
task optimise {
description = "Optimise all the images"
// both ImageMagick and optipng need to be installed
doLast {
fileTree("src").matching{ include '**/*.png' }.each{ f ->
BigDecimal resolution=0, width=0
new ByteArrayOutputStream().withStream { output ->
exec {
commandLine = 'magick'
standardOutput = output
args = ['identify', '-format', '%x', f.absolutePath]
}
resolution = output.toString() as BigDecimal
}
new ByteArrayOutputStream().withStream { output ->
exec {
commandLine = 'magick'
standardOutput = output
args = ['identify', '-format', '%w', f.absolutePath]
}
width = output.toString() as BigDecimal
}
if (resolution != 72 || width > 900) {
logger.warn('Found image {} which has resolution {} and width {}. Rescaling now.', f.absolutePath, resolution, width)
exec {
commandLine = 'convert'
args = [f.absolutePath, '-strip', '-units' ,'PixelsPerInch', '-density', '72', '-resize', '900>', f.absolutePath]
}
}
exec {
commandLine = 'optipng'
args = ['-fix', '-strip all', f.absolutePath]
}
}
}
}
}
// Skip beta and other non-final releases in the update report
dependencyUpdates.resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'ea'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
}
if (rejected) {
selection.reject('Release candidate')
}
}
}
}