-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
139 lines (124 loc) · 5.58 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
// gradle build script for the arc42 template family
//
// free software - without guarantee, use at your own risk
// ========================================================
apply plugin: 'base'
buildscript {
// these are the BUILDSCRIPT deps - required to execute
// build targets and -operations
repositories {
mavenCentral()
maven {
url = "https://plugins.gradle.org/m2/"
}
jcenter()
}
dependencies {
classpath( 'org.asciidoctor:asciidoctor-gradle-plugin:0.7.1' )
}
}
// set common output directory for all subprojects
project.ext.globalBuildDir = project.buildDir
logger.info "globalBuildDir = "+globalBuildDir
project.description = """
${'='*80}
This project builds a set of different arc42-templates from the golden master (asciidoc)
${'='*80}
"""
project.ext.config = new ConfigSlurper().parse file('buildconfig.groovy').text
project.ext.languages = []
new File(config.goldenMaster.sourcePath).eachDir { dir ->
if (dir.name =~ /^[A-Z]{2}$/) {
languages << dir.name
}
}
task createTemplatesFromGoldenMaster (
description: 'takes the golden master and creates a version with help and without help for each available language',
group: 'arc42-template'
) {
inputs.dir file(config.goldenMaster.sourcePath)
outputs.dir file(config.goldenMaster.targetPath+'/'+languages[0])
doLast {
//convention over configuration:
//let's fetch the available languages from the source dir
logger.lifecycle "found templates in the following languages: "+languages
languages.each { language ->
def pathToGoldenMaster = config.goldenMaster.sourcePath + '/' + language + '/asciidoc/'
def sourceSub = file(pathToGoldenMaster+'/src/.')
def sourceMain = file(pathToGoldenMaster+'/.')
logger.info "copy golden master from ${sourceMain.path} ..."
//the list of features/tags available in the golden master
def allFeatures = config.goldenMaster.allFeatures
//the template styles with their corresponding features
def templateStyles = config.goldenMaster.templateStyles
templateStyles.each { templateName, featuresWanted ->
def featuresToRemove = allFeatures - featuresWanted
def pathToTarget = config.goldenMaster.targetPath +'/'+language+'/asciidoc/'+ templateName
def target = file(pathToTarget + '/src/.')
target.mkdirs()
logger.info " to ${target.path}"
logger.lifecycle "create %buildDir%${target.path - buildDir}"
[sourceMain,sourceSub].each { source ->
source.eachFile { sourceFile ->
if (sourceFile.name.endsWith('.adoc') || sourceFile.name.endsWith('.config')) {
def targetFile = file(target.path + '/' + sourceFile.name)
def template = sourceFile.getText('utf-8')
featuresToRemove.each { feature ->
template = template.replaceAll(/(?ms)\[role="arc42/ + feature + /"\][ \r\n]+[*]{4}.*?[*]{4}/, '')
}
targetFile.write(template, 'utf-8')
}
}
}
def pathToDEGoldenMaster = config.goldenMaster.sourcePath + '/' + 'DE' + '/asciidoc/'
//copy images
logger.info "copy images folder from " + pathToDEGoldenMaster + '/../../images'
logger.info " to " + pathToTarget + '/images'
if (templateName=='plain') {
//only copy the logo
copy {
from pathToDEGoldenMaster + '/../../images/arc42-logo.png'
into pathToTarget + '/images'
}
} else {
//copy logo plus example images
copy {
from pathToDEGoldenMaster + '/../../images/.'
into pathToTarget + '/images'
include "**/*-${language}.*"
include "**/*-EN.*"
include "**/arc42-logo.png"
}
}
}
}
}
}
task createDistribution (
dependsOn: [],
description: 'bundles the converted templates into downloadable zip files',
group: 'arc42-template'
) {
outputs.dir file(config.distribution.targetPath)
languages.each { language ->
config.goldenMaster.templateStyles.each { projectName, styles ->
def shortName = projectName.replaceAll("^.*[/\\\\]", "").replaceAll("[^a-zA-Z]", "")
config.formats.each { format, params ->
def taskName = "createDistributionFor_${language}_${shortName}_$format"
tasks.create(name: taskName, type: Zip) {
baseName = "arc42-template-${language}-${shortName}-$format"
archiveName = baseName + '.zip'
destinationDir = file(config.distribution.targetPath)
//archivePath = "$shortName/$format"
include "**/*"
from "./build/$language/$format/$projectName"
doLast {}
}
//tasks[taskName].execute()
tasks.createDistribution.dependsOn << taskName
}
}
}
}
//the following line does not work :-(
//findProject('publish').tasks.publishGhPages.mustRunAfter createDistribution