| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.main; |
| 16 | |
| 17 | import java.io.File; |
| 18 | |
| 19 | import org.jdesktop.application.TaskService; |
| 20 | |
| 21 | import net.sourceforge.hiveboard.util.ExitManager; |
| 22 | import net.sourceforge.hivegui.application.HiveGuiApplicationMain; |
| 23 | |
| 24 | public class HiveBoardMain extends HiveGuiApplicationMain |
| 25 | { |
| 26 | static private final String PROP_CONFIG_DIR = "config-dir"; |
| 27 | static private final String ARG_GUITEST = "-guitest"; |
| 28 | static private final String DEFAULT_CONFIG_DIR = "etc"; |
| 29 | |
| 30 | protected HiveBoardMain() |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * HiveBoard client main entry point. |
| 36 | * @param args command line arguments. |
| 37 | */ |
| 38 | static public void main(String[] args) |
| 39 | { |
| 40 | launch(HiveBoardMain.class, args); |
| 41 | } |
| 42 | |
| 43 | @Override protected void checkArguments(String[] args) |
| 44 | { |
| 45 | super.checkArguments(args); |
| 46 | for (String arg: args) |
| 47 | { |
| 48 | if (ARG_GUITEST.equals(arg)) |
| 49 | { |
| 50 | _guiTest = true; |
| 51 | // For GUI tests, change session storage directory |
| 52 | File dir = new File("dist/runtime/session").getAbsoluteFile(); |
| 53 | getContext().getLocalStorage().setDirectory(dir); |
| 54 | break; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public boolean isGuiTest() |
| 60 | { |
| 61 | return _guiTest; |
| 62 | } |
| 63 | |
| 64 | @Override protected String getDefaultConfigDir() |
| 65 | { |
| 66 | return DEFAULT_CONFIG_DIR; |
| 67 | } |
| 68 | |
| 69 | @Override protected void initProperties() |
| 70 | { |
| 71 | System.getProperties().setProperty(PROP_CONFIG_DIR, getConfigDir()); |
| 72 | super.initProperties(); |
| 73 | } |
| 74 | |
| 75 | // NB: Logging and HiveMind Registry have been shutdown already: don't use them! |
| 76 | @Override protected void end() |
| 77 | { |
| 78 | // First shutdown all running TaskService (because they may have |
| 79 | // active threads -not daemons- that will prevent JVM exit |
| 80 | for (TaskService service: getContext().getTaskServices()) |
| 81 | { |
| 82 | service.shutdownNow(); |
| 83 | } |
| 84 | // Exit by disposing of all windows (ie ending EDT) |
| 85 | ExitManager.exit(0, true); |
| 86 | } |
| 87 | |
| 88 | private boolean _guiTest = false; |
| 89 | } |