94 lines
3.2 KiB
Groovy
94 lines
3.2 KiB
Groovy
import org.gradle.plugins.ide.eclipse.model.SourceFolder
|
|
|
|
|
|
def snowballVersion = '3.0.1'
|
|
def snowballArchiveName = "libstemmer_java-${snowballVersion}.tar.gz"
|
|
def snowballDistributionDirectoryName = "libstemmer_java-${snowballVersion}"
|
|
def snowballRootRelativePath = 'third-party/snowball'
|
|
def snowballSourceRelativePath = "${snowballRootRelativePath}/source"
|
|
def snowballJavaSourceRelativePath = "${snowballSourceRelativePath}/${snowballDistributionDirectoryName}/java"
|
|
def snowballDownloadUrl = "https://snowballstem.org/dist/${snowballArchiveName}"
|
|
def snowballDownloadFile = layout.buildDirectory.file("${snowballRootRelativePath}/${snowballArchiveName}")
|
|
def snowballExtractDirectory = layout.buildDirectory.dir(snowballSourceRelativePath)
|
|
def snowballJavaSourceDirectory = layout.buildDirectory.dir(snowballJavaSourceRelativePath)
|
|
def snowballJavaSourceClasspathPath = provider {
|
|
project.relativePath(snowballJavaSourceDirectory.get().asFile)
|
|
}
|
|
def snowballEclipseClasspathAttributes = [
|
|
gradle_scope : 'jmh',
|
|
gradle_used_by_scope: 'jmh',
|
|
test : 'true'
|
|
]
|
|
def isAbsoluteClasspathPath = { String path ->
|
|
path.startsWith('/') || path ==~ /^[A-Za-z]:[\\\/].*/
|
|
}
|
|
|
|
tasks.register('downloadSnowballJava') {
|
|
group = 'build setup'
|
|
description = 'Downloads the official Snowball Java source distribution for benchmark-only use.'
|
|
|
|
outputs.file(snowballDownloadFile)
|
|
|
|
doLast {
|
|
File targetFile = snowballDownloadFile.get().asFile
|
|
targetFile.parentFile.mkdirs()
|
|
|
|
if (!targetFile.exists()) {
|
|
new URL(snowballDownloadUrl).withInputStream { inputStream ->
|
|
targetFile.withOutputStream { outputStream ->
|
|
outputStream << inputStream
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.register('extractSnowballJava', Copy) {
|
|
group = 'build setup'
|
|
description = 'Extracts the official Snowball Java source distribution.'
|
|
|
|
dependsOn(tasks.named('downloadSnowballJava'))
|
|
|
|
from(tarTree(resources.gzip(snowballDownloadFile)))
|
|
into(snowballExtractDirectory)
|
|
}
|
|
|
|
sourceSets {
|
|
jmh {
|
|
java {
|
|
srcDir(snowballJavaSourceDirectory)
|
|
}
|
|
}
|
|
}
|
|
|
|
tasks.named('compileJmhJava') {
|
|
dependsOn(tasks.named('extractSnowballJava'))
|
|
}
|
|
|
|
eclipse {
|
|
classpath {
|
|
file {
|
|
whenMerged { classpath ->
|
|
String generatedSnowballPath = snowballJavaSourceClasspathPath.get()
|
|
String modelSnowballPath = snowballJavaSourceRelativePath
|
|
|
|
classpath.entries.removeAll { entry ->
|
|
entry.hasProperty('path') && (
|
|
entry.path == generatedSnowballPath ||
|
|
entry.path == modelSnowballPath ||
|
|
isAbsoluteClasspathPath(entry.path)
|
|
)
|
|
}
|
|
|
|
SourceFolder snowballEntry = new SourceFolder(generatedSnowballPath, null)
|
|
snowballEntry.output = 'bin/jmh'
|
|
snowballEclipseClasspathAttributes.each { String name, String value ->
|
|
snowballEntry.entryAttributes[name] = value
|
|
}
|
|
|
|
classpath.entries.add(snowballEntry)
|
|
}
|
|
}
|
|
}
|
|
}
|