Skip to content

Commit 68ec235

Browse files
authored
Vendor locally built Derby (#155)
Adds the Gradle's task deployLocallyDerbyArtifacts (and its dependants) to checkout, through SVNKit, and build Derby artifacts for a specific release branch. The build leverages Gradle's embedded ant and copy the interested artifacts (derby and derbyclient) into a local repository. The artifacts in local repository are generated each time the project is vendored, doing a checkout of a specific Subversion revision it's granted the reproducibility. Updates also the vendor and generateGemJarRequiresFile to cope with the new locally shipped artifacts.
1 parent c9f043e commit 68ec235

File tree

5 files changed

+173
-15
lines changed

5 files changed

+173
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 5.4.8
2+
- Update Derby with locally built 10.15.2.1 version [#155](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/155)
3+
14
## 5.4.7
25
- Update sequel version to >= 5.74.0. It fixes the generic jdbc adapter to properly handle disconnect errors [#153](https://github.com/logstash-plugins/logstash-integration-jdbc/pull/153)
36

build.gradle

Lines changed: 166 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,202 @@
11
import java.nio.file.Files
2+
import org.tmatesoft.svn.core.SVNDepth
3+
import org.tmatesoft.svn.core.SVNURL
4+
import org.tmatesoft.svn.core.wc.SVNClientManager
5+
import org.tmatesoft.svn.core.wc.SVNRevision
6+
import org.tmatesoft.svn.core.wc.SVNUpdateClient
27

38
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING
49

510
apply plugin: 'java'
611
apply plugin: 'idea'
712
apply plugin: 'maven-publish'
813

9-
def DERBY_VERSION = '10.14.1.0'
14+
def DERBY_VERSION = '10.15.2.1'
15+
def DERBY_MINOR = '10.15'
16+
long DERBY_REVISION = 1905585
17+
18+
buildscript {
19+
ext {
20+
svnkitVersion = '1.10.11'
21+
}
22+
23+
repositories {
24+
mavenCentral()
25+
}
26+
dependencies {
27+
classpath "org.tmatesoft.svnkit:svnkit:${svnkitVersion}"
28+
}
29+
}
30+
31+
class SvnCheckout extends DefaultTask {
32+
33+
@Input
34+
String svnRef = 'https://svn.apache.org/repos/asf/db/derby/code/branches/'
35+
36+
@Input
37+
String branch
38+
39+
@Input
40+
long revision
41+
42+
@OutputDirectory
43+
File getCheckoutDir() {
44+
return project.layout.buildDirectory.dir(branch).get().asFile
45+
}
46+
47+
SvnCheckout() {
48+
description = "Checkout a branch from svnRef"
49+
group = "org.logstash.tooling"
50+
}
51+
52+
@TaskAction
53+
def checkout() {
54+
SVNClientManager clientManager = SVNClientManager.newInstance();
55+
SVNUpdateClient client = clientManager.getUpdateClient();
56+
SVNURL svnurl = SVNURL.parseURIEncoded(svnRef + branch);
57+
58+
println "Starting checkout"
59+
long revision = client.doCheckout(svnurl, checkoutDir, SVNRevision.HEAD,
60+
SVNRevision.create(revision), SVNDepth.UNKNOWN, true);
61+
println "Checked out at revision ${revision} in folder ${checkoutDir}"
62+
}
63+
}
1064

1165
repositories {
1266
mavenCentral()
1367
}
1468

1569

1670
dependencies {
17-
implementation "org.apache.derby:derby:${DERBY_VERSION}"
18-
implementation "org.apache.derby:derbyclient:${DERBY_VERSION}"
71+
implementation files("local_repository/derby-${DERBY_VERSION}.jar", "local_repository/derbyclient-${DERBY_VERSION}.jar")
72+
}
73+
74+
tasks.register("svnCheckout", SvnCheckout) {
75+
branch = DERBY_MINOR
76+
revision = DERBY_REVISION
77+
description = "Checkout Derby sources for branch ${DERBY_MINOR} from Subversion repository at revision ${DERBY_REVISION}"
78+
}
79+
80+
ant.lifecycleLogLevel = "WARN"
81+
82+
tasks.register("importAnt") {
83+
dependsOn svnCheckout
84+
description = "Load Derby's Ant project definition"
85+
86+
doLast {
87+
ant.importBuild(layout.buildDirectory.file("${DERBY_MINOR}/build.xml").get().asFile) { antTargetName ->
88+
'ant-' + antTargetName
89+
}
90+
println "Ant imported"
91+
}
92+
}
93+
94+
tasks.register("buildDerby") {
95+
dependsOn importAnt
96+
group = 'build'
97+
description = "Build Derby checked out sources using its Apache Ant script"
98+
99+
doLast {
100+
ant.antProject.setBasedir(layout.buildDirectory.dir(DERBY_MINOR).get().asFile.toString())
101+
ant.antProject.executeTarget("clobber")
102+
ant.antProject.executeTarget("buildsource")
103+
ant.antProject.executeTarget("buildjars")
104+
}
105+
}
106+
107+
def readFullDerbyVersion(String derbyVersionBranch) {
108+
def releasePropertiesFile = layout.buildDirectory.file("${derbyVersionBranch}/tools/ant/properties/release.properties").get().asFile
109+
def props = new Properties()
110+
releasePropertiesFile.withInputStream { props.load(it) }
111+
112+
return props.getProperty('release.id.long')
113+
}
114+
115+
tasks.register('deployLocallyDerbyArtifacts') {
116+
dependsOn buildDerby
117+
group = 'build'
118+
description = "Copy Derby and Derby Client in local repository, which can be used to resolve dependencies"
119+
120+
doLast {
121+
String derbyFullVersion = readFullDerbyVersion(DERBY_MINOR)
122+
copy {
123+
from layout.buildDirectory.dir("${DERBY_MINOR}/jars/sane/derbyshared.jar")
124+
into file('local_repository/')
125+
rename 'derbyshared.jar', "derby-${derbyFullVersion}.jar"
126+
}
127+
copy {
128+
from layout.buildDirectory.dir("${DERBY_MINOR}/jars/sane/derbyclient.jar")
129+
into file('local_repository/')
130+
rename 'derbyclient.jar', "derbyclient-${derbyFullVersion}.jar"
131+
}
132+
}
19133
}
20134

21-
task generateGemJarRequiresFile {
135+
clean {
136+
delete "${projectDir}/local_repository"
137+
}
138+
139+
tasks.register("generateGemJarRequiresFile") {
140+
dependsOn deployLocallyDerbyArtifacts
141+
22142
doLast {
23143
File jars_file = file('lib/logstash-integration-jdbc_jars.rb')
24144
jars_file.newWriter().withWriter { w ->
25145
w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n"
26146
w << "require \'jar_dependencies\'\n"
27147
configurations.runtimeClasspath.allDependencies.each {
28-
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
148+
if (!(it instanceof SelfResolvingDependency)) {
149+
w << "require_jar(\'${it.group}\', \'${it.name}\', \'${it.version}\')\n"
150+
} else {
151+
// in this case the single dependency contains all the files, looping
152+
// on those to create the require_jar statements
153+
configurations.runtimeClasspath.each { File depJarFile ->
154+
String artifactName = depJarFile.name.split('-')[0]
155+
String artifactVersion = depJarFile.name.split('-')[1].split('\\.jar')[0]
156+
def group = "org.apache.derby"
157+
w << "require_jar(\'${group}\', \'${artifactName}\', \'${artifactVersion}\')\n"
158+
}
159+
}
29160
}
30161
}
31162
}
32163
}
33164

34-
task vendor {
165+
tasks.register("vendor") {
166+
dependsOn deployLocallyDerbyArtifacts
167+
35168
doLast {
36169
String vendorPathPrefix = "vendor/jar-dependencies"
37170
configurations.runtimeClasspath.allDependencies.each { dep ->
38-
File f = configurations.runtimeClasspath.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
39-
String groupPath = dep.group.replaceAll('\\.', '/')
40-
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
41-
newJarFile.mkdirs()
42-
Files.copy(f.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
171+
if (!(dep instanceof SelfResolvingDependency)) {
172+
// dep is an instance of org.gradle.api.artifacts.ExternalDependency
173+
copyExternalDependencyJarToVendor(dep, vendorPathPrefix)
174+
} else {
175+
// in this case the single dependency contains all the files, looping and
176+
// move those in the expected location
177+
configurations.runtimeClasspath.each { File depJarFile ->
178+
copyLocalDependencyJarToVendor(depJarFile, vendorPathPrefix, "org/apache/derby")
179+
}
180+
}
43181
}
44182
}
45183
}
46184

185+
private void copyExternalDependencyJarToVendor(Dependency dep, String vendorPathPrefix) {
186+
File f = configurations.runtimeClasspath.filter { it.absolutePath.contains("${dep.group}/${dep.name}/${dep.version}") }.singleFile
187+
String groupPath = dep.group.replaceAll('\\.', '/')
188+
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${dep.name}/${dep.version}/${dep.name}-${dep.version}.jar")
189+
newJarFile.mkdirs()
190+
Files.copy(f.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
191+
}
192+
193+
private void copyLocalDependencyJarToVendor(File depJarFile, String vendorPathPrefix, String groupPath) {
194+
String artifactName = depJarFile.name.split('-')[0]
195+
String artifactVersion = depJarFile.name.split('-')[1].split('\\.jar')[0]
196+
197+
File newJarFile = file("${vendorPathPrefix}/${groupPath}/${artifactName}/${artifactVersion}/${depJarFile.name}")
198+
newJarFile.mkdirs()
199+
Files.copy(depJarFile.toPath(), newJarFile.toPath(), REPLACE_EXISTING)
200+
}
201+
47202
vendor.dependsOn(generateGemJarRequiresFile)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.
22

33
require 'jar_dependencies'
4-
require_jar('org.apache.derby', 'derby', '10.14.1.0')
5-
require_jar('org.apache.derby', 'derbyclient', '10.14.1.0')
4+
require_jar('org.apache.derby', 'derby', '10.15.2.1')
5+
require_jar('org.apache.derby', 'derbyclient', '10.15.2.1')

logstash-integration-jdbc.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |s|
22
s.name = 'logstash-integration-jdbc'
3-
s.version = '5.4.7'
3+
s.version = '5.4.8'
44
s.licenses = ['Apache License (2.0)']
55
s.summary = "Integration with JDBC - input and filter plugins"
66
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

0 commit comments

Comments
 (0)