Revision 41706 trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java

View differences:

Launcher.java
98 98
import org.apache.commons.configuration.PropertiesConfiguration;
99 99
import org.apache.commons.io.FileUtils;
100 100
import org.apache.commons.lang3.JavaVersion;
101
import org.apache.commons.lang3.StringUtils;
101 102
import org.apache.commons.lang3.SystemUtils;
102 103
import org.apache.log4j.AppenderSkeleton;
103 104
import org.apache.log4j.PatternLayout;
......
330 331
	protected static MultiSplashWindow splashWindow;
331 332
	protected static String appName;
332 333
	protected static Locale locale;
333
	protected static PluginsConfig pluginsConfig = new PluginsConfig();
334
	protected static PluginsConfig pluginsConfig = new PluginsConfig();      
334 335
	protected static PluginsServices pluginsServices = new PluginsServices();
335 336
	protected static MDIFrame frame;
336 337
	protected static HashMap<Class<? extends IExtension>, ExtensionDecorator> classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
......
512 513
			this.addError("Can't downloads plugins", ex);
513 514
		}
514 515

  
515
		// Initialize andami libraries
516 516
		splashWindow.process(translate("SplashWindow.initialize_install_manager"));
517
		PluginsManager pluginmgr = PluginsLocator.getManager();
518
		File defaultAddonsRepository = pluginmgr.getPluginsFolder();
519
		InstallerManager installerManager = InstallerLocator.getInstallerManager();
520
		installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository,"plugin");
517
                initializeInstallerManager();
521 518

  
522
		splashWindow.process(translate("SplashWindow.initialize_list_of_addons_installeds"));
523
		// ---------------------------------------------
524
		// Get the list of installed packages
525
		
526
		PackageInfo[] installedPackages = null;
527
		try {
528
			installedPackages = installerManager.getInstalledPackages(
529
                                pluginmgr.getPluginsFolder()
530
                        );
531
		} catch (MakePluginPackageServiceException e) {
532
			// Do nothing, ignore errors
533
		}
519
                
520
                InstallerManager installerManager = InstallerLocator.getInstallerManager();
521
                PackageInfo[] installedPackages = null;
522
                try {
523
                    installedPackages = installerManager.getInstalledPackages();
524
                } catch (MakePluginPackageServiceException e) {
525
                    // Do nothing, ignore errors
526
                }
527
                logger.info("Dump system information");
528
                logger_info(getInformation(installedPackages));
529
                saveEnvironInformation(installedPackages);
534 530

  
535
		splashWindow.process(translate("SplashWindow.Dump_system_information"));
536
		logger.info("Dump system information");
537
		logger_info(getInformation(installedPackages));
538
		saveEnvironInformation(installedPackages);
539

  
540
		// Se leen los config.xml de los plugins
531
                
532
                // Se leen los config.xml de los plugins
541 533
		splashWindow.process(translate("SplashWindow.load_plugins_configuration"));
542 534
		try {
543 535
			logger.info("Load plugins information");
544
			this.loadPlugins(andamiConfig.getPluginsDirectory());
536
			this.loadPlugins();
545 537
		} catch (Throwable ex) {
546 538
			this.addError("Can't load plugins", ex);
547 539
		}
......
636 628
			}
637 629
		});
638 630

  
639
		/* 
640
		 * Initialize local repository folders of the installer 
641
		 */
642
		message(translate("SplashWindow.initializing_local_addon_repository_folders"));
643
		initializeLocalAddOnRepositoryFolders();
644

  
645 631
		message(translate("SplashWindow.initializing_server_data_persistence"));
646 632
		ServerDataPersistence.registerPersistence();
647 633
		
......
711 697
		PluginsLocator.getManager().executeStartupTasks();
712 698

  
713 699
	}
714
	
700

  
701
        private void initializeInstallerManager() {
702
            PluginsManager pluginmgr = PluginsLocator.getManager();
703
            InstallerManager installerManager = InstallerLocator.getInstallerManager();
704

  
705
            // 
706
            // Configure repository of plugins
707
            //
708
            List<File> folders = pluginmgr.getPluginsFolders();
709
            for ( File folder : folders ) {
710
                installerManager.addLocalAddonRepository(folder, "plugin");
711
            }
712
            installerManager.setDefaultLocalAddonRepository(folders.get(0), "plugin");
713
            
714
            // 
715
            // Configure repository of iconsets
716
            //
717
            IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
718
            FolderSet fset = iconManager.getRepository();
719
            Iterator<FolderSet.FolderEntry> it = fset.iterator();
720
            boolean first = true;
721
            while( it.hasNext() ) {
722
                    FolderEntry entry = it.next();
723
                    installerManager.addLocalAddonRepository(entry.getFolder(),"iconset");
724
                    if( first ) {
725
                        first = false;
726
                        installerManager.setDefaultLocalAddonRepository(entry.getFolder(),"iconset");
727
                    }
728
            }
729
                
730
        }
