1
+ /**
2
+ * Build process for ColdBox Modules
3
+ * Adapt to your needs.
4
+ */
5
+ component {
6
+
7
+ /**
8
+ * Constructor
9
+ */
10
+ function init (){
11
+ // Setup Pathing
12
+ variables .cwd = getCWD ().reReplace ( " [\\/]$" , " " );
13
+ variables .artifactsDir = cwd & " /.artifacts" ;
14
+ variables .buildDir = cwd & " /.tmp" ;
15
+
16
+ // Source Excludes Not Added to final binary
17
+ variables .excludes = [
18
+ " build" ,
19
+ " java" ,
20
+ " resources" ,
21
+ " test-harness" ,
22
+ " server-.*\.json" ,
23
+ " ^\..*" ,
24
+ " .git" ,
25
+ " .tmp" ,
26
+ " .artifacts" ,
27
+ " .engine"
28
+ ];
29
+
30
+ // Cleanup + Init Build Directories
31
+ [
32
+ variables .buildDir ,
33
+ variables .artifactsDir
34
+ ].each ( function ( item ){
35
+ if ( directoryExists ( item ) ) {
36
+ directoryDelete ( item , true );
37
+ }
38
+ // Create directories
39
+ directoryCreate ( item , true , true );
40
+ } );
41
+
42
+ return this ;
43
+ }
44
+
45
+ /**
46
+ * Run the build process: test, build source, docs, checksums
47
+ *
48
+ * @projectName The project name used for resources and slugs
49
+ * @version The version you are building
50
+ * @buldID The build identifier
51
+ * @branch The branch you are building
52
+ */
53
+ function run (
54
+ required projectName ,
55
+ version = " 1.0.0" ,
56
+ buildID = createUUID (),
57
+ branch = " development"
58
+ ){
59
+ // Create project mapping
60
+ fileSystemUtil .createMapping ( arguments .projectName , variables .cwd );
61
+
62
+ buildJavaDeps ();
63
+
64
+ // Build the source
65
+ buildSource ( argumentCollection = arguments );
66
+
67
+ // checksums
68
+ buildChecksums ();
69
+
70
+ // Finalize Message
71
+ print
72
+ .line ()
73
+ .boldMagentaLine ( " Build Process is done! Enjoy your build!" )
74
+ .toConsole ();
75
+ }
76
+
77
+ function buildJavaDeps (){
78
+ task ( " tasks/BuildJavaDeps" )
79
+ .inWorkingDirectory ( variables .cwd )
80
+ .run ();
81
+ }
82
+
83
+ /**
84
+ * Build the source
85
+ *
86
+ * @projectName The project name used for resources and slugs
87
+ * @version The version you are building
88
+ * @buldID The build identifier
89
+ * @branch The branch you are building
90
+ */
91
+ function buildSource (
92
+ required projectName ,
93
+ version = " 1.0.0" ,
94
+ buildID = createUUID (),
95
+ branch = " development"
96
+ ){
97
+ // Build Notice ID
98
+ print
99
+ .line ()
100
+ .boldMagentaLine (
101
+ " Building #arguments .projectName # v#arguments .version #+#arguments .buildID # from #cwd # using the #arguments .branch # branch."
102
+ )
103
+ .toConsole ();
104
+
105
+ ensureExportDir ( argumentCollection = arguments );
106
+
107
+ // Project Build Dir
108
+ variables .projectBuildDir = variables .buildDir & " /#projectName #" ;
109
+ directoryCreate (
110
+ variables .projectBuildDir ,
111
+ true ,
112
+ true
113
+ );
114
+
115
+ // Copy source
116
+ print .blueLine ( " Copying source to build folder..." ).toConsole ();
117
+ copy (
118
+ variables .cwd ,
119
+ variables .projectBuildDir
120
+ );
121
+
122
+ // Create build ID
123
+ fileWrite (
124
+ " #variables .projectBuildDir #/#projectName #-#version #+#buildID #" ,
125
+ " Built with love on #dateTimeFormat ( now (), " full" ) #"
126
+ );
127
+
128
+ // Updating Placeholders
129
+ print .greenLine ( " Updating version identifier to #arguments .version #" ).toConsole ();
130
+ command ( " tokenReplace" )
131
+ .params (
132
+ path = " /#variables .projectBuildDir #/**" ,
133
+ token = " @build.version@" ,
134
+ replacement = arguments .version
135
+ )
136
+ .run ();
137
+
138
+ print .greenLine ( " Updating build identifier to #arguments .buildID #" ).toConsole ();
139
+ command ( " tokenReplace" )
140
+ .params (
141
+ path = " /#variables .projectBuildDir #/**" ,
142
+ token = (
arguments .
branch == " master" ? " @build.number@" : " [email protected] @" ),
143
+ replacement = ( arguments .branch == " master" ? arguments .buildID : " -snapshot" )
144
+ )
145
+ .run ();
146
+
147
+ // zip up source
148
+ var destination = " #variables .exportsDir #/#projectName #-#version #.zip" ;
149
+ print .greenLine ( " Zipping code to #destination #" ).toConsole ();
150
+ cfzip (
151
+ action = " zip" ,
152
+ file = " #destination #" ,
153
+ source = " #variables .projectBuildDir #" ,
154
+ overwrite = true ,
155
+ recurse = true
156
+ );
157
+
158
+ // Copy box.json for convenience
159
+ fileCopy (
160
+ " #variables .projectBuildDir #/box.json" ,
161
+ variables .exportsDir
162
+ );
163
+ }
164
+
165
+
166
+ /* ******************************************** PRIVATE HELPERS *********************************************/
167
+
168
+ /**
169
+ * Build Checksums
170
+ */
171
+ private function buildChecksums (){
172
+ print .greenLine ( " Building checksums" ).toConsole ();
173
+ command ( " checksum" )
174
+ .params (
175
+ path = " #variables .exportsDir #/*.zip" ,
176
+ algorithm = " SHA-512" ,
177
+ extension = " sha512" ,
178
+ write = true
179
+ )
180
+ .run ();
181
+ command ( " checksum" )
182
+ .params (
183
+ path = " #variables .exportsDir #/*.zip" ,
184
+ algorithm = " md5" ,
185
+ extension = " md5" ,
186
+ write = true
187
+ )
188
+ .run ();
189
+ }
190
+
191
+ /**
192
+ * DirectoryCopy is broken in lucee
193
+ */
194
+ private function copy ( src , target , recurse = true ){
195
+ // process paths with excludes
196
+ directoryList (
197
+ src ,
198
+ false ,
199
+ " path" ,
200
+ function ( path ){
201
+ var isExcluded = false ;
202
+ variables .excludes .each ( function ( item ){
203
+ if ( path .replaceNoCase ( variables .cwd , " " , " all" ).reFindNoCase ( item ) ) {
204
+ isExcluded = true ;
205
+ }
206
+ } );
207
+ return ! isExcluded ;
208
+ }
209
+ ).each ( function ( item ){
210
+ // Copy to target
211
+ if ( fileExists ( item ) ) {
212
+ print .blueLine ( " Copying #item #" ).toConsole ();
213
+ fileCopy ( item , target );
214
+ } else {
215
+ print .greenLine ( " Copying directory #item #" ).toConsole ();
216
+ directoryCopy (
217
+ item ,
218
+ target & " /" & item .replace ( src , " " ),
219
+ true
220
+ );
221
+ }
222
+ } );
223
+ }
224
+
225
+ /**
226
+ * Gets the last Exit code to be used
227
+ **/
228
+ private function getExitCode (){
229
+ return ( createObject ( " java" , " java.lang.System" ).getProperty ( " cfml.cli.exitCode" ) ?: 0 );
230
+ }
231
+
232
+ /**
233
+ * Ensure the export directory exists at artifacts/NAME/VERSION/
234
+ */
235
+ private function ensureExportDir (
236
+ required projectName ,
237
+ version = " 1.0.0"
238
+ ){
239
+ if ( structKeyExists ( variables , " exportsDir" ) && directoryExists ( variables .exportsDir ) ){
240
+ return ;
241
+ }
242
+ // Prepare exports directory
243
+ variables .exportsDir = variables .artifactsDir & " /#projectName #/#arguments .version #" ;
244
+ directoryCreate ( variables .exportsDir , true , true );
245
+ }
246
+ }e
0 commit comments