forked from marklogic/ml-gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
marklogic#107 Accounting for new DefaultAntBuilder constructor in Gra…
…dle 2.14
- Loading branch information
Showing
2 changed files
with
48 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 47 additions & 39 deletions
86
src/main/groovy/com/marklogic/gradle/task/client/PrepareRestApiDependenciesTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> modulePaths = getAppConfig().modulePaths | ||
List<String> newModulePaths = new ArrayList<String>() | ||
|
||
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<String> modulePaths = getAppConfig().modulePaths | ||
List<String> newModulePaths = new ArrayList<String>() | ||
|
||
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" | ||
} | ||
} | ||
} | ||
} |