From 1142c0b0e3c203505138cc46a9d880db737c335e Mon Sep 17 00:00:00 2001 From: Rob Rudin Date: Fri, 22 Jul 2016 08:47:32 -0400 Subject: [PATCH] #107 Accounting for new DefaultAntBuilder constructor in Gradle 2.14 --- build.gradle | 2 +- .../PrepareRestApiDependenciesTask.groovy | 86 ++++++++++--------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index 346cf73ac..e2b269c42 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ if (project.hasProperty("myBintrayUser")) { licenses = ['Apache-2.0'] vcsUrl = 'https://github.com/rjrudin/' + project.name + '.git' version { - name = "2.2.0" + name = project.version released = new Date() } } diff --git a/src/main/groovy/com/marklogic/gradle/task/client/PrepareRestApiDependenciesTask.groovy b/src/main/groovy/com/marklogic/gradle/task/client/PrepareRestApiDependenciesTask.groovy index 1633500a5..9794341c3 100644 --- a/src/main/groovy/com/marklogic/gradle/task/client/PrepareRestApiDependenciesTask.groovy +++ b/src/main/groovy/com/marklogic/gradle/task/client/PrepareRestApiDependenciesTask.groovy @@ -1,51 +1,59 @@ package com.marklogic.gradle.task.client +import com.marklogic.gradle.task.MarkLogicTask import org.gradle.api.artifacts.Configuration import org.gradle.api.internal.project.DefaultAntBuilder +import org.gradle.api.internal.project.ant.AntLoggingAdapter import org.gradle.api.tasks.TaskAction -import com.marklogic.gradle.task.MarkLogicTask - /** * Purpose of this task is to unzip each restApi dependency to the build directory and then register the path of each - * unzipped directory in AppConfig.modulePaths. + * unzipped directory in AppConfig.modulePaths. */ class PrepareRestApiDependenciesTask extends MarkLogicTask { - @TaskAction - void prepareRestApiDependencies() { - String configurationName = "mlRestApi" - if (getProject().configurations.find {it.name == configurationName}) { - Configuration config = getProject().getConfigurations().getAt(configurationName) - if (config.files) { - println "Found " + configurationName + " configuration, will unzip all of its dependencies to build/mlRestApi" - - def buildDir = new File("build/mlRestApi") - buildDir.delete() - buildDir.mkdirs() - - // Constructing a DefaultAntBuilder seems to avoid Xerces-related classpath issues - def ant = new DefaultAntBuilder(getProject()) - for (f in config.files) { - println "Unzipping file: " + f.getAbsolutePath() - ant.unzip(src: f, dest: buildDir, overwrite: "true") - } - - List modulePaths = getAppConfig().modulePaths - List newModulePaths = new ArrayList() - - for (dir in buildDir.listFiles()) { - if (dir.isDirectory()) { - newModulePaths.add(new File(dir, "ml-modules").getAbsolutePath()) - } - } - - // The config paths of the dependencies should be before the original config paths - newModulePaths.addAll(modulePaths) - getAppConfig().setModulePaths(newModulePaths) - - println "Finished unzipping mlRestApi dependencies; will now include modules at " + getAppConfig().modulePaths + "\n" - } - } - } + @TaskAction + void prepareRestApiDependencies() { + String configurationName = "mlRestApi" + if (getProject().configurations.find { it.name == configurationName }) { + Configuration config = getProject().getConfigurations().getAt(configurationName) + if (config.files) { + println "Found " + configurationName + " configuration, will unzip all of its dependencies to build/mlRestApi" + + def buildDir = new File("build/mlRestApi") + buildDir.delete() + buildDir.mkdirs() + + // Constructing a DefaultAntBuilder seems to avoid Xerces-related classpath issues + // The DefaultAntBuilder constructor changed between Gradle 2.13 and 2.14, and we want + // to support both, so we try the 2.14 approach first and then 2.13 + def ant = null + try { + ant = new DefaultAntBuilder(getProject(), new AntLoggingAdapter()) + } catch (Exception ex) { + ant = new DefaultAntBuilder(getProject()) + } + + for (f in config.files) { + println "Unzipping file: " + f.getAbsolutePath() + ant.unzip(src: f, dest: buildDir, overwrite: "true") + } + + List modulePaths = getAppConfig().modulePaths + List newModulePaths = new ArrayList() + + for (dir in buildDir.listFiles()) { + if (dir.isDirectory()) { + newModulePaths.add(new File(dir, "ml-modules").getAbsolutePath()) + } + } + + // The config paths of the dependencies should be before the original config paths + newModulePaths.addAll(modulePaths) + getAppConfig().setModulePaths(newModulePaths) + + println "Finished unzipping mlRestApi dependencies; will now include modules at " + getAppConfig().modulePaths + "\n" + } + } + } }