/** * Is the current context already part of metadata path. * * @param context the current structure context * @return true if already part of parent's context metadata path */ protected boolean isMetadataPath(StructureContext context) { StructureContext parentContext = context.getParentContext(); if (parentContext == null) return false; StructureMetaData smd = parentContext.getMetaData(); ContextInfo info = smd.getContext(""); List<MetaDataEntry> metadataPaths = info.getMetaDataPath(); if (metadataPaths != null && metadataPaths.isEmpty() == false) { String relativePath = AbstractStructureDeployer.getRelativePath(context.getParent(), context.getFile()); for (MetaDataEntry entry : metadataPaths) if (relativePath.equalsIgnoreCase(entry.getPath())) return true; } return false; } }
/** * Add all children as candidates * * @param root the root context * @param parent the parent context * @param metaData the structure meta data * @param deployers the structure deployers * @param attributes the visitor attributes uses {@link VisitorAttributes#DEFAULT} when null * @throws Exception for any error */ protected void addChildren(VirtualFile root, VirtualFile parent, StructureMetaData metaData, VFSStructuralDeployers deployers, VisitorAttributes attributes) throws Exception { if (parent == null) throw new IllegalArgumentException("Null parent"); StructureContext context = new StructureContext(root, null, parent, metaData, deployers, null); addChildren(context, attributes); }
/** * Create a new child structure context * * @param file the candidate file * @param metaData the structure metadata to build * @param parentContext the parentContext * @throws IllegalArgumentException for a null parameter */ public StructureContext(VirtualFile file, StructureMetaData metaData, StructureContext parentContext) { this(getRoot(parentContext), parentContext.getFile(), file, metaData, parentContext.getDeployers(), parentContext); }
/** * Apply structure metadata on context. * * @param context the structure context * @param contextInfo the new created context */ protected void applyStructure(StructureContext context, ContextInfo contextInfo) { boolean trace = log.isTraceEnabled(); if (context == null) throw new IllegalArgumentException("Null context"); VirtualFile root = context.getRoot(); applyContextInfo(context, contextInfo); context.addChild(contextInfo); if (trace) log.trace("Added context " + context + " from " + root.getName()); }
public boolean doDetermineStructure(StructureContext structureContext) throws DeploymentException VirtualFile file = structureContext.getFile(); try if (ignoreRelativePath == false && (structureContext.getParentContext() != null)) String relativePath = file.getPathNameRelativeTo(structureContext.getRoot()) + "/"; ofactory = new StructureMetaDataObjectFactory(relativePath); UnmarshallerFactory factory = UnmarshallerFactory.newInstance(); Unmarshaller unmarshaller = factory.newUnmarshaller(); unmarshaller.unmarshal(url.toString(), ofactory, structureContext.getMetaData()); mountChildren(structureContext); isJBossStructure = true;
public boolean doDetermineStructure(StructureContext structureContext) throws DeploymentException VirtualFile file = structureContext.getFile(); try if (structureContext.isTopLevel() == false) if (isSupportsCandidateAnnotations()) StructureContext parentContext = structureContext.getParentContext(); if (parentContext != null && parentContext.isCandidateAnnotationScanning()) structureContext.removeChild(context);
boolean valid; boolean trace = log.isTraceEnabled(); VirtualFile file = structureContext.getFile(); try if(structureContext.determineChildStructure(module) == false) for (ContextInfo ctx : structureContext.getMetaData().getContexts())
public boolean determineStructure(StructureContext context) throws DeploymentException { try { VirtualFile file = context.getFile(); // jar structure should already handle top level dirs if (context.isTopLevel() == false && isLeaf(file) == false && isMetadataPath(context) == false) { List<VirtualFile> children = file.getChildren(); if (children != null && children.isEmpty() == false) { VFSStructuralDeployers structuralDeployers = context.getDeployers(); // get top while (context.getParentContext() != null) context = context.getParentContext(); for (VirtualFile child : children) structuralDeployers.determineStructure(child, context); } } return false; } catch (Exception e) { throw DeploymentException.rethrowAsDeploymentException("Error determining structure.", e); } }
/** * Get the parent deployment context * * @return the parent. */ public VirtualFile getParent() { return context.getFile(); }
public boolean determineStructure(StructureContext structureContext) throws DeploymentException VirtualFile file = structureContext.getFile(); structureContext.determineChildStructure(child); structureContext.removeChild(context);
public boolean determineStructure(VirtualFile file, StructureContext parentContext) throws DeploymentException { StructureMetaData structure = StructureMetaDataFactory.createStructureMetaData(); StructureContext context = new StructureContext(file, structure, parentContext); boolean result = doDetermineStructure(context); if (result) { String relativePath = AbstractStructureDeployer.getRelativePath(context.getParent(), file); // Something said it recognised it ContextInfo recognised = structure.getContext(""); if (recognised == null) throw new IllegalStateException("Something recognised the deployment, but there is no context? " + file); // Create the context in the parent structure ContextInfo parentContextInfo; List<MetaDataEntry> metaDataPath = recognised.getMetaDataPath(); if (metaDataPath == null || metaDataPath.isEmpty()) parentContextInfo = StructureMetaDataFactory.createContextInfo(relativePath, recognised.getClassPath()); else parentContextInfo = StructureMetaDataFactory.createContextInfo(recognised.getClassPath(), metaDataPath, relativePath); // copy the modification type information parentContextInfo.setModificationType(recognised.getModificationType()); StructureMetaData structureMetaData = parentContext.getMetaData(); structureMetaData.addContext(parentContextInfo); MutableAttachments attachments = (MutableAttachments) parentContextInfo.getPredeterminedManagedObjects(); attachments.addAttachment(StructureMetaData.class, structure); } return result; }
public boolean doDetermineStructure(StructureContext structureContext) throws DeploymentException VirtualFile file = structureContext.getFile(); try structureContext.removeChild(context);
public boolean determineStructure(StructureContext structureContext) throws DeploymentException VirtualFile file = structureContext.getFile(); try log.trace(file + " is a leaf"); if (structureContext.isTopLevel() == false) structureContext.removeChild(context);
public void visit(VirtualFile file) { String path = AbstractStructureDeployer.getRelativePath(context, file); StructureMetaData metaData = context.getMetaData(); ContextInfo contextInfo = metaData.getContext(path); if (contextInfo == null) { // Ignore directories when asked if (ignoreDirectories && file.isDirectory()) return; // Apply any filter if (filter != null && filter.accepts(file) == false) return; try { // Ask the deployers to process this file context.determineChildStructure(file); } catch (Exception e) { log.debugf("Ignoring %1s reason=%2s", file, e); } } } }
/** * Iterate through the contexts and mount anything that looks like an archive * * @param structureContext the context * @throws IOException if errors occur during mounting */ protected void mountChildren(StructureContext structureContext) throws IOException { final StructureMetaData structureMetaData = structureContext.getMetaData(); final VirtualFile structureRoot = structureContext.getFile(); for(ContextInfo contextInfo : structureMetaData.getContexts()) { final String contextPath = contextInfo.getPath(); if(hasValidSuffix(contextPath)) { final VirtualFile child = structureRoot.getChild(contextPath); if(child.exists() && child.isFile()) { if ((contextInfo.getModificationType() == ModificationType.EXPLODE) || isWAR(child)) performExpandedMount(child); else performMount(child); } } } }
/** * Add a child context * * @param child the child */ public void addChild(ContextInfo child) { if (child == null) throw new IllegalArgumentException("Null child"); getMetaData().addContext(child); }
return true; StructureContext parentContext = context.getParentContext(); if (parentContext == null) return true; Set<CandidateAnnotationsCallback> callbacks = parentContext.getCallbacks(CandidateAnnotationsCallback.class); if (callbacks.isEmpty()) return true;
/** * Helper method to check parent is not null before retrieving parameters * * @param parentContext the parent context * @return the root * @throws IllegalArgumentException for a null parent */ private static VirtualFile getRoot(StructureContext parentContext) { if (parentContext == null) throw new IllegalArgumentException("Null parentContext"); return parentContext.getRoot(); }
/** * Determine the child structure * * @param child the child * @return true when recognised * @throws DeploymentException for any error */ public boolean determineChildStructure(VirtualFile child) throws DeploymentException { if (child == null) throw new IllegalArgumentException("Null child"); return getDeployers().determineStructure(child, this); }
/** * Get the relative path between two virtual files * * @param context the structure context * @param child the child * @return the relative path */ public static String getRelativePath(StructureContext context, VirtualFile child) { if (context == null) throw new IllegalArgumentException("Null context"); return getRelativePath(context.getParent(), child); }