【发布时间】:2018-02-09 06:48:19
【问题描述】:
我目前有一个使用 2 个 ant 目标(复制和移动)的 Gradle 任务。这两个蚂蚁任务给了我正确的结果。但是,我想知道是否可以将它们加入一个 ant 目标以加快执行时间并减少代码量。
我曾尝试使用 2 个映射器来做到这一点,但显然我只能使用一个映射器。我曾尝试使用chainedmapper 和compositemapper,但结果不是我所期望的。
我想要什么
我有一些文件需要更改其所有扩展名(.icls -> .xml),并且我有一个文件要重命名为(ChroMATERIAL IntelliJ IDEA -> ChroMATERIAL)
Starting file name final file name
------------------ ---------------
ChroMATERIAL - Darker.icls -> ChroMATERIAL - Darker.xml
ChroMATERIAL - Darcula.icls -> ChroMATERIAL - Darcula.xml
ChroMATERIAL IntelliJ IDEA.icls -> ChroMATERIAL.xml
下面的代码是我在收到错误消息之前最初尝试使用的代码。最后的代码是我目前使用的解决方法。
编辑:我确实更喜欢基于蚂蚁的等级任务。我查看了似乎允许多个映射器的纯 ant 文件,这是我认为我需要的,但我无法获得类似的工作。
我尝试了什么
task syncFiles {
doLast {
// Sync files from IntelliJ's color scheme and rename extension
ant.copy(todir: sourceDir) {
ant.fileset(dir: intelliJColorSchemeDir)
// NOTE: This is an error message. Can only have one mapper!
ant.mapper(type: "glob", from: "*.icls", to: "*.xml")
ant.mapper(type: "glob", from: "ChroMATERIAL IntelliJ IDEA.xml", to: "ChroMATERIAL.xml")
}
}
}
我当前的实现
这就是我想用 2 个映射器将其变成一个 ant 任务。我相信这可以变成更苗条的代码,只调用一次ant。我也希望这段代码执行得快一点。
task syncFiles {
doLast {
// Sync files from IntelliJ's color scheme and rename extension
ant.copy(todir: sourceDir) {
ant.fileset(dir: intelliJColorSchemeDir)
ant.mapper(type: "glob", from: "*.icls", to: "*.xml")
}
// Rename one specific file. I want this mapper to be joined with the above mapper
ant.move(todir: sourceDir) {
ant.fileset(dir: sourceDir)
ant.mapper(type: "glob", from: "ChroMATERIAL IntelliJ IDEA.xml", to: "ChroMATERIAL.xml")
}
}
}
【问题讨论】:
标签: intellij-idea gradle ant build.gradle mapper