コード例 #1
0
 public String getRelativePath() {
   if (relativePath == null) {
     StringBuffer sb = new StringBuffer();
     for (VirtualFile f = file; f != null && !root.equals(f); f = f.getParent()) {
       if (sb.length() > 0) sb.insert(0, '/');
       sb.insert(0, f.getName());
     }
     relativePath = sb.toString();
   }
   return relativePath;
 }
コード例 #2
0
 /** {@inheritDoc} */
 public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
   final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
   if (assemblyFile == null) {
     return new ArrayList<String>(assembly.getChildNames(mountPoint, target));
   }
   final List<String> directoryEntries = new LinkedList<String>();
   for (VirtualFile child : assemblyFile.getChildren()) {
     directoryEntries.add(child.getName());
   }
   return directoryEntries;
 }
コード例 #3
0
  /**
   * Process a deployment for jboss-service.xml files. Will parse the xml file and attach a
   * configuration discovered during processing.
   *
   * @param phaseContext the deployment unit context
   * @throws DeploymentUnitProcessingException
   */
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    final VirtualFile deploymentRoot =
        phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

    if (deploymentRoot == null || !deploymentRoot.exists()) return;

    VirtualFile serviceXmlFile = null;
    if (deploymentRoot.isDirectory()) {
      serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
    } else if (deploymentRoot
        .getName()
        .toLowerCase(Locale.ENGLISH)
        .endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
      serviceXmlFile = deploymentRoot;
    }
    if (serviceXmlFile == null || !serviceXmlFile.exists()) return;

    final XMLMapper xmlMapper = XMLMapper.Factory.create();
    final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser =
        new JBossServiceXmlDescriptorParser(
            JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
    xmlMapper.registerRootElement(
        new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
    xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);

    InputStream xmlStream = null;
    try {
      xmlStream = serviceXmlFile.openStream();
      final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
      final ParseResult<JBossServiceXmlDescriptor> result =
          new ParseResult<JBossServiceXmlDescriptor>();
      xmlMapper.parseDocument(result, reader);
      final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
      if (xmlDescriptor != null)
        phaseContext
            .getDeploymentUnit()
            .putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
      else throw SarMessages.MESSAGES.failedXmlParsing(serviceXmlFile);
    } catch (Exception e) {
      throw SarMessages.MESSAGES.failedXmlParsing(e, serviceXmlFile);
    } finally {
      VFSUtils.safeClose(xmlStream);
    }
  }
コード例 #4
0
 public String getName() {
   return entry.getName();
 }
コード例 #5
0
  /**
   * Finds a ejb-jar.xml (at WEB-INF of a .war or META-INF of a .jar) parses the file and creates
   * metadata out of it. The metadata is then attached to the deployment unit.
   *
   * @param deploymentPhase
   * @throws DeploymentUnitProcessingException
   */
  @Override
  public void deploy(DeploymentPhaseContext deploymentPhase)
      throws DeploymentUnitProcessingException {

    // get hold of the deployment unit.
    DeploymentUnit deploymentUnit = deploymentPhase.getDeploymentUnit();

    // get the root of the deployment unit
    VirtualFile deploymentRoot =
        deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();

    // Locate a ejb-jar.xml
    VirtualFile ejbJarXml = null;
    // EJB 3.1 FR 20.4 Enterprise Beans Packaged in a .war
    // TODO: Is there a better way to do this?
    if (deploymentRoot.getName().toLowerCase().endsWith(WAR_FILE_EXTENSION)) {
      // it's a .war file, so look for the ejb-jar.xml in WEB-INF
      ejbJarXml = deploymentRoot.getChild(EJB_JAR_XML_LOCATION_IN_WAR);
    } else if (deploymentRoot.getName().toLowerCase().endsWith(JAR_FILE_EXTENSION)) {
      ejbJarXml = deploymentRoot.getChild(EJB_JAR_XML_LOCATION_IN_JAR);
    } else {
      // neither a .jar nor a .war. Return
      return;
    }

    if (ejbJarXml == null || !ejbJarXml.exists()) {
      // no ejb-jar.xml found, nothing to do!
      return;
    }
    // Mark it as a EJB deployment
    EjbDeploymentMarker.mark(deploymentUnit);
    if (!deploymentUnit.hasAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION)) {
      final EEModuleDescription moduleDescription =
          deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
      final EjbJarDescription ejbModuleDescription = new EjbJarDescription(moduleDescription);
      deploymentUnit.putAttachment(
          EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbModuleDescription);
    }

    // get the XMLStreamReader and parse the ejb-jar.xml
    MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
    InputStream stream = null;
    try {
      stream = ejbJarXml.openStream();

      XMLStreamReader reader = this.getXMLStreamReader(stream, ejbJarXml, dtdInfo);

      EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo);
      // attach the EjbJarMetaData to the deployment unit
      deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA, ejbJarMetaData);

    } catch (XMLStreamException xmlse) {
      throw new DeploymentUnitProcessingException(
          "Exception while parsing ejb-jar.xml: " + ejbJarXml.getPathName(), xmlse);
    } catch (IOException ioe) {
      throw new DeploymentUnitProcessingException(
          "Failed to create reader for ejb-jar.xml: " + ejbJarXml.getPathName(), ioe);
    } finally {
      try {
        if (stream != null) {
          stream.close();
        }
      } catch (IOException ioe) {
        logger.debug("Ignoring exception while closing the InputStream ", ioe);
      }
    }
  }
