KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > emma > report > reportCommand


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: reportCommand.java,v 1.1.1.1.2.1 2004/07/16 23:32:29 vlad_r Exp $
8  */

9 package com.vladium.emma.report;
10
11 import java.io.IOException JavaDoc;
12
13 import com.vladium.util.ClassLoaderResolver;
14 import com.vladium.util.Strings;
15 import com.vladium.util.args.IOptsParser;
16 import com.vladium.util.asserts.$assert;
17 import com.vladium.emma.Command;
18 import com.vladium.emma.IAppConstants;
19 import com.vladium.emma.IAppErrorCodes;
20 import com.vladium.emma.EMMARuntimeException;
21
22 // ----------------------------------------------------------------------------
23
/**
24  * @author Vlad Roubtsov, (C) 2003
25  */

26 public
27 final class reportCommand extends Command
28 {
29     // public: ................................................................
30

31     public reportCommand (final String JavaDoc usageToolName, final String JavaDoc [] args)
32     {
33         super (usageToolName, args);
34     }
35
36     public synchronized void run ()
37     {
38         ClassLoader JavaDoc loader;
39         try
40         {
41             loader = ClassLoaderResolver.getClassLoader ();
42         }
43         catch (Throwable JavaDoc t)
44         {
45             loader = getClass ().getClassLoader ();
46         }
47         
48         try
49         {
50             // process 'args':
51
{
52                 final IOptsParser parser = getOptParser (loader);
53                 final IOptsParser.IOpts parsedopts = parser.parse (m_args);
54                 
55                 // check if usage is requested before checking args parse errors etc:
56
{
57                     final int usageRequestLevel = parsedopts.usageRequestLevel ();
58
59                     if (usageRequestLevel > 0)
60                     {
61                         usageexit (parser, usageRequestLevel, null);
62                         return;
63                     }
64                 }
65                 
66                 final IOptsParser.IOpt [] opts = parsedopts.getOpts ();
67                 
68                 if (opts == null) // this means there were args parsing errors
69
{
70                     parsedopts.error (m_out, STDOUT_WIDTH);
71                     usageexit (parser, IOptsParser.SHORT_USAGE, null);
72                     return;
73                 }
74                 
75                 // process parsed args:
76

77                 try
78                 {
79                     for (int o = 0; o < opts.length; ++ o)
80                     {
81                         final IOptsParser.IOpt opt = opts [o];
82                         final String JavaDoc on = opt.getCanonicalName ();
83                         
84                         if (! processOpt (opt))
85                         {
86                             if ("in".equals (on))
87                             {
88                                 m_datapath = getListOptValue (opt, PATH_DELIMITERS, true);
89                             }
90                             else if ("sp".equals (on))
91                             {
92                                 m_srcpath = getListOptValue (opt, PATH_DELIMITERS, true);
93                             }
94                             else if ("r".equals (on))
95                             {
96                                 m_reportTypes = Strings.merge (opt.getValues (), COMMA_DELIMITERS, true);
97                             }
98                         }
99                     }
100                     
101                     // user '-props' file property overrides:
102

103                     if (! processFilePropertyOverrides ()) return;
104                     
105                     // process prefixed opts:
106

107                     processCmdPropertyOverrides (parsedopts);
108                 }
109                 catch (IOException JavaDoc ioe)
110                 {
111                     throw new EMMARuntimeException (IAppErrorCodes.ARGS_IO_FAILURE, ioe);
112                 }
113                 
114                 // handle cmd line-level defaults:
115
{
116                 }
117             }
118             
119             // run the reporter:
120
{
121                 final ReportProcessor processor = ReportProcessor.create ();
122                 processor.setAppName (IAppConstants.APP_NAME); // for log prefixing
123

124                 processor.setDataPath (m_datapath);
125                 processor.setSourcePath (m_srcpath);
126                 if ($assert.ENABLED) $assert.ASSERT (m_reportTypes != null, "m_reportTypes no set");
127                 processor.setReportTypes (m_reportTypes); // no "txt" default for report processor
128
processor.setPropertyOverrides (m_propertyOverrides);
129                 
130                 processor.run ();
131             }
132         }
133         catch (EMMARuntimeException yre)
134         {
135             // TODO: see below
136

137             exit (true, yre.getMessage (), yre, RC_UNEXPECTED); // does not return
138
return;
139         }
140         catch (Throwable JavaDoc t)
141         {
142             // TODO: embed: OS/JVM fingerprint, build #, etc
143
// TODO: save stack trace in a file and prompt user to send it to ...
144

145             exit (true, "unexpected failure: ", t, RC_UNEXPECTED); // does not return
146
return;
147         }
148
149         exit (false, null, null, RC_OK);
150     }
151     
152     // protected: .............................................................
153

154
155     protected void initialize ()
156     {
157         super.initialize ();
158     }
159     
160     protected String JavaDoc usageArgsMsg ()
161     {
162         return "[options]";
163     }
164
165     // package: ...............................................................
166

167     // private: ...............................................................
168

169     
170     private String JavaDoc [] m_datapath; // list of data files, not a real path
171
private String JavaDoc [] m_srcpath;
172     private String JavaDoc [] m_reportTypes;
173     
174 } // end of class
175
// ----------------------------------------------------------------------------
Popular Tags