Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build
checkpoint.sha
.gradle
.idea
lib/logstash-integration-jdbc_jars.rb
75 changes: 35 additions & 40 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,67 +213,62 @@ clean {
delete "${projectDir}/local_repository"
}

tasks.register("generateGemJarRequiresFile") {
task generateGemJarRequiresFile {
dependsOn deployLocallyDerbyArtifacts

doLast {
File jars_file = file('lib/logstash-integration-jdbc_jars.rb')
File jars_file = file("lib/logstash-integration-jdbc_jars.rb")
jars_file.newWriter().withWriter { w ->
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
w << "require \'jar_dependencies\'\n"
configurations.runtimeClasspath.allDependencies.each {
if (!(it instanceof SelfResolvingDependency)) {
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
configurations.runtimeClasspath.incoming.artifacts.artifacts.each { artifact ->
def id = artifact.id.componentIdentifier
if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
w << "require_jar(\'${id.group}\', \'${id.module}\', \'${id.version}\')\n"
} else {
// in this case the single dependency contains all the files, looping
// on those to create the require_jar statements
configurations.runtimeClasspath.each { File depJarFile ->
String artifactName = depJarFile.name.split('-')[0]
String artifactVersion = depJarFile.name.split('-')[1].split('\\.jar')[0]
def group = "org.apache.derby"
w << "require_jar(\'${group}\', \'${artifactName}\', \'${artifactVersion}\')\n"
// Handle local Derby JAR files
String fileName = artifact.file.name
if (fileName.startsWith("derby")) {
String artifactName = fileName.split('-')[0]
String artifactVersion = fileName.replace('.jar', '').split('-')[1]
w << "require_jar(\'org.apache.derby\', \'${artifactName}\', \'${artifactVersion}\')\n"
}
}
}
}
}
}

tasks.register("vendor") {
task vendor {
dependsOn deployLocallyDerbyArtifacts

doLast {
String vendorPathPrefix = "vendor/jar-dependencies"
configurations.runtimeClasspath.allDependencies.each { dep ->
if (!(dep instanceof SelfResolvingDependency)) {
// dep is an instance of org.gradle.api.artifacts.ExternalDependency
copyExternalDependencyJarToVendor(dep, vendorPathPrefix)
configurations.runtimeClasspath.incoming.artifacts.artifacts.each { artifact ->
def id = artifact.id.componentIdentifier
if (id instanceof org.gradle.api.artifacts.component.ModuleComponentIdentifier) {
String artifactGroup = id.group
String artifactName = id.module
String artifactVersion = id.version
String groupPath = artifactGroup.replaceAll('\\.', '/')
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${artifactName}/${artifactVersion}/${artifactName}-${artifactVersion}.jar")
if (!newJarFile.parentFile.exists()) {
newJarFile.parentFile.mkdirs()
}
Files.copy(artifact.file.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
} else {
// in this case the single dependency contains all the files, looping and
// move those in the expected location
configurations.runtimeClasspath.each { File depJarFile ->
copyLocalDependencyJarToVendor(depJarFile, vendorPathPrefix, "org/apache/derby")
// Handle local Derby JAR files
String fileName = artifact.file.name
if (fileName.startsWith("derby")) {
String artifactName = fileName.split('-')[0]
String artifactVersion = fileName.replace('.jar', '').split('-')[1]
File newJarFile = file("${vendorPathPrefix}/org/apache/derby/${artifactName}/${artifactVersion}/${fileName}")
if (!newJarFile.parentFile.exists()) {
newJarFile.parentFile.mkdirs()
}
Files.copy(artifact.file.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
}
}
}
}
}

private void copyExternalDependencyJarToVendor(Dependency dep, String vendorPathPrefix) {
File f = configurations.runtimeClasspath.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
String groupPath = dep.group.replaceAll('\\.', '/')
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
newJarFile.mkdirs()
Files.copy(f.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
}

private void copyLocalDependencyJarToVendor(File depJarFile, String vendorPathPrefix, String groupPath) {
String artifactName = depJarFile.name.split('-')[0]
String artifactVersion = depJarFile.name.split('-')[1].split('\\.jar')[0]

File newJarFile = file("${vendorPathPrefix}/${groupPath}/${artifactName}/${artifactVersion}/${depJarFile.name}")
newJarFile.mkdirs()
Files.copy(depJarFile.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
}

vendor.dependsOn(generateGemJarRequiresFile)