/*
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2006, University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs;

import java.awt.GraphicsEnvironment;
import java.lang.reflect.Method;

/**
 * Class to launch the appropriate GUI
 * @author pugh
 */
public class LaunchAppropriateUI {
	public static void main(String args[]) throws Exception {
		int launchProperty = getLaunchProperty();
		// Sanity-check the loaded BCEL classes
		if(!CheckBcel.check()) {
			System.exit(1);
		}
		if (GraphicsEnvironment.isHeadless() || launchProperty == 0)
			FindBugs2.main(args);
		else {
			String version = System.getProperty("java.version");

			Class<?> launchClass = null;
			if ("1.5".compareTo(version) <= 0) try {
				launchClass = Class.forName("edu.umd.cs.findbugs.gui2.Driver", false,
						LaunchAppropriateUI.class.getClassLoader());
			} catch (ClassNotFoundException e) {
				assert true;
			}
			if (launchClass == null || launchProperty == 1) 
				launchClass = edu.umd.cs.findbugs.gui.FindBugsFrame.class;

			Method mainMethod = launchClass.getMethod("main", args.getClass());
			mainMethod.invoke(null, (Object) args);
		}
	}

	/** user should set -Dfindbugs.launchUI=0 for textui,
	 *  or -Dfindbugs.launchUI=1 for the original swing gui.
	 *  Any other value (or the absense of any value) will
	 *  not change the default behavior, which is to launch
	 *  the newer "gui2" on systems that support it.
	 *  
	 * @return 0, 1, or 2 (or possibly another user-set int value)
	 */
	public static int getLaunchProperty() {
		String s = System.getProperty("findbugs.launchUI", "2");
		try {
			return Integer.parseInt(s);
		} catch (NumberFormatException nfe) {
			return 2;
		}
	}

}

@@ -59,16 +59,20 @@
 C) 2006,
+2008
  Univers
@@ -978,16 +978,20 @@
 ate GUI%0A
+ * %0A
  * @auth
@@ -993,17 +993,22 @@
 @author 
-p
+Bill P
 ugh%0A */%0A
@@ -1042,16 +1042,107 @@
 ateUI %7B%0A
+%09public static final int SHOW_HELP = 1000;%0A%09public static final int SHOW_VERSION = 1001;%0A%09%0A
 %09public 
@@ -1390,16 +1390,18 @@
 ty == 0)
+ %7B
 %0A%09%09%09Find
@@ -1420,16 +1420,176 @@
 rgs);%0A%09%09
+%7D else if (launchProperty == SHOW_HELP) %7B%0A%09%09%09ShowHelp.main(args);%0A%09%09%7D else if (launchProperty == SHOW_VERSION) %7B%0A%09%09%09Version.main(new String%5B%5D%7B%22-release%22%7D);%0A%09%09%7D 
 else %7B%0A%09
@@ -2258,16 +2258,146 @@
 ng gui.%0A
+%09 * -Dfindbugs.launchUI=version runs the ShowVersion main() method.%0A%09 * -Dfindbugs.launchUI=help runs the ShowHelp main() method.%0A
 %09 *  Any
@@ -2579,14 +2579,36 @@
  1, 
-or 2 (
+2, SHOW_VERSION, SHOW_HELP, 
 or p
@@ -2641,17 +2641,16 @@
 nt value
-)
 %0A%09 */%0A%09p
@@ -2747,16 +2747,133 @@
 , %222%22);%0A
+%09%09%0A%09%09if (s.equals(%22help%22)) %7B%0A%09%09%09return SHOW_HELP;%0A%09%09%7D%0A%09%09%0A%09%09if (s.equals(%22version%22)) %7B%0A%09%09%09return SHOW_VERSION;%0A%09%09%7D%0A%09%09%0A
 %09%09try %7B%0A

Add support for launching version and help programs.