1 /*
2 Bloof - visualize the evolution of your software project
3 Copyright ( C ) 2003 Lukasz Pekacki <lukasz@pekacki.de>
4 http://bloof.sf.net/
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along with
15 this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 $RCSfile: Main.java,v $
19 Created on $Date: 2003/09/06 08:46:35 $
20 */
21 package net.sf.bloof.script;
22
23 import jargs.gnu.CmdLineParser;
24
25 import java.io.File;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.HashMap;
31 import java.util.logging.LogManager;
32
33 import net.sf.bloof.Bloof;
34 import net.sf.bloof.script.intl.Messages;
35 import net.sf.bloof.script.intl.Text;
36 import net.sf.bloof.script.logging.LogFormatter;
37
38 /***
39 * Bloof Main Class; it starts the Application
40 * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
41 * @version $Id: Main.java,v 1.1 2003/09/06 08:46:35 pekacki Exp $
42 */
43 public class Main {
44
45 /***
46 * Fail starting Bloof
47 * @param aString Reason
48 */
49 public static void fail(String aString) {
50 System.err.println("Bloof execution failed. " + aString + "\nExiting.");
51 System.exit(1);
52 }
53
54 /***
55 * Method initLogManager
56 * initializes the logging API
57 */
58 private static void initLogManager() {
59 try {
60 sLm.readConfiguration(LogFormatter.class.getResourceAsStream(sLoggingProperties));
61 } catch (IOException e) {
62 System.err.println("ERROR: Logging could not be initialized!");
63 }
64 }
65
66 /***
67 * Main method of Bloof
68 * @param aArgs command line options
69 */
70 public static void main(String[] aArgs) {
71 printNameAndVersion();
72 System.setProperty("java.awt.headless", "true");
73 parseCommandLine(aArgs);
74 }
75
76 private static void parseCommandLine(String[] aArgs) {
77 CmdLineParser parser = new CmdLineParser();
78 CmdLineParser.Option verbosity = parser.addStringOption('v', "verbosity");
79 CmdLineParser.Option license = parser.addBooleanOption('l', "license");
80 CmdLineParser.Option help = parser.addBooleanOption('h', "help");
81 CmdLineParser.Option inputFile = parser.addStringOption('i', "input");
82
83 try {
84
85 parser.parse(aArgs);
86 } catch (CmdLineParser.OptionException e) {
87 System.err.println(e.getMessage());
88 printProperUsageAndExit();
89 System.exit(2);
90 }
91 String verbosityValue = (String) parser.getOptionValue(verbosity);
92 Boolean licenseValue = (Boolean) parser.getOptionValue(license);
93 Boolean helpValue = (Boolean) parser.getOptionValue(help);
94 String inputFileValue = (String) parser.getOptionValue(inputFile);
95 if (inputFileValue == null) {
96 sInputStream = System.in;
97 } else {
98 try {
99 sInputStream = new FileInputStream(new File(inputFileValue));
100 } catch (FileNotFoundException e1) {
101 System.err.println(e1.getMessage());
102 System.exit(2);
103 }
104 }
105 if (helpValue != null && helpValue.booleanValue()) {
106 printHelpAndExit();
107 }
108 if (licenseValue != null && licenseValue.booleanValue()) {
109 printLicenseAndExit();
110 }
111 if (verbosityValue != null) {
112 if (verbosityValue.equalsIgnoreCase("VERBOSE")) {
113 sLoggingProperties = LOGGING_CONFIG_VERBOSE;
114 System.out.print("verbosity level: -> VERBOSE <-");
115 System.out.print("\n");
116 }
117 if (verbosityValue.equalsIgnoreCase("DEBUG")) {
118 sLoggingProperties = LOGGING_CONFIG_DEBUG;
119 System.out.print("verbosity level: -> DEBUG <-");
120 System.out.print("\n");
121 }
122 }
123 initLogManager();
124
125 startApplication();
126
127 }
128
129 /***
130 * Method printHelp.
131 */
132 private static void printHelpAndExit() {
133 System.out.print(Messages.getString(Text.COMMANDLINE_USAGE) + Messages.NL);
134 System.out.print("\n");
135 System.out.print(Messages.getString(Text.COMMANDLINE_ARGUMENTS) + Messages.NL);
136 System.out.print("\n");
137 System.exit(0);
138
139 }
140
141 private static void printLicenseAndExit() {
142 System.out.print(Messages.getString(Text.COPYRIGHT) + Messages.NL);
143 System.out.print("\n");
144 System.out.print(Messages.getString(Text.LICENSE) + Messages.NL);
145 System.out.print("\n");
146 System.exit(0);
147 }
148
149 /***
150 * Method printNameAndVersion
151 */
152 private static void printNameAndVersion() {
153 System.out.print(Messages.getString(Text.BLOOF_COMMANDLINE) + Messages.NL);
154 System.out.print("\n");
155
156 }
157
158 private static void printProperUsageAndExit() {
159 System.out.print(Messages.getString(Text.COMMANDLINE_USAGE) + Messages.NL);
160 System.out.print("\n");
161 System.exit(1);
162 }
163
164 /***
165 * Method startApplication.
166 */
167 private static void startApplication() {
168 ScriptController control = new ScriptController();
169 HashMap shellParams = new HashMap();
170 shellParams.put(ScriptController.PARAM_CONTROLLER, control);
171 shellParams.put(ScriptShell.PARAM_INPUT_STREAM, sInputStream);
172 ScriptShell shell = new ScriptShell(shellParams);
173 Thread shellThread = new Thread(shell);
174 shellThread.setName("Bloof Shell");
175 shellThread.start();
176 Bloof.addProgressListener(control);
177 Bloof.addBloofEventListener(control);
178 Bloof.addBloofExceptionListener(control);
179 }
180
181 /***
182 * debug logging
183 */
184 public static final String LOGGING_CONFIG_DEBUG = "logging-debug.properties";
185 /***
186 * default logging
187 */
188 public static final String LOGGING_CONFIG_SILENT = "logging-silent.properties";
189
190 /***
191 * verbose logging
192 */
193 public static final String LOGGING_CONFIG_VERBOSE = "logging-verbose.properties";
194 private static LogManager sLm = LogManager.getLogManager();
195 private static InputStream sInputStream;
196 private static String sLoggingProperties = LOGGING_CONFIG_SILENT;
197 }
This page was automatically generated by Maven