-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from nextflow-io/improve-gradle
Improve Gradle build
- Loading branch information
Showing
11 changed files
with
342 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import nextflow.gradle.plugins.NextflowPlugin | ||
|
||
apply plugin: NextflowPlugin | ||
|
||
ext{ | ||
github_organization = 'nextflow-io' | ||
github_username = project.findProperty('github_username') ?: 'abhi18av' | ||
github_access_token = project.findProperty('github_access_token') ?: System.getenv('GITHUB_TOKEN') | ||
github_commit_email = project.findProperty('github_commit_email') ?: '[email protected]' | ||
} | ||
|
||
nextflowPlugin{ | ||
githubOrganization = github_organization | ||
extensionPoints = [ | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
id 'groovy-gradle-plugin' | ||
id "io.nextflow.nf-build-plugin" version "1.0.1" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation 'commons-codec:commons-codec:1.15' | ||
} |
41 changes: 41 additions & 0 deletions
41
buildSrc/src/main/groovy/nextflow/gradle/plugins/GenerateIdxTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package nextflow.gradle.plugins | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
|
||
abstract class GenerateIdxTask extends DefaultTask{ | ||
|
||
@Internal | ||
abstract ListProperty<String> extensionPoints | ||
|
||
@OutputFile | ||
final abstract RegularFileProperty outputFile = | ||
project.objects.fileProperty().convention(project.layout.buildDirectory.file( | ||
"resources/main/META-INF/extensions.idx")) | ||
|
||
GenerateIdxTask() { | ||
setGroup('nextflow') | ||
} | ||
|
||
@TaskAction | ||
def runTask() { | ||
def output = outputFile.get().asFile | ||
|
||
if( extensionPoints.getOrElse([]).size() ){ | ||
output.text = extensionPoints.getOrElse([]).join('\n') | ||
return | ||
} | ||
|
||
def matcher = new SourcesMatcher(project) | ||
def extensionsClassName = matcher.pluginExtensions | ||
def traceClassName = matcher.traceObservers | ||
def all = extensionsClassName+traceClassName | ||
output.text = all.join('\n') | ||
} | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
buildSrc/src/main/groovy/nextflow/gradle/plugins/JsonPluginTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package nextflow.gradle.plugins | ||
|
||
import groovy.json.JsonOutput | ||
import org.apache.commons.codec.digest.DigestUtils | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Internal | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.api.tasks.bundling.Jar | ||
|
||
import java.time.OffsetDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
abstract class JsonPluginTask extends DefaultTask{ | ||
|
||
@Internal | ||
abstract Property<String> getDownloadUrl() | ||
|
||
@Internal | ||
final abstract RegularFileProperty zipFile = | ||
project.objects.fileProperty().convention(project.layout.buildDirectory.file( | ||
"plugin/${project.name}-${project.version}.zip")) | ||
|
||
@OutputFile | ||
final abstract RegularFileProperty outputFile = | ||
project.objects.fileProperty().convention(project.layout.buildDirectory.file( | ||
"plugin/${project.name}-${project.version}-meta.json")) | ||
|
||
|
||
JsonPluginTask(){ | ||
setGroup('nextflow') | ||
dependsOn 'zipPlugin' | ||
} | ||
|
||
|
||
protected String resolveURL(){ | ||
"${downloadUrl.get()}/${project.version}/${project.name}-${project.version}.zip" | ||
} | ||
|
||
protected static String now() { | ||
OffsetDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) | ||
} | ||
|
||
protected static String computeSha512(File file) { | ||
if( !file.exists() ) | ||
throw new GradleException("Missing file: $file -- cannot compute SHA-512") | ||
return DigestUtils.sha512Hex(file.bytes) | ||
} | ||
|
||
@TaskAction | ||
def runTask() { | ||
def jarTask = project.tasks.findByName('jar') as Jar | ||
def manifest = jarTask.manifest | ||
def json = [ | ||
version: "$project.version", | ||
date: now(), | ||
url: resolveURL(), | ||
requires: manifest.attributes['Plugin-Requires'], | ||
sha512sum: computeSha512(zipFile.get().asFile) | ||
] | ||
outputFile.get().asFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json)) | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
buildSrc/src/main/groovy/nextflow/gradle/plugins/NextflowPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nextflow.gradle.plugins | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
class NextflowPlugin implements Plugin<Project>{ | ||
|
||
@Override | ||
void apply(Project target) { | ||
|
||
NextflowPluginExtension nextflowPluginExtension = target.extensions.create('nextflowPlugin',NextflowPluginExtension) | ||
|
||
target.subprojects.find{it.name=="plugins"}.subprojects.each{ project -> | ||
project.tasks.register('zipPlugin', ZipPluginTask,{ | ||
|
||
}) | ||
project.tasks.register('unzipPlugin', UnzipPluginTask,{ | ||
|
||
}) | ||
project.tasks.register('jsonPlugin', JsonPluginTask, { | ||
downloadUrl = nextflowPluginExtension.downloadUrl | ||
}) | ||
project.tasks.register('generateIdx', GenerateIdxTask, { | ||
extensionPoints = nextflowPluginExtension.extensionPoints | ||
}) | ||
project.tasks.findByName("processResources")?.dependsOn(project.tasks.findByName("generateIdx")) | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
buildSrc/src/main/groovy/nextflow/gradle/plugins/NextflowPluginExtension.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package nextflow.gradle.plugins | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.provider.ListProperty | ||
import org.gradle.api.provider.Property | ||
|
||
class NextflowPluginExtension { | ||
|
||
final Property<String> downloadUrl | ||
|
||
final Property<String> nextflowVersion | ||
|
||
final Property<String> githubOrganization | ||
|
||
final Property<String> pluginClassName | ||
|
||
final ListProperty<String> extensionPoints | ||
|
||
final private Project project | ||
|
||
NextflowPluginExtension(Project project){ | ||
this.project = project | ||
nextflowVersion = project.objects.property(String) | ||
downloadUrl = project.objects.property(String) | ||
githubOrganization = project.objects.property(String) | ||
pluginClassName = project.objects.property(String) | ||
extensionPoints = project.objects.listProperty(String) | ||
} | ||
|
||
void setNextflowVersion(String nextflowVersion){ | ||
this.nextflowVersion.set(nextflowVersion) | ||
} | ||
|
||
String getNextflowVersion(){ | ||
this.nextflowVersion.getOrElse("23.04.0") | ||
} | ||
|
||
void setDownloadUrl(String downloadUrl){ | ||
this.downloadUrl.set(downloadUrl) | ||
} | ||
|
||
String getDownloadUrl() { | ||
return downloadUrl.getOrElse("https://github.com/${getGithubOrganization()}/${project.name}/releases/download") | ||
} | ||
|
||
String getGithubOrganization() { | ||
return githubOrganization.get() | ||
} | ||
|
||
void setGithubOrganization(String githubOrganization){ | ||
this.githubOrganization.set(githubOrganization) | ||
} | ||
|
||
String getPluginClassName() { | ||
SourcesMatcher matcher = new SourcesMatcher(project) | ||
String resolved = matcher.pluginClassName | ||
return pluginClassName.getOrElse(resolved) | ||
} | ||
|
||
void setPluginClassName(String pluginClassName){ | ||
this.pluginClassName.set(pluginClassName) | ||
} | ||
|
||
void setExtensionPoints(List<String> extensions){ | ||
this.extensionPoints.set(extensions) | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
buildSrc/src/main/groovy/nextflow/gradle/plugins/SourcesMatcher.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package nextflow.gradle.plugins | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.tasks.SourceSet | ||
import org.gradle.api.tasks.SourceSetContainer | ||
|
||
class SourcesMatcher { | ||
|
||
Project project | ||
SourcesMatcher(Project project){ | ||
this.project = project | ||
} | ||
|
||
|
||
String getPluginClassName(){ | ||
return findSources(/class (\w+) extends BasePlugin/).first() | ||
} | ||
|
||
List<String> getPluginExtensions(){ | ||
return findSources(/class (\w+) extends PluginExtensionPoint/) + | ||
findSources(/class (\w+) extends Executor implements ExtensionPoint/) | ||
} | ||
|
||
List<String> getTraceObservers(){ | ||
return findSources(/class (\w+) implements TraceObserverFactory/) | ||
} | ||
|
||
List<String> findSources( def regexp ){ | ||
def sourceSets = project.extensions.getByType(SourceSetContainer) | ||
def mainSourceSet = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME) | ||
def sources = mainSourceSet.allSource | ||
def root = project.projectDir | ||
|
||
def matcher = sources.findAll{ | ||
def source = it.text | ||
def matcher = source =~ regexp | ||
if( matcher.size() != 1 ){ | ||
return null | ||
} | ||
it | ||
} | ||
matcher.collect { file -> | ||
def source = file.toString() - "$root.absolutePath/src/main/" | ||
return source.split('\\.').dropRight(1).join().split(File.separator).drop(1).join('.') | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
buildSrc/src/main/groovy/nextflow/gradle/plugins/UnzipPluginTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nextflow.gradle.plugins | ||
import org.gradle.api.tasks.Copy | ||
|
||
|
||
class UnzipPluginTask extends Copy{ | ||
|
||
UnzipPluginTask(){ | ||
setGroup('nextflow') | ||
dependsOn project.tasks.zipPlugin | ||
outputs.upToDateWhen {false} | ||
from project.zipTree(project.tasks.zipPlugin.outputs.files.first()) | ||
into "${System.getProperty("user.home")}/.nextflow/plugins/${project.name}-${project.version}" | ||
} | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
buildSrc/src/main/groovy/nextflow/gradle/plugins/ZipPluginTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package nextflow.gradle.plugins | ||
|
||
|
||
import org.gradle.api.file.RegularFileProperty | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.bundling.Jar | ||
|
||
|
||
class ZipPluginTask extends Jar{ | ||
|
||
@OutputFile | ||
final abstract RegularFileProperty outputFile = | ||
project.objects.fileProperty().convention(project.layout.buildDirectory.file( | ||
"plugin/${project.name}-${project.version}.zip")) | ||
|
||
ZipPluginTask() { | ||
setGroup('nextflow') | ||
|
||
dependsOn(project.tasks.findByName('build')) | ||
dependsOn(project.tasks.generateIdx) | ||
|
||
into( 'classes',{ | ||
with project.tasks.findByName('jar') | ||
}) | ||
|
||
into('lib',{ | ||
from(project.configurations.find {it.name=='runtimeClasspath'}) | ||
}) | ||
|
||
manifest { | ||
Jar jar = project.tasks.findByName('jar') as Jar | ||
from(jar.manifest) | ||
} | ||
|
||
archiveExtension.set('zip') | ||
setPreserveFileTimestamps(false) | ||
setReproducibleFileOrder(true) | ||
|
||
def directory = project.objects.fileProperty().convention( | ||
project.layout.buildDirectory.file("plugin")) | ||
getDestinationDirectory().set(directory.get().asFile) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=0.0.2-rc1 |
Oops, something went wrong.