Skip to content

Commit 1142c0b

Browse files
committed
#107 Accounting for new DefaultAntBuilder constructor in Gradle 2.14
1 parent b5a5fe6 commit 1142c0b

File tree

2 files changed

+48
-40
lines changed

2 files changed

+48
-40
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if (project.hasProperty("myBintrayUser")) {
6262
licenses = ['Apache-2.0']
6363
vcsUrl = 'https://github.com/rjrudin/' + project.name + '.git'
6464
version {
65-
name = "2.2.0"
65+
name = project.version
6666
released = new Date()
6767
}
6868
}
Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,59 @@
11
package com.marklogic.gradle.task.client
22

3+
import com.marklogic.gradle.task.MarkLogicTask
34
import org.gradle.api.artifacts.Configuration
45
import org.gradle.api.internal.project.DefaultAntBuilder
6+
import org.gradle.api.internal.project.ant.AntLoggingAdapter
57
import org.gradle.api.tasks.TaskAction
68

7-
import com.marklogic.gradle.task.MarkLogicTask
8-
99
/**
1010
* Purpose of this task is to unzip each restApi dependency to the build directory and then register the path of each
11-
* unzipped directory in AppConfig.modulePaths.
11+
* unzipped directory in AppConfig.modulePaths.
1212
*/
1313
class PrepareRestApiDependenciesTask extends MarkLogicTask {
1414

15-
@TaskAction
16-
void prepareRestApiDependencies() {
17-
String configurationName = "mlRestApi"
18-
if (getProject().configurations.find {it.name == configurationName}) {
19-
Configuration config = getProject().getConfigurations().getAt(configurationName)
20-
if (config.files) {
21-
println "Found " + configurationName + " configuration, will unzip all of its dependencies to build/mlRestApi"
22-
23-
def buildDir = new File("build/mlRestApi")
24-
buildDir.delete()
25-
buildDir.mkdirs()
26-
27-
// Constructing a DefaultAntBuilder seems to avoid Xerces-related classpath issues
28-
def ant = new DefaultAntBuilder(getProject())
29-
for (f in config.files) {
30-
println "Unzipping file: " + f.getAbsolutePath()
31-
ant.unzip(src: f, dest: buildDir, overwrite: "true")
32-
}
33-
34-
List<String> modulePaths = getAppConfig().modulePaths
35-
List<String> newModulePaths = new ArrayList<String>()
36-
37-
for (dir in buildDir.listFiles()) {
38-
if (dir.isDirectory()) {
39-
newModulePaths.add(new File(dir, "ml-modules").getAbsolutePath())
40-
}
41-
}
42-
43-
// The config paths of the dependencies should be before the original config paths
44-
newModulePaths.addAll(modulePaths)
45-
getAppConfig().setModulePaths(newModulePaths)
46-
47-
println "Finished unzipping mlRestApi dependencies; will now include modules at " + getAppConfig().modulePaths + "\n"
48-
}
49-
}
50-
}
15+
@TaskAction
16+
void prepareRestApiDependencies() {
17+
String configurationName = "mlRestApi"
18+
if (getProject().configurations.find { it.name == configurationName }) {
19+
Configuration config = getProject().getConfigurations().getAt(configurationName)
20+
if (config.files) {
21+
println "Found " + configurationName + " configuration, will unzip all of its dependencies to build/mlRestApi"
22+
23+
def buildDir = new File("build/mlRestApi")
24+
buildDir.delete()
25+
buildDir.mkdirs()
26+
27+
// Constructing a DefaultAntBuilder seems to avoid Xerces-related classpath issues
28+
// The DefaultAntBuilder constructor changed between Gradle 2.13 and 2.14, and we want
29+
// to support both, so we try the 2.14 approach first and then 2.13
30+
def ant = null
31+
try {
32+
ant = new DefaultAntBuilder(getProject(), new AntLoggingAdapter())
33+
} catch (Exception ex) {
34+
ant = new DefaultAntBuilder(getProject())
35+
}
36+
37+
for (f in config.files) {
38+
println "Unzipping file: " + f.getAbsolutePath()
39+
ant.unzip(src: f, dest: buildDir, overwrite: "true")
40+
}
41+
42+
List<String> modulePaths = getAppConfig().modulePaths
43+
List<String> newModulePaths = new ArrayList<String>()
44+
45+
for (dir in buildDir.listFiles()) {
46+
if (dir.isDirectory()) {
47+
newModulePaths.add(new File(dir, "ml-modules").getAbsolutePath())
48+
}
49+
}
50+
51+
// The config paths of the dependencies should be before the original config paths
52+
newModulePaths.addAll(modulePaths)
53+
getAppConfig().setModulePaths(newModulePaths)
54+
55+
println "Finished unzipping mlRestApi dependencies; will now include modules at " + getAppConfig().modulePaths + "\n"
56+
}
57+
}
58+
}
5159
}

0 commit comments

Comments
 (0)