1 23 24 28 29 30 package com.sun.enterprise.deployment.backend; 31 32 import java.io.*; 33 import java.util.jar.JarFile ; 34 import java.util.jar.Manifest ; 35 import java.util.jar.Attributes ; 36 import java.net.URL ; 37 import com.sun.logging.LogDomains; 38 import java.util.logging.*; 39 import java.util.*; 40 import java.util.zip.ZipException ; 41 import java.rmi.RemoteException ; 42 43 44 49 50 public class OptionalPkgDependency { 51 52 private static Hashtable optionalPackageStore = new Hashtable(); 54 55 private static Set extDirJars = new LinkedHashSet(); 59 60 private static Logger logger = LogDomains.getLogger(LogDomains.DPL_LOGGER); 61 62 public OptionalPkgDependency() { 63 } 64 65 public static boolean optionalPkgDependencyLogic(Manifest manifest, String archiveUri) { 66 67 boolean dependencySatisfied = true; 68 69 String extensionList = null; 70 try { 71 extensionList = manifest.getMainAttributes(). 72 getValue(Attributes.Name.EXTENSION_LIST); 73 logger.fine("extensionList..." + extensionList); 74 } catch (Exception npe) { 75 if (logger.isLoggable(Level.FINE)) { 77 logger.log(Level.FINE, 78 "OptionalPkgDependency : exception occurred ==> " + npe.toString()); 79 } 80 } 81 82 if (extensionList == null) 83 return dependencySatisfied; 84 85 StringTokenizer st = 86 new StringTokenizer(extensionList, " "); 87 while (st.hasMoreTokens()) { 88 89 String token = st.nextToken().trim(); 90 String extName = manifest.getMainAttributes(). 91 getValue(token + "-" + Attributes.Name.EXTENSION_NAME); 92 93 String specVersion = manifest.getMainAttributes(). 94 getValue(token + "-" + Attributes.Name.SPECIFICATION_VERSION); 95 96 if (specVersion == null) { 97 specVersion = new String (""); 98 } 99 if (!optionalPackageStore.containsKey(extName)) { 100 logger.log(Level.WARNING, 101 "enterprise.deployment.backend.optionalpkg.dependency.notexist", 102 new Object [] {extName, archiveUri}); 103 dependencySatisfied = false; 104 } else if (!specVersion.equals("") && 105 (optionalPackageStore.get(extName).toString().equals("")) || 106 !specVersion.equals(optionalPackageStore.get(extName).toString())) { 107 logger.log(Level.WARNING, 108 "enterprise.deployment.backend.optionalpkg.dependency.notexist", 109 new Object [] {extName, archiveUri}); 110 dependencySatisfied = false; 111 } 112 } 113 if (dependencySatisfied == true) { 114 logger.log(Level.INFO, 115 "enterprise.deployment.backend.optionalpkg.dependency.satisfied", 116 new Object [] {archiveUri}); 117 } 118 return dependencySatisfied; 119 } 120 121 125 public static void satisfyOptionalPackageDependencies() { 126 127 String ext_dirStr = new String ( 128 System.getProperty("java.ext.dirs")); 129 logger.fine("ext_dirStr..." + ext_dirStr); 130 131 Vector ext_dirs = new Vector(); 132 StringTokenizer st = new StringTokenizer(ext_dirStr, File.pathSeparator); 133 while (st.hasMoreTokens()) { 134 String next = st.nextToken(); 135 logger.log(Level.FINE,"string tokens..." + next); 136 ext_dirs.addElement(next); 137 } 138 139 for (int v = 0; v < ext_dirs.size(); v++) { 140 141 File ext_dir = new File ((String )ext_dirs.elementAt(v)); 142 143 if (logger.isLoggable(Level.FINE)) { 144 logger.log(Level.FINE,"extension dir..." + ext_dir); 145 } 146 147 148 File [] optionalPackages = ext_dir.listFiles(); 149 if (optionalPackages != null) { 150 try { 151 for (int i = 0; i < optionalPackages.length; i++) { 152 153 if (logger.isLoggable(Level.FINE)) { 154 logger.log(Level.FINE,"optional package..." + optionalPackages[i]); 155 } 156 157 if (!optionalPackages[i].isDirectory()) { 158 JarFile jarFile = new JarFile (optionalPackages[i]); 159 Manifest manifest = jarFile.getManifest(); 160 jarFile.close(); 161 162 extDirJars.add(optionalPackages[i].toString()); 163 164 if (manifest!=null) { 166 String extNameOfOptionalPkg = manifest.getMainAttributes(). 167 getValue(Attributes.Name.EXTENSION_NAME); 168 logger.fine("extNameOfOptionalPkg..." + extNameOfOptionalPkg); 169 String specVersion = manifest.getMainAttributes(). 170 getValue(Attributes.Name.SPECIFICATION_VERSION); 171 logger.fine("specVersion..." + specVersion); 172 if (extNameOfOptionalPkg != null) { 173 if (specVersion == null) { 174 logger.log(Level.WARNING, 175 "enterprise.tools.deployment.backend.optionalpkg.dependency.specversion.null", 176 new Object [] {extNameOfOptionalPkg}); 177 specVersion = new String (""); 178 } 179 optionalPackageStore.put(extNameOfOptionalPkg, 180 specVersion); 181 182 } 183 } 184 } 185 } 186 for (int i = 0; i < optionalPackages.length; i++) { 187 if (!optionalPackages[i].isDirectory()) { 188 JarFile jarFile = null; 189 try { 190 jarFile = new JarFile (optionalPackages[i]); 191 Manifest m = jarFile.getManifest(); 192 if (m!=null) { 193 optionalPkgDependencyLogic(m, optionalPackages[i].getAbsolutePath()); 194 } 195 } finally { 196 if (jarFile!=null) 197 jarFile.close(); 198 } 199 200 } 201 } 202 } catch (IOException e) { 203 logger.log(Level.WARNING, 204 "enterprise.deployment.backend.optionalpkg.dependency.exception", new Object [] {e.getMessage()}); 205 } 206 } 207 } 208 } 209 210 215 public static String getExtDirFilesAsClasspath() { 216 217 StringBuffer classpath = new StringBuffer (); 218 219 for(Iterator iter = extDirJars.iterator(); iter.hasNext();) { 220 String next = (String ) iter.next(); 221 if( classpath.length() > 0 ) { 222 classpath.append(File.pathSeparator); 223 } 224 classpath.append(next); 225 } 226 227 return classpath.toString(); 228 } 229 230 } 231 | Popular Tags |