Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Verify bundle checksum in Liferay Workspace
// Make sure we can use the classes from the Download plugin, like the Verify below
buildscript {
repositories { jcenter() }
dependencies { classpath group: "de.undercouch", name: "gradle-download-task", version: "4.0.4" }
}
apply plugin: de.undercouch.gradle.tasks.download.DownloadTaskPlugin
[
'SHA-256': 'liferay.workspace.bundle.checksum[sha-256]',
'MD5': 'liferay.workspace.bundle.checksum[md5]',
].each { checksumAlgorithm, expectedSumPropName ->
// Verify checksum using given algorithm, but only if the project property
// with the expected checksum was provided
def expectedSum = findProperty(expectedSumPropName)
if (expectedSum) {
def bundleFileName = gradle.liferayWorkspace.bundleUrl.substring(gradle.liferayWorkspace.bundleUrl.lastIndexOf('/') + 1)
def verifyBundle = tasks.register("verifyBundle${checksumAlgorithm}", Verify) {
src new File(gradle.liferayWorkspace.bundleCacheDir, bundleFileName)
algorithm checksumAlgorithm
checksum expectedSum
doFirst {
logger.info "[workspace-extra] Verifying checksum of the used bundle file '${src}', as found in the bundleCacheDir"
}
}
tasks.findByName('downloadBundle').configure {
finalizedBy verifyBundle
}
}
}
@sustacek
Copy link
Author

sustacek commented Dec 2, 2020

Requires:

  • Gradle 5.x (because of tasks.register)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment