Gradle获取父目录的文件集合

时间:2015-05-13 22:26:48

标签: java gradle build.gradle

我尝试配置一个任务,该任务将从一组二进制junit测试结果生成单个报告,但我无法创建包含所有路径的Set rs = CreateObject("ADODB.Recordset") With rs .Fields.Append "SortKey", 4 .Fields.Append "Txt", 201, 5000 .Open Do Until Inp.AtEndOfStream Lne = Inp.readline .AddNew .Fields("SortKey").value = CSng(SortKey) .Fields("Txt").value = Lne .UpDate Loop .Sort = "SortKey ASC" .Filter = "SortKey > 5" Do While not .EOF Outp.writeline .Fields("Txt").Value .MoveNext Loop End With 结果文件位于。

我的任务定义如下

FileCollection

哪里???是我无法上班的部分。

我可以使用以下代码获取构建结构中的output.bin文件列表,但我需要将其转换为文件所在目录列表。

task aggregateTestREports(type: org.gradle.api.tasks.tests.TestSupport) {
   destinationDir = reportDir
   testResultsDirs = ???
}

我尝试过这样从基类创建自定义类,并将该行的结果传递给fileTree(dir: '.', includes: ['**/test-results/binary/test/output.bin']) 参数并动态计算文件

testOutputBinFiles

但这会给我一个错误,即返回值与class AggregateTestReport extends TestReport { @Input def testOutputBinFiles def getTestResultDirs() { def parents = [] testOutputBinFiles.each { File file -> parents << file.parentFile.absoluteFile } parents } }

不兼容

FileCollection的文档表明获得新文档的唯一方法是使用FileCollection函数,但是在自定义类中无法获取新文件

2 个答案:

答案 0 :(得分:2)

由于我的项目中的测试编写方式存在问题,因为dnault的回答引入的依赖性导致我们的测试失败。最终,当我们解决导致此问题的项目中的问题时,他的解决方案将起作用,因此我接受了答案。为了完整起见,我的权宜之计解决方案最终成为了

def resultPaths(FileCollection testOutputBinFiles) {
  def parents = []
  testOutputBinFiles.each {
     File file -> parents << file.parentFile.absoluteFile
  }
  parents
}

task aggregateTestReports(type: org.gradle.api.tasks.testing.TestReport) {
  destinationDir = reportDir
  reportOn resultPaths(fileTree(dir: '.', includes: ['**/test-results/binary/test/output.bin']))
}

答案 1 :(得分:1)

您可以使用&#39; reportOn&#39;来声明var store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly); try { X509Certificate2Collection collection = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false); return TakeFirstCertificate(collection); } finally { store.Close(); } 类型的任务。列出要汇总的TestReport任务的属性:

Test

这种方法在&#34; Gradle in Action&#34;的第7.3.3节中概述。作者Benjamin Muschko(强烈推荐阅读)。