1 25 26 package net.sourceforge.cobertura.merge; 27 28 import java.io.File ; 29 import java.util.ArrayList ; 30 import java.util.Iterator ; 31 import java.util.List ; 32 33 import net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler; 34 import net.sourceforge.cobertura.coveragedata.ProjectData; 35 import net.sourceforge.cobertura.util.CommandLineBuilder; 36 import net.sourceforge.cobertura.util.Header; 37 38 public class Main 39 { 40 41 public Main(String [] args) 42 { 43 File dataFile = CoverageDataFileHandler.getDefaultDataFile(); 44 File baseDir = null; 45 List filesToMerge = new ArrayList (); 46 47 for (int i = 0; i < args.length; i++) 49 { 50 if (args[i].equals("--datafile")) 51 dataFile = new File (args[++i]); 52 else if (args[i].equals("--basedir")) 53 baseDir = new File (args[++i]); 54 else 55 filesToMerge.add( new File (baseDir, args[i])); 56 } 57 58 ProjectData projectData = null; 60 if (dataFile.isFile()) 61 projectData = CoverageDataFileHandler.loadCoverageData(dataFile); 62 if (projectData == null) 63 projectData = new ProjectData(); 64 65 if (filesToMerge.isEmpty()) 66 { 67 System.err.println("Error: No files were specified for merging."); 68 System.exit(1); 69 } 70 71 Iterator iter = filesToMerge.iterator(); 73 while (iter.hasNext()) 74 { 75 File newDataFile = (File )iter.next(); 76 ProjectData projectDataNew = CoverageDataFileHandler 77 .loadCoverageData(newDataFile); 78 if (projectDataNew != null) 79 projectData.merge(projectDataNew); 80 } 81 82 CoverageDataFileHandler.saveCoverageData(projectData, dataFile); 84 } 85 86 public static void main(String [] args) 87 { 88 Header.print(System.out); 89 90 try { 91 args = CommandLineBuilder.preprocessCommandLineArguments( args); 92 } catch( Exception ex) { 93 System.err.println( "Error: Cannot process arguments: " + ex.getMessage()); 94 System.exit(1); 95 } 96 new Main(args); 97 } 98 } 99 | Popular Tags |