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 dependencies {
23 compile project(path: ':installers:mac:tar', configuration: 'buildTar')
24 }
25
26 // Copy task cannot be used here because Gradle does not preserve the symlink
27 task retrieveArtifacts(type: Exec) {
28 // Set environment variable CORRETTO_ARTIFACTS_PATH to the path of "amazon-corretto-<version>.jdk" to be packaged
29 def artifactsPath = System.getenv("CORRETTO_ARTIFACTS_PATH")
30 workingDir buildRoot
31 if (artifactsPath == null) {
32 dependsOn project.configurations.compile
33 commandLine "tar", "xf", project.configurations.compile.singleFile
34 } else {
35 commandLine "cp", "-Rf", "${artifactsPath}", buildRoot
36 }
37 }
38
39 task copyResources(type: Copy) {
40 from "."
41 include 'resources/**'
42 into buildRoot
43 }
44
45 task inflatePkgTemplate {
46 dependsOn copyResources
47 doLast {
48 copy {
49 from('templates/distribution.xml.template') {
50 rename { file -> file.replace('.template', '') }
51 filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: ["full": project.version.full, "major": project.version.major, "macos-arch": (correttoArch == "aarch64" ? "arm64" : "x86_64")])
52 }
53 into "${buildRoot}/resources"
54 }
55
56 copy {
57 from('templates/introduction.html.template') {
58 rename { file -> file.replace('.template', '') }
59 filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: project.version)
60 }
61 into "${buildRoot}/resources"
62 }
63 }
64 }
65
66 task setupDirectories {
67 dependsOn retrieveArtifacts
68 doLast {
69 exec {
70 workingDir buildRoot
71 commandLine "mkdir", "-p", "pkgroot/"
72 }
73
74 exec {
75 workingDir buildRoot
76 commandLine "cp", "-Rf", "amazon-corretto-${project.version.major}.jdk", "pkgroot/"
77 }
78
79 exec {
80 workingDir buildRoot
81 commandLine "mkdir", "-p", "build/components"
82 }
83 }
84 }
85
86 task generateInstaller {
87 dependsOn retrieveArtifacts
88 dependsOn copyResources
89 dependsOn inflatePkgTemplate
90 dependsOn setupDirectories
91 outputs.dir distributionDir
92
93 doLast {
94 exec {
95 workingDir buildRoot
96 commandLine "pkgbuild",
97 "--root", "pkgroot",
98 "--identifier", "com.amazon.corretto.${project.version.major}",
99 "--version", project.version.full,
100 "--ownership", "recommended",
101 "--scripts", "resources",
102 "--install-location", "/Library/Java/JavaVirtualMachines/",
103 "build/components/amazon-corretto-${project.version.major}.jdk.pkg"
104 }
105
106 exec {
107 workingDir buildRoot
108 commandLine "productbuild",
109 "--distribution", "resources/distribution.xml",
110 "--resources", "resources",
111 "--package-path", "build/components",
112 "--version", project.version.full,
113 "${distributionDir}/amazon-corretto-${project.version.full}-macosx-${correttoArch}.pkg"
114 }
115 }
116 }
117
118 build.dependsOn generateInstaller
119
120 artifacts {
121 archives file: generateInstaller.outputs.getFiles().getSingleFile(), builtBy: generateInstaller
122 }