Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 40548cf12a629633afddc0229ebb005ea733b94d (plain) (blame)
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Define global variables

// When the parameters change, this should be increased so that the build does nothing other than update the parameters used for the next build.
def pipelineVersion = '1'

def justjURL = 'https://download.eclipse.org/justj'

def testPrefix = "jres-test"
def testExtraPrefix = "archive/jres-test"
def defaultPrefix = "jres"

def java11 = [
  label: 'Java 11',
  BUILD_DESCRIPTION: 'Build jdk.java.net Java 11',
  PUBLISH_LOCATION_PREFIX: "${defaultPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${defaultPrefix}/11/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java11Adoptium = [
  label: 'Java 11 (Adoptium)',
  BUILD_DESCRIPTION: 'Build Adoptium Java 11',
  PUBLISH_LOCATION_PREFIX: "${defaultPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${defaultPrefix}/11/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12+7/OpenJDK11U-jdk_x64_windows_hotspot_11.0.12_7.zip
    ''',
  JDK_URLS_MACOS: '''
    https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12+7/OpenJDK11U-jdk_x64_mac_hotspot_11.0.12_7.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12+7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12+7/OpenJDK11U-jdk_aarch64_linux_hotspot_11.0.12_7.tar.gz
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java17Adoptium = [
  label: 'Java 17 (Adoptium)',
  BUILD_DESCRIPTION: 'Build Adoptium Java 17',
  PUBLISH_LOCATION_PREFIX: "${defaultPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${defaultPrefix}/17/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17+35/OpenJDK17-jdk_x64_windows_hotspot_17_35.zip
    ''',
  JDK_URLS_MACOS: '''
    https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17+35/OpenJDK17-jdk_x64_mac_hotspot_17_35.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17+35/OpenJDK17-jdk_aarch64_mac_hotspot_17_35.tar.gz
    ''',
  JDK_URLS_LINUX: '''
    https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17+35/OpenJDK17-jdk_x64_linux_hotspot_17_35.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17+35/OpenJDK17-jdk_aarch64_linux_hotspot_17_35.tar.gz
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java14 = [
  label: 'Java 14 (test)',
  BUILD_DESCRIPTION: 'Build jdk.java.net Java 14 (-test)',
  PUBLISH_LOCATION_PREFIX: "${testPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${testPrefix}/14/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_windows-x64_bin.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_osx-x64_bin.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_linux-x64_bin.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java14Extra = [
  label: 'Java 14 (++test)',
  BUILD_DESCRIPTION: 'Build jdk.java.net and adoptopenjdk.net Java 14 (++test)',
  PUBLISH_LOCATION_PREFIX: "${testExtraPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${testExtraPrefix}/14/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_windows-x64_bin.zip
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7.1/OpenJDK14U-jdk_x64_windows_hotspot_14.0.1_7.zip
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7.1_openj9-0.20.0/OpenJDK14U-jdk_x64_windows_openj9_14.0.1_7_openj9-0.20.0.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_osx-x64_bin.tar.gz
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7/OpenJDK14U-jdk_x64_mac_hotspot_14.0.1_7.tar.gz
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7.2_openj9-0.20.0/OpenJDK14U-jdk_x64_mac_openj9_14.0.1_7_openj9-0.20.0.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk14.0.2/205943a0976c4ed48cb16f1043c5c647/12/GPL/openjdk-14.0.2_linux-x64_bin.tar.gz
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7/OpenJDK14U-jdk_x64_linux_hotspot_14.0.1_7.tar.gz
    https://github.com/AdoptOpenJDK/openjdk14-binaries/releases/download/jdk-14.0.1+7_openj9-0.20.0/OpenJDK14U-jdk_x64_linux_openj9_14.0.1_7_openj9-0.20.0.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java11Extra = [
  label: 'Java 11 (++test)',
  BUILD_DESCRIPTION: 'Build jdk.java.net and adoptopenjdk.net Java 11 (++test)',
  PUBLISH_LOCATION_PREFIX: "${testExtraPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${testExtraPrefix}/11/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10.2/OpenJDK11U-jdk_x64_windows_hotspot_11.0.7_10.zip
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10.1_openj9-0.20.0/OpenJDK11U-jdk_x64_windows_openj9_11.0.7_10_openj9-0.20.0.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_x64_mac_hotspot_11.0.7_10.tar.gz
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10.2_openj9-0.20.0/OpenJDK11U-jdk_x64_mac_openj9_11.0.7_10_openj9-0.20.0.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10/OpenJDK11U-jdk_x64_linux_hotspot_11.0.7_10.tar.gz
    https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.7+10_openj9-0.20.0/OpenJDK11U-jdk_x64_linux_openj9_11.0.7_10_openj9-0.20.0.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java15 = [
  label: 'Java 15 (test)',
  BUILD_DESCRIPTION: 'Build jdk.java.net Java 15 (-test)',
  PUBLISH_LOCATION_PREFIX: "${testPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${testPrefix}/15/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_windows-x64_bin.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_osx-x64_bin.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-aarch64_bin.tar.gz
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def java16 = [
  label: 'Java 16 (test)',
  BUILD_DESCRIPTION: 'Build jdk.java.net Java 16 (-test)',
  PUBLISH_LOCATION_PREFIX: "${testPrefix}",
  JUSTJ_MANIFEST_URL: "${justjURL}/${testPrefix}/16/downloads/latest/justj.manifest",
  JDK_URLS_WINDOWS: '''
    https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_windows-x64_bin.zip
    ''',
  JDK_URLS_MACOS: '''
    https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_osx-x64_bin.tar.gz
    ''',
  JDK_URLS_MACOS_AARCH64: '''
    ''',
  JDK_URLS_LINUX: '''
    https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz
    ''',
  JDK_URLS_LINUX_AARCH64: '''
    https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-aarch64_bin.tar.gz
    ''',
  BUILD_TYPE: 'nightly',
  PROMOTE: 'true'
]

def parambuilds = [
  java11Adoptium,
  java17Adoptium,
  java11,
  java11Extra,
  java14,
  java14Extra,
  java15,
  java16
]

def javaDefault = update(java17Adoptium, [
    BUILD_DESCRIPTION: 'Build Adoptium Java 17',
    PUBLISH_LOCATION_PREFIX: "${defaultPrefix}",
    JUSTJ_MANIFEST_URL: "${justjURL}/${defaultPrefix}/17/downloads/latest/justj.manifest"
  ])

// Use declarative syntax to run commands inside a Groovy sand-box container.
pipeline {
  agent { label 'migration' }

  options {
    buildDiscarder(logRotator(numToKeepStr: '10'))
    disableConcurrentBuilds()
  }

  tools {
    maven 'apache-maven-latest'
    jdk 'openjdk-jdk11-latest'
  }

  environment {
    JUSTJ_CHECKOUT = 'false'
    JUSTJ_BUILD_TIME_STAMP = sh(returnStdout: true, script: 'date +%Y%m%d_%H%M').trim()
    JUSTJ_URL = "${justjURL}"
    JUSTJ_STORAGE_LOCATION = '/home/data/httpd/download.eclipse.org/justj'
  }

  parameters {
    string(
      name: 'PIPELINE_VERSION',
      defaultValue: "${pipelineVersion}",
      description: """${pretty(
        '''
        If the parameter definitions have changed, this version will be out-dated.
        The script will run but will do nothing other than updating the parameter definitions of the job as a side-effect.
        '''
      )}""")

    string(
      name: 'BUILD_DESCRIPTION',
      defaultValue: 'Build Adoptium Java 17',
      description: """${pretty(
        "Use one of the following links to reconfigure the other parameters below.<br/>${buttons(parambuilds)}"
        )}""")

    string(
      name: 'PUBLISH_LOCATION_PREFIX',
      defaultValue: "${javaDefault.PUBLISH_LOCATION_PREFIX}",
      description: """${pretty(
        '''
        The location under <a href="''' + justjURL + '''/" target="jres">''' + justjURL + '''/${PUBLISH_LOCATION_PREFIX}/${java.version}/downloads/</a> where to publish the results.
        <br/>
        Generally just use the default unless you plan to delete the results after the promotion.
        '''
        )}""")

    string(
      name: 'JUSTJ_MANIFEST_URL',
      defaultValue: "${javaDefault.JUSTJ_MANIFEST_URL}",
      description: """${pretty(
        '''
        Reuse an existing build of the JREs rather than building new ones.
        In general, copy a justj.manifest link from an existing <a href="''' + "${justjURL}/${defaultPrefix}" + '''" target="jres">jres/${java.version}/downloads/latest/justj.manifest</a>.
        The JDK URLs specified below will be ignored in this case.
        <b>To build new JREs, clear this parameter field!<b>
        <b>To do a release build, ensure that this field specifies the ${java.version} to be released.<b>
        '''
        )}""")

    text(
      name: 'JDK_URLS_WINDOWS',
      defaultValue: "${pretty(javaDefault.JDK_URLS_WINDOWS)}",
      description: 'One or more URLs to a Windows zip of a JDK, e.g., from <a href="https://adoptium.net/" target="jdk">https://adoptium.net/</a> or <a href="https://jdk.java.net/" target="jdk">https://jdk.java.net/</a>.')

    text(
      name: 'JDK_URLS_MACOS',
      defaultValue: "${pretty(javaDefault.JDK_URLS_MACOS)}",
      description: 'One or more URLs to a MacOS tar.gz of a JDK for x86_64, e.g., from <a href="https://adoptium.net/" target="jdk">https://adoptium.net/</a> or <a href="https://jdk.java.net/" target="jdk">https://jdk.java.net/</a>.')

    text(
      name: 'JDK_URLS_MACOS_AARCH64',
      defaultValue: "${pretty(javaDefault.JDK_URLS_MACOS_AARCH64)}",
      description: 'One or more URLs to a MacOS tar.gz of a JDK for aarch64, e.g., from <a href="https://adoptium.net/" target="jdk">https://adoptium.net/</a> or <a href="https://jdk.java.net/" target="jdk">https://jdk.java.net/</a>.')

    text(
      name: 'JDK_URLS_LINUX',
      defaultValue: "${pretty(javaDefault.JDK_URLS_LINUX)}",
      description: 'One or more URLs to a Linux tar.gz of a JDK for x86_64, e.g., from <a href="https://adoptium.net/" target="jdk">https://adoptium.net/</a> or <a href="https://jdk.java.net/" target="jdk">https://jdk.java.net/</a>.')

    text(
      name: 'JDK_URLS_LINUX_AARCH64',
      defaultValue: "${pretty(javaDefault.JDK_URLS_LINUX_AARCH64)}",
      description: 'One or more URLs to a Linux tar.gz of a JDK for aarch64, e.g., from <a href="https://adoptium.net/" target="jdk">https://adoptium.net/</a> or <a href="https://jdk.java.net/" target="jdk">https://jdk.java.net/</a>.')

    choice(
      name: 'BUILD_TYPE',
      choices: ['nightly', 'milestone', 'release'],
      description: """${pretty(
        '''
        The type of build to produce.
        A release build will not do a new build but rather will promote the most recent milestone build.
        None of the values specified above are therefore relevant in this case, <b>except that the Java version of the JUSTJ_MANIFEST_URL determines which update site will be released</b>.
        '''
        )}""")

    booleanParam(
      name: 'PROMOTE',
      defaultValue: false,
      description: 'Whether to promote the p2 repository to the download server.'
    )
  }

  stages {
    stage('Git Checkout') {
      when {
        environment name: 'JUSTJ_CHECKOUT', value: 'true'
      }
      steps {
        script {
          def gitVariables = checkout(
            poll: false,
            scm: [
              $class: 'GitSCM',
              branches: [[name: '*/master']],
              doGenerateSubmoduleConfigurations: false,
              submoduleCfg: [],
              userRemoteConfigs: [[url: 'https://git.eclipse.org/r/justj/justj.git']]
            ]
          )

          echo "$gitVariables"
          env.GIT_COMMIT = gitVariables.GIT_COMMIT
        }
      }
    }

    stage('Setup Environment') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        not { environment name: 'BUILD_NUMBER', value: '1' }
      }
      steps {
        sh '''
        echo 'Setting up environment...'
        ls -R releng
        chmod +x releng/org.eclipse.justj.releng/*.sh
        '''
        stash includes: 'releng/org.eclipse.justj.releng/**', name: 'releng-stash'
        script {
          env.PIPELINE_VERSION = params.PIPELINE_VERSION
          env.PUBLISH_LOCATION_PREFIX = params.PUBLISH_LOCATION_PREFIX
          env.JUSTJ_MANIFEST_URL = params.JUSTJ_MANIFEST_URL
          env.JDK_URLS_WINDOWS = pretty(params.JDK_URLS_WINDOWS)
          env.JDK_URLS_MACOS = pretty(params.JDK_URLS_MACOS)
          env.JDK_URLS_MACOS_AARCH64 = pretty(params.JDK_URLS_MACOS_AARCH64)
          env.JDK_URLS_LINUX = pretty(params.JDK_URLS_LINUX)
          env.JDK_URLS_LINUX_AARCH64 = pretty(params.JDK_URLS_LINUX_AARCH64)
          env.BUILD_TYPE = params.BUILD_TYPE
          env.PROMOTE = params.PROMOTE
          if (params.JUSTJ_MANIFEST_URL != '') {
            env.JAVA_MAJOR_VERSION = sh(returnStdout: true, script: 'echo $(basename $(dirname $(dirname $(dirname $JUSTJ_MANIFEST_URL))))').trim()
            env.JUSTJ_PUBLISH_LOCATION = "${env.PUBLISH_LOCATION_PREFIX}/${env.JAVA_MAJOR_VERSION}"
          }
        }
      }
    }

    stage('Build JREs') {
      when {
        environment name: 'JUSTJ_MANIFEST_URL', value: ''
        not {environment name: 'BUILD_TYPE', value: 'release' }
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        not { environment name: 'BUILD_NUMBER', value: '1' }
      }

      parallel {

        stage('Build Linux JRES') {
          when {
            not { environment name: 'JDK_URLS_LINUX', value: '' }
          }

          steps {
            sh '''
            releng/org.eclipse.justj.releng/build-jre.sh
            '''
          }
        }

        stage('Build Linux JRES AArch64') {
          agent {
            label 'aarch64'
          }

          when {
            beforeAgent true
            not { environment name: 'JDK_URLS_LINUX_AARCH64', value: '' }
          }

          options { skipDefaultCheckout true }

          steps {
            cleanWs()
            unstash 'releng-stash'
            sh '''
            releng/org.eclipse.justj.releng/build-jre.sh
            '''
            stash includes: '*org.eclipse.justj.*.tar.gz', name: 'linux-aarch64-stash'
          }
        }

        stage('Build Windows JREs') {
          agent {
            label 'windows'
          }

          when {
            beforeAgent true
            not { environment name: 'JDK_URLS_WINDOWS', value: '' }
          }

          options { skipDefaultCheckout true }

          steps {
            cleanWs()
            unstash 'releng-stash'
            bat '''
              bash -ex releng/org.eclipse.justj.releng/build-jre.sh
              '''
            stash includes: '*org.eclipse.justj.*.tar.gz', name: 'win-stash'
          }
        }

        stage('Build MacOS JREs') {
          stages {
            stage('Build MacOS JREs x86_64') {
              agent {
                label 'macos && arm64'
              }

              when {
                beforeAgent true
                not { environment name: 'JDK_URLS_MACOS', value: '' }
              }

              options { skipDefaultCheckout true }

              steps {
                cleanWs()
                unstash 'releng-stash'
                sh '''
                export ARCH=x86_64
                releng/org.eclipse.justj.releng/build-jre.sh
                '''
                stash includes: 'org.eclipse.justj.*.tar.gz', name: 'mac-stash'
              }
            }

            stage('Build MacOS JREs Aarch64') {
              agent {
                label 'macos && arm64'
              }

              when {
                beforeAgent true
                not { environment name: 'JDK_URLS_MACOS_AARCH64', value: '' }
              }

              options { skipDefaultCheckout true }

              steps {
                cleanWs()
                unstash 'releng-stash'
                sh '''
                export ARCH=aarch64
                releng/org.eclipse.justj.releng/build-jre.sh
                '''
                stash includes: 'org.eclipse.justj.*.tar.gz', name: 'mac-aarch64-stash'
              }
            }
          }
        }
      }
    }

    stage('Compose JREs') {
      when {
        environment name: 'JUSTJ_MANIFEST_URL', value: ''
        not {environment name: 'BUILD_TYPE', value: 'release' }
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        not { environment name: 'BUILD_NUMBER', value: '1' }
      }

      steps {
        script {
          if (env.JDK_URLS_MACOS != '') {
            unstash 'mac-stash'
          }

          if (env.JDK_URLS_MACOS_AARCH64 != '') {
            unstash 'mac-aarch64-stash'
          }

          if (env.JDK_URLS_WINDOWS != '') {
            unstash 'win-stash'
          }

          if (env.JDK_URLS_LINUX_AARCH64 != '') {
            unstash 'linux-aarch64-stash'
          }

          // Look for the java.version property in each JRE's properties file, extract out just the major version, and boil those down to unique values.
          env.JAVA_MAJOR_VERSION = sh(returnStdout: true, script: 'echo $(for i in org.eclipse.justj.*.tar.gz; do tar -xOzf $i org.eclipse.justj.properties | grep "java.version=" | sed "s/^java.version=//g; s/[^0-9].*$//g"; done | sort -u)').trim()
          env.JUSTJ_PUBLISH_LOCATION = "${env.PUBLISH_LOCATION_PREFIX}/${env.JAVA_MAJOR_VERSION}"
          env.JUSTJ_JRE_PUBLISH_LOCATION = "${env.JUSTJ_PUBLISH_LOCATION}/downloads/${env.JUSTJ_BUILD_TIME_STAMP}"
        }

        sh '''
          # Check that there is only one major version present.
          echo "JAVA_MAJOR_VERSION='$JAVA_MAJOR_VERSION'"
          echo "JUSTJ_PUBLISH_LOCATION='$JUSTJ_PUBLISH_LOCATION'"
          echo "JUSTJ_JRE_PUBLISH_LOCATION='$JUSTJ_JRE_PUBLISH_LOCATION'"
          if [[ $(echo $JAVA_MAJOR_VERSION | wc -w) == 1 ]]; then
            echo "One Java major version."
          else
            echo "Inconsistent Java major versions."
            exit 1
          fi
          '''
        sh 'ls org.eclipse.justj.*.tar.gz > justj.manifest'
        dir('releng/org.eclipse.justj.releng/index') {
          sh '''
            mvn --no-transfer-progress -Djustj.manifest.location=../../../justj.manifest -Djustj.manifest.url=$JUSTJ_URL/$JUSTJ_JRE_PUBLISH_LOCATION/justj.manifest clean verify
            '''
        }

        archiveArtifacts 'org.eclipse.justj.*.tar.gz'
        archiveArtifacts 'justj.manifest'
        archiveArtifacts 'index.html'

        sshagent(['projects-storage.eclipse.org-bot-ssh']) {
          sh '''
            ssh genie.justj@projects-storage.eclipse.org "
            mkdir -p $JUSTJ_STORAGE_LOCATION/$JUSTJ_JRE_PUBLISH_LOCATION
            "

            scp index.html justj.manifest org.eclipse.justj.*.tar.gz genie.justj@projects-storage.eclipse.org:$JUSTJ_STORAGE_LOCATION/$JUSTJ_JRE_PUBLISH_LOCATION

            ssh genie.justj@projects-storage.eclipse.org "
              mkdir -p $JUSTJ_STORAGE_LOCATION/$JUSTJ_PUBLISH_LOCATION/downloads/latest
              cd $JUSTJ_STORAGE_LOCATION/$JUSTJ_PUBLISH_LOCATION/downloads/latest
              ls ../$JUSTJ_BUILD_TIME_STAMP/org.eclipse.justj.*.tar.gz > justj.manifest
              cp ../$JUSTJ_BUILD_TIME_STAMP/index.html .
              "
            '''
        }
      }
    }

    // Even if we are doing a release build, we must generate the infrastructure needed to publish the release.
    //
    stage('Reconcile/Generate JRE Model') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        not { environment name: 'BUILD_NUMBER', value: '1' }
      }
      steps {
        dir('model/org.eclipse.justj.model') {
          sh '''
            # Use the one we built just now or the one that was specified in the parameters.
            if [[ "$JUSTJ_MANIFEST_URL" == "" ]]; then
              sed 's%source=".*[.]manifest"%source="'$JUSTJ_URL/$JUSTJ_JRE_PUBLISH_LOCATION'/justj.manifest"%g' < justj.jregen > justj-transformed.jregen
            else
              sed 's%source=".*[.]manifest"%source="'$JUSTJ_MANIFEST_URL'"%g' < justj.jregen > justj-transformed.jregen
            fi
            cat justj-transformed.jregen
            mv justj-transformed.jregen justj.jregen
            mvn --no-transfer-progress clean verify
          '''
          archiveArtifacts 'justj.jregen,*-gen/'
        }
      }
    }

    stage('Build JRE p2 Repository') {
      when {
        environment name: 'PIPELINE_VERSION', value: pipelineVersion
        not { environment name: 'BUILD_NUMBER', value: '1' }
      }
      steps {
        sshagent(['projects-storage.eclipse.org-bot-ssh']) {
          dir('model/org.eclipse.justj.model/jre-gen') {
            sh '''
              if [[ $PROMOTE == false ]]; then
                promotion_argument='-Dorg.eclipse.justj.p2.manager.args='
              fi
              if [[ $BUILD_TYPE == 'release' ]]; then
                extra_argument='-DMAVEN_BUILD=false'
              fi
              mvn --no-transfer-progress $promotion_argument $extra_argument -Dorg.eclipse.justj.p2.manager.extra.args="-super $PUBLISH_LOCATION_PREFIX" -DPACK_AND_SIGN=true -Dorg.eclipse.justj.p2.manager.build.url=$JOB_URL -Dorg.eclipse.justj.p2.manager.relative=$JUSTJ_PUBLISH_LOCATION/updates -Dbuild.type=$BUILD_TYPE -Dgit.commit=$GIT_COMMIT -Dbuild.id=$BUILD_NUMBER clean verify
              '''
            script {
              if (params.BUILD_TYPE != 'release') {
                dir('releng/org.eclipse.justj.site/target') {
                  archiveArtifacts 'repository/,org.eclipse.justj.site*.zip'
                }
              }
            }
          }
        }
      }
    }
  }

  post {
    failure {
      mail to: 'ed.merks@gmail.com',
      subject: "[JustJ CI] Build Failure ${currentBuild.fullDisplayName}",
      mimeType: 'text/html',
      body: "Project: ${env.JOB_NAME}<br/>Build Number: ${env.BUILD_NUMBER}<br/>Build URL: ${env.BUILD_URL}<br/>Console: ${env.BUILD_URL}/console"
    }
    fixed {
      mail to: 'ed.merks@gmail.com',
      subject: "[JustJ CI] Back to normal ${currentBuild.fullDisplayName}",
      mimeType: 'text/html',
      body: "Project: ${env.JOB_NAME}<br/>Build Number: ${env.BUILD_NUMBER}<br/>Build URL: ${env.BUILD_URL}<br/>Console: ${env.BUILD_URL}/console"
    }
    cleanup {
      deleteDir()
    }
  }
}