コード例 #6
0
 public boolean accepts(VirtualFile file) {
   return file.getName().endsWith(Immutant.DESCRIPTOR_SUFFIX);
 }
コード例 #7
0
 public String getName() {
   return file.getName();
 }
コード例 #8
0
  protected void processDeployment(
      final String hostName, final WarMetaData warMetaData, final DeploymentUnitContext context)
      throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = VirtualFileAttachment.getVirtualFileAttachment(context);
    final Module module = context.getAttachment(ModuleDeploymentProcessor.MODULE_ATTACHMENT_KEY);
    if (module == null) {
      throw new DeploymentUnitProcessingException(
          "failed to resolve module for deployment " + deploymentRoot);
    }
    final ClassLoader classLoader = module.getClassLoader();
    final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();

    // Create the context
    final StandardContext webContext = new StandardContext();
    final ContextConfig config = new JBossContextConfig(context);
    // Set the deployment root
    try {
      webContext.setDocBase(deploymentRoot.getPhysicalFile().getAbsolutePath());
    } catch (IOException e) {
      throw new DeploymentUnitProcessingException(e);
    }
    webContext.addLifecycleListener(config);

    // Set the path name
    final String deploymentName = context.getName();
    String pathName = null;
    if (metaData.getContextRoot() == null) {
      pathName = deploymentRoot.getName();
      if (pathName.equals("ROOT.war")) {
        pathName = "";
      } else {
        pathName = "/" + pathName.substring(0, pathName.length() - 4);
      }
    } else {
      pathName = metaData.getContextRoot();
      if ("/".equals(pathName)) {
        pathName = "";
      }
    }
    webContext.setPath(pathName);
    webContext.setIgnoreAnnotations(true);

    // Add a dummy realm for now
    Realm realm = new MemoryRealm();
    webContext.setRealm(realm);

    //
    final Loader loader = new WebCtxLoader(classLoader);
    final InstanceManager manager = new WebInjectionContainer(classLoader);
    webContext.setInstanceManager(manager);
    webContext.setLoader(loader);

    // Set the session cookies flag according to metadata
    switch (metaData.getSessionCookies()) {
      case JBossWebMetaData.SESSION_COOKIES_ENABLED:
        webContext.setCookies(true);
        break;
      case JBossWebMetaData.SESSION_COOKIES_DISABLED:
        webContext.setCookies(false);
        break;
    }

    String metaDataSecurityDomain = metaData.getSecurityDomain();
    if (metaDataSecurityDomain != null) {
      metaDataSecurityDomain = metaDataSecurityDomain.trim();
    }

    // Add the context service
    final BatchBuilder builder = context.getBatchBuilder();
    builder
        .addService(
            WebSubsystemElement.JBOSS_WEB.append(deploymentName),
            new WebDeploymentService(webContext))
        .addDependency(
            WebSubsystemElement.JBOSS_WEB_HOST.append(hostName),
            Host.class,
            new WebContextInjector(webContext))
        .setInitialMode(Mode.ACTIVE);
  }
