PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package org.diffkit.diff.testcase
17
18import org.apache.commons.lang.ClassUtils 
19import org.apache.commons.lang.StringUtils;
20
21import org.diffkit.util.DKStringUtil 
22
23
24/**
25 * @author jpanico
26 */
27public class PrintTestCaseIndex {
28   
29   public static void main(String[] args_){
30      def instance = new PrintTestCaseIndex()
31      
32      instance.writeIndexFile('TestCases.txt')
33   }
34   
35   private void writeIndexFile(String filename_){
36      println "filename_->$filename_"
37      def readmeDirPath = this.defaultDataPath
38      println "readmeDirPath->$readmeDirPath"
39      URL dataPathUrl = this.class.classLoader.getResource(readmeDirPath)
40      println "dataPathUrl->$dataPathUrl"
41      File dataDir = [dataPathUrl.toURI()]
42      println "dataDir->$dataDir"
43      File indexFile = [dataDir, filename_]
44      println "indexFile->$indexFile"
45      def readmeFileList = dataDir.listFiles( {dir, fileName-> fileName ==~ /.*?\.README\.txt/ } as FilenameFilter )
46      println "readmeFileList->$readmeFileList" 
47      Arrays.sort( readmeFileList, {left, right->
48         DKStringUtil.StringNumberComparator.INSTANCE.compare(left.name, right.name)
49      } as Comparator 
50      )
51      println "readmeFileList->$readmeFileList"
52      
53      if(indexFile.exists())
54         indexFile.delete()
55      
56      readmeFileList.each { 
57         def matcher = it.text =~ /(test\d+) README\s+=+\s+Description\s+-+\s+(?s:(.+(?=\s+Assumptions)))/
58         indexFile <<  matcher[0][1].trim() << '\n'
59         indexFile << StringUtils.repeat('-', matcher[0][1].trim().size())  << '\n'
60         indexFile <<  matcher[0][2].trim() << '\n\n'
61      }
62   }
63   
64   private  String getDefaultDataPath(){
65      return DKStringUtil.packageNameToResourcePath(ClassUtils.getPackageName(this.getClass()) )
66   }
67}