Revision 41312 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
Launcher.java | ||
---|---|---|
32 | 32 |
import java.awt.KeyboardFocusManager; |
33 | 33 |
import java.awt.Point; |
34 | 34 |
import java.awt.Toolkit; |
35 |
import java.awt.Window; |
|
36 | 35 |
import java.awt.event.ActionEvent; |
37 | 36 |
import java.awt.event.ActionListener; |
38 | 37 |
import java.io.BufferedOutputStream; |
... | ... | |
49 | 48 |
import java.io.OutputStreamWriter; |
50 | 49 |
import java.io.Reader; |
51 | 50 |
import java.io.StringWriter; |
52 |
import java.lang.reflect.InvocationTargetException; |
|
53 | 51 |
import java.net.Authenticator; |
54 | 52 |
import java.net.MalformedURLException; |
55 | 53 |
import java.net.PasswordAuthentication; |
... | ... | |
64 | 62 |
import java.text.MessageFormat; |
65 | 63 |
import java.util.ArrayList; |
66 | 64 |
import java.util.Arrays; |
65 |
import java.util.Collections; |
|
67 | 66 |
import java.util.Comparator; |
68 | 67 |
import java.util.Enumeration; |
69 | 68 |
import java.util.HashMap; |
... | ... | |
76 | 75 |
import java.util.Properties; |
77 | 76 |
import java.util.Set; |
78 | 77 |
import java.util.TreeSet; |
79 |
import java.util.logging.Level; |
|
80 | 78 |
import java.util.prefs.Preferences; |
81 | 79 |
|
82 | 80 |
import javax.swing.ImageIcon; |
... | ... | |
96 | 94 |
import org.apache.commons.cli.ParseException; |
97 | 95 |
import org.apache.commons.cli.PosixParser; |
98 | 96 |
import org.apache.commons.io.FileUtils; |
97 |
import org.apache.commons.lang3.JavaVersion; |
|
98 |
import org.apache.commons.lang3.SystemUtils; |
|
99 | 99 |
import org.apache.log4j.AppenderSkeleton; |
100 | 100 |
import org.apache.log4j.PatternLayout; |
101 | 101 |
import org.apache.log4j.PropertyConfigurator; |
... | ... | |
376 | 376 |
install = true; |
377 | 377 |
} |
378 | 378 |
} |
379 |
|
|
379 | 380 |
try { |
380 | 381 |
if (install) { |
381 | 382 |
launcher.doInstall(args); |
... | ... | |
697 | 698 |
/* |
698 | 699 |
* Executes additional tasks required by plugins |
699 | 700 |
*/ |
700 |
PluginsLocator.getManager().executeOnStartupTasks();
|
|
701 |
PluginsLocator.getManager().executeStartupTasks(); |
|
701 | 702 |
|
702 | 703 |
} |
703 | 704 |
|
... | ... | |
775 | 776 |
* @throws IOException |
776 | 777 |
* @throws ConfigurationException |
777 | 778 |
*/ |
778 |
private void initializeApp(String[] args) throws IOException, |
|
779 |
ConfigurationException { |
|
780 |
if (!validJVM()) { |
|
781 |
System.exit(-1); |
|
782 |
} |
|
783 |
|
|
784 |
// Clean temporal files |
|
785 |
Utilities.cleanUpTempFiles(); |
|
786 |
|
|
779 |
private void initializeApp(String[] args) throws IOException, ConfigurationException { |
|
787 | 780 |
if( args.length<1 ) { |
788 | 781 |
appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG" |
789 | 782 |
} else { |
790 | 783 |
appName = args[0]; |
791 | 784 |
} |
792 |
|
|
793 | 785 |
getOrCreateConfigFolder(); |
794 |
|
|
795 | 786 |
configureLogging(appName); |
787 |
if (!validJVM()) { |
|
788 |
logger.error("Not a valid JRE. Exit application."); |
|
789 |
System.exit(-1); |
|
790 |
} |
|
791 |
// Clean temporal files |
|
792 |
Utilities.cleanUpTempFiles(); |
|
796 | 793 |
|
797 | 794 |
if( args.length<2 ) { |
798 | 795 |
loadAndamiConfig("gvSIG/extensiones"); // Valor por defecto |
... | ... | |
971 | 968 |
* |
972 | 969 |
* @return Theme |
973 | 970 |
*/ |
974 |
private Theme getTheme(String pluginsDirectory) {
|
|
975 |
File infoFile = new File(Launcher.getApplicationFolder(),"package.info");
|
|
976 |
File themeFile = null;
|
|
977 |
Theme theme = new Theme(loadProperties(infoFile));
|
|
971 |
private Theme getTheme(String pluginsDirectory) {
|
|
972 |
File infoFile = new File(Launcher.getApplicationFolder(), "package.info");
|
|
973 |
File themeFile = null; |
|
974 |
List<Theme> themes = new ArrayList<Theme>();
|
|
978 | 975 |
|
979 |
// Try to get theme from args |
|
980 |
String name = PluginServices.getArgumentByName("andamiTheme"); |
|
981 |
if (name != null) { |
|
982 |
themeFile = new File(name); |
|
983 |
logger.info("search andami-theme in {}", themeFile |
|
984 |
.getAbsolutePath()); |
|
985 |
if (themeFile.exists()) { |
|
986 |
theme.readTheme(themeFile); |
|
987 |
logger.info("andami-theme found in {}", themeFile |
|
988 |
.getAbsolutePath()); |
|
989 |
return theme; |
|
990 |
} |
|
991 |
} |
|
976 |
// Try to get theme from args |
|
977 |
String name = PluginServices.getArgumentByName("andamiTheme"); |
|
978 |
if ( name != null ) { |
|
979 |
themeFile = new File(name); |
|
980 |
logger.info("search andami-theme in {}", themeFile.getAbsolutePath()); |
|
981 |
if ( themeFile.exists() ) { |
|
982 |
Theme theme = new Theme(loadProperties(infoFile)); |
|
983 |
theme.readTheme(themeFile); |
|
984 |
logger.info("andami-theme found in {}", themeFile.getAbsolutePath()); |
|
985 |
return theme; |
|
986 |
} |
|
987 |
} |
|
992 | 988 |
|
993 |
// Try to get theme from a plugin |
|
994 |
File pluginsDir = new File(pluginsDirectory); |
|
995 |
if (!pluginsDir.isAbsolute()) { |
|
996 |
pluginsDir = new File(getApplicationFolder(), pluginsDirectory); |
|
997 |
} |
|
998 |
if (pluginsDir.exists()) { |
|
999 |
logger.info("search andami-theme in plugins folder."); |
|
1000 |
File[] pluginDirs = pluginsDir.listFiles(); |
|
1001 |
if (pluginDirs.length > 0) { |
|
1002 |
for (int i = 0; i < pluginDirs.length; i++) { |
|
1003 |
File pluginThemeFile = new File(pluginDirs[i], "theme" |
|
1004 |
+ File.separator + "andami-theme.xml"); |
|
1005 |
if (pluginThemeFile.exists()) { |
|
1006 |
themeFile = pluginThemeFile; |
|
1007 |
// This if is a hack to allow more themes than the |
|
1008 |
// one available in org.gvsig.app. Remove this |
|
1009 |
// when a the theme format is changed to allow for |
|
1010 |
// priorities |
|
1011 |
if (!"org.gvsig.app".equals(pluginDirs[i].getName())) { |
|
1012 |
break; |
|
1013 |
} |
|
1014 |
} |
|
1015 |
} |
|
1016 |
} |
|
1017 |
} |
|
989 |
// Try to get theme from a plugin |
|
990 |
File pluginsDir = new File(pluginsDirectory); |
|
991 |
if ( !pluginsDir.isAbsolute() ) { |
|
992 |
pluginsDir = new File(getApplicationFolder(), pluginsDirectory); |
|
993 |
} |
|
994 |
if ( pluginsDir.exists() ) { |
|
995 |
logger.info("search andami-theme in plugins folder '"+pluginsDir.getAbsolutePath()+"'."); |
|
996 |
File[] pluginDirs = pluginsDir.listFiles(); |
|
997 |
if ( pluginDirs.length > 0 ) { |
|
998 |
for ( int i = 0; i < pluginDirs.length; i++ ) { |
|
999 |
File pluginThemeFile = new File(pluginDirs[i], |
|
1000 |
"theme" + File.separator + "andami-theme.xml"); |
|
1001 |
if ( pluginThemeFile.exists() ) { |
|
1002 |
Theme theme = new Theme(loadProperties(infoFile)); |
|
1003 |
theme.readTheme(pluginThemeFile); |
|
1004 |
themes.add(theme); |
|
1005 |
} |
|
1006 |
} |
|
1007 |
} |
|
1008 |
} |
|
1018 | 1009 |
|
1019 |
// The theme file will be the one into a plugin or by default the one |
|
1020 |
// in the org.gvsig.app plugin |
|
1021 |
if (themeFile != null && themeFile.exists()) { |
|
1022 |
theme.readTheme(themeFile); |
|
1023 |
logger.info("andami-theme found in plugin {}", themeFile |
|
1024 |
.getAbsolutePath()); |
|
1025 |
return theme; |
|
1026 |
} |
|
1010 |
// Try to get theme from dir gvSIG in user home |
|
1011 |
themeFile = new File(getAppHomeDir(), "theme" + File.separator |
|
1012 |
+ "andami-theme.xml"); |
|
1013 |
logger.info("search andami-theme in user's home {}", themeFile |
|
1014 |
.getAbsolutePath()); |
|
1015 |
if ( themeFile.exists() ) { |
|
1016 |
Theme theme = new Theme(loadProperties(infoFile)); |
|
1017 |
theme.readTheme(themeFile); |
|
1018 |
themes.add(theme); |
|
1019 |
} |
|
1027 | 1020 |
|
1028 |
// Try to get theme from dir gvSIG in user home |
|
1029 |
themeFile = new File(getAppHomeDir(), "theme" + File.separator |
|
1030 |
+ "andami-theme.xml"); |
|
1031 |
logger.info("search andami-theme in user's home {}", themeFile |
|
1032 |
.getAbsolutePath()); |
|
1033 |
if (themeFile.exists()) { |
|
1034 |
theme.readTheme(themeFile); |
|
1035 |
logger.info("andami-theme found in user's home {}", themeFile |
|
1036 |
.getAbsolutePath()); |
|
1037 |
return theme; |
|
1038 |
} |
|
1021 |
// Try to get theme from the instalation dir of gvSIG. |
|
1022 |
themeFile = new File(getApplicationDirectory(), "theme" |
|
1023 |
+ File.separator + "andami-theme.xml"); |
|
1024 |
logger.info("search andami-theme in installation folder {}", themeFile |
|
1025 |
.getAbsolutePath()); |
|
1026 |
if ( themeFile.exists() ) { |
|
1027 |
Theme theme = new Theme(loadProperties(infoFile)); |
|
1028 |
theme.readTheme(themeFile); |
|
1029 |
themes.add(theme); |
|
1030 |
} |
|
1039 | 1031 |
|
1040 |
// Try to get theme from the instalation dir of gvSIG. |
|
1041 |
themeFile = new File(getApplicationDirectory(), "theme" |
|
1042 |
+ File.separator + "andami-theme.xml"); |
|
1043 |
logger.info("search andami-theme in installation folder {}", themeFile |
|
1044 |
.getAbsolutePath()); |
|
1045 |
if (themeFile.exists()) { |
|
1046 |
theme.readTheme(themeFile); |
|
1047 |
logger.info("andami-theme found in instalation folder {}", |
|
1048 |
themeFile.getAbsolutePath()); |
|
1049 |
return theme; |
|
1050 |
} |
|
1051 |
logger.info("Apply default andami-theme."); |
|
1052 |
return theme; |
|
1053 |
} |
|
1032 |
Collections.sort(themes, new Comparator<Theme>() { |
|
1033 |
public int compare(Theme t1, Theme t2) { |
|
1034 |
return t2.getPriority()-t1.getPriority(); |
|
1035 |
} |
|
1036 |
}); |
|
1037 |
if( logger.isInfoEnabled() ) { |
|
1038 |
logger.info("Found andami-themes in:"); |
|
1039 |
for( Theme theme : themes) { |
|
1040 |
logger.info(" - "+theme.getPriority()+", "+ theme.getSource().getAbsolutePath()); |
|
1041 |
} |
|
1042 |
} |
|
1043 |
Theme theme = themes.get(0); |
|
1044 |
logger.info("Using theme '"+theme.getSource()+"'."); |
|
1045 |
return theme; |
|
1046 |
} |
|
1054 | 1047 |
|
1055 | 1048 |
/** |
1056 |
* Establece los datos que ten�amos guardados respecto de la configuraci�n
|
|
1049 |
* Establece los datos que tengamos guardados respecto de la configuracion
|
|
1057 | 1050 |
* del proxy. |
1058 | 1051 |
*/ |
1059 | 1052 |
private void configureProxy() { |
... | ... | |
1135 | 1128 |
} |
1136 | 1129 |
|
1137 | 1130 |
private boolean validJVM() { |
1138 |
char thirdCharacter = System.getProperty("java.version").charAt(2); |
|
1139 |
if (thirdCharacter < '4') { |
|
1140 |
return false; |
|
1141 |
} else { |
|
1142 |
return true; |
|
1143 |
} |
|
1131 |
if( !SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_4)) { |
|
1132 |
logger.warn("gvSIG requires Java version 1.4 or higher."); |
|
1133 |
logger.warn("The Java HOME is '"+SystemUtils.getJavaHome().getAbsolutePath()+"'."); |
|
1134 |
return false; |
|
1135 |
} |
|
1136 |
if( SystemUtils.isJavaAwtHeadless() ) { |
|
1137 |
logger.warn("The java used by gvSIG does not contain the libraries for access to the graphical interface (AWT-headless)"); |
|
1138 |
logger.warn("The Java HOME is '"+SystemUtils.getJavaHome().getAbsolutePath()+"'."); |
|
1139 |
return false; |
|
1140 |
} |
|
1141 |
return true; |
|
1144 | 1142 |
} |
1145 | 1143 |
|
1146 | 1144 |
private void loadPluginsPersistence() throws ConfigurationException { |
... | ... | |
3238 | 3236 |
*/ |
3239 | 3237 |
public void closeAndami() { |
3240 | 3238 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
3241 |
pluginsManager.executeOnShutdownTasks();
|
|
3239 |
pluginsManager.executeShutdownTasks(); |
|
3242 | 3240 |
|
3243 | 3241 |
try { |
3244 | 3242 |
saveAndamiConfig(); |
Also available in: Unified diff