01: /*
02: * Cobertura - http://cobertura.sourceforge.net/
03: *
04: * Copyright (C) 2003 jcoverage ltd.
05: * Copyright (C) 2005 Mark Doliner
06: * Copyright (C) 2005 Joakim Erdfelt
07: * Copyright (C) 2005 Mark Sinke
08: * Copyright (C) 2005 Grzegorz Lukasik
09: *
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;
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: public Main(String[] args) {
41: File dataFile = CoverageDataFileHandler.getDefaultDataFile();
42: File baseDir = null;
43: List filesToMerge = new ArrayList();
44:
45: // Go through all the parameters
46: for (int i = 0; i < args.length; i++) {
47: if (args[i].equals("--datafile"))
48: dataFile = new File(args[++i]);
49: else if (args[i].equals("--basedir"))
50: baseDir = new File(args[++i]);
51: else
52: filesToMerge.add(new File(baseDir, args[i]));
53: }
54:
55: // Load coverage data
56: ProjectData projectData = null;
57: if (dataFile.isFile())
58: projectData = CoverageDataFileHandler
59: .loadCoverageData(dataFile);
60: if (projectData == null)
61: projectData = new ProjectData();
62:
63: if (filesToMerge.isEmpty()) {
64: System.err
65: .println("Error: No files were specified for merging.");
66: System.exit(1);
67: }
68:
69: // Merge everything
70: Iterator iter = filesToMerge.iterator();
71: while (iter.hasNext()) {
72: File newDataFile = (File) iter.next();
73: ProjectData projectDataNew = CoverageDataFileHandler
74: .loadCoverageData(newDataFile);
75: if (projectDataNew != null)
76: projectData.merge(projectDataNew);
77: }
78:
79: // Save the combined data file
80: CoverageDataFileHandler.saveCoverageData(projectData, dataFile);
81: }
82:
83: public static void main(String[] args) {
84: Header.print(System.out);
85:
86: try {
87: args = CommandLineBuilder
88: .preprocessCommandLineArguments(args);
89: } catch (Exception ex) {
90: System.err.println("Error: Cannot process arguments: "
91: + ex.getMessage());
92: System.exit(1);
93: }
94: new Main(args);
95: }
96: }
|