1 /*
 2  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation. Amazon designates this
 8  * particular file as subject to the "Classpath" exception as provided
 9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 import groovy.text.GStringTemplateEngine
23 
24 dependencies {
25     compile project(path: ':openjdksrc', configuration: 'archives')
26 }
27 
28 def tarName = "java-${version.major}-amazon-corretto"
29 def tarVersion = "${version.major}.${version.minor}.${version.security}+${version.build}"
30 
31 def javaVersion = "${version.major}.${version.minor}.${version.security}"
32 def buildId = "${version.build}"
33 def releaseId = "${version.revision}"
34 /**
35  * Apply version numbers to the RPM spec file template and copy
36  * to the build root.
37  */
38 task inflateRpmSpec {
39     inputs.file 'java-amazon-corretto.spec.template'
40     outputs.file "$buildDir/java-${version.major}-amazon-corretto.spec"
41     doLast {
42         def renderedTemplate = new GStringTemplateEngine()
43                 .createTemplate(file('java-amazon-corretto.spec.template'))
44                 .make(
45                 [
46                     java_spec_version   : version.major,
47                     java_major_version   : version.major,
48                     java_security_version   : version.security,
49                     java_version        : javaVersion,
50                     build_id            : buildId,
51                     release_id          : releaseId,
52                     version_opt         : versionOpt,
53                     debug_level         : correttoDebugLevel,
54                     boot_jdk_major_version : version.major.toInteger() - 1,
55                     boot_jdk_major_v_backup : version.major.toInteger() - 2,
56                     experimental_feature: project.findProperty("corretto.experimental_feature") ?: "%{nil}",
57                     additional_configure_options: project.findProperty("corretto.additional_configure_options") ?: "%{nil}",
58                     zlib_option: project.findProperty("corretto.zlib_option") ?: "system",
59                     use_gcc_ver: project.findProperty("corretto.use_gcc_ver") ?: "%{nil}"
60                 ])
61         outputs.files.singleFile.text = renderedTemplate
62     }
63 }
64 
65 task copySourceTar(type: Tar) {
66     dependsOn project.configurations.compile, inflateRpmSpec
67     compression = Compression.GZIP
68     archiveFileName = project.configurations.compile.singleFile.name
69     from("$buildDir") {
70         include "java-${project.version.major}-amazon-corretto.spec"
71         into 'rpm'
72     }
73     from(tarTree(project.configurations.compile.singleFile)) {
74         into '/'
75     }
76     // Include the man pages tarball if it exists
77     from(file("${buildDir}/distributions/jdk${project.version.major}-manpages.tar.gz")) {
78         into '/'
79     }
80 }
81 
82 task rpmBuild(type: Exec) {
83     dependsOn copySourceTar
84     workingDir "$buildDir"
85     executable = '/usr/bin/rpmbuild'
86     args  = ['-vv',
87         '-bs',
88         '--define',
89         "dist .${project.findProperty('corretto.amzn_dist') ?: 'amzn2'}",
90         '--define',
91         "_topdir ${buildDir}/rpmbuild",
92         '--define',
93         "_sourcedir ${buildDir}/distributions",
94         '--define',
95         "_srcrpmdir ${buildDir}/distributions",
96         "java-${version.major}-amazon-corretto.spec"]
97 
98 }