| 1 15 16 30 package ixenon.free.nodes; 31 32 import java.io.*; 33 import java.util.*; 34 import java.awt.*; 35 import java.awt.event.*; 36 37 import javax.swing.*; import javax.swing.event.*; import javax.swing.tree.*; 41 import ixenon.free.swing.*; import ixenon.free.install.*; 44 56 public class CreateRuntimeBatch extends AbstractInstallable 57 implements Installable 58 { 59 public final static int SLEEP_TIME=75; 61 protected File rootDirectory; 62 protected File binaryDirectory; 63 protected String envHomeVar; 64 protected String rootFilename; 65 protected String mainClass; 66 protected String [] jarFileList; 67 68 82 public CreateRuntimeBatch ( String nodeName, 83 String rootDir, 84 String binDir, 85 String envHomeVar, 86 String rootFilename, 87 String mainClass, 88 String [] jarFileList ) 89 { 90 this( nodeName, new File(rootDir), new File(binDir), 91 envHomeVar, rootFilename, mainClass, jarFileList ); 92 } 93 94 108 public CreateRuntimeBatch( String nodeName, 109 File rootDir, 110 File binDir, 111 String envHomeVar, 112 String rootFilename, 113 String mainClass, 114 String [] jarFileList ) 115 { 116 super( nodeName, null, true ); 117 118 if (envHomeVar == null) 119 envHomeVar = "THISAPPHOME"; 120 rootDirectory = rootDir; 121 binaryDirectory = binDir; 122 this.envHomeVar = envHomeVar; 123 this.rootFilename = rootFilename; 124 this.mainClass = mainClass; 125 this.jarFileList = jarFileList; 126 } 127 128 132 public Component getVisualComponent() 133 { 134 return (null); 135 } 136 137 141 public Component getConfigurableComponent() 142 { 143 return (null); 144 } 145 146 153 public void install() throws InstallException 154 { 155 FreeInstallerApplication theApp = 156 FreeInstallerApplication.getInstance(); 157 158 if ( !rootDirectory.exists() ) 159 rootDirectory.mkdirs(); 160 161 if ( !rootDirectory.isDirectory() ) 162 throw new InstallException( 163 "no such root directory:`"+rootDirectory.getAbsolutePath()+"'" ); 164 165 if ( !binaryDirectory.exists() ) 166 binaryDirectory.mkdirs(); 167 168 if ( !binaryDirectory.isDirectory() ) 169 throw new InstallException( 170 "no such binary directory:`"+binaryDirectory.getAbsolutePath()+"'" ); 171 172 theApp.getProgressFrame().setStatusText( getNodeName() ); 174 175 JProgressBar pbar = theApp.getProgressFrame().getProgressBarNode(); 176 int index = 0; 177 SwingUtilities.invokeLater( new ResetProgressBar( pbar, 0, 2, 0 ) ); 178 179 try { Thread.sleep(SLEEP_TIME); } catch (InterruptedException ie) { ; } 181 182 createNTDosBatch(); 183 SwingUtilities.invokeLater( new UpdateProgressBar( pbar, ++index ) ); 184 185 createUnixShellScript(); 186 SwingUtilities.invokeLater( new UpdateProgressBar( pbar, ++index ) ); 187 } 188 189 190 protected void createNTDosBatch() throws InstallException 191 { 192 File dstFile = new File( binaryDirectory, rootFilename+".bat" ); 193 194 if (dstFile.exists() ) 196 dstFile.delete(); 197 198 PrintWriter pwriter=null; 199 FileWriter fwriter=null; 200 201 FreeInstallerApplication theApp = 202 FreeInstallerApplication.getInstance(); 203 204 String fileSep = "\\"; String pathSep = ";"; 207 if (generateUninstall) 209 uninstallable.addFile( dstFile ); 210 211 theApp.printInfo( "Creating a NT/DOS batch command file: `" + dstFile.getPath()+"'" ); 212 try { 213 fwriter = new FileWriter( dstFile ); 214 pwriter = new PrintWriter( fwriter ); 215 216 pwriter.println( "REM Windows/DOS Batch file"); 217 pwriter.println( "REM for "+theApp.getProductName() + " by " + theApp.getCompanyName() +" [c]" ); 218 pwriter.println( "REM Automagically generated by FreeInstaller V"+ApplicationVersion.getVersionString() ); 219 pwriter.println(); 220 221 pwriter.println( "REM set "+envHomeVar+"=<path to the application>" ); 224 pwriter.println( "set "+envHomeVar+"="+rootDirectory.getPath() ); 225 226 pwriter.println( "set PATH="+binaryDirectory.getPath()+pathSep+"%PATH%"); 228 229 String finalClassPath = "%"+envHomeVar+"%"+fileSep+"lib"; 232 233 for (int k=0; k<jarFileList.length; ++k) 234 if ( jarFileList[k] != null) 235 finalClassPath += InstallUtilities.convertUnixPathToNTPath( pathSep+jarFileList[k] ); 236 237 finalClassPath += pathSep+"%CLASSPATH%"; 238 239 String appresPath = 241 InstallUtilities.convertUnixPathToNTPath( 242 "%USRPROFILE%"+pathSep+System.getProperty("user.home")+ 243 pathSep+theApp.getMainFrame().getPrefix()+fileSep+"lib" ); 244 245 pwriter.println( ""); 246 pwriter.println( "java -Dappres.path=\""+appresPath+"\" -classpath \""+finalClassPath+"\" "+mainClass ); 247 pwriter.println( ""); 248 pwriter.println( "@echo if Java does not run by search path, specify the full path to"); 249 pwriter.println( "@echo the Sun JDK or Java Runtime Environment in this batch command."); 250 pwriter.println( ""); 251 pwriter.println( "REM pause"); 252 253 pwriter.flush(); 254 InstallUtilities.setFilePermissions( dstFile, InstallConstants.INST_EXE_PERMS ); 255 256 } 257 catch (IOException ioe) { 258 throw new InstallException( 259 "I/O exception occurred writing file:"+ dstFile.getPath()+ 260 "\ndetails:"+ioe.getMessage() ); 261 } 262 finally { 263 if (fwriter != null) try { fwriter.close(); } catch (Exception e) { ; } 264 if (pwriter != null) try { pwriter.close(); } catch (Exception e) { ; } 265 } 266 } 267 268 269 270 protected void createUnixShellScript() throws InstallException 271 { 272 File dstFile = new File( binaryDirectory, "run-"+rootFilename ); 273 274 if (dstFile.exists() ) 276 dstFile.delete(); 277 278 PrintWriter pwriter=null; 279 FileWriter fwriter=null; 280 281 FreeInstallerApplication theApp = 282 FreeInstallerApplication.getInstance(); 283 284 String fileSep = System.getProperty("file.separator"); 285 String pathSep = System.getProperty("path.separator"); 286 287 theApp.printInfo( "Creating a UNIX Shell script file: `" + dstFile.getPath()+"'" ); 288 if (generateUninstall) 290 uninstallable.addFile( dstFile ); 291 292 try { 293 fwriter = new FileWriter( dstFile ); 294 pwriter = new PrintWriter( fwriter ); 295 296 pwriter.println( "#!/bin/sh"); 297 pwriter.println( "export PATH || exec /bin/sh $0 $argv:q"); 298 pwriter.println(); 299 pwriter.println( "#\n# DESCRIPTION:\n#\tA shell script batch to launch:" ); 300 301 pwriter.println( "#\t" +theApp.getProductName() + " by " + theApp.getCompanyName() +" [c]" ); 302 pwriter.println( "#\tAutomagically generated by FreeInstaller V"+ApplicationVersion.getVersionString() ); 303 pwriter.println( "#"); 304 pwriter.println(); 305 306 pwriter.println( "## "+envHomeVar+"=<path to the application>" ); 309 pwriter.println( ""+envHomeVar+"="+rootDirectory.getPath() ); 310 pwriter.println( "## export "+envHomeVar+"" ); 311 312 pwriter.println( "PATH="+binaryDirectory.getPath()+pathSep+"${PATH}"); 314 pwriter.println( "export PATH" ); 315 316 String finalClassPath = "${"+envHomeVar+"}"+fileSep+"lib"; 319 320 for (int k=0; k<jarFileList.length; ++k) 321 if (jarFileList[k] != null) 322 finalClassPath += pathSep+jarFileList[k]; 323 324 finalClassPath += pathSep+"${CLASSPATH}"; 325 String appresPath = 327 InstallUtilities.convertNTPathToUnixPath( 328 "${HOME}" +pathSep+ 329 theApp.getMainFrame().getPrefix()+fileSep+"lib" ); 330 331 pwriter.println( ""); 332 pwriter.println( "java -Dappres.path=\""+appresPath+"\" -Denv=\"`env`\" -classpath \""+finalClassPath+"\" "+mainClass ); 333 pwriter.println( "status=$?\n"); 334 pwriter.println( "echo if Java does not run by search path, specify the full path to"); 335 pwriter.println( "echo the Sun JDK or Java Runtime Environment in this script file."); 336 pwriter.println( ""); 337 pwriter.println( "## echo \"Please press [RETURN] to continue\""); 338 pwriter.println( "## read DUMMYVARIABLE"); 339 pwriter.println( "exit $status\n# end"); 340 341 pwriter.flush(); 342 InstallUtilities.setFilePermissions( dstFile, InstallConstants.INST_EXE_PERMS ); 343 } 344 catch (IOException ioe) { 345 throw new InstallException( 346 "I/O exception occurred writing file:"+ dstFile.getPath()+ 347 "\ndetails:"+ioe.getMessage() ); 348 } 349 finally { 350 if (fwriter != null) try { fwriter.close(); } catch (Exception e) { ; } 351 if (pwriter != null) try { pwriter.close(); } catch (Exception e) { ; } 352 } 353 354 } 355 356 359 public void cleanup() throws InstallException 360 { 361 } 363 364 } 365 366 | Popular Tags |