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_redline = 'AARCH64'
 34             break;
 35         case 'x86':
 36             arch_redline = "i386"
 37             break
 38         case 'x64':
 39             arch_redline = 'x86_64'
 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}"
 47 def jdkBinaryDir = "${buildRoot}/${project.correttoJdkArchiveName}"
 48 def jdkPackageName = "java-${project.version.major}-amazon-corretto-devel"
 49 
 50 ospackage {
 51     version = project.version.upstream
 52     release = project.version.revision
 53 
 54     url = "${packageInfo.url}"
 55     vendor = "${packageInfo.vendor}"
 56     packager = "${packageInfo.packager}"
 57     license = "${packageInfo.license}"
 58     buildHost = "${packageInfo.buildHost}"
 59     user = 'root'
 60     permissionGroup = 'root'
 61     epoch = 1
 62     arch = arch_redline
 63     os = LINUX
 64     type = BINARY
 65 }
 66 
 67 /**
 68  * Uncompress and copy the universal Corretto artifact
 69  * tar for RPM packaging.
 70  */
 71 task extractUniversalTar(type: Copy) {
 72     dependsOn project.configurations.compile
 73     from tarTree(project.configurations.compile.singleFile)
 74     into buildRoot
 75 }
 76 
 77 /**
 78  * Populate version numbers, java home and alternatives
 79  * priority to postin_javac.sh.template and preun_javac.sh.template.
 80  * Create script copies under build root scripts folder.
 81  */
 82 task inflateRpmScriptTemplate(type: Copy) {
 83     dependsOn extractUniversalTar
 84     // Use the same priority as IcedTea JDK RPM distribution, based on java version
 85     def priority = String.format("1%2s%2s%3s", project.version.major, project.version.minor, project.version.security).replace(' ', '0')
 86     from('scripts') {
 87         include '**/*.template'
 88         rename { file -> file.replace('.template', '') }
 89         filter(org.apache.tools.ant.filters.ReplaceTokens,
 90                 tokens: project.version + [alternatives_priority: priority])
 91     }
 92     into "${buildRoot}/scripts"
 93 }
 94 
 95 /**
 96  * Generate RPM for JDK, with package published under
 97  * distributions folder.
 98  */
 99 task generateJdkRpm(type: Rpm) {
100     description = 'Create the RPM package for Corretto JDK'
101     dependsOn inflateRpmScriptTemplate
102     packageName = jdkPackageName
103     packageDescription = packageInfo.description
104     summary = "Amazon Corretto ${project.version.major} development environment"
105     packageGroup = 'Development/Tools'
106     // Remove after https://github.com/nebula-plugins/gradle-ospackage-plugin/issues/401 is merged and released
107     sourcePackage = "${jdkPackageName}-${project.version.major}.${project.version.minor}.${project.version.security}.${project.version.build}-${project.version.revision}.src.rpm"
108 
109     prefix(jdkHome)
110     postInstall file("$buildRoot/scripts/postin_java.sh")
111     postInstall file("$buildRoot/scripts/postin_javac.sh")
112     preUninstall file("$buildRoot/scripts/preun_java.sh")
113     preUninstall file("$buildRoot/scripts/preun_javac.sh")
114 
115     requires('zlib')
116 
117     provides(jdkPackageName, "${epoch}:${version}-${release}", EQUAL)
118     provides("java", "${epoch}:${version}-${release}", EQUAL)
119     provides("java-${project.version.major}-devel", "${epoch}:${version}", EQUAL)
120     provides("java-${project.version.major}-openjdk-devel", "${epoch}:${version}", EQUAL)
121     provides("java-${project.version.major}-openjdk-devel", "${epoch}:${version}-${release}", EQUAL)
122     provides("java-sdk-${project.version.major}", "${epoch}:${version}", EQUAL)
123     provides("java-sdk-${project.version.major}-openjdk", "${epoch}:${version}-${release}", EQUAL)
124     provides("java-${project.version.major}", "${epoch}:${version}", EQUAL)
125     provides("java-${project.version.major}-openjdk", "${epoch}:${version}", EQUAL)
126     provides("jre", "${epoch}:${version}", EQUAL)
127     provides("jre-${project.version.major}", "${epoch}:${version}", EQUAL)
128     provides("jre-${project.version.major}-openjdk", "${epoch}:${version}", EQUAL)
129 
130     from(jdkBinaryDir) {
131         include(project.configurationFiles)
132         fileType CONFIG | NOREPLACE
133         into jdkHome
134     }
135 
136     from(jdkBinaryDir) {
137         into jdkHome
138         exclude 'legal'
139         exclude(project.configurationFiles)
140     }
141 
142     // Copy legal directory specifically to set permission correctly.
143     // See https://github.com/corretto/corretto-11/issues/129
144     from("${jdkBinaryDir}/legal") {
145         into "${jdkHome}/legal"
146         fileMode = 0444
147     }
148 
149     if (!project.excludeReadmeJavaSE) {
150         from("${jdkBinaryDir}/README.JAVASE") {
151             into jdkHome
152             fileMode = 0444
153         }
154     }   
155 }
156 
157 artifacts {
158     archives generateJdkRpm
159 }