1 23 24 package com.sun.enterprise.tools.upgrade; 25 26 import java.io.*; 27 import java.util.logging.*; 28 29 import com.sun.enterprise.tools.upgrade.cli.*; 30 import com.sun.enterprise.tools.upgrade.common.*; 31 import com.sun.enterprise.tools.upgrade.gui.MainFrame; 32 import com.sun.enterprise.tools.upgrade.gui.util.*; 33 import com.sun.enterprise.util.i18n.StringManager; 34 import com.sun.enterprise.tools.upgrade.logging.*; 35 import com.sun.enterprise.util.ASenvPropertyReader; 36 import com.sun.enterprise.util.SystemPropertyConstants; 37 38 public class UpgradeToolMain { 39 40 static{ 41 String domainRoot = System.getProperty("com.sun.aas.domainRoot"); 42 if(domainRoot == null){ 43 System.out.println("Configuration Error: AS_DEFS_DOMAINS_PATH is not set."); 44 System.exit(1); 45 } 46 String upgradeLogPath =domainRoot+File.separator+"upgrade.log"; 47 try{ 48 File f = new File(domainRoot); 49 if(!f.exists()){ 50 System.out.println("Configuration Error: AS_DEFS_DOMAINS_PATH: "+ domainRoot + " does not exist."); 51 System.exit(1); 52 } 53 LogService.initialize(upgradeLogPath); 54 }catch(Exception e){ 55 System.out.println("Could not create upgrade.log file: " + e.getLocalizedMessage()); 56 } 57 } 58 59 static Logger _logger=LogService.getLogger(LogService.UPGRADE_LOGGER); 60 private CommonInfoModel commonInfo; 61 private UpgradeHarness harness; 62 private String certDbPassword; 63 private String aliasname; 64 private String keyStorePassword; 65 private StringManager sm; 66 public UpgradeToolMain() { 67 final ASenvPropertyReader reader = new ASenvPropertyReader( 68 System.getProperty(SystemPropertyConstants.CONFIG_ROOT_PROPERTY)); 69 reader.setSystemProperties(); 70 71 sm = StringManager.getManager(LogService.UPGRADE_LOGGER); 72 _logger.log(Level.INFO, sm.getString("enterprise.tools.upgrade.start_upgrade_tool")); 73 commonInfo = new CommonInfoModel(); 74 String targetDomainRoot = System.getProperty("com.sun.aas.domainRoot"); 75 if(targetDomainRoot == null) { 76 targetDomainRoot = new File("").getAbsolutePath(); 77 } 78 commonInfo.setTargetDomainRoot(targetDomainRoot); 79 String targetVersion = System.getProperty("com.sun.aas.utool.targetVersion"); 80 if(targetVersion != null){ 81 _logger.info("asupgrade " + targetVersion); 82 commonInfo.setTargetVersionAndEdition(targetVersion); 83 if(!targetVersion.equalsIgnoreCase(UpgradeConstants.VERSION_AS90_PE)){ 84 commonInfo.setMasterPassword(""); 85 } 86 } else { 87 _logger.log(Level.SEVERE, sm.getString("enterprise.tools.upgrade.nullTargetError")); 88 System.exit(1); 89 } 90 91 harness = new UpgradeHarness(); 92 commonInfo.setOSName(System.getProperty("os.name")); 93 String targetInstallPath = System.getProperty("com.sun.aas.installRoot"); 94 String osName = System.getProperty("os.name"); 96 String asenv = null; 97 String asadmin = null; 98 if(osName.indexOf("Windows") != -1) 99 asadmin = targetInstallPath + File.separator + "bin" + File.separator + "asupgrade.bat"; 100 else 101 asadmin = targetInstallPath + File.separator + "bin" + File.separator + "asupgrade"; 102 try { 103 if(! new File(asadmin).exists()) { 104 _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.configError")); 105 System.exit(1); 106 } 107 }catch (Exception e) { 108 _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),e); 109 } 110 commonInfo.setTargetInstallDir(targetInstallPath); 111 } 112 public void startGUI(String [] args){ 113 _logger.log(Level.INFO,sm.getString("enterprise.tools.upgrade.start_upgrade_tool_gui")); 114 if(args.length > 0){ 115 CliLogMessageListener l = new CliLogMessageListener(); 116 LogService.addLogMessageListener(l); new ArgsParser(args, commonInfo).parse(); 118 LogService.removeLogMessageListener(l); 119 } 120 MainFrame gui = new MainFrame(commonInfo); 121 LogService.addLogMessageListener(gui); 122 gui.addDialogListener(new DialogListener(){ 123 public void dialogProcessed(DialogEvent evt){ 124 processUIEvent(evt); 125 } 126 }); 127 UpdateProgressManager.getProgressManager().addUpgradeUpdateListener(gui); 128 gui.setVisible(true); 129 } 130 131 public void startCLI(String [] args){ 132 _logger.log(Level.INFO,sm.getString("enterprise.tools.upgrade.start_upgrade_tool_cli")); 133 LogService.addLogMessageListener(new CliLogMessageListener()); 134 try{ 135 CLIParser parser = new CLIParser(commonInfo, args); 136 }catch(Exception e){ 137 _logger.log(Level.INFO,sm.getString("enterprise.tools.upgrade.unexpected_parsing"),e); 138 System.exit(1); 139 } 140 this.upgrade(); 141 } 142 143 private void processUIEvent(DialogEvent evt){ 144 if(evt.getAction() == DialogEvent.FINISH_ACTION || 145 evt.getAction() == DialogEvent.CANCEL_ACTION){ 146 System.exit(0); 147 }else if(evt.getAction() == DialogEvent.UPGRADE_ACTION){ 148 this.upgrade(); 149 } 150 } 151 152 private void upgrade(){ 153 harness.setCommonInfoModel(commonInfo); 154 _logger.log(Level.INFO,sm.getString("enterprise.tools.upgrade.start_upgrade_harness")); 155 harness.startUpgrade(); 156 commonInfo.deletePasswordFile(); 157 } 158 159 public static void main(String [] args) { 160 UpgradeToolMain main = new UpgradeToolMain(); 161 StringBuffer argsStringBuff = new StringBuffer (); 162 for(int i=0;i<args.length;i++){ 163 argsStringBuff.append(args[i]); 164 argsStringBuff.append(" "); 165 } 166 _logger.info("asupgrade " + argsStringBuff.toString()); 167 if(args.length==0){ 168 main.startGUI(args); 169 } else if (args[0].equals("-c") || args[0].equals("--console")|| args[0].equals("-V")|| args[0].equals("--version")){ 170 main.startCLI(args); 172 } else { 173 main.startGUI(args); 174 } 175 } 176 } 177 | Popular Tags |