From f2ecde098be5c9e6aed9c83f633593f7bddbcd46 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:34:11 -0800 Subject: [PATCH 1/9] tasks.register --- plugins/build.gradle | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index 94680690..64e4c374 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -86,7 +86,7 @@ subprojects { /* * Creates plugin zip and json meta file in plugin `build/libs` directory */ - task makeZip(type: Jar) { + tasks.register('makeZip', Jar) { into('classes') { with jar } into('lib') { from configurations.runtimeClasspath } manifest.from file('src/resources/META-INF/MANIFEST.MF') @@ -94,21 +94,26 @@ subprojects { preserveFileTimestamps = false reproducibleFileOrder = true + String pluginVersion = project.version + String archiveName = "${project.name}-${pluginVersion}" + String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${project.version}/${archiveName}.zip" + String zipName = "$buildDir/libs/${archiveName}.zip" + String jsonName = "$buildDir/libs/${archiveName}-meta.json" doLast { // create the meta file - final zip = new File("$buildDir/libs/${project.name}-${project.version}.zip") - final json = new File("$buildDir/libs/${project.name}-${project.version}-meta.json") + final zip = new File(zipName) + final json = new File(jsonName) json.text = """\ { -"version": "${project.version}", +"version": "${pluginVersion}", "date": "${timestamp}", -"url": "https://github.com/${github_organization}/${project.name}/releases/download/${project.version}/${project.name}-${project.version}.zip", +"url": downloadUrl, "requires": "${metaFromManifest('Plugin-Requires', file('src/resources/META-INF/MANIFEST.MF'))}", "sha512sum": "${computeSha512(zip)}" } """ } - outputs.file("$buildDir/libs/${project.name}-${project.version}.zip") + outputs.file(zipName) } /* From ba965aefb0f4bba4f7949b34c6c57f3fcf9072ff Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:39:50 -0800 Subject: [PATCH 2/9] zipFilePath --- plugins/build.gradle | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index 64e4c374..aa489476 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -82,6 +82,15 @@ subprojects { tasks.withType(Jar).configureEach { duplicatesStrategy = DuplicatesStrategy.INCLUDE } + + /* + * Set project variables for the plugin + */ + + String pluginVersion = project.version + String archiveName = "${project.name}-${pluginVersion}" + String zipFilePath = "$buildDir/libs/${archiveName}.zip" + String jsonFilePath = "$buildDir/libs/${archiveName}-meta.json" /* * Creates plugin zip and json meta file in plugin `build/libs` directory @@ -94,15 +103,11 @@ subprojects { preserveFileTimestamps = false reproducibleFileOrder = true - String pluginVersion = project.version - String archiveName = "${project.name}-${pluginVersion}" String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${project.version}/${archiveName}.zip" - String zipName = "$buildDir/libs/${archiveName}.zip" - String jsonName = "$buildDir/libs/${archiveName}-meta.json" doLast { // create the meta file - final zip = new File(zipName) - final json = new File(jsonName) + final zip = new File(zipFilePath) + final json = new File(jsonFilePath) json.text = """\ { "version": "${pluginVersion}", @@ -113,7 +118,7 @@ subprojects { } """ } - outputs.file(zipName) + outputs.file(zipFilePath) } /* @@ -134,8 +139,7 @@ subprojects { tasks.named('makeZip').get().outputs.files.singleFile } into "$buildDir/plugins" - outputs.file("$buildDir/plugins/${project.name}-${project.version}.zip") - def zipFilePath = "$buildDir/plugins/${project.name}-${project.version}.zip" + outputs.file(zipFilePath) def destDirPath = "$buildDir/plugins/${project.name}-${project.version}" doLast { @@ -154,7 +158,7 @@ subprojects { dependsOn tasks.named('processResources') // Ensure resources are processed doFirst { destinationDirectory.get().asFile.mkdirs() - println "Inputs:" + println "makeZip.inputs:" println " Classes: ${tasks.named('classes').get().outputs.files.files}" println " Resources: ${tasks.named('processResources').get().outputs.files.files}" } @@ -163,10 +167,7 @@ subprojects { /* * "install" the plugin the project root build/plugins directory */ - def providerList = [ - "$buildDir/libs/${project.name }-${project.version }.zip", - "$buildDir/libs/${project.name}-${project.version}-meta.json" - ] + def providerList = [ zipFilePath, jsonFilePath] project.parent.tasks.getByName('assemble').dependsOn << copyPluginZip task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { assets = providers.provider { providerList } as Provider> From d117b114f0d99e32f20ef59ea183b2038b32d3b1 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:30:32 -0800 Subject: [PATCH 3/9] pluginsDir --- plugins/build.gradle | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index aa489476..49d991da 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -91,6 +91,7 @@ subprojects { String archiveName = "${project.name}-${pluginVersion}" String zipFilePath = "$buildDir/libs/${archiveName}.zip" String jsonFilePath = "$buildDir/libs/${archiveName}-meta.json" + String pluginsDir = "$buildDir/plugins" /* * Creates plugin zip and json meta file in plugin `build/libs` directory @@ -103,7 +104,7 @@ subprojects { preserveFileTimestamps = false reproducibleFileOrder = true - String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${project.version}/${archiveName}.zip" + String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${pluginVersion}/${archiveName}.zip" doLast { // create the meta file final zip = new File(zipFilePath) @@ -112,7 +113,7 @@ subprojects { { "version": "${pluginVersion}", "date": "${timestamp}", -"url": downloadUrl, +"url": "${downloadUrl}", "requires": "${metaFromManifest('Plugin-Requires', file('src/resources/META-INF/MANIFEST.MF'))}", "sha512sum": "${computeSha512(zip)}" } @@ -138,9 +139,9 @@ subprojects { from { tasks.named('makeZip').get().outputs.files.singleFile } - into "$buildDir/plugins" + into pluginsDir outputs.file(zipFilePath) - def destDirPath = "$buildDir/plugins/${project.name}-${project.version}" + def destDirPath = "$pluginsDir/$archiveName" doLast { if (!file(zipFilePath).exists()) { From 68c28e9d17633fb3021ced46da6f061143c7053e Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:39:39 -0800 Subject: [PATCH 4/9] layout.buildDirectory.file --- plugins/build.gradle | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index 49d991da..b0b1b55b 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -89,9 +89,10 @@ subprojects { String pluginVersion = project.version String archiveName = "${project.name}-${pluginVersion}" - String zipFilePath = "$buildDir/libs/${archiveName}.zip" - String jsonFilePath = "$buildDir/libs/${archiveName}-meta.json" - String pluginsDir = "$buildDir/plugins" + File zipFile = layout.buildDirectory.file("libs/${archiveName}.zip").get().asFile + File jsonFile = layout.buildDirectory.file("libs/${archiveName}-meta.json").get().asFile + File pluginsDir = layout.buildDirectory.dir("plugins").get().asFile + String zipFilePath = zipFile.absolutePath /* * Creates plugin zip and json meta file in plugin `build/libs` directory @@ -107,15 +108,13 @@ subprojects { String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${pluginVersion}/${archiveName}.zip" doLast { // create the meta file - final zip = new File(zipFilePath) - final json = new File(jsonFilePath) - json.text = """\ + jsonFile.text = """\ { "version": "${pluginVersion}", "date": "${timestamp}", "url": "${downloadUrl}", "requires": "${metaFromManifest('Plugin-Requires', file('src/resources/META-INF/MANIFEST.MF'))}", -"sha512sum": "${computeSha512(zip)}" +"sha512sum": "${computeSha512(zipFile)}" } """ } @@ -139,10 +138,9 @@ subprojects { from { tasks.named('makeZip').get().outputs.files.singleFile } - into pluginsDir + into pluginsDir.absolutePath outputs.file(zipFilePath) - def destDirPath = "$pluginsDir/$archiveName" - + def destDirPath = new File(pluginsDir, archiveName).absolutePath doLast { if (!file(zipFilePath).exists()) { throw new GradleException("File ${zipFilePath} does not exist! Cannot unzip.") @@ -168,7 +166,7 @@ subprojects { /* * "install" the plugin the project root build/plugins directory */ - def providerList = [ zipFilePath, jsonFilePath] + def providerList = [ zipFilePath, jsonFile.absolutePath] project.parent.tasks.getByName('assemble').dependsOn << copyPluginZip task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { assets = providers.provider { providerList } as Provider> From bba2d8ddeccc55b49c46ecb45026ef8f8ed1edef Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:42:16 -0800 Subject: [PATCH 5/9] remove zipFilePath --- plugins/build.gradle | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index b0b1b55b..c8eddf4b 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -92,7 +92,6 @@ subprojects { File zipFile = layout.buildDirectory.file("libs/${archiveName}.zip").get().asFile File jsonFile = layout.buildDirectory.file("libs/${archiveName}-meta.json").get().asFile File pluginsDir = layout.buildDirectory.dir("plugins").get().asFile - String zipFilePath = zipFile.absolutePath /* * Creates plugin zip and json meta file in plugin `build/libs` directory @@ -118,7 +117,7 @@ subprojects { } """ } - outputs.file(zipFilePath) + outputs.file(zipFile) } /* @@ -139,14 +138,14 @@ subprojects { tasks.named('makeZip').get().outputs.files.singleFile } into pluginsDir.absolutePath - outputs.file(zipFilePath) + outputs.file(zipFile) def destDirPath = new File(pluginsDir, archiveName).absolutePath doLast { - if (!file(zipFilePath).exists()) { - throw new GradleException("File ${zipFilePath} does not exist! Cannot unzip.") + if (!zipFile.exists()) { + throw new GradleException("File ${zipFile} does not exist! Cannot unzip.") } ant.unzip( - src: zipFilePath, + src: zipFile.absolutePath, dest: destDirPath ) } @@ -166,7 +165,7 @@ subprojects { /* * "install" the plugin the project root build/plugins directory */ - def providerList = [ zipFilePath, jsonFile.absolutePath] + def providerList = [ zipFile.absolutePath, jsonFile.absolutePath] project.parent.tasks.getByName('assemble').dependsOn << copyPluginZip task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { assets = providers.provider { providerList } as Provider> From cc7617c068d0e86fb0531e6a2b9ca31756ea145f Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:46:24 -0800 Subject: [PATCH 6/9] reformat --- plugins/build.gradle | 87 +++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index c8eddf4b..b62dd8af 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -15,11 +15,9 @@ import java.time.format.DateTimeFormatter * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + * of any kind, either express or implied. + * See the License for specific language governing permissions and limitations. */ plugins { @@ -28,14 +26,19 @@ plugins { id 'io.nextflow.nf-build-plugin' version '1.0.1' } -ext.github_organization = project.findProperty('github_organization') ?: 'nextflow-io' -ext.github_username = project.findProperty('github_username') ?: 'pditommaso' -ext.github_access_token = project.findProperty('github_access_token') ?: System.getenv('GITHUB_TOKEN') -ext.github_commit_email = project.findProperty('github_commit_email') ?: 'paolo.ditommaso@gmail.com' -ext.github_index_url = "https://github.com/${github_organization}/plugins/main/plugins.json" as GStringImpl +/* Project Constants */ +ext { + github_organization = project.findProperty('github_organization') ?: 'nextflow-io' + github_username = project.findProperty('github_username') ?: 'pditommaso' + github_access_token = project.findProperty('github_access_token') ?: System.getenv('GITHUB_TOKEN') + github_commit_email = project.findProperty('github_commit_email') ?: 'paolo.ditommaso@gmail.com' + github_index_url = "https://github.com/${github_organization}/plugins/main/plugins.json" as GStringImpl +} +// Disable default JAR generation jar.enabled = false +/* Utility Functions */ static String computeSha512(File file) { if (!file.exists()) { throw new GradleException("Missing file: $file -- cannot compute SHA-512") @@ -49,7 +52,9 @@ static String now() { List allPlugins() { def plugins = [] - new File(rootProject.rootDir, 'plugins') .eachDir { if (it.name.startsWith('nf-')) plugins.add(it.name) } + new File(rootProject.rootDir, 'plugins').eachDir { + if (it.name.startsWith('nf-')) plugins.add(it.name) + } return plugins } @@ -59,7 +64,7 @@ String metaFromManifest(String meta, File file) { def m = regex.matcher(str) if (m.find()) { def ver = m.group(1) - println "Set plugin '${file.parentFile.parentFile.parentFile.parentFile.name}' version=${ver}" + println "Set plugin '${file.parentFile.parentFile.parentFile.parentFile.name}' version=$ver" return ver } throw new GradleException("Cannot find '$meta' for plugin: $file") @@ -67,6 +72,7 @@ String metaFromManifest(String meta, File file) { def timestamp = now() +/* Configure Subprojects */ subprojects { apply plugin: 'java' apply plugin: 'groovy' @@ -82,20 +88,15 @@ subprojects { tasks.withType(Jar).configureEach { duplicatesStrategy = DuplicatesStrategy.INCLUDE } - - /* - * Set project variables for the plugin - */ + /* Plugin Variables */ String pluginVersion = project.version String archiveName = "${project.name}-${pluginVersion}" File zipFile = layout.buildDirectory.file("libs/${archiveName}.zip").get().asFile File jsonFile = layout.buildDirectory.file("libs/${archiveName}-meta.json").get().asFile File pluginsDir = layout.buildDirectory.dir("plugins").get().asFile - /* - * Creates plugin zip and json meta file in plugin `build/libs` directory - */ + /* Task to Create Plugin Zip and Metadata */ tasks.register('makeZip', Jar) { into('classes') { with jar } into('lib') { from configurations.runtimeClasspath } @@ -106,54 +107,49 @@ subprojects { String downloadUrl = "https://github.com/${github_organization}/${project.name}/releases/download/${pluginVersion}/${archiveName}.zip" doLast { - // create the meta file + // Generate the metadata file jsonFile.text = """\ { -"version": "${pluginVersion}", -"date": "${timestamp}", -"url": "${downloadUrl}", -"requires": "${metaFromManifest('Plugin-Requires', file('src/resources/META-INF/MANIFEST.MF'))}", -"sha512sum": "${computeSha512(zipFile)}" + "version": "${pluginVersion}", + "date": "${timestamp}", + "url": "${downloadUrl}", + "requires": "${metaFromManifest('Plugin-Requires', file('src/resources/META-INF/MANIFEST.MF'))}", + "sha512sum": "${computeSha512(zipFile)}" } """ } outputs.file(zipFile) } - /* - * Copy the plugin dependencies in the subproject `build/target/libs` directory - */ + /* Task to Copy Plugin Dependencies */ tasks.register('copyPluginLibs', Sync) { from configurations.runtimeClasspath into 'build/target/libs' duplicatesStrategy = DuplicatesStrategy.EXCLUDE } - /* - * Copy the plugin in the project root build/plugins directory - */ + /* Task to Copy Plugin ZIP to Plugins Directory */ tasks.register('copyPluginZip', Copy) { dependsOn project.tasks.named('makeZip') - from { - tasks.named('makeZip').get().outputs.files.singleFile - } + from { tasks.named('makeZip').get().outputs.files.singleFile } into pluginsDir.absolutePath outputs.file(zipFile) + def destDirPath = new File(pluginsDir, archiveName).absolutePath doLast { if (!zipFile.exists()) { throw new GradleException("File ${zipFile} does not exist! Cannot unzip.") } ant.unzip( - src: zipFile.absolutePath, - dest: destDirPath + src: zipFile.absolutePath, + dest: destDirPath ) } } tasks.named('makeZip').configure { - dependsOn tasks.named('classes') // Ensure compiled classes are available - dependsOn tasks.named('processResources') // Ensure resources are processed + dependsOn tasks.named('classes') // Ensure compiled classes are available + dependsOn tasks.named('processResources') // Ensure processed resources doFirst { destinationDirectory.get().asFile.mkdirs() println "makeZip.inputs:" @@ -162,10 +158,8 @@ subprojects { } } - /* - * "install" the plugin the project root build/plugins directory - */ - def providerList = [ zipFile.absolutePath, jsonFile.absolutePath] + /* "Install" the Plugin */ + def providerList = [zipFile.absolutePath, jsonFile.absolutePath] project.parent.tasks.getByName('assemble').dependsOn << copyPluginZip task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { assets = providers.provider { providerList } as Provider> @@ -178,13 +172,14 @@ subprojects { } } -tasks.register('upload') { dependsOn[subprojects.uploadPlugin] } +/* Upload Task */ +tasks.register('upload') { + dependsOn subprojects.uploadPlugin +} classes.dependsOn subprojects.copyPluginLibs -/* - * Merge and publish the plugins index file - */ +/* Publish Plugins Index File */ tasks.register('publishIndex', GithubRepositoryPublisher) { indexUrl = github_index_url repos = allPlugins() From 330827c1b9a7f93e7f65bf96971a3d698456440f Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:49:48 -0800 Subject: [PATCH 7/9] global properties --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e1b78046..41b277e9 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,7 @@ install: compile # publish: - echo "Ensure you have set 'github_organization=' in gradle.properties" - ls gradle.properties # create locally or globally if it does not exist + echo "Ensure you have set 'github_organization=' in ~/.gradle/gradle.properties" + ls $(HOME)/.gradle/gradle.properties # create locally or globally if it does not exist ./gradlew :plugins:$(PROJECT):upload ./gradlew :plugins:publishIndex From 1a80ba1b7dc34767015eface19ededd7ca045569 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:49:56 -0800 Subject: [PATCH 8/9] named('assemble'). --- plugins/build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index b62dd8af..229fd221 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -160,7 +160,9 @@ subprojects { /* "Install" the Plugin */ def providerList = [zipFile.absolutePath, jsonFile.absolutePath] - project.parent.tasks.getByName('assemble').dependsOn << copyPluginZip + project.parent.tasks.named('assemble').configure { + dependsOn(copyPluginZip) + } task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { assets = providers.provider { providerList } as Provider> release = providers.provider { project.version } as Provider From ccd27eb5cdb0f978a173886f69519eb4945372fb Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:52:35 -0800 Subject: [PATCH 9/9] tasks.register('uploadPlugin' --- plugins/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/build.gradle b/plugins/build.gradle index 229fd221..47d18a70 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -163,7 +163,8 @@ subprojects { project.parent.tasks.named('assemble').configure { dependsOn(copyPluginZip) } - task uploadPlugin(type: GithubUploader, dependsOn: makeZip) { + tasks.register('uploadPlugin', GithubUploader) { + dependsOn tasks.named('makeZip') // Lazy dependency assets = providers.provider { providerList } as Provider> release = providers.provider { project.version } as Provider repo = providers.provider { project.name }