1 31 32 package org.opencms.setup; 33 34 import org.opencms.main.CmsLog; 35 import org.opencms.main.CmsShell; 36 37 import java.io.File ; 38 import java.io.FileInputStream ; 39 import java.io.FileNotFoundException ; 40 import java.io.PipedOutputStream ; 41 import java.io.PrintStream ; 42 43 52 public class CmsUpdateThread extends Thread { 53 54 55 public static PrintStream m_tempErr; 56 57 58 private CmsSetupLoggingThread m_loggingThread; 59 60 61 private PipedOutputStream m_pipedOut; 62 63 64 private CmsShell m_shell; 65 66 67 private PrintStream m_tempOut; 68 69 70 private CmsUpdateBean m_updateBean; 71 72 77 public CmsUpdateThread(CmsUpdateBean updateBean) { 78 79 super("OpenCms: Workplace update"); 80 81 m_updateBean = updateBean; 83 m_pipedOut = new PipedOutputStream (); 85 m_loggingThread = new CmsSetupLoggingThread(m_pipedOut, m_updateBean.getLogName()); 86 } 87 88 93 public CmsSetupLoggingThread getLoggingThread() { 94 95 return m_loggingThread; 96 } 97 98 103 public boolean isFinished() { 104 105 return m_loggingThread.isFinished(); 106 } 107 108 111 public void kill() { 112 113 if (m_shell != null) { 114 m_shell.exit(); 115 } 116 if (m_loggingThread != null) { 117 m_loggingThread.stopThread(); 118 } 119 m_shell = null; 120 m_updateBean = null; 121 } 122 123 128 public void printToStdOut(String str) { 129 130 m_tempOut.println(str); 131 } 132 133 136 public void run() { 137 138 m_tempOut = System.out; 140 m_tempErr = System.err; 141 try { 142 System.setOut(new PrintStream (m_pipedOut)); 144 System.setErr(new PrintStream (m_pipedOut)); 145 146 m_loggingThread.start(); 148 149 m_shell = new CmsShell( 151 m_updateBean.getWebAppRfsPath() + "WEB-INF" + File.separator, 152 m_updateBean.getServletMapping(), 153 m_updateBean.getDefaultWebApplication(), 154 "${user}@${project}>", 155 m_updateBean); 156 157 try { 158 try { 159 if (CmsLog.INIT.isInfoEnabled()) { 160 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 163 org.opencms.main.Messages.INIT_DOT_0)); 164 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 165 org.opencms.main.Messages.INIT_DOT_0)); 166 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 167 org.opencms.main.Messages.INIT_DOT_0)); 168 CmsLog.INIT.info(org.opencms.setup.Messages.get().getBundle().key( 169 org.opencms.setup.Messages.INIT_WELCOME_UPDATE_0)); 170 CmsLog.INIT.info(org.opencms.setup.Messages.get().getBundle().key( 171 org.opencms.setup.Messages.INIT_UPDATE_WORKPLACE_START_0)); 172 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 173 org.opencms.main.Messages.INIT_DOT_0)); 174 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 175 org.opencms.main.Messages.INIT_DOT_0)); 176 for (int i = 0; i < org.opencms.main.Messages.COPYRIGHT_BY_ALKACON.length; i++) { 177 CmsLog.INIT.info(". " + org.opencms.main.Messages.COPYRIGHT_BY_ALKACON[i]); 178 } 179 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 180 org.opencms.main.Messages.INIT_DOT_0)); 181 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 182 org.opencms.main.Messages.INIT_DOT_0)); 183 CmsLog.INIT.info(org.opencms.main.Messages.get().getBundle().key( 184 org.opencms.main.Messages.INIT_LINE_0)); 185 186 } 187 m_shell.start(new FileInputStream (new File (m_updateBean.getWebAppRfsPath() 188 + CmsUpdateBean.FOLDER_UPDATE 189 + "cmsupdate.txt"))); 190 if (CmsLog.INIT.isInfoEnabled()) { 191 CmsLog.INIT.info(org.opencms.setup.Messages.get().getBundle().key( 192 org.opencms.setup.Messages.INIT_UPDATE_WORKPLACE_FINISHED_0)); 193 } 194 } catch (FileNotFoundException e) { 195 e.printStackTrace(); 196 } 197 kill(); 199 m_pipedOut.close(); 200 } catch (Throwable t) { 201 } 203 } finally { 204 System.setOut(m_tempOut); 206 System.setErr(m_tempErr); 207 } 208 } 209 } | Popular Tags |