@@ -143,37 +143,47 @@ task packageDebugSymbols(type: Tar) {
143143 }
144144}
145145
146- task packageBuildResults ( type : Tar ) {
146+ task packageBuildResults {
147147 description ' Compresses the JDK image and puts the results in build/distributions.'
148148 dependsOn packageDebugSymbols
149149 dependsOn bundleThirdPartyBinaries
150- archiveName " ${ project.correttoJdkArchiveName} .tar.gz"
151- compression Compression . GZIP
152- from(buildRoot) {
153- include project. rootFiles
154- into project. correttoJdkArchiveName
155- }
156- from(jdkResultingImage) {
157- include ' bin/**'
158- include ' conf/**'
159- include ' include/**'
160- include ' jmods/**'
161- include ' lib/**'
162- include ' man/man1/**'
163- include ' release'
164- exclude ' **/*.diz'
165- into project. correttoJdkArchiveName
166- }
167150
168- // Copy legal directory specifically to set permission correctly.
169- // See https://github.com/corretto/corretto-11/issues/129
170- from(" ${ jdkResultingImage} /legal" ) {
171- include ' **'
172- fileMode 0444
173- into " ${ project.correttoJdkArchiveName} /legal"
151+ def outputTarFile = " ${ distributionDir} /${ project.correttoJdkArchiveName} .tar"
152+ def prefix = project. correttoJdkArchiveName
153+
154+ // Omit legal files in the root of the package
155+ def javaBaseLegalFiles = file(" $jdkResultingImage /legal/java.base" ). listFiles(). findAll { it. isFile() }. collect { it. name };
156+ def rootFilesNoLegal = project. rootFiles. findAll { ! (it in javaBaseLegalFiles) }
157+
158+ inputs. files(rootFilesNoLegal)
159+ inputs. dir(jdkResultingImage)
160+ outputs. file(" ${ outputTarFile} .gz" )
161+
162+ doLast {
163+ def tarSymlinkOption = project. keepSymlinks ? ' ' : ' -L'
164+
165+ // -s option adds prefix to each file name, but not to symlink targets (S modifier)
166+ def script = """
167+ set -ex
168+
169+ output=`realpath "$outputTarFile "`
170+ rm -f "\$ output.gz"
171+ pushd "$buildRoot "
172+ bsdtar -cvf "\$ output" -s '|^|$prefix /|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' "${ rootFilesNoLegal.join('" "')} "
173+ popd
174+ pushd "$jdkResultingImage "
175+ bsdtar -rvf "\$ output" -s '|^|$prefix /|S' --exclude '*.diz' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' bin conf include jmods lib man/man1
176+ find legal -type f | xargs -n100 chmod 444
177+ find legal -type d | xargs -n100 chmod 755
178+ bsdtar -rvf "\$ output" -s '|^|$prefix /|S' $tarSymlinkOption --uid 0 --uname '' --gid 0 --gname '' legal
179+ popd
180+ gzip -9 "\$ output"
181+ """
182+
183+ runCmdAndLog(project, [' bash' , ' -c' , script])
174184 }
175185}
176186
177187artifacts {
178- archives packageBuildResults
188+ archives file : packageBuildResults . outputs . files . singleFile, builtBy : packageBuildResults
179189}
0 commit comments