Revision 41717

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.swing/org.gvsig.installer.swing.api/src/main/java/org/gvsig/installer/swing/api/JProgressPanel.java
36 36

  
37 37
	public abstract void bind(TaskStatus taskStatus);
38 38

  
39
	public abstract void showErrorMessage(String msg, Exception ex);
39
	public abstract void showErrorMessage(String msg, Throwable ex);
40 40

  
41 41
}
trunk/org.gvsig.desktop/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
35 35
import java.awt.Toolkit;
36 36
import java.awt.event.ActionEvent;
37 37
import java.awt.event.ActionListener;
38
import java.awt.event.WindowEvent;
39
import java.awt.event.WindowListener;
38 40
import java.io.BufferedOutputStream;
39 41
import java.io.BufferedReader;
40 42
import java.io.File;
......
452 454
			args = new String[] { "gvSIG", "gvSIG/extensiones" };
453 455
		}
454 456

  
455
		initializeApp(args);
457
		initializeApp(args, null);
456 458

  
457 459
		// Solucionamos el problema de permisos que se produc?do con Java
458 460
		// Web Start con este codigo.
......
781 783
	 * @throws IOException
782 784
	 * @throws ConfigurationException
783 785
	 */
784
	private void initializeApp(String[] args) throws IOException, ConfigurationException {
786
	private void initializeApp(String[] args, String applicationClasifier) throws IOException, ConfigurationException {
785 787
		if( args.length<1 ) {
786 788
			appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG"
787 789
		} else {
788 790
			appName = args[0];
789 791
		}
790 792
		getOrCreateConfigFolder();
791
		configureLogging(appName);
793
		configureLogging(appName, applicationClasifier);
792 794
		if (!validJVM()) {
793 795
                    logger.error("Not a valid JRE. Exit application.");
794 796
                    System.exit(-1);
......
866 868
	 * @param args
867 869
	 * @throws IOException
868 870
	 */
869
	private void configureLogging(String appName) throws IOException {
871
	private void configureLogging(String appName, String applicationClasifier) throws IOException {
870 872
		// Configurar el log4j
871 873

  
874
                String pathname;
875
                if( StringUtils.isBlank(applicationClasifier) ) {
876
                    pathname = appHomeDir + File.separator + appName + ".log";
877
                } else {
878
                    pathname = appHomeDir + File.separator + appName + "-" + applicationClasifier + ".log";
879
                }
872 880
		URL config = Launcher.class.getClassLoader().getResource("log4j.properties");
873 881
		if( config == null ) {
874 882
			config = Launcher.class.getClassLoader().getResource("default-log4j/log4j.properties");
875 883
		}
876 884
		PropertyConfigurator.configure(config);
877 885
		PatternLayout l = new PatternLayout("%p %t %C - %m%n");
878
		RollingFileAppender fa = new RollingFileAppender(l, appHomeDir
879
				+ File.separator + appName + ".log", false);
886
		RollingFileAppender fa = new RollingFileAppender(l, pathname, false);
880 887
		fa.setMaxFileSize("512KB");
881 888
		fa.setMaxBackupIndex(3);
882 889
		org.apache.log4j.Logger.getRootLogger().addAppender(fa);
883 890
		logger.info("Loadded log4j.properties from " + config.toString());
891
                if( StringUtils.isBlank(applicationClasifier) ) {
892
                    logger.info("Application "+ appName );
893
                } else {
894
                    logger.info("Application "+ appName + "-" + applicationClasifier );
895
                }
884 896
	}
885 897

  
886 898
	private class NotificationAppender extends AppenderSkeleton {
......
3465 3477
	 * @throws Exception
3466 3478
	 *             if there is any error
3467 3479
	 */
3468
	private void doInstall(String[] args) throws Exception {
3469
		String installURL = null;
3470
		String installURLFile = null;
3471
		String gvSIGVersion = null;
3472
		String[] myArgs = new String[3];
3473
		PackageInfo packageInfo = null; 
3480
    private void doInstall(String[] args) throws Exception {
3481
        String installURL = null;
3482
        String installURLFile = null;
3483
        String gvSIGVersion = null;
3484
        String[] myArgs = new String[3];
3485
        PackageInfo packageInfo = null;
3474 3486

  
3475
		Options options = new Options();
3476
		options.addOption("i", "install", false, "install");
3477
		options.addOption("u", "installURL", true, "installURL");
3478
		options.addOption("f", "installURLFile", true, "installURLFile");
3479
		options.addOption("v", "installVersion", true, "installVersion");
3480
		options.addOption("A", "applicationName", true, "applicationName");
3481
		options.addOption("P", "pluginsFolder", true, "pluginsFolder");
3482
		options.addOption("l", "language", true, "language");
3487
        Options options = new Options();
3488
        options.addOption("i", "install", false, "install");
3489
        options.addOption("u", "installURL", true, "installURL");
3490
        options.addOption("f", "installURLFile", true, "installURLFile");
3491
        options.addOption("v", "installVersion", true, "installVersion");
3492
        options.addOption("A", "applicationName", true, "application name, default is gvSIG");
3493
        options.addOption("P", "pluginsFolder", true, "pluginsFolder");
3494
        options.addOption("l", "language", true, "language");
3483 3495

  
3484
		
3485
		/*
3486
		 * Los parametros que deberian pasarse en el instalador oficial de gvSIG serian:
3487
		 * 
3488
		 * --install
3489
		 * --applicationName=gvSIG
3490
		 * --language=es
3491
		 * --pluginsFolder=gvSIG/extensiones
3492
		 * 
3493
		 * Opcionales (casi mejor que dejar los de por defecto y no pasarselos):
3494
		 * --installVersion=2.0.0
3495
		 * --installURL=http://downloads.gvsig.org/download/gvsig-desktop/dists
3496
		 * --installURLFile=gvSIG/extensiones/org.gvsig.installer.app.extension/defaultDownloadsURLs
3497
		 * 
3498
		 */
3499
		CommandLineParser parser = new PosixParser();
3500
		CommandLine line = null;
3501
		try {
3502
			line = parser.parse(options, args);
3503
			boolean hasAllMandatoryOptions = true;
3504
			if (!line.hasOption("install")) {
3505
				hasAllMandatoryOptions = false;
3506
			}
3507
			
3508
			if (line.hasOption("installVersion")) {
3509
				gvSIGVersion = line.getOptionValue("installVersion");
3510
			}
3511
			if (line.hasOption("applicationName")) {
3512
				myArgs[0] = line.getOptionValue("applicationName");
3513
			} else {
3514
				hasAllMandatoryOptions = false;
3515
			}
3516
			if (line.hasOption("pluginsFolder")) {
3517
				myArgs[1] = line.getOptionValue("pluginsFolder");
3518
			} else {
3519
				myArgs[1] = "gvSIG/extensiones";
3520
				hasAllMandatoryOptions = false;
3521
			}
3522
			if (line.hasOption("language")) {
3523
				myArgs[2] = "language=" + line.getOptionValue("language");
3524
			} else {
3525
			    // prevent null
3526
			    myArgs[2] = "";
3527
			}
3528
			
3529
			if (line.hasOption("installURL")) {
3530
				installURL = line.getOptionValue("installURL");
3531
			} else {
3532
				installURL = "http://downloads.gvsig.org/download/gvsig-desktop/";
3533
			}
3534
			
3535
			if (line.hasOption("installURLFile")) {
3536
				installURLFile = line.getOptionValue("installURLFile");
3537
			} else {
3538
				installURLFile = myArgs[1] + "/org.gvsig.installer.app.mainplugin/defaultDownloadsURLs";
3539
			}
3496
                // This options are managed by the gvSIG.sh but need to be declared here to avoid
3497
        // errors.
3498
        options.addOption(null, "debug", false, "Activate the JVM remote debug");
3499
        options.addOption(null, "pause", false, "Pause when activate JVM debug");
3540 3500

  
3541
			if (!hasAllMandatoryOptions) {
3542
				System.err
3543
						.println(Messages.get("usage")
3544
								+ ": Launcher --applicationName=appName --pluginsFolder=plugins-directory "
3545
								+ "[--installURLFile=File] "
3546
								+ "--install [--installURL=URL] [language=locale]");
3547
				return;
3548
			}
3549
		} catch (ParseException exp) {
3550
			System.out.println("Unexpected exception:" + exp.getMessage());
3551
		}
3501
        /*
3502
         * Los parametros que deberian pasarse en el instalador oficial de gvSIG serian:
3503
         * 
3504
         * --install
3505
         * --applicationName=gvSIG
3506
         * --language=es
3507
         * --pluginsFolder=gvSIG/extensiones
3508
         * 
3509
         * Opcionales (casi mejor que dejar los de por defecto y no pasarselos):
3510
         * --installVersion=2.0.0
3511
         * --installURL=http://downloads.gvsig.org/download/gvsig-desktop/dists
3512
         * --installURLFile=gvSIG/extensiones/org.gvsig.installer.app.extension/defaultDownloadsURLs
3513
         * 
3514
         */
3515
        CommandLineParser parser = new PosixParser();
3516
        CommandLine line = null;
3517
        try {
3518
            line = parser.parse(options, args);
3519
            boolean hasAllMandatoryOptions = true;
3520
            if ( !line.hasOption("install") ) {
3521
                hasAllMandatoryOptions = false;
3522
            }
3552 3523

  
3553
		initializeApp(myArgs);
3554
		initializeLibraries();
3555
		AndamiConfig config = getAndamiConfig();
3556
		config.setLocaleLanguage(locale.getLanguage());
3557
		config.setLocaleCountry(locale.getCountry());
3558
		config.setLocaleVariant(locale.getVariant());
3559
		
3560
		InstallerManager installerManager = InstallerLocator.getInstallerManager();
3561
		
3562
		packageInfo = getPackageInfo(myArgs[1]);
3563
		
3564
		// set the gvSIG version to the install manager, to compose the download URL
3565
		if( packageInfo!=null ) {
3566
			installerManager.setVersion(packageInfo.getVersion());
3567
		} else {
3568
			installerManager.setVersion(gvSIGVersion);
3569
		}
3570
		if( !installURL.contains(";") &&
3571
			!installURL.endsWith(InstallerManager.PACKAGE_EXTENSION) && 
3572
			!installURL.endsWith(InstallerManager.PACKAGE_INDEX_EXTENSION) ) {
3573
			if( packageInfo!=null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA) ||
3574
			 	packageInfo.getState().startsWith(InstallerManager.STATE.RC) ||
3575
			 	packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL)) ) {
3576
				installURL = installURL + "dists/<%Version%>/builds/<%Build%>/packages.gvspki";			
3577
			}
3578
		}
3579
		// Configure default index download URL
3580
		SwingInstallerLocator.getSwingInstallerManager().setDefaultDownloadURL(installURL);
3524
            if ( line.hasOption("installVersion") ) {
3525
                gvSIGVersion = line.getOptionValue("installVersion");
3526
            }
3527
            if ( line.hasOption("applicationName") ) {
3528
                myArgs[0] = line.getOptionValue("applicationName");
3529
            } else {
3530
                myArgs[0] = "gvSIG";
3531
            }
3532
            if ( line.hasOption("pluginsFolder") ) {
3533
                myArgs[1] = line.getOptionValue("pluginsFolder");
3534
            } else {
3535
                myArgs[1] = "gvSIG/extensiones";
3536
            }
3537
            if ( line.hasOption("language") ) {
3538
                myArgs[2] = "language=" + line.getOptionValue("language");
3539
            } else {
3540
                // prevent null
3541
                myArgs[2] = "";
3542
            }
3581 3543

  
3582
		SwingInstallerLocator.getSwingInstallerManager().setDefaultDownloadURL(new File(installURLFile));
3544
            if ( line.hasOption("installURL") ) {
3545
                installURL = line.getOptionValue("installURL");
3546
            } else {
3547
                installURL = "http://downloads.gvsig.org/download/gvsig-desktop/";
3548
            }
3583 3549

  
3584
		// Launch installer
3585
		PluginsManager manager = PluginsLocator.getManager();
3550
            if ( line.hasOption("installURLFile") ) {
3551
                installURLFile = line.getOptionValue("installURLFile");
3552
            } else {
3553
                installURLFile = myArgs[1] + "/org.gvsig.installer.app.mainplugin/defaultDownloadsURLs";
3554
            }
3586 3555

  
3587
		File defaultAddonsRepository = PluginsLocator.getManager()
3588
				.getPluginsFolder();
3589
		installerManager.addLocalAddonRepository(defaultAddonsRepository);
3590
		installerManager
3591
				.setDefaultLocalAddonRepository(defaultAddonsRepository);
3556
            if ( !hasAllMandatoryOptions ) {
3557
                System.err.println(Messages.get("usage") + ": Launcher " +
3558
                        "--install "+
3559
                        "[--applicationName=appName] " + 
3560
                        "[--pluginsFolder=plugins-directory] " +
3561
                        "[--installURLFile=File] " +
3562
                        "[--installURL=URL] " +
3563
                        "[--language=locale]"
3564
                );
3565
                return;
3566
            }
3567
        } catch (ParseException exp) {
3568
            System.out.println("Unexpected exception:" + exp.getMessage());
3569
            System.exit(-1);
3570
        }
3592 3571

  
3593
		AbstractInstallPackageWizard installPackageWizard = SwingInstallerLocator
3594
				.getSwingInstallerManager().createInstallPackageWizard(
3595
						manager.getApplicationFolder(),
3596
						manager.getInstallFolder());
3597
		installPackageWizard
3598
				.setWizardActionListener(new InstallerWizardActionListener() {
3572
        initializeApp(myArgs, "installer");
3573
        initializeLibraries();
3574
        
3575
        AndamiConfig config = getAndamiConfig();
3576
        config.setLocaleLanguage(locale.getLanguage());
3577
        config.setLocaleCountry(locale.getCountry());
3578
        config.setLocaleVariant(locale.getVariant());
3599 3579

  
3600
					public void finish(InstallerWizardPanel installerWizard) {
3601
						System.exit(0);
3602
					}
3580
        initializeInstallerManager();
3581
        
3582
        InstallerManager installerManager = InstallerLocator.getInstallerManager();
3603 3583

  
3604
					public void cancel(InstallerWizardPanel installerWizard) {
3605
						System.exit(0);
3606
					}
3607
				});
3584
        packageInfo = getPackageInfo(myArgs[1]);
3608 3585

  
3609
		// the wizard will show the Typical or Advanced mode option.
3610
		installPackageWizard.setAskTypicalOrCustom(true);
3611
		// default packages will be selected.
3612
		installPackageWizard.setSelectDefaultPackages(true);
3586
        // set the gvSIG version to the install manager, to compose the download URL
3587
        if ( packageInfo != null ) {
3588
            installerManager.setVersion(packageInfo.getVersion());
3589
        } else {
3590
            installerManager.setVersion(gvSIGVersion);
3591
        }
3592
        if ( !installURL.contains(";")
3593
                && !installURL.endsWith(InstallerManager.PACKAGE_EXTENSION)
3594
                && !installURL.endsWith(InstallerManager.PACKAGE_INDEX_EXTENSION) ) {
3595
            if ( packageInfo != null && (packageInfo.getState().startsWith(InstallerManager.STATE.BETA)
3596
                    || packageInfo.getState().startsWith(InstallerManager.STATE.RC)
3597
                    || packageInfo.getState().equalsIgnoreCase(InstallerManager.STATE.FINAL)) ) {
3598
                installURL = installURL + "dists/<%Version%>/builds/<%Build%>/packages.gvspki";
3599
            }
3600
        }
3601
        // Configure default index download URL
3602
        SwingInstallerLocator.getSwingInstallerManager().setDefaultDownloadURL(installURL);
3613 3603

  
3604
        SwingInstallerLocator.getSwingInstallerManager().setDefaultDownloadURL(new File(installURLFile));
3614 3605

  
3615
		// 1. Create the frame.
3616
		JFrame frame = new JFrame(Messages.get("gvsig_package_installer"));
3606
        // Launch installer
3607
        PluginsManager manager = PluginsLocator.getManager();
3617 3608

  
3618
		// 2. What happens when the frame closes?
3619
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3620
		Runtime.getRuntime().addShutdownHook(new Thread() {
3609
        AbstractInstallPackageWizard installPackageWizard = SwingInstallerLocator
3610
                .getSwingInstallerManager().createInstallPackageWizard(
3611
                        manager.getApplicationFolder(),
3612
                        manager.getInstallFolder());
3613
        installPackageWizard.setWizardActionListener(new InstallerWizardActionListener() {
3614
            public void finish(InstallerWizardPanel installerWizard) {
3615
                logger.info("Finish installation.");
3616
                System.exit(0);
3617
            }
3621 3618

  
3622
			@Override
3623
			public void run() {
3624
				getTerminationProcess().saveAndamiConfig();
3625
			}
3626
		});
3619
            public void cancel(InstallerWizardPanel installerWizard) {
3620
                logger.info("Cancel installation.");
3621
                System.exit(0);
3622
            }
3623
        });
3627 3624

  
3628
		// 3. Add the installer panel to the frame
3629
		frame.getContentPane().add(installPackageWizard, BorderLayout.CENTER);
3625
        // the wizard will show the Typical or Advanced mode option.
3626
        installPackageWizard.setAskTypicalOrCustom(true);
3627
        // default packages will be selected.
3628
        installPackageWizard.setSelectDefaultPackages(true);
3630 3629

  
3631
		// 4. Size the frame and center on the screen
3632
		frame.pack();
3633
		frame.setLocationRelativeTo(null);
3630
        // 1. Create the frame.
3631
        JFrame frame = new JFrame(Messages.get("gvsig_package_installer"));
3634 3632

  
3635
		// 5. Show it.
3636
		frame.setVisible(true);
3637
	}
3633
        // 2. What happens when the frame closes?
3634
        frame.addWindowListener(new WindowListener() {
3635
            public void windowOpened(WindowEvent we) {
3636
                logger.info("Open window installation.");
3637
            }
3638
            public void windowClosing(WindowEvent we) {
3639
                logger.info("Closing installation.");
3640
                System.exit(0);
3641
            }
3642
            public void windowClosed(WindowEvent we) {
3643
                logger.info("Close installation.");
3644
                System.exit(0);
3645
            }
3646
            public void windowIconified(WindowEvent we) {
3647
            }
3648
            public void windowDeiconified(WindowEvent we) {
3649
            }
3650
            public void windowActivated(WindowEvent we) {
3651
                logger.info("Activate window installation.");
3652
            }
3653
            public void windowDeactivated(WindowEvent we) {
3654
                logger.info("Deactivate window installation.");
3655
            }
3656
        });
3657
        //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
3638 3658

  
3659
        // 3. Add the installer panel to the frame
3660
        frame.getContentPane().add(installPackageWizard, BorderLayout.CENTER);
3661

  
3662
        // 4. Size the frame and center on the screen
3663
        frame.pack();
3664
        frame.setLocationRelativeTo(null);
3665

  
3666
        // 5. Show it.
3667
        frame.setVisible(true);
3668
    }
3669

  
3639 3670
	public static String getInformation() {
3640 3671
		return getInformation(null);
3641 3672
	}

Also available in: Unified diff