コード例 #9
0
  /** {@inheritDoc} */
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final List<ResourceRoot> resourceRoots = DeploymentUtils.allResourceRoots(deploymentUnit);

    if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
      return;
    }

    final DeploymentUnit parent = deploymentUnit.getParent();
    final DeploymentUnit topLevelDeployment = parent == null ? deploymentUnit : parent;
    final VirtualFile toplevelRoot =
        topLevelDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    final ExternalModuleService externalModuleService =
        topLevelDeployment.getAttachment(Attachments.EXTERNAL_MODULE_SERVICE);

    final Map<VirtualFile, ResourceRoot> files = new HashMap<VirtualFile, ResourceRoot>();
    for (ResourceRoot resourceRoot : resourceRoots) {
      files.put(resourceRoot.getRoot(), resourceRoot);
    }
    final Deque<ResourceRoot> libResourceRoots = new ArrayDeque<ResourceRoot>();
    // scan /lib entries for class-path items
    for (ResourceRoot resourceRoot : resourceRoots) {
      if (ModuleRootMarker.isModuleRoot(resourceRoot)
          && !SubDeploymentMarker.isSubDeployment(resourceRoot)) {
        libResourceRoots.add(resourceRoot);
      }
    }
    while (!libResourceRoots.isEmpty()) {
      final ResourceRoot resourceRoot = libResourceRoots.pop();
      final String[] items = getClassPathEntries(resourceRoot);
      for (String item : items) {
        final VirtualFile classPathFile = resourceRoot.getRoot().getParent().getChild(item);
        if (!classPathFile.exists()) {
          log.warnf("Class Path entry %s in %s not found. ", item, resourceRoot.getRoot());
        } else if (isInside(classPathFile, toplevelRoot)) {
          if (!files.containsKey(classPathFile)) {
            log.warnf(
                "Class Path entry %s in %s does not point to a valid jar for a Class-Path reference.",
                item, resourceRoot.getRoot());
          } else {
            final ResourceRoot target = files.get(classPathFile);
            if (SubDeploymentMarker.isSubDeployment(target)) {
              // for now we do not allow ear Class-Path references to subdeployments
              log.warnf(
                  "Class Path entry  in "
                      + resourceRoot.getRoot()
                      + "  may not point to a sub deployment.");
            } else if (!ModuleRootMarker.isModuleRoot(target)) {
              // otherwise just add it to the lib dir
              ModuleRootMarker.mark(target);
              libResourceRoots.push(target);
              log.debugf(
                  "Resource %s added to logical lib directory due to Class-Path entry in %s",
                  classPathFile, target.getRoot());
            }
            // otherwise it is already part of lib, so we leave it alone for now
          }
        } else if (item.startsWith("/")) {
          ModuleIdentifier moduleIdentifier = externalModuleService.addExternalModule(item);
          deploymentUnit.addToAttachmentList(Attachments.CLASS_PATH_ENTRIES, moduleIdentifier);
          log.debugf("Resource %s added as external jar %s", classPathFile, resourceRoot.getRoot());
        } else {
          // this is a dep on another deployment
          deploymentUnit.addToAttachmentList(
              Attachments.CLASS_PATH_ENTRIES,
              ModuleIdentifier.create(ServiceModuleLoader.MODULE_PREFIX + classPathFile.getName()));
        }
      }
    }
  }
コード例 #10
0
ファイル: ResourceRoot.java プロジェクト: pepite/jboss-as
 public ResourceRoot(final VirtualFile root, final MountHandle mountHandle) {
   this(root.getName(), root, mountHandle);
 }