KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > UpgradeToolMain


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc certDbPassword;
63     private String JavaDoc aliasname;
64     private String JavaDoc 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 JavaDoc targetDomainRoot = System.getProperty("com.sun.aas.domainRoot");
75         if(targetDomainRoot == null) {
76            targetDomainRoot = new File("").getAbsolutePath();
77         }
78         commonInfo.setTargetDomainRoot(targetDomainRoot);
79         String JavaDoc 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 JavaDoc targetInstallPath = System.getProperty("com.sun.aas.installRoot");
94         //Test for valid configuration by checking installRoot
95
String JavaDoc osName = System.getProperty("os.name");
96         String JavaDoc asenv = null;
97         String JavaDoc 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 JavaDoc e) {
108             _logger.log(Level.WARNING,sm.getString("enterprise.tools.upgrade.unknownError"),e);
109         }
110         commonInfo.setTargetInstallDir(targetInstallPath);
111     }
112     public void startGUI(String JavaDoc [] 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); //to log and output command line parsing
117
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 JavaDoc [] 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 JavaDoc 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 JavaDoc [] args) {
160         UpgradeToolMain main = new UpgradeToolMain();
161         StringBuffer JavaDoc argsStringBuff = new StringBuffer JavaDoc();
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             //start CLI
171
main.startCLI(args);
172         } else {
173             main.startGUI(args);
174         }
175     }
176 }
177
Popular Tags