|
1 | 1 | package com.marklogic.gradle.task.client |
2 | 2 |
|
| 3 | +import com.marklogic.gradle.task.MarkLogicTask |
3 | 4 | import org.gradle.api.artifacts.Configuration |
4 | 5 | import org.gradle.api.internal.project.DefaultAntBuilder |
| 6 | +import org.gradle.api.internal.project.ant.AntLoggingAdapter |
5 | 7 | import org.gradle.api.tasks.TaskAction |
6 | 8 |
|
7 | | -import com.marklogic.gradle.task.MarkLogicTask |
8 | | - |
9 | 9 | /** |
10 | 10 | * 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. |
12 | 12 | */ |
13 | 13 | class PrepareRestApiDependenciesTask extends MarkLogicTask { |
14 | 14 |
|
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 | + } |
51 | 59 | } |
0 commit comments