1 22 package org.jboss.deployment; 23 24 import java.io.File ; 25 import java.io.FileFilter ; 26 import java.net.JarURLConnection ; 27 import java.net.URL ; 28 import java.net.URLConnection ; 29 import java.util.Arrays ; 30 import java.util.Enumeration ; 31 import java.util.jar.JarEntry ; 32 import java.util.jar.JarFile ; 33 34 import org.jboss.util.Strings; 35 36 49 public class JARDeployer extends SubDeployerSupport 50 implements JARDeployerMBean 51 { 52 58 private static final String [] DEFAULT_ENHANCED_SUFFIXES = new String [] { 59 "700:.jar", "750:.zip", "900:.last" }; 63 64 private String [] descriptorNames = { 65 ".xml" 66 }; 67 68 71 public JARDeployer() 72 { 73 super.setEnhancedSuffixes(DEFAULT_ENHANCED_SUFFIXES); 74 } 75 76 public String [] getDescriptorNames() 77 { 78 return descriptorNames; 79 } 80 81 public void setDescriptorNames(String [] descriptorNames) 82 { 83 this.descriptorNames = descriptorNames; 84 } 85 86 88 protected void stopService() 89 { 90 93 } 95 96 98 107 public boolean accepts(DeploymentInfo di) 108 { 109 boolean trace = log.isTraceEnabled(); 110 111 try 112 { 113 if (di.shortName.indexOf('.') != -1 && super.accepts(di) == false) 117 { 118 return false; 119 } 120 121 URL wdDir = di.localCl.findResource("WEB-INF/"); 123 if (wdDir != null) 124 { 125 return false; 126 } 127 128 URL ddDir; 135 try 136 { 137 ddDir = di.localCl.findResource("META-INF/"); 138 if (ddDir == null) 139 { 140 log.debug("No META-INF or WEB-INF resource found, assuming it if for us"); 141 return true; 142 } 143 } 144 catch (ClassCastException e) 145 { 146 ddDir = new URL (di.url, "META-INF/"); 148 } 149 150 if (ddDir.getProtocol().equals("file")) 151 { 152 log.trace("File protocol: "+ddDir); 153 File file = new File (ddDir.getFile()); 154 if (!file.exists()) 155 { 156 log.warn("File not found: " + file); 157 return true; 158 } 159 160 File [] entries = file.listFiles( 162 new FileFilter () 163 { 164 public boolean accept(File pathname) 165 { 166 boolean accept = false; 167 String name = pathname.getName(); 168 for(int n = 0; accept == false && n < descriptorNames.length; n ++) 169 { 170 String d = descriptorNames[n]; 171 accept = name.endsWith(d); 172 } 173 return accept; 174 } 175 } 176 ); 177 log.debug("XML entries found: " + entries.length); 178 return entries.length == 0; 179 } else if (ddDir.getProtocol().equals("jar") == true) 181 { 182 log.trace("jar protocol: " + ddDir); 183 JarFile jarFile = null; 184 185 try 186 { 187 URLConnection con = ddDir.openConnection(); 188 JarURLConnection jarConn = (JarURLConnection ) con; 189 192 jarConn.setUseCaches(false); 193 jarFile = jarConn.getJarFile(); 194 195 if (trace) 197 log.trace("Descriptor names=" + Arrays.asList(descriptorNames)); 198 for (Enumeration e = jarFile.entries(); e.hasMoreElements();) 199 { 200 JarEntry entry = (JarEntry )e.nextElement(); 201 String name = entry.getName(); 202 if (trace) 203 log.trace("Looking at entry: '" + name + "'"); 204 205 if (name.startsWith("META-INF/") && Strings.count(name, "/") == 1) 208 { 209 for (int n = 0; n < descriptorNames.length; n ++) 210 { 211 if (name.endsWith(descriptorNames[n])) 212 { 213 log.debug("Found entry: '" + name + "', matching: '" 214 + descriptorNames[n] + "', rejecting jar"); 215 216 return false; 218 } 219 } 220 } 221 } 222 } 223 catch (Exception e) 224 { 225 log.warn("Looking inside jar failed; ignoring", e); 226 return false; 227 } 228 finally 229 { 230 if (jarFile != null) 231 jarFile.close(); 232 jarFile = null; 233 } 234 235 log.debug("No xml files found"); 236 return true; 237 } 238 else 239 { 240 log.debug("Unrecognized protocol: " + ddDir.getProtocol()); 241 } 242 243 return false; 244 } 245 catch (Exception e) 246 { 247 log.trace("Ignored error", e); 248 return false; 249 } 250 } 251 } 252 | Popular Tags |