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 plugins {
 23     id 'com.netflix.nebula.ospackage' version 'latest.release'
 24 }
 25 
 26 dependencies {
 27     compile project(path: ':installers:linux:universal:tar', configuration: 'archives')
 28 }
 29 
 30 ext {
 31     switch (project.correttoArch) {
 32         case 'aarch64':
 33             arch_deb = 'arm64'
 34             break;
 35         case 'x86':
 36             arch_deb = "i386"
 37             break
 38         case 'x64':
 39             arch_deb = 'amd64'
 40             break
 41     }
 42 }
 43 
 44 def jvmDir = '/usr/lib/jvm'
 45 def jdkInstallationDirName = "java-${project.version.major}-amazon-corretto"
 46 def jdkHome = "${jvmDir}/${jdkInstallationDirName}".toString()
 47 def jdkBinaryDir = "${buildRoot}/${project.correttoJdkArchiveName}"
 48 def jdkPackageName = "java-${project.version.major}-amazon-corretto-jdk"
 49 
 50 def alternativesPriority = String.format("1%2s%2s%3s", project.version.major, project.version.minor, project.version.security).replace(' ', '0')
 51 
 52 def jinfoName = ".${jdkInstallationDirName}.jinfo"
 53 
 54 ospackage {
 55     // Valid version must start with a digit and only contain [A-Za-z0-9.+:~-]
 56     // See http://manpages.ubuntu.com/manpages/artful/en/man5/deb-version.5.html
 57     version = project.version.upstream
 58     release = project.version.revision
 59 
 60     url = "${packageInfo.url}"
 61     vendor = "${packageInfo.vendor}"
 62     packager = "${packageInfo.packager}"
 63     license = "${packageInfo.license}"
 64     buildHost = "${packageInfo.buildHost}"
 65     maintainer = "${packageInfo.maintainer}"
 66     packageGroup = 'java'
 67     priority = 'optional'
 68     user = 'root'
 69     permissionGroup = 'root'
 70     epoch = 1
 71     arch = arch_deb
 72     multiArch = SAME
 73 }
 74 
 75 /**
 76  * Uncompress and copy the universal Corretto artifact
 77  * tar for DEB packaging.
 78  */
 79 task extractUniversalTar(type: Copy) {
 80     dependsOn project.configurations.compile
 81     from tarTree(project.configurations.compile.singleFile)
 82     into buildRoot
 83 }
 84 
 85 /**
 86  * Populate version numbers, java home and alternatives
 87  * priority to postin_jdk.sh.template and preun_jdk.sh.template.
 88  * Create script copies under build root scripts folder.
 89  */
 90 task inflateDebScriptTemplate(type: Copy) {
 91     dependsOn extractUniversalTar
 92     // In trusty repo, openjdk7 has priority 1071 and openjdk6 has 1061
 93     // Corretto uses the same priority in both rpm and deb
 94     def priority =
 95             from('scripts') {
 96                 include '**/*.template'
 97                 rename { file -> file.replace('.template', '') }
 98                 filter(org.apache.tools.ant.filters.ReplaceTokens,
 99                         tokens: project.version + [java_home: jdkHome, alternatives_priority: alternativesPriority,
100                                                    jdk_tools: jdkTools.join(' ')])
101             }
102     into "${buildRoot}/scripts"
103 }
104 
105 /**
106  * Inflate jinfo file used by update-java-alternatives command.
107  * Create script copy under buildRoot/jinfo folder. See
108  * http://manpages.ubuntu.com/manpages/xenial/man8/update-java-alternatives.8.html#files
109  */
110 task inflateJinfoTemplate(type: Copy) {
111     from('jinfo') {
112         include '**/*.template'
113         rename('jinfo.template', jinfoName)
114         filter(org.apache.tools.ant.filters.ReplaceTokens,
115                 tokens: project.version + [java_home     : jdkHome, alternatives_priority: alternativesPriority,
116                                            directory_name: jdkInstallationDirName.toString()])
117         expand(jdk_tools: jdkTools)
118     }
119     into "${buildRoot}/jinfo"
120 }
121 
122 /**
123  * Generate DEB for JDK, with package published under
124  * distributions folder.
125  */
126 task generateJdkDeb(type: Deb) {
127     description = 'Create the DEB package for Corretto JDK'
128     dependsOn inflateDebScriptTemplate
129     dependsOn inflateJinfoTemplate
130 
131     packageName = jdkPackageName
132     packageDescription = "Amazon Corretto\'s packaging of the OpenJDK ${project.version.major} code."
133     summary = "Amazon Corretto ${project.version.major} development environment"
134 
135     postInstall file("$buildRoot/scripts/postin_jdk.sh")
136     preUninstall file("$buildRoot/scripts/preun_jdk.sh")
137 
138     requires('java-common')
139     requires('zlib1g')
140     // jdk
141     provides('java-compiler')
142     provides('java-sdk')
143     provides('java5-sdk')
144     provides('java6-sdk')
145     provides('java7-sdk')
146     provides('java7-jdk')
147     provides('java8-jdk')
148     provides('java11-sdk')
149     17.upto(project.version.major.toInteger()) {
150       provides("java${it}-sdk")
151     }
152     // TODO: Move this to the jre when splitting the fat deb
153     provides('java-runtime')
154     provides('java5-runtime')
155     provides('java6-runtime')
156     provides('java7-runtime')
157     provides('java8-runtime')
158     provides('java11-runtime')
159     17.upto(project.version.major.toInteger()) {
160       provides("java${it}-runtime")
161     }
162     // TODO: Move this to the headless jre when splitting the fat deb
163     provides('java-runtime-headless')
164     provides('java5-runtime-headless')
165     provides('java6-runtime-headless')
166     provides('java7-runtime-headless')
167     provides('java8-runtime-headless')
168     provides('java11-runtime-headless')
169     17.upto(project.version.major.toInteger()) {
170       provides("java${it}-runtime-headless")
171     }
172 
173     from(jdkBinaryDir) {
174         include(project.configurationFiles)
175         // Deb actually uses configuationFile and not fileType see https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/118#issuecomment-656004360
176         // Path must be the fully qualified install path
177         configurationFile = project.configurationFiles.collect{ "${jdkHome}/${it}" }.join("\n")
178         into jdkHome
179     }
180 
181     from(jdkBinaryDir) {
182         into jdkHome
183         exclude 'legal'
184         exclude(project.configurationFiles)
185     }
186 
187     // Copy legal directory specifically to set permission correctly.
188     // See https://github.com/corretto/corretto-11/issues/129
189     from("${jdkBinaryDir}/legal") {
190         into "${jdkHome}/legal"
191         fileMode = 0444
192     }
193 
194     if (!project.excludeReadmeJavaSE) {
195         from("${jdkBinaryDir}/README.JAVASE") {
196             into jdkHome
197             fileMode = 0444
198         }
199     }
200 
201     from("${buildRoot}/jinfo") {
202         include '**/*.jinfo'
203         into jvmDir
204     }
205 }
206 
207 artifacts {
208     archives generateJdkDeb
209 }