731

  
715 732
	private void message(final String msg) {
716 733
		if (!SwingUtilities.isEventDispatchThread()) {
717 734
			try {
......
734 751
		}
735 752
	}
736 753

  
737
	private void initializeLocalAddOnRepositoryFolders() {
738
		InstallerManager installerManager = InstallerLocator.getInstallerManager();
739

  
740
		File defaultAddonsRepository = PluginsLocator.getManager().getPluginsFolder();
741

  
742
		installerManager.addLocalAddonRepository(defaultAddonsRepository,"plugin");
743
		installerManager.setDefaultLocalAddonRepository(defaultAddonsRepository);
744
		
745
		IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
746
		FolderSet fset = iconManager.getRepository();
747
		Iterator<FolderSet.FolderEntry> it = fset.iterator();
748
		while( it.hasNext() ) {
749
			FolderEntry entry = it.next();
750
			installerManager.addLocalAddonRepository(entry.getFolder(),"iconset");
751
		}
752
	}
753
	
754

  
755
	
756
	/**
757
     * 
758
     */
759 754
	private void initializeLibraries() {
760 755
		List<ClassLoader> classLoaders = new ArrayList<ClassLoader>(
761 756
				pluginsOrdered.size() + 1);
......
2132 2127
			}
2133 2128
		}
2134 2129
	}
2130
        
