|
1 | 1 | 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 |
2 | 7 |
|
3 | 8 | import static java.nio.file.StandardCopyOption.REPLACE_EXISTING |
4 | 9 |
|
5 | 10 | apply plugin: 'java' |
6 | 11 | apply plugin: 'idea' |
7 | 12 | apply plugin: 'maven-publish' |
8 | 13 |
|
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 | +} |
10 | 64 |
|
11 | 65 | repositories { |
12 | 66 | mavenCentral() |
13 | 67 | } |
14 | 68 |
|
15 | 69 |
|
16 | 70 | 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 | + } |
19 | 133 | } |
20 | 134 |
|
21 | | -task generateGemJarRequiresFile { |
| 135 | +clean { |
| 136 | + delete "${projectDir}/local_repository" |
| 137 | +} |
| 138 | + |
| 139 | +tasks.register("generateGemJarRequiresFile") { |
| 140 | + dependsOn deployLocallyDerbyArtifacts |
| 141 | + |
22 | 142 | doLast { |
23 | 143 | File jars_file = file('lib/logstash-integration-jdbc_jars.rb') |
24 | 144 | jars_file.newWriter().withWriter { w -> |
25 | 145 | w << "# AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.\n\n" |
26 | 146 | w << "require \'jar_dependencies\'\n" |
27 | 147 | 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 | + } |
29 | 160 | } |
30 | 161 | } |
31 | 162 | } |
32 | 163 | } |
33 | 164 |
|
34 | | -task vendor { |
| 165 | +tasks.register("vendor") { |
| 166 | + dependsOn deployLocallyDerbyArtifacts |
| 167 | + |
35 | 168 | doLast { |
36 | 169 | String vendorPathPrefix = "vendor/jar-dependencies" |
37 | 170 | 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 | + } |
43 | 181 | } |
44 | 182 | } |
45 | 183 | } |
46 | 184 |
|
| 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 | + |
47 | 202 | vendor.dependsOn(generateGemJarRequiresFile) |
0 commit comments