def pretty(string) {
  return string.replaceAll("^\r?\n", "").replaceAll("\r?\n\$", "").replace("\r", "").stripIndent()
}

def update(map1, map2) {
  def result = map1.clone()
  result.putAll(map2)
  return result
}

def buttons(list) {
  // Styling links as buttons.
  //
  def buttonStyle = '''
     margin-left: 2em;
     margin-top: 1ex;
     margin-bottom: 1ex;
     font-weight: bold;
     border: 1px solid Chocolate;
     background-color: DarkOrange;
     color: white;
     padding: 0.25ex 0.25em;
     text-align: center;
     text-decoration: none;
     display: inline-block;
   '''.replaceAll("\\s+", " ").trim()

  def result = ""
  list.each {
    result +=  "\n<a href='parambuild?${parambuild(it)}' style='${buttonStyle}'>${it.label}</a>"
  }
  return result
}

def parambuild(arguments) {
  def result = ""
  arguments.each { entry ->
    // Ignore lower case entries
    if (entry.key.matches("[A-Z0-9_]+")) {
      if (!result.isEmpty()) {
        result += "&"
      }
      result += entry.key
      result += "="
      result += encode(entry.value);
    }
  }
  return result
}

def encode(string) {
  return string.replace("\r", "").replaceAll("^\n", "").replaceAll("\\s+\$", "").stripIndent().replace("\r", "").replace("%", "%25").replace("&", "%26").replace("\n", "%0A").replace("+", "%2B").replace(" ", "+")
}

Back to the top