1 23 24 25 package com.sun.enterprise.addon; 26 27 import java.io.*; 28 import java.lang.reflect.*; 29 import java.net.URL ; 30 import java.net.URLClassLoader ; 31 import java.util.jar.*; 32 import java.util.*; 33 import java.util.logging.Level ; 34 import java.util.logging.Logger ; 35 36 44 public class AddonInstaller { 45 46 47 48 public AddonInstaller() { 49 50 } 51 52 57 public void installAllAddons(String installDir, String instanceRoot){ 58 59 String addonJar = ""; 60 Registry registry = null; 62 FileInputStream in = null; 63 FileOutputStream out = null; 64 try { 65 String addonDir = installDir + File.separator + AddonConstants.LIB + File.separator + AddonConstants.ADDONS; 66 String domainConfigRoot = instanceRoot + File.separator + AddonConstants.CONFIG; 67 String domainRegistry = domainConfigRoot + File.separator + AddonConstants.DOMAIN_REGISTRY; 69 File registryFile = new File(domainRegistry); 70 registry = new Registry(); 71 registry.load(registryFile); 72 File libAddonDirectory = new File(addonDir); 73 File[] fileArray = libAddonDirectory.listFiles(); 74 75 for(int i = 0;i<fileArray.length;i++) { 76 addonJar = fileArray[i].getName(); 77 String jarExtension = ""; 78 int dotLastIndex = addonJar.lastIndexOf("."); 79 String jarNameWithoutExtension = addonJar; 80 if(dotLastIndex != -1) { 81 jarExtension = addonJar.substring(dotLastIndex + 1); 82 jarNameWithoutExtension = addonJar.substring(0, dotLastIndex); 83 } 84 if(jarExtension.equalsIgnoreCase("jar")) { 85 String key = jarNameWithoutExtension + "." + "enabled"; 88 String installed = registry.getProperty(key); 89 if(installed != null && installed.equals("true")) { 90 Logger.getAnonymousLogger().log(Level.FINE, "Addon "+addonJar+" is already installed"); 91 continue; 92 } 93 Addon addon = new Addon(fileArray[i]); 94 boolean install = addon.install(installDir,instanceRoot); 95 if(install) 96 registry.setProperty(key, "true"); 97 98 } 99 } 100 registry.store(); 101 102 }catch(Exception ex) { 103 Logger.getAnonymousLogger().log(Level.WARNING, "Error while installing the addon "+addonJar, ex); 104 }finally { 105 try { 106 if(registry != null) 107 registry.close(); 108 }catch(Exception e) { 109 110 } 111 } 112 113 } 114 115 116 117 public static void main(String [] args) { 118 AddonInstaller installer = new AddonInstaller(); 119 installer.installAllAddons(args[0], args[1]); 120 } 121 122 } 123 | Popular Tags |