1 22 package org.jboss.deployers.plugins.structure.vfs.war; 23 24 import java.io.IOException ; 25 import java.util.List ; 26 27 import org.jboss.deployers.plugins.structure.ContextInfoImpl; 28 import org.jboss.deployers.plugins.structure.vfs.AbstractStructureDeployer; 29 import org.jboss.deployers.spi.structure.vfs.StructureMetaData; 30 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers; 31 import org.jboss.virtual.VirtualFile; 32 import org.jboss.virtual.VirtualFileFilter; 33 import org.jboss.virtual.VisitorAttributes; 34 import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter; 35 36 42 public class WARStructure extends AbstractStructureDeployer 43 { 44 45 public static final VirtualFileFilter DEFAULT_WEB_INF_LIB_FILTER = 46 new SuffixMatchFilter(".jar", VisitorAttributes.DEFAULT); 47 48 49 private VirtualFileFilter webInfLibFilter = DEFAULT_WEB_INF_LIB_FILTER; 50 51 55 public WARStructure() 56 { 57 setRelativeOrder(1000); 58 } 59 60 65 public VirtualFileFilter getWebInfLibFilter() 66 { 67 return webInfLibFilter; 68 } 69 70 76 public void setWebInfLibFilter(VirtualFileFilter webInfLibFilter) 77 { 78 if (webInfLibFilter == null) 79 throw new IllegalArgumentException ("Null filter"); 80 this.webInfLibFilter = webInfLibFilter; 81 } 82 83 public boolean determineStructure(VirtualFile root, StructureMetaData metaData, StructuredDeployers deployers) 84 { 85 try 86 { 87 if (root.isLeaf() == false) 88 { 89 if (root.getName().endsWith(".war") == false) 91 { 92 try 93 { 94 root.findChild("WEB-INF"); 95 log.trace("... ok - directory has a WEB-INF subdirectory"); 96 } 97 catch (IOException e) 98 { 99 log.trace("... no - doesn't look like a war and no WEB-INF subdirectory."); 100 return false; 101 } 102 } 103 else 104 { 105 log.trace("... ok - name ends in .war."); 106 } 107 108 ContextInfoImpl context = new ContextInfoImpl(root.getPathName()); 109 context.setMetaDataPath("WEB-INF"); 111 112 addClassPath(root, root, false, true, context); 114 try 115 { 116 VirtualFile classes = root.findChild("WEB-INF/classes"); 118 addClassPath(root, classes, true, false, context); 120 } 121 catch(IOException e) 122 { 123 log.trace("No WEB-INF/classes for: " + root.getPathName()); 124 } 125 try 127 { 128 VirtualFile webinfLib = root.findChild("WEB-INF/lib"); 129 List <VirtualFile> archives = webinfLib.getChildren(webInfLibFilter); 130 for (VirtualFile jar : archives) 131 { 132 addClassPath(root, jar, true, true, context); 133 } 134 } 135 catch (IOException ignored) 136 { 137 log.trace("No WEB-INF/lib for: " + root.getPathName()); 138 } 139 metaData.addContext(context); 140 141 return true; 143 } 144 else 145 { 146 log.trace("... no - not a directory or an archive."); 147 return false; 148 } 149 } 150 catch (Exception e) 151 { 152 log.warn("Error determining structure: " + root.getName(), e); 153 return false; 154 } 155 } 156 } 157 | Popular Tags |