-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathbuild.groovy
More file actions
235 lines (193 loc) · 8.46 KB
/
build.groovy
File metadata and controls
235 lines (193 loc) · 8.46 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env groovy
/**
* build.groovy - Main build orchestration script for arc42-generator
*
* This script replaces the Gradle build system with a standalone Groovy solution.
*
* Pipeline:
* 1. Load configuration from buildconfig.groovy
* 2. Create templates from Golden Master (Templates.groovy)
* 3. Discover generated templates (Discovery.groovy)
* 4. Convert templates to all formats (Converter.groovy)
* 5. Create ZIP distributions (Packager.groovy)
*
* Usage:
* groovy build.groovy # Full build (all steps)
* groovy build.groovy templates # Only generate templates
* groovy build.groovy convert # Only convert (assumes templates exist)
* groovy build.groovy distribution # Only create distributions
* groovy build.groovy convert --format=html # Convert to specific format only
* groovy build.groovy --parallel=false # Disable parallel execution
*/
// ============================================================================
// Configuration
// ============================================================================
def startTime = System.currentTimeMillis()
def projectRoot = new File('.')
// Parse command-line arguments
def cliArgs = []
try {
if (binding.hasVariable('args')) {
cliArgs = binding.args as List
}
} catch (Exception e) {
cliArgs = []
}
def targetPhase = 'all'
def useParallel = true
def targetFormat = null
if (cliArgs) {
targetPhase = cliArgs.find { !it.startsWith('--') } ?: 'all'
useParallel = !cliArgs.contains('--parallel=false')
def formatArg = cliArgs.find { it.startsWith('--format=') }
if (formatArg) {
targetFormat = formatArg.split('=')[1]
}
}
println """
╔═══════════════════════════════════════════════════════════════════════════╗
║ arc42 Template Generator ║
║ Standalone Groovy Build System ║
╚═══════════════════════════════════════════════════════════════════════════╝
"""
println "Build started: ${new Date()}"
println "Target phase: ${targetPhase}"
println "Parallel execution: ${useParallel}"
if (targetFormat) {
println "Target format: ${targetFormat}"
}
println ""
// ============================================================================
// Load Configuration
// ============================================================================
println "=== Loading Configuration ==="
def config
try {
config = new ConfigSlurper().parse(new File('buildconfig.groovy').toURI().toURL())
println "✓ Configuration loaded from buildconfig.groovy"
def formats = config.formats.keySet() as List
println " Templates: ${config.goldenMaster.templateStyles.keySet().size()} styles"
println " Formats: ${formats.size()} (${formats.take(5).join(', ')}${formats.size() > 5 ? '...' : ''})"
println ""
} catch (Exception e) {
println "✗ Failed to load buildconfig.groovy: ${e.message}"
System.exit(1)
}
// ============================================================================
// Load Helper Classes
// ============================================================================
println "=== Loading Helper Classes ==="
def gcl = new GroovyClassLoader()
def templatesClass
def discoveryClass
def converterClass
def packagerClass
try {
templatesClass = gcl.parseClass(new File('lib/Templates.groovy'))
println "✓ Loaded Templates.groovy"
discoveryClass = gcl.parseClass(new File('lib/Discovery.groovy'))
println "✓ Loaded Discovery.groovy"
converterClass = gcl.parseClass(new File('lib/Converter.groovy'))
println "✓ Loaded Converter.groovy"
packagerClass = gcl.parseClass(new File('lib/Packager.groovy'))
println "✓ Loaded Packager.groovy"
println ""
} catch (Exception e) {
println "✗ Failed to load helper classes: ${e.message}"
e.printStackTrace()
System.exit(1)
}
// Create instances
def templates = templatesClass.newInstance(config, projectRoot)
def discovery = discoveryClass.newInstance(config, projectRoot)
def converter = converterClass.newInstance(config, projectRoot)
def packager = packagerClass.newInstance(config, projectRoot)
// ============================================================================
// Phase 1: Generate Templates from Golden Master
// ============================================================================
if (targetPhase in ['all', 'templates']) {
try {
templates.createFromGoldenMaster()
} catch (Exception e) {
println "\n✗ Template generation failed: ${e.message}"
e.printStackTrace()
System.exit(1)
}
}
// ============================================================================
// Phase 2: Discover Generated Templates
// ============================================================================
def discoveredTemplates = []
if (targetPhase in ['all', 'convert']) {
println "=== Discovering Templates ==="
try {
discoveredTemplates = discovery.discoverTemplates()
if (discoveredTemplates.isEmpty()) {
println "✗ No templates found. Run 'groovy build.groovy templates' first."
System.exit(1)
}
} catch (Exception e) {
println "\n✗ Template discovery failed: ${e.message}"
if (e.message?.contains('does not exist')) {
println "\nHint: Run 'groovy build.groovy templates' first to generate templates."
}
System.exit(1)
}
}
// ============================================================================
// Phase 3: Convert Templates to All Formats
// ============================================================================
if (targetPhase in ['all', 'convert']) {
try {
def formatsToConvert = targetFormat ? [targetFormat] : (config.formats.keySet() as List)
converter.convertAll(discoveredTemplates, formatsToConvert, useParallel)
} catch (Exception e) {
println "\n✗ Conversion failed: ${e.message}"
e.printStackTrace()
System.exit(1)
}
}
// ============================================================================
// Phase 4: Create ZIP Distributions
// ============================================================================
if (targetPhase in ['all', 'distribution']) {
try {
// Discover templates if not already done
if (discoveredTemplates.isEmpty()) {
println "=== Discovering Templates ==="
discoveredTemplates = discovery.discoverTemplates()
}
def formatsToPackage = targetFormat ? [targetFormat] : (config.formats.keySet() as List)
packager.createAllDistributions(discoveredTemplates, formatsToPackage, useParallel)
} catch (Exception e) {
println "\n✗ Distribution creation failed: ${e.message}"
e.printStackTrace()
System.exit(1)
}
}
// ============================================================================
// Summary
// ============================================================================
def endTime = System.currentTimeMillis()
def duration = (endTime - startTime) / 1000.0
println """
╔═══════════════════════════════════════════════════════════════════════════╗
║ BUILD SUCCESSFUL ║
╚═══════════════════════════════════════════════════════════════════════════╝
"""
println "Duration: ${String.format('%.1f', duration)}s"
if (targetPhase in ['all', 'convert'] && discoveredTemplates) {
def languages = discoveredTemplates*.language.unique().size()
def styles = discoveredTemplates*.style.unique().size()
def formats = targetFormat ? 1 : (config.formats.keySet().size())
def totalOutputs = languages * styles * formats
println """
Summary:
Languages: ${languages}
Styles: ${styles}
Formats: ${formats}
Total outputs: ${totalOutputs}
"""
}
println "Build completed: ${new Date()}"
println ""