-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathguide-build.gradle
174 lines (158 loc) · 6.2 KB
/
guide-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
173
buildscript {
repositories {
mavenLocal()
maven { url = "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-docs:3.2.7"
}
}
import groovy.json.*
apply plugin:'base'
def GRAILS_GUIDES_GROUP = 'X - Grails Guides'
def commonGithubOrg = 'grails'
def commonGithubSlug = 'grails-guides'
def commonBranch = 'master'
task prepareResources {
group = GRAILS_GUIDES_GROUP
description = 'Downloads grails-guides repository master branch and unzip it to build folder'
doLast {
ant.mkdir(dir:buildDir)
ant.get(src:"https://github.com/${commonGithubOrg}/${commonGithubSlug}/archive/${commonBranch}.zip", dest:"${buildDir}/resources.zip")
ant.unzip(src:"${buildDir}/resources.zip", dest:"${buildDir}/resources")
}
}
task copyLocalGuideImgResources(type: Copy) {
group = GRAILS_GUIDES_GROUP
description = 'Copy local image resources to build folder'
onlyIf { new File('src/main/resources/img').exists() }
mustRunAfter prepareResources
from ('src/main/resources/img') {
include '*.png'
include '*.gif'
include '*.jpg'
include '*.svg'
include '*.jpeg'
}
into "${buildDir}/resources/grails-guides-master/src/main/resources/img"
}
task publishGuide(type: grails.doc.gradle.PublishGuide) {
group = GRAILS_GUIDES_GROUP
description = 'Generate Guide'
dependsOn prepareResources, copyLocalGuideImgResources
def localResourcesDir = "${buildDir}/resources/${commonGithubSlug}-${commonBranch}"
// def localResourcesDir = "../grails-guides/"
// No language setting because we want the English guide to be
// generated with a 'en' in the path, but the source is in 'en'
// so that it's easy to track with git.
targetDir = project.file("${buildDir}/docs")
sourceRepo = "https://github.com/${githubSlug}/edit/$githubBranch/src/main/docs"
sourceDir = new File(projectDir, "src/main/docs")
propertiesFiles = [ new File(projectDir, "gradle.properties"), new File(projectDir, "complete/gradle.properties") ]
asciidoc = true
resourcesDir = project.file("${localResourcesDir}/src/main/resources")
properties = [
'safe':'UNSAFE',
'commondir':project.file("${localResourcesDir}/src/main/docs"),
'sourceDir':project.file('complete').absolutePath,
'javaee': 'https://docs.oracle.com/javaee/7/api/',
'javase': 'https://docs.oracle.com/javase/7/docs/api/',
'groovyapi': 'http://docs.groovy-lang.org/latest/html/gapi/',
'grailsapi': 'http://docs.grails.org/latest/api/',
'gormapi': 'http://gorm.grails.org/latest/api/',
'springapi': 'https://docs.spring.io/spring/docs/current/javadoc-api/'
]
doLast {
ant.move(file:"${project.buildDir}/docs/guide/single.html",
tofile:"${project.buildDir}/docs/guide/index.html", overwrite:true)
new File(project.buildDir, "docs/index.html").text = '''
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="refresh" content="0; url=guide/index.html" />
</head>
</body>
</html>
'''
}
}
task updateGuidesJson {
group = GRAILS_GUIDES_GROUP
description = 'Updates the gh-pages/guides.json with the Guide information as JSON'
doLast {
def jsonSlurper = new JsonSlurper()
def f = new File("gh-pages/guides.json")
def json = []
if(f.exists()) {
json = f.withReader {
jsonSlurper.parse(it)
}
}
def existing = json.find {
it.name == project.name && it.githubBranch == project.githubBranch
}
if (!existing) {
existing = json.find {
it.name == project.name &&
'master' == project.githubBranch &&
!it.githubBranch
}
}
def data = [:]
if(existing) {
data = existing
}
else {
json.add(data)
}
data.putAll(
githubBranch: project.githubBranch,
name: project.name,
title: project.title,
subtitle: project.subtitle,
authors:project.authors,
githubSlug:project.githubSlug,
category:project.category,
publicationDate:project.publicationDate
)
if(project.hasProperty('tags')) {
data.put("tags", project.tags.split(',')*.trim())
}
if ( f.exists() ) {
f.text = JsonOutput.toJson(json)
}
}
}
def isPropertyUndefined = { propertyName ->
!project.hasProperty(propertyName) || project.getProperty(propertyName) == 'TODO'
}
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(":publishGuide")) {
if ( isPropertyUndefined('title') ) {
throw new GradleException("Set project property `title` in gradle.properties")
}
if ( isPropertyUndefined('subtitle') ) {
throw new GradleException("Set project property `subtitle` in gradle.properties")
}
if ( isPropertyUndefined('authors') ) {
throw new GradleException("Set project property `authors` in gradle.properties")
}
if ( isPropertyUndefined('githubSlug') || !project.getProperty("githubSlug").startsWith('grails-guides/') ) {
throw new GradleException("Set project property `githubSlug` in gradle.properties. It must start with grails-guides/")
}
if ( isPropertyUndefined('tags') ) {
throw new GradleException("Set project property `tags` in gradle.properties")
}
if ( isPropertyUndefined('category') ) {
throw new GradleException("Set project property `category` in gradle.properties")
}
if ( isPropertyUndefined('publicationDate') ) {
throw new GradleException("Set project property `publicationDate` dd MMM yyyy in gradle.properties")
} else {
try {
Date.parse('dd MMM yyyy', project.getProperty('publicationDate'))
} catch(java.text.ParseException e) {
}
}
}
}