KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cobertura > merge > Main


1 /*
2  * Cobertura - http://cobertura.sourceforge.net/
3  *
4  * Copyright (C) 2003 jcoverage ltd.
5  * Copyright (C) 2005 Mark Doliner
6  * Copyright (C) 2005 Joakim Erdfelt
7  * Copyright (C) 2005 Mark Sinke
8  * Copyright (C) 2005 Grzegorz Lukasik
9  *
10  * Cobertura is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published
12  * by the Free Software Foundation; either version 2 of the License,
13  * or (at your option) any later version.
14  *
15  * Cobertura is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Cobertura; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  */

25
26 package net.sourceforge.cobertura.merge;
27
28 import java.io.File JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.List JavaDoc;
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 JavaDoc[] args)
42     {
43         File JavaDoc dataFile = CoverageDataFileHandler.getDefaultDataFile();
44         File JavaDoc baseDir = null;
45         List JavaDoc filesToMerge = new ArrayList JavaDoc();
46
47         // Go through all the parameters
48
for (int i = 0; i < args.length; i++)
49         {
50             if (args[i].equals("--datafile"))
51                 dataFile = new File JavaDoc(args[++i]);
52             else if (args[i].equals("--basedir"))
53                 baseDir = new File JavaDoc(args[++i]);
54             else
55                 filesToMerge.add( new File JavaDoc(baseDir, args[i]));
56         }
57
58         // Load coverage data
59
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         // Merge everything
72
Iterator JavaDoc iter = filesToMerge.iterator();
73         while (iter.hasNext())
74         {
75             File JavaDoc newDataFile = (File JavaDoc)iter.next();
76             ProjectData projectDataNew = CoverageDataFileHandler
77                     .loadCoverageData(newDataFile);
78             if (projectDataNew != null)
79                 projectData.merge(projectDataNew);
80         }
81
82         // Save the combined data file
83
CoverageDataFileHandler.saveCoverageData(projectData, dataFile);
84     }
85
86     public static void main(String JavaDoc[] args)
87     {
88         Header.print(System.out);
89
90         try {
91             args = CommandLineBuilder.preprocessCommandLineArguments( args);
92         } catch( Exception JavaDoc 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