/tst/org/diffkit/diff/testcase/PrintTestCaseIndex.groovy

http://diffkit.googlecode.com/ · Groovy · 67 lines · 39 code · 10 blank · 18 comment · 1 complexity · 6223e8ca2d9753d5b8aeb075b0a696fa MD5 · raw file

  1. /**
  2. * Copyright 2010-2011 Joseph Panico
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.diffkit.diff.testcase
  17. import org.apache.commons.lang.ClassUtils
  18. import org.apache.commons.lang.StringUtils;
  19. import org.diffkit.util.DKStringUtil
  20. /**
  21. * @author jpanico
  22. */
  23. public class PrintTestCaseIndex {
  24. public static void main(String[] args_){
  25. def instance = new PrintTestCaseIndex()
  26. instance.writeIndexFile('TestCases.txt')
  27. }
  28. private void writeIndexFile(String filename_){
  29. println "filename_->$filename_"
  30. def readmeDirPath = this.defaultDataPath
  31. println "readmeDirPath->$readmeDirPath"
  32. URL dataPathUrl = this.class.classLoader.getResource(readmeDirPath)
  33. println "dataPathUrl->$dataPathUrl"
  34. File dataDir = [dataPathUrl.toURI()]
  35. println "dataDir->$dataDir"
  36. File indexFile = [dataDir, filename_]
  37. println "indexFile->$indexFile"
  38. def readmeFileList = dataDir.listFiles( {dir, fileName-> fileName ==~ /.*?\.README\.txt/ } as FilenameFilter )
  39. println "readmeFileList->$readmeFileList"
  40. Arrays.sort( readmeFileList, {left, right->
  41. DKStringUtil.StringNumberComparator.INSTANCE.compare(left.name, right.name)
  42. } as Comparator
  43. )
  44. println "readmeFileList->$readmeFileList"
  45. if(indexFile.exists())
  46. indexFile.delete()
  47. readmeFileList.each {
  48. def matcher = it.text =~ /(test\d+) README\s+=+\s+Description\s+-+\s+(?s:(.+(?=\s+Assumptions)))/
  49. indexFile << matcher[0][1].trim() << '\n'
  50. indexFile << StringUtils.repeat('-', matcher[0][1].trim().size()) << '\n'
  51. indexFile << matcher[0][2].trim() << '\n\n'
  52. }
  53. }
  54. private String getDefaultDataPath(){
  55. return DKStringUtil.packageNameToResourcePath(ClassUtils.getPackageName(this.getClass()) )
  56. }
  57. }