1 22 package org.jboss.deployers.plugins.structure; 23 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.HashMap ; 28 import java.util.List ; 29 30 import org.jboss.deployers.plugins.structure.AbstractDeploymentContext; 31 import org.jboss.deployers.spi.DeploymentException; 32 import org.jboss.deployers.spi.structure.DeploymentContext; 33 import org.jboss.deployers.spi.structure.vfs.ClassPathInfo; 34 import org.jboss.deployers.spi.structure.vfs.ContextInfo; 35 import org.jboss.deployers.spi.structure.vfs.StructureBuilder; 36 import org.jboss.deployers.spi.structure.vfs.StructureMetaData; 37 import org.jboss.logging.Logger; 38 import org.jboss.virtual.VFS; 39 import org.jboss.virtual.VFSUtils; 40 import org.jboss.virtual.VirtualFile; 41 import org.jboss.virtual.VisitorAttributes; 42 import org.jboss.virtual.plugins.vfs.helpers.SuffixMatchFilter; 43 44 51 public class DefaultStructureBuilder 52 implements StructureBuilder 53 { 54 private static Logger log = Logger.getLogger(DefaultStructureBuilder.class); 55 56 public void populateContext(DeploymentContext context, StructureMetaData metaData) 57 throws DeploymentException 58 { 59 HashMap <String , DeploymentContext> contextMap = new HashMap <String , DeploymentContext>(); 60 VirtualFile root = context.getRoot(); 62 ContextInfo rootInfo = metaData.getContext(root.getPathName()); 63 if( rootInfo == null ) 64 throw new DeploymentException("Failed to find ContextInfo for context root: "+root); 65 66 VFS vfs = root.getVFS(); 68 contextMap.put(root.getPathName(), context); 69 try 70 { 71 for(ContextInfo info : metaData.getContexts()) 72 { 73 String vfsPath = info.getVfsPath(); 74 VirtualFile vf = vfs.findChild(vfsPath); 75 ContextInfo parentInfo = info.getParent(); 76 String parentPath = parentInfo != null ? parentInfo.getVfsPath() : ""; 77 DeploymentContext ctx = contextMap.get(vfsPath); 78 DeploymentContext parent = contextMap.get(parentPath); 79 if( ctx == null ) 80 { 81 if( parent != null ) 82 { 83 ctx = new AbstractDeploymentContext(vf, true, parent); 84 parent.addChild(ctx); 85 } 86 else 87 ctx = new AbstractDeploymentContext(vf); 88 } 89 processContext(ctx, vf, info, contextMap); 90 } 91 } 92 catch(Exception e) 93 { 94 throw new DeploymentException("Failed to process context: "+context.getName(), e); 95 } 96 contextMap.clear(); 97 } 98 99 protected void processContext(DeploymentContext context, VirtualFile virtualFile, 100 ContextInfo info, HashMap <String , DeploymentContext> contextMap) 101 { 102 boolean trace = log.isTraceEnabled(); 103 if( trace ) 104 log.trace("Processing context: "+context+", info: "+info); 105 String metaDataPath = info.getMetaDataPath(); 106 if( metaDataPath != null && metaDataPath.length() > 0 ) 107 context.setMetaDataPath(metaDataPath); 108 ArrayList <VirtualFile> paths = new ArrayList <VirtualFile>(); 109 List <ClassPathInfo> classPath = info.getClassPath(); 110 boolean classPathHadVF = false; 111 if( classPath != null ) 112 { 113 for(ClassPathInfo cp : classPath) 114 { 115 try 116 { 117 VirtualFile child = virtualFile.findChild(cp.getPath()); 118 String suffixesOpt = (String ) cp.getOption("suffixes"); 119 String [] suffixes = null; 120 if( suffixesOpt != null ) 121 suffixes = suffixesOpt.split(","); 122 if( suffixes == null || suffixes.length == 0 ) 124 { 125 paths.add(child); 126 if( classPathHadVF == false ) 127 classPathHadVF = child.equals(virtualFile); 128 if( trace ) 129 log.trace("Added simple classpath entry: "+child); 130 VFSUtils.addManifestLocations(child, paths); 132 } 133 else 135 { 136 SuffixMatchFilter filter = new SuffixMatchFilter(Arrays.asList(suffixes), VisitorAttributes.DEFAULT); 137 List <VirtualFile> matches = child.getChildren(filter); 138 if( matches != null ) 139 { 140 paths.addAll(matches); 141 if( trace ) 142 log.trace("Added classpath matches: "+matches); 143 for(VirtualFile file : matches) 145 { 146 VFSUtils.addManifestLocations(file, paths); 147 if( classPathHadVF == false ) 148 classPathHadVF = child.equals(virtualFile); 149 } 150 } 151 } 152 } 153 catch(IOException e) 154 { 155 log.debug("Failed to find cp element: "+cp+", "+e.getMessage()); 156 } 157 } 158 } 159 160 if( classPathHadVF == false ) 162 { 163 try 164 { 165 if( virtualFile.isLeaf() == false ) 167 VFSUtils.addManifestLocations(virtualFile, paths); 168 } 169 catch(IOException ignore) 170 { 171 } 172 } 173 if( paths.size() > 0 ) 175 context.setClassPath(paths); 176 contextMap.put(virtualFile.getPathName(), context); 178 } 179 180 } 181 | Popular Tags |