2131
        private URL[] getPluginClasspathURLs(PluginConfig pluginConfig) {
2132
            URL[] urls = null;
2135 2133

  
2136
	private void pluginsClassLoaders() {
2137
		Set<String> installed = new HashSet<String>();
2134
            String libfolderPath = pluginConfig.getLibraries().getLibraryDir();
2135
            File libFolderFile = new File(pluginConfig.getPluginFolder(), libfolderPath);
2138 2136

  
2139
		// Se itera hasta que est�n todos instalados
2140
		while (installed.size() != pluginsConfig.size()) {
2141
			boolean circle = true;
2137
            File[] files = libFolderFile.listFiles(new FileFilter() {
2142 2138

  
2143
			// Hacemos una pasada por todos los plugins
2144
			Iterator<String> i = pluginsConfig.keySet().iterator();
2139
                public boolean accept(File pathname) {
2140
                    return (pathname.getName().toUpperCase().endsWith(".JAR")
2141
                            || pathname.getName().toUpperCase().endsWith(".ZIP"));
2142
                }
2143
            });
2144
            if ( files == null ) {
2145
                urls = new URL[0];
2146
            } else {
2147
                urls = new URL[files.length];
2148
                for ( int j = 0; j < files.length; j++ ) {
2149
                    try {
2150
                        urls[j] = new URL("file:" + files[j]);
2151
                    } catch (MalformedURLException e) {
2152
                        logger.warn("Can't add file '" + files[j] + "' to the classpath of plugin '" + pluginConfig.getPluginName() + "'.");
2153
                    }
2154
                }
2155
            }
2156
            return urls;
2157
        }
2145 2158

  
2146
			while (i.hasNext()) {
2147
				String pluginName = i.next();
2148
				PluginConfig config = (PluginConfig) pluginsConfig
2149
						.get(pluginName);
2159
        private void pluginsClassLoaders() {
2160
             Set<String> installed = new HashSet<String>();
2150 2161

  
2151
				if (installed.contains(pluginName)) {
2152
					continue;
2153
				}
2162
             // Se itera hasta que est�n todos instalados
2163
             while ( installed.size() != pluginsConfig.size() ) {
2164
                 boolean circle = true;
2154 2165

  
2155
				// Se obtienen las dependencias y sus class loaders
2156
				boolean ready = true;
2157
				Depends[] dependencies = config.getDepends();
2158
				List<PluginClassLoader> loaders = new ArrayList<PluginClassLoader>();
2166
                 // Hacemos una pasada por todos los plugins
2167
                 Iterator<String> i = pluginsConfig.keySet().iterator();
2159 2168

  
2160
				for (int j = 0; j < dependencies.length; j++) {
2161
					Depends dependency = dependencies[j];
2162
					String dependencyName = dependency.getPluginName();
2163
					PluginConfig dependencyPluginConfig = pluginsConfig.get(dependencyName);
2164
					PluginServices dependencyPluginService = pluginsServices.get(dependencyName);
2165
					
2166
					if( getDeprecatedPluginNames().contains(dependencyName) ) {
2167
						logger.warn("Plugin '"+pluginName+"' use a deprecated plugin name '"+dependencyName+"' as dependency. Must use '"+pluginsConfig.getMainKey(dependencyName)+"'.");
2168
					}
2169
					if ( dependencyPluginConfig == null) {
2170
						if( dependency.getOptional() ) {
2171
							this.logger.info("Plugin '"+pluginName+"', optional dependency '"+dependencyName+"' not found");
2172
						} else {
2173
							this.addError(Messages.getString("Launcher.Dependencia_no_resuelta_en_plugin")
2174
										+ " "
2175
										+ pluginName
2176
										+ ": "
2177
										+ dependencies[j].getPluginName());
2178
						}
2179
					} else {
2180
						if ( dependencyPluginService!=null && 
2181
							installed.contains(dependencyPluginService.getPluginName())) {
2182
							loaders.add(dependencyPluginService.getClassLoader());
2183
						} else {
2184
//							if( !dependency.getOptional() ) {
2185
								ready = false;
2186
//							}
2187
						}
2188
					}
2189
				}
2169
                 while ( i.hasNext() ) {
2170
                     String pluginName = i.next();
2171
                     PluginConfig config = (PluginConfig) pluginsConfig
2172
                             .get(pluginName);
2190 2173

  
2191
				// Si no est�n sus dependencias satisfechas se aborta la
2192
				// instalaci�n
2193
				if (!ready) {
2194
					continue;
2195
				}
2174
                     if ( installed.contains(pluginName) ) {
2175
                         continue;
2176
                     }
2196 2177

  
2197
				// Se genera el class loader
2198
				String jardir = config.getLibraries().getLibraryDir();
2199
				File jarDir = new File(andamiConfig.getPluginsDirectory(),
2200
						pluginName + File.separator + jardir);
2201
				File[] jarFiles = jarDir.listFiles(new FileFilter() {
2178
                     // Se obtienen las dependencias y sus class loaders
2179
                     boolean ready = true;
2180
                     Depends[] dependencies = config.getDepends();
2181
                     List<PluginClassLoader> loaders = new ArrayList<PluginClassLoader>();
2202 2182

  
2203
					public boolean accept(File pathname) {
2204
						return (pathname.getName().toUpperCase()
2205
								.endsWith(".JAR"))
2206
								|| (pathname.getName().toUpperCase()
2207
										.endsWith(".ZIP"));
2208
					}
2209
				});
2210
				URL[] urls = null;
2211
				if( jarFiles==null ) {
2212
					urls = new URL[0];
2213
				} else {
2214
					urls = new URL[jarFiles.length];
2215
	
2216
					for (int j = 0; j < jarFiles.length; j++) {
2217
						try {
2218
							urls[j] = new URL("file:" + jarFiles[j]);
2219
						} catch (MalformedURLException e) {
2220
							this.addError(Messages
2221
									.getString("Launcher.No_se_puede_acceder_a")
2222
									+ " " + jarFiles[j]);
2223
						}
2224
					}
2225
				}
2226
				
2227
				PluginClassLoader loader;
2183
                     for ( int j = 0; j < dependencies.length; j++ ) {
2184
                         Depends dependency = dependencies[j];
2185
                         String dependencyName = dependency.getPluginName();
2186
                         PluginConfig dependencyPluginConfig = pluginsConfig.get(dependencyName);
2187
                         PluginServices dependencyPluginService = pluginsServices.get(dependencyName);
2228 2188

  
2229
				try {
2230
					loader = new PluginClassLoader(urls, andamiConfig
2231
							.getPluginsDirectory()
2232
							+ File.separator + pluginName, Launcher.class
2233
							.getClassLoader(), loaders);
2189
                         if ( getDeprecatedPluginNames().contains(dependencyName) ) {
2190
                             logger.warn("Plugin '" + pluginName + "' use a deprecated plugin name '" + dependencyName + "' as dependency. Must use '" + pluginsConfig.getMainKey(dependencyName) + "'.");
2191
                         }
2192
                         if ( dependencyPluginConfig == null ) {
2193
                             if ( dependency.getOptional() ) {
2194
                                 this.logger.info("Plugin '" + pluginName + "', optional dependency '" + dependencyName + "' not found");
2195
                             } else {
2196
                                 this.addError(Messages.getString("Launcher.Dependencia_no_resuelta_en_plugin")
2197
                                         + " "
2198
                                         + pluginName
2199
                                         + ": "
2200
                                         + dependencies[j].getPluginName());
2201
                             }
2202
                         } else {
2203
                             if ( dependencyPluginService != null
2204
                                     && installed.contains(dependencyPluginService.getPluginName()) ) {
2205
                                 loaders.add(dependencyPluginService.getClassLoader());
2206
                             } else {
2207
     //							if( !dependency.getOptional() ) {
2208
                                 ready = false;
2209
     //							}
2210
                             }
2211
                         }
2212
                     }
2234 2213

  
2235
					PluginServices ps = new PluginServices(loader, PluginsConfig.getAlternativeNames(config));
2214
                                     // Si no est�n sus dependencias satisfechas se aborta la
2215
                     // instalaci�n
2216
                     if ( !ready ) {
2217
                         continue;
2218
                     }
2236 2219

  
2237
					pluginsServices.put(ps.getPluginName(), ps);
2220
                     // Se genera el class loader
2221
                     URL[] urls = getPluginClasspathURLs(config);
2222
                     PluginClassLoader loader;
2238 2223

  
2239
					installed.add(pluginName);
2240
					// FJP: Los metemos ordenados para luego no cargar uno que
2241
					// necesita de otro antes de tiempo. Esto lo usaremos al
2242
					// inicializar los plugins
2243
					pluginsOrdered.add(pluginName);
2224
                     try {
2225
                         loader = new PluginClassLoader(
2226
                                 urls, 
2227
                                 config.getPluginFolder().getAbsolutePath(), 
2228
                                 Launcher.class.getClassLoader(), 
2229
                                 loaders
2230
                         );                         
2231
                         PluginServices ps = new PluginServices(
2232
                                 loader, 
2233
                                 PluginsConfig.getAlternativeNames(config)
2234
                         );
2235
                         pluginsServices.put(ps.getPluginName(), ps);
2236
                         installed.add(pluginName);
2237
                         pluginsOrdered.add(pluginName);
2244 2238

  
2245
					circle = false;
2246
				} catch (IOException e) {
2247
					this
2248
							.addError(
2249
									Messages
2250
											.getString("Launcher.Error_con_las_librerias_del_plugin"),
2251
									e);
2252
					pluginsConfig.remove(pluginName);
2253
					i = pluginsConfig.keySet().iterator();
2254
				}
2255
			}
2239
                         circle = false;
2240
                     } catch (IOException e) {
2241
                         logger.warn("Can't create PluginServices for '"+config.getPluginName()+"'.",e);
2242
                         pluginsConfig.remove(pluginName);
2243
                         i = pluginsConfig.keySet().iterator();
2244
                     }
2245
                 }
2256 2246

  
2257
			if (circle) {
2258
				dumpPluginsDependencyInformation();
2259
				this.addError("Has circular dependencies betewn plugins");
2260
				break;
2261
			}
2262
		}
2247
                 if ( circle ) {
2248
                     dumpPluginsDependencyInformation();
2249
                     this.addError("Has circular dependencies betewn plugins");
2250
                     break;
2251
                 }
2252
             }
2263 2253

  
2264
		// Se eliminan los plugins que no fueron instalados
2265
		Iterator<String> i = pluginsConfig.keySet().iterator();
2254
             // Se eliminan los plugins que no fueron instalados
2255
             Iterator<String> i = pluginsConfig.keySet().iterator();
2266 2256

  
2267
		while (i.hasNext()) {
2268
			String pluginName = i.next();
2269
			PluginServices ps = (PluginServices) pluginsServices
2270
					.get(pluginName);
2257
             while ( i.hasNext() ) {
2258
                 String pluginName = i.next();
2259
                 PluginServices ps = (PluginServices) pluginsServices
2260
                         .get(pluginName);
2271 2261

  
2272
			if (ps == null) {
2273
				pluginsConfig.remove(pluginName);
2274
				i = pluginsConfig.keySet().iterator();
2275
			}
2276
		}
2277
		registerActions();
2278
	}
2262
                 if ( ps == null ) {
2263
                     pluginsConfig.remove(pluginName);
2264
                     i = pluginsConfig.keySet().iterator();
2265
                 }
2266
             }
2267
             registerActions();
2268
         }
2279 2269

  
2280 2270
	private void dumpPluginsDependencyInformation() {
2281 2271
		logger.info("Plugin dependency information");
......
2323 2313
	static String getPluginsDir() {
2324 2314
		return andamiConfig.getPluginsDirectory();
2325 2315
	}
2316
        
2317
        static File getPluginFolder(String pluginName) {
2318
            return pluginsConfig.get(pluginName).getPluginFolder();
2319
        }
2326 2320

  
2327 2321
	static void setPluginsDir(String s) {
2328 2322
		andamiConfig.setPluginsDirectory(s);
......
2332 2326
		return frame;
2333 2327
	}
2334 2328

  
2335
	private void loadPlugins(String pluginsDirectory) {
2336
		File pDir = new File(pluginsDirectory);
2329
        
2330
        private void loadPlugins() {
2331
            InstallerManager installerManager = InstallerLocator.getInstallerManager();
2332
            List<File> repositoriesFolders = installerManager.getLocalAddonRepositories("plugin");
2333
            for ( File repositoryFolder : repositoriesFolders ) {
2334
                logger.info("Loading plugins from repository folder " + repositoryFolder.getAbsolutePath() + ".");
2337 2335

  
2338
		if (!pDir.exists()) {
2339
			logger
2340
					.error("\n\tPlugins directory not found: "
2341
							+ pDir.getAbsolutePath()
2342
							+ "\n\tDid you specify the correct directory in the Launch Configuration parameters?\n\tExiting now...");
2343
			System.exit(-1);
2344
			return;
2345
		}
2336
                if ( !repositoryFolder.exists() ) {
2337
                    logger.warn("Plugins repository folder not found '" + repositoryFolder.getAbsolutePath() + "'.");
2338
                    continue;
2339
                }
2346 2340

  
2347
		File[] pluginDirs = pDir.listFiles();
2348
		if (pluginDirs.length == 0) {
2349
			logger
2350
					.error("\n\tPlugins directory is empty: "
2351
							+ pDir.getAbsolutePath()
2352
							+ "Did you specify the correct directory in the Launch Configuration parameters?\n\tExiting now...");
2353
			System.exit(-1);
2354
			return;
2355
		}
2341
                File[] pluginsFolders = repositoryFolder.listFiles();
2342
                if ( pluginsFolders.length == 0 ) {
2343
                    logger.warn("Plugins repository folder is empty '" + repositoryFolder.getAbsolutePath() + "'.");
2344
                    continue;
2345
                }
2356 2346

  
2357
		for (int i = 0; i < pluginDirs.length; i++) {
2358
			if (pluginDirs[i].isDirectory()) {
2359
				String pluginName =  pluginDirs[i].getName();
2360
				File configXml = new File(pluginDirs[i].getAbsolutePath(),
2361
						"config.xml");
2347
                for ( int i = 0; i < pluginsFolders.length; i++ ) {
2348
                    File pluginFolder = pluginsFolders[i];
2349
                    if ( !pluginFolder.isDirectory() ) {
2350
                        continue;
2351
                    }
2352
                    String pluginName = pluginFolder.getName();
2353
                    File pluginConfigFile = new File(pluginFolder, "config.xml");
2354
                    if ( !pluginConfigFile.exists() ) {
2355
                        logger.info("Plugin '" + pluginName + "' not has a config.xml file (" + pluginConfigFile.getAbsolutePath() + ".");
2356
                        continue;
2357
                    }
2358
                    try {
2359
                        FileInputStream is = new FileInputStream(pluginConfigFile);
2360
                        Reader xml = org.gvsig.utils.xml.XMLEncodingUtils.getReader(is);
2361
                        if ( xml == null ) {
2362
                            // the encoding was not correctly detected, use system default
2363
                            xml = new FileReader(pluginConfigFile);
2364
                        } else {
2365
                            // use a buffered reader to improve performance
2366
                            xml = new BufferedReader(xml);
2367
                        }
2368
                        PluginConfig pluginConfig = (PluginConfig) PluginConfig.unmarshal(xml);
2369
                        pluginConfig.setPluginName(pluginName);
2370
                        pluginConfig.setPluginFolder(pluginFolder);
2371
                        pluginsConfig.put(pluginName, pluginConfig);
2362 2372

  
2363
				try {
2364
					FileInputStream is = new FileInputStream(configXml);
2365
					Reader xml = org.gvsig.utils.xml.XMLEncodingUtils.getReader(is);
2366
					if (xml == null) {
2367
						// the encoding was not correctly detected, use system
2368
						// default
2369
						xml = new FileReader(configXml);
2370
					} else {
2371
						// use a buffered reader to improve performance
2372
						xml = new BufferedReader(xml);
2373
					}
2374
					PluginConfig pConfig = (PluginConfig) PluginConfig.unmarshal(xml);
2375
					pluginsConfig.put(pluginDirs[i].getName(), pConfig);
2376
				} catch (FileNotFoundException e) {
2377
					logger.info("Plugin '"+pluginName+"' without config.xml ("
2378
									+ pluginDirs[i].getAbsolutePath() + ").");
2379
				} catch (MarshalException e) {
2380
					this.addError("Can't load plugin '"+pluginName+"', incorrect config.xml." + e.getMessage() +" ("
2381
							+ pluginDirs[i].getAbsolutePath() + ").", e);
2382
				} catch (ValidationException e) {
2383
					this.addError("Can't load plugin '"+pluginName+"', invalid config.xml." + e.getMessage() +" ("
2384
							+ pluginDirs[i].getAbsolutePath() + ").", e);
2385
				}
2386
			}
2387
		}
2373
                    } catch (FileNotFoundException e) {
2374
                        logger.info("Can't read plugin config file from plugin '" + pluginName + "' ('" + pluginConfigFile.getAbsolutePath() + ").");
2388 2375

  
2389
		if (pluginsConfig.size() == 0) {
2390
			logger.error("No valid plugin was found. The plugins directory currently is: "
2391
							+ pDir.getAbsolutePath()
2392
							+ "\n\tDid you specify the correct directory in the Launch Configuration parameters?\n\tExiting now...");
2393
			System.exit(-1);
2394
			return;
2395
		}
2396
	}
2376
                    } catch (MarshalException e) {
2377
                        logger.warn("Can't load plugin the config file from plugin '" + pluginName + "' is incorect. " + e.getMessage() + " ('" + pluginConfigFile.getAbsolutePath() + ").", e);
2397 2378

  
2379
                    } catch (ValidationException e) {
2380
                        logger.warn("Can't load plugin the config file from plugin '" + pluginName + "' is invalid. " + e.getMessage() + " ('" + pluginConfigFile.getAbsolutePath() + ").", e);
2381

  
2382
                    }
2383
                }
2384
            }
2385
            if ( pluginsConfig.isEmpty() ) {
2386
                logger.warn("No valid plugin was found.");
2387
                System.exit(-1);
2388
            }
2389
        }
2390

  
2398 2391
	private static Locale getLocale(String language, String country,
2399 2392
			String variant) {
2400 2393
		if (variant != null) {
......
3646 3639
	public static String getInformation() {
3647 3640
		return getInformation(null);
3648 3641
	}
3649
	
3650
	public static String getInformation(PackageInfo[] pkgs) {
3651
		PluginsManager pluginmgr = PluginsLocator.getManager();
3652 3642

  
3653
		StringWriter writer = new StringWriter();
3643
        private static final int INFO_OS_NAME = 0;
3644
        private static final int INFO_OS_ARCH = 1;
3645
        private static final int INFO_OS_VERSION = 2;
3646
        private static final int INFO_OS_ADITIONAL = 3;
3647
        private static final int INFO_JRE_VENDOR = 4;
3648
        private static final int INFO_JRE_VERSION = 5;
3649
        private static final int INFO_JRE_HOME = 6;
3650
        private static final int INFO_PROXY_HOST = 7;
3651
        private static final int INFO_PROXY_PORT = 8;
3652
        private static final int INFO_PROXY_USER = 9;
3653
        private static final int INFO_PROXY_PASSWORD = 10;
3654
        private static final int INFO_APP_LOCALE = 11;
3655
        private static final int INFO_APP_FOLDER = 12;
3656
        private static final int INFO_APP_HOME = 13;
3657
        private static final int INFO_APP_INSTALL_FOLDER = 14;
3658
        private static final int INFO_APP_PLUGINS_FOLDER = 15;
3659
        private static final int INFO_APP_THEME = 16;
3660
        private static final int INFO_APP_SKIN = 17;
3661
        private static final int INFO_PACKAGES = 18;
3662
        
3663
        
3664
        public static String getInformation(PackageInfo[] pkgs) {
3665
            
3666
            String template = "OS\n" 
3667
                    +"    name    : {"+INFO_OS_NAME+"}\n"
3668
                    +"    arch    : {"+INFO_OS_ARCH+"}\n"
3669
                    +"    version : {"+INFO_OS_VERSION+"} \n"
3670
                    +"{"+INFO_OS_ADITIONAL+"}"
3671
                    +"JRE\n"
3672
                    +"    vendor  : {"+INFO_JRE_VENDOR+"}\n"
3673
                    +"    version : {"+INFO_JRE_VERSION+"}\n"
3674
                    +"    home    : {"+INFO_JRE_HOME+"}\n"
3675
                    +"HTTP Proxy\n"
3676
                    +"    http.proxyHost     : {"+INFO_PROXY_HOST+"}\n"
3677
                    +"    http.proxyPort     : {"+INFO_PROXY_PORT+"}\n"
3678
                    +"    http.proxyUserName : {"+INFO_PROXY_USER+"}\n"
3679
                    +"    http.proxyPassword : {"+INFO_PROXY_PASSWORD+"}\n"
3680
                    +"Application\n"
3681
                    +"    locale language         : {"+INFO_APP_LOCALE+"}\n"
3682
                    +"    application forlder     : {"+INFO_APP_FOLDER+"}\n"
3683
                    +"    application home forlder: {"+INFO_APP_HOME+"}\n"
3684
                    +"    install forlder         : {"+INFO_APP_INSTALL_FOLDER+"}\n"
3685
                    +"    plugins forlder         : {"+INFO_APP_PLUGINS_FOLDER+"}\n"
3686
                    +"    theme                   : {"+INFO_APP_THEME+"}\n"
3687
                    +"    Skin                    : {"+INFO_APP_SKIN+"}\n"
3688
                    +"Installed packages\n"
3689
                    +"{"+INFO_PACKAGES+"}";
3690
            
3654 3691

  
3655
		Properties props = System.getProperties();
3692
            String values[] = new String[INFO_PACKAGES+1];
3693
            
3694
            PluginsManager pluginmgr = PluginsLocator.getManager();
3695
            LocaleManager localemgr = PluginsLocator.getLocaleManager();
3696
            
3697
            Properties props = System.getProperties();
3656 3698

  
3657
		// OS information
3658
		String osName = props.getProperty("os.name");
3659
		writer.write("OS\n");
3660
		writer.write("    name   : " + osName + "\n");
3661
		writer.write("    arch   : " + props.get("os.arch") + "\n");
3662
		writer.write("    version: " + props.get("os.version") + "\n");
3663
		if (osName.startsWith("Linux")) {
3664
			try {
3665
				String[] command = { "lsb_release", "-a" };
3666
				Process p = Runtime.getRuntime().exec(command);
3667
				InputStream is = p.getInputStream();
3668
				BufferedReader reader = new BufferedReader(
3669
						new InputStreamReader(is));
3670
				String line;
3671
				while ((line = reader.readLine()) != null) {
3672
					writer.write("    " + line + "\n");
3673
				}
3674
			} catch (Exception ex) {
3675
				writer
3676
						.write("Can't get detailled os information (lsb_release -a).");
3677
			}
3678
		}
3699
            
3700
            // OS information
3701
            values[INFO_OS_NAME] = props.getProperty("os.name");
3702
            values[INFO_OS_ARCH] = props.getProperty("os.arch");
3703
            values[INFO_OS_VERSION] = props.getProperty("os.version");
3704
            
3705
            if ( values[INFO_OS_NAME].startsWith("Linux") ) {
3706
                try {
3707
                    StringWriter writer = new StringWriter();
3708
            
3709
                    String[] command = {"lsb_release", "-a"};
3710
                    Process p = Runtime.getRuntime().exec(command);
3711
                    InputStream is = p.getInputStream();
3712
                    BufferedReader reader = new BufferedReader(new InputStreamReader(is));
3713
                    String line;
3714
                    while ( (line = reader.readLine()) != null ) {
3715
                        writer.write("    " + line + "\n");
3716
                    }
3717
                    values[INFO_OS_ADITIONAL] = writer.toString();
3718
                } catch (Exception ex) {
3719
                    logger.warn("Can't get detailled os information (lsb_release -a).", ex);
3720
                }
3721
            }
3679 3722

  
3680
		// JRE information
3681
		writer.write("JRE\n");
3682
		writer.write("    vendor : " + props.get("java.vendor") + "\n");
3683
		writer.write("    version: " + props.get("java.version") + "\n");
3684
		writer.write("    home   : " + props.get("java.home") + "\n");
3723
            values[INFO_JRE_VENDOR] = props.getProperty("java.vendor");
3724
            values[INFO_JRE_VERSION] = props.getProperty("java.version");
3725
            values[INFO_JRE_HOME] = props.getProperty("java.home");
3726
            values[INFO_PROXY_HOST] = props.getProperty("http.proxyHost");
3727
            values[INFO_PROXY_PORT] = props.getProperty("http.proxyPort");
3728
            values[INFO_PROXY_USER] = props.getProperty("http.proxyUserName");
3685 3729

  
3686
		writer.write("HTTP Proxy\n");
3687
		writer.write("    http.proxyHost     : " + props.get("http.proxyHost")
3688
				+ "\n");
3689
		writer.write("    http.proxyPort     : " + props.get("http.proxyPort")
3690
				+ "\n");
3691
		writer.write("    http.proxyUserName : "
3692
				+ props.get("http.proxyUserName") + "\n");
3693
                
3694
                String proxyPass = (String) props.get("http.proxyPassword");
3695
                if( proxyPass!=null ) {
3696
                    proxyPass = "**********";
3697
                }
3698
		writer.write("    http.proxyPassword : " + proxyPass + "\n");
3730
            if ( props.get("http.proxyPassword") == null ) {
3731
                values[INFO_PROXY_PASSWORD] = "(null)";
3732
            } else {
3733
                values[INFO_PROXY_PASSWORD] = "***********";
3734
            }
3699 3735

  
3700
		String skinName = "(unknow)";
3701
		try {
3702
			skinName = MDIManagerFactory.getSkinExtension().getClassName();
3703
		} catch (Throwable e) {
3704
			// Ignore
3705
		}
3706
		writer.write("Application\n");
3707
		writer.write("    locale language         : "
3708
				+ Launcher.getAndamiConfig().getLocaleLanguage() + "\n");
3709
		writer.write("    application forlder     : "
3710
				+ pluginmgr.getApplicationFolder() + "\n");
3711
		writer.write("    application home forlder: "
3712
				+ pluginmgr.getApplicationHomeFolder() + "\n");
3713
		writer.write("    install forlder         : "
3714
				+ pluginmgr.getInstallFolder() + "\n");
3715
		writer.write("    plugins forlder         : "
3716
				+ pluginmgr.getPluginsFolder() + "\n");
3717
		writer.write("    theme                   : "
3718
				+ Launcher.theme.getSource() + "\n");
3719
		writer.write("    Skin                    : " + skinName + "\n");
3736
            try {
3737
                values[INFO_APP_SKIN] = MDIManagerFactory.getSkinExtension().getClassName();
3738
            } catch (Throwable e) {
3739
                values[INFO_APP_SKIN] = "(unknow)";
3740
            }
3741
            values[INFO_APP_LOCALE] = localemgr.getCurrentLocale().toString();
3742
            values[INFO_APP_FOLDER] = pluginmgr.getApplicationFolder().getAbsolutePath();
3743
            values[INFO_APP_HOME] = pluginmgr.getApplicationHomeFolder().getAbsolutePath();
3744
            values[INFO_APP_INSTALL_FOLDER] = pluginmgr.getInstallFolder().getAbsolutePath();
3745
            values[INFO_APP_PLUGINS_FOLDER] = StringUtils.join(pluginmgr.getPluginsFolders());
3746
            values[INFO_APP_THEME] = Launcher.theme.getSource().getAbsolutePath();
3720 3747

  
3721
		try {
3722
			if( pkgs == null ) {
3723
				InstallerManager installmgr = InstallerLocator.getInstallerManager();
3724
				pkgs = installmgr.getInstalledPackages(pluginmgr
3725
						.getPluginsFolder());
3726
			}
3727
			writer.write("Installed packages\n");
3728
			for (int i = 0; i < pkgs.length; i++) {
3729
				writer.write("    ");
3730
				writer.write(pkgs[i].toStringCompact());
3731
				writer.write("\n");
3732
			}
3733
		} catch (Throwable e) {
3734
			writer.write("Can't get installed package information.");
3735
		}
3736
		return writer.toString();
3737
	}
3748
            try {
3749
                if ( pkgs == null ) {
3750
                    InstallerManager installmgr = InstallerLocator.getInstallerManager();
3751
                    pkgs = installmgr.getInstalledPackages();
3752
                }
3753
                StringWriter writer = new StringWriter();
3754
                for ( int i = 0; i < pkgs.length; i++ ) {
3755
                    writer.write("    ");
3756
                    writer.write(pkgs[i].toStringCompact());
3757
                    writer.write("\n");
3758
                }
3759
                values[INFO_PACKAGES] = writer.toString();
3760
                
3761
            } catch (Throwable e) {
3762
                logger.warn("Can't get installed package information.",e);
3763
            }
3764
            
3765
            String s = MessageFormat.format(template, values);
3766
            return s;
3767
        }
3738 3768

  
3739 3769
	private void logger_info(String msg) {
3740 3770
		String info[] = msg.split("\n");
......
3804 3834
		}
3805 3835
		splashWindow.toBack();
3806 3836
		DisablePluginsConflictingDialog dlg = new DisablePluginsConflictingDialog(packages, incompatiblePlugins);
3807
//		dlg.setAlwaysOnTop(true);
3808 3837
		dlg.setVisible(true);
3809 3838
		splashWindow.toFront();
3810 3839
		switch(dlg.getAction()) {
......
3814 3843
		case DisablePluginsConflictingDialog.CONTINUE:
3815 3844
			break;
3816 3845
		}
3817
		List<String> pluginsToDesable = dlg.getPluginNamesToDisable();
3818
		if( pluginsToDesable  == null ) {
3846
		List<String> pluginsToDissable = dlg.getPluginNamesToDisable();
3847
		if( pluginsToDissable  == null ) {
3819 3848
			return;
3820 3849
		}
3821
		PluginConfig x = pluginsConfig.get("org.gvsig.projection.app.mainplugin");
3822 3850
		
3823
		Iterator<String> it2 = pluginsToDesable.iterator();
3851
		Iterator<String> it2 = pluginsToDissable.iterator();
3824 3852
		while( it2.hasNext() ) {
3825 3853
			String pluginName = it2.next();
3826
			logger.info("Disabling plugin '"+pluginName+"' by user action.");
3854
			logger.info("Dissabling plugin '"+pluginName+"' by user action.");
3827 3855
			pluginsConfig.remove(pluginName);
3828
		}
3829
		PluginConfig y = pluginsConfig.get("org.gvsig.projection.app.mainplugin");
3830
		
3856
		}		
3831 3857
	}
3832 3858
	
3833 3859
	private class DisablePluginsConflictingDialog extends JDialog {

Also available in: Unified diff