Пример #1
0
  @Override
  public void updateResource(
      final String archiveName, final Map<String, byte[]> replacedResources) {
    final ModuleIdentifier moduleId = getModuleIdentifier(archiveName);
    final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId);
    if (loader == null) {
      return;
    }

    final DeploymentUnit deploymentUnit =
        (DeploymentUnit)
            CurrentServiceRegistry.getServiceRegistry()
                .getRequiredService(Services.deploymentUnitName(archiveName))
                .getValue();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    for (final Map.Entry<String, byte[]> entry : replacedResources.entrySet()) {
      final VirtualFile file = root.getRoot().getChild(entry.getKey());
      try {
        final FileOutputStream stream = new FileOutputStream(file.getPhysicalFile(), false);
        try {
          stream.write(entry.getValue());
        } finally {
          stream.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
 @Override
 public boolean equals(Object obj) {
   if (obj == this) return true;
   if (!(obj instanceof VFS3FileScannedItem)) return false;
   return file.equals(((VFS3FileScannedItem) obj).file)
       && root.equals(((VFS3FileScannedItem) obj).root);
 }
Пример #3
0
  @Override
  public Set<String> getUpdatedResources(
      final String deploymentName, final Map<String, Long> updatedResources) {
    final ModuleIdentifier moduleId = getModuleIdentifier(deploymentName);
    final ModuleClassLoader loader = loadersByModuleIdentifier.get(moduleId);
    if (loader == null) {
      return Collections.emptySet();
    }

    final DeploymentUnit deploymentUnit =
        (DeploymentUnit)
            CurrentServiceRegistry.getServiceRegistry()
                .getRequiredService(Services.deploymentUnitName(deploymentName))
                .getValue();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    final Set<String> resources = new HashSet<String>();
    for (final Map.Entry<String, Long> entry : updatedResources.entrySet()) {
      final VirtualFile file = root.getRoot().getChild(entry.getKey());
      if (file.exists()) {
        long last = file.getLastModified();
        if (entry.getValue() > last) {
          resources.add(entry.getKey());
        }
      }
    }
    return resources;
  }
  protected VirtualFile getFile(DeploymentUnit unit)
      throws DeploymentUnitProcessingException, IOException {
    List<VirtualFile> matches = new ArrayList<VirtualFile>();

    ResourceRoot resourceRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (resourceRoot == null) {
      return null;
    }
    VirtualFile root = resourceRoot.getRoot();

    if (this.knobFilter.accepts(root)) {
      return root;
    }

    matches = root.getChildren(this.knobFilter);

    if (matches.size() > 1) {
      throw new DeploymentUnitProcessingException("Multiple Immutant descriptors found in " + root);
    }

    VirtualFile file = null;
    if (matches.size() == 1) {
      file = matches.get(0);
    }

    return file;
  }
  public void deploy(final DeploymentPhaseContext phaseContext)
      throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
      return;
    }
    final ResourceRoot deploymentRoot =
        deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    final VirtualFile deploymentFile = deploymentRoot.getRoot();
    final VirtualFile applicationXmlFile = deploymentFile.getChild(JBOSS_APP_XML);
    if (!applicationXmlFile.exists()) {
      return;
    }

    InputStream inputStream = null;
    try {
      inputStream = applicationXmlFile.openStream();
      final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
      inputFactory.setXMLResolver(NoopXmlResolver.create());
      XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream);
      final JBossAppMetaData appMetaData = JBossAppMetaDataParser.parse(xmlReader);
      if (appMetaData != null) {
        final EarMetaData earMetaData = deploymentUnit.getAttachment(Attachments.EAR_METADATA);
        if (earMetaData != null) {
          JBossAppMetaDataMerger.merge(appMetaData, null, earMetaData);
        }
        deploymentUnit.putAttachment(Attachments.JBOSS_APP_METADATA, appMetaData);
      }
    } catch (Exception e) {
      throw new DeploymentUnitProcessingException("Failed to parse " + applicationXmlFile, e);
    } finally {
      VFSUtils.safeClose(inputStream);
    }
  }
Пример #6
0
 /** {@inheritDoc} */
 public CodeSigner[] getCodeSigners(VirtualFile mountPoint, VirtualFile target) {
   final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
   if (assemblyFile == null) {
     return null;
   }
   return assemblyFile.getCodeSigners();
 }
Пример #7
0
 /** {@inheritDoc} */
 public boolean exists(VirtualFile mountPoint, VirtualFile target) {
   if (mountPoint.equals(target)) {
     return true;
   }
   final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
   if (assemblyFile != null) {
     return assemblyFile.exists();
   }
   return assembly.contains(mountPoint, target);
 }
Пример #8
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;
 }
 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;
 }
Пример #10
0
 /** {@inheritDoc} */
 public Resource getResource(final String name) {
   try {
     final VirtualFile file = root.getChild(PathUtils.canonicalize(name));
     if (!file.exists()) {
       return null;
     }
     return new VFSEntryResource(file, file.toURL());
   } catch (MalformedURLException e) {
     // must be invalid...?  (todo: check this out)
     return null;
   }
 }
  @SuppressWarnings("unchecked")
  public void deploy(VFSDeploymentUnit unit) throws DeploymentException {
    TorqueBoxMetaData globalMetaData = unit.getAttachment(TorqueBoxMetaData.class);

    log.debug("Global torquebox.yml: " + globalMetaData);

    Object data = null;

    if (globalMetaData != null) {
      data = globalMetaData.getSection(getSectionName());
      log.debug("Global data section for " + getSectionName() + ": " + data);
    }

    if (data == null && isSupportsStandalone()) {
      VirtualFile metaDataFile = getMetaDataFile(unit, getFileName());

      if ((metaDataFile != null) && metaDataFile.exists()) {
        log.warn("Usage of " + getFileName() + " is deprecated.  Please use torquebox.yml.");
        InputStream in = null;
        try {
          in = metaDataFile.openStream();
          Yaml yaml = new Yaml();
          data = (Map<String, ?>) yaml.load(in);
        } catch (YAMLException e) {
          log.warn("Error parsing: " + metaDataFile + ": " + e.getMessage());
          data = null;
        } catch (IOException e) {
          throw new DeploymentException(e);
        } finally {
          if (in != null) {
            try {
              in.close();
            } catch (IOException e) {
              throw new DeploymentException(e);
            }
          }
        }
      }
    }

    if (data == null) {
      return;
    }

    try {
      parse(unit, data);
    } catch (DeploymentException e) {
      throw e;
    } catch (Exception e) {
      throw new DeploymentException(e);
    }
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();

    if (deploymentUnit.hasAttachment(ClojureMetaData.ATTACHMENT_KEY)) {
      return;
    }

    Timer t = new Timer("parsing deployment descriptor");
    String deploymentName = deploymentUnit.getName();

    try {
      VirtualFile descriptor = getDescriptorFile(deploymentUnit);
      if (descriptor == null) {
        return;
      }

      ClojureMetaData appMetaData =
          new ClojureMetaData(deploymentName, ClojureMetaData.parse(descriptor.getPhysicalFile()));

      appMetaData.attachTo(deploymentUnit);

      File root = appMetaData.getRoot();

      if (root == null) {
        throw new DeploymentUnitProcessingException("No application root specified.");
      }

      if (!root.exists()) {
        throw new DeploymentUnitProcessingException(
            "Application root does not exist: " + root.getAbsolutePath());
      }

      VirtualFile virtualRoot = VFS.getChild(root.toURI());
      MountHandle mountHandle = null;

      if (!root.isDirectory()) {
        // Expand the referenced root if it's not a directory (ie .ima archive)
        mountHandle =
            new MountHandle(
                VFS.mountZipExpanded(virtualRoot, virtualRoot, TempFileProviderService.provider()));
      }

      deploymentUnit.putAttachment(
          Attachments.DEPLOYMENT_ROOT, new ResourceRoot(virtualRoot, mountHandle));
      deploymentUnit.putAttachment(ClojureMetaData.DESCRIPTOR_FILE, descriptor.getPhysicalFile());

    } catch (Exception e) {
      throw new DeploymentUnitProcessingException(e);
    }
    t.done();
  }
  private void mount(File file, DeploymentUnit unit, JarMountMap mountMap) throws IOException {
    VirtualFile mountPath =
        VFS.getChild(File.createTempFile(file.getName(), ".jar", tmpMountDir(unit)).toURI());
    log.debug(unit.getName() + ": mounting " + file);
    final ResourceRoot childResource =
        new ResourceRoot(
            mountPath,
            new MountHandle(VFS.mountZip(file, mountPath, TempFileProviderService.provider())));
    ModuleRootMarker.mark(childResource);
    unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);

    mountMap.put(mountPath.toURL().toExternalForm(), file.toURI().toURL().toExternalForm());
  }
 private ServletContainerInitializer loadSci(
     ClassLoader classLoader, VirtualFile sci, String jar, boolean error)
     throws DeploymentUnitProcessingException {
   ServletContainerInitializer service = null;
   InputStream is = null;
   try {
     // Get the ServletContainerInitializer class name
     is = sci.openStream();
     BufferedReader reader = new BufferedReader(new InputStreamReader(is));
     String servletContainerInitializerClassName = reader.readLine();
     int pos = servletContainerInitializerClassName.indexOf('#');
     if (pos > 0) {
       servletContainerInitializerClassName =
           servletContainerInitializerClassName.substring(0, pos);
     }
     servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
     // Instantiate the ServletContainerInitializer
     service =
         (ServletContainerInitializer)
             classLoader.loadClass(servletContainerInitializerClassName).newInstance();
   } catch (Exception e) {
     if (error) {
       throw MESSAGES.errorProcessingSCI(jar, e);
     } else {
       UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
     }
   } finally {
     try {
       if (is != null) is.close();
     } catch (IOException e) {
       // Ignore
     }
   }
   return service;
 }
 public ModuleIdentifier addExternalModule(VirtualFile externalModule) {
   ModuleIdentifier identifier =
       ModuleIdentifier.create(EXTERNAL_MODULE_PREFIX + externalModule.getPathName());
   ServiceName serviceName = ServiceModuleLoader.moduleSpecServiceName(identifier);
   ServiceController<?> controller = serviceContainer.getService(serviceName);
   if (controller == null) {
     try {
       ExternalModuleSpecService service =
           new ExternalModuleSpecService(identifier, externalModule.getPhysicalFile());
       serviceContainer.addService(serviceName, service).setInitialMode(Mode.ON_DEMAND).install();
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return identifier;
 }
  @Test
  public void testLoadCorrectJbossWeb() throws Exception {
    final VirtualFile jbossWebxml = mock(VirtualFile.class);
    when(jbossWebxml.exists()).thenReturn(Boolean.TRUE);
    when(jbossWebxml.openStream())
        .thenReturn(
            JBossWebParsingDeploymentProcessorTest.class.getResourceAsStream("jboss-web.xml"));

    final VirtualFile deploymentRoot = mock(VirtualFile.class);
    when(deploymentRoot.getChild("WEB-INF/jboss-web.xml")).thenReturn(jbossWebxml);

    final ResourceRoot resourceRoot = mock(ResourceRoot.class);
    when(resourceRoot.getRoot()).thenReturn(deploymentRoot);
    when(deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT))
        .thenReturn(resourceRoot);
    processor.deploy(phaseContext);
  }
Пример #17
0
 /**
  * Construct new instance.
  *
  * @param rootName The module root name
  * @param root The root virtual file
  * @param usePhysicalCodeSource {@code true} to use the physical root URL for code sources, {@code
  *     false} to use the VFS URL
  * @throws IOException if the manifest could not be read or the root URL is invalid
  */
 public VFSResourceLoader(
     final String rootName, final VirtualFile root, final boolean usePhysicalCodeSource)
     throws IOException {
   this.root = root;
   this.rootName = rootName;
   manifest = VFSUtils.getManifest(root);
   rootUrl = usePhysicalCodeSource ? VFSUtils.getRootURL(root) : root.asFileURL();
 }
Пример #18
0
 private VirtualFile getExistingFile(final VirtualFile mountPoint, final VirtualFile target)
     throws FileNotFoundException {
   final VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
   if (assemblyFile == null) {
     throw new FileNotFoundException(target.getPathName());
   }
   return assemblyFile;
 }
 private List<ServletContainerInitializer> loadSci(
     ClassLoader classLoader,
     VirtualFile sci,
     String jar,
     boolean error,
     Set<Class<? extends ServletContainerInitializer>> sciClasses)
     throws DeploymentUnitProcessingException {
   final List<ServletContainerInitializer> scis = new ArrayList<ServletContainerInitializer>();
   InputStream is = null;
   try {
     // Get the ServletContainerInitializer class name
     is = sci.openStream();
     BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
     String servletContainerInitializerClassName = reader.readLine();
     while (servletContainerInitializerClassName != null) {
       try {
         int pos = servletContainerInitializerClassName.indexOf('#');
         if (pos >= 0) {
           servletContainerInitializerClassName =
               servletContainerInitializerClassName.substring(0, pos);
         }
         servletContainerInitializerClassName = servletContainerInitializerClassName.trim();
         if (!servletContainerInitializerClassName.isEmpty()) {
           // Instantiate the ServletContainerInitializer
           ServletContainerInitializer service =
               (ServletContainerInitializer)
                   classLoader.loadClass(servletContainerInitializerClassName).newInstance();
           if (service != null) {
             if (sciClasses.add(service.getClass())) {
               scis.add(service);
             }
           }
         }
         servletContainerInitializerClassName = reader.readLine();
       } catch (Exception e) {
         if (error) {
           throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
         } else {
           UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
         }
       }
     }
   } catch (Exception e) {
     if (error) {
       throw UndertowLogger.ROOT_LOGGER.errorProcessingSCI(jar, e);
     } else {
       UndertowLogger.ROOT_LOGGER.skippedSCI(jar, e);
     }
   } finally {
     try {
       if (is != null) is.close();
     } catch (IOException e) {
       // Ignore
     }
   }
   return scis;
 }
 private static boolean isInside(VirtualFile classPathFile, VirtualFile toplevelRoot) {
   VirtualFile[] parentPaths = classPathFile.getParentFiles();
   for (VirtualFile path : parentPaths) {
     if (path == toplevelRoot) {
       // inside the deployment
       return true;
     }
   }
   return false;
 }
  private static PersistenceUnitMetadata getPersistenceUnit(
      DeploymentUnit current, final String absolutePath, String puName) {
    final String path;
    if (absolutePath.startsWith("../")) {
      path = absolutePath.substring(3);
    } else {
      path = absolutePath;
    }
    final VirtualFile parent =
        current.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getParent();
    final VirtualFile resolvedPath = parent.getChild(path);

    List<ResourceRoot> resourceRoots =
        DeploymentUtils.allResourceRoots(DeploymentUtils.getTopDeploymentUnit(current));

    for (ResourceRoot resourceRoot : resourceRoots) {
      if (resourceRoot.getRoot().equals(resolvedPath)) {
        PersistenceUnitMetadataHolder holder =
            resourceRoot.getAttachment(PersistenceUnitMetadataHolder.PERSISTENCE_UNITS);
        if (holder != null) {
          for (PersistenceUnitMetadata pu : holder.getPersistenceUnits()) {
            if (traceEnabled) {
              ROOT_LOGGER.tracef(
                  "getPersistenceUnit check '%s' against pu '%s'",
                  puName, pu.getPersistenceUnitName());
            }
            if (pu.getPersistenceUnitName().equals(puName)) {
              if (traceEnabled) {
                ROOT_LOGGER.tracef(
                    "getPersistenceUnit matched '%s' against pu '%s'",
                    puName, pu.getPersistenceUnitName());
              }
              return pu;
            }
          }
        }
      }
    }

    throw MESSAGES.persistenceUnitNotFound(absolutePath, puName, current);
  }
  @Override
  public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {

    // Check if we already have an OSGi deployment
    DeploymentUnit depUnit = phaseContext.getDeploymentUnit();
    if (depUnit.hasAttachment(OSGiConstants.OSGI_METADATA_KEY)) return;

    // Get the OSGi XService properties
    VirtualFile virtualFile = depUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    VirtualFile xserviceFile = virtualFile.getChild(XSERVICE_PROPERTIES_NAME);
    if (xserviceFile.exists() == false) return;

    try {
      Properties props = new Properties();
      props.load(xserviceFile.openStream());
      OSGiMetaData metadata = OSGiMetaDataBuilder.load(props);
      depUnit.putAttachment(OSGiConstants.OSGI_METADATA_KEY, metadata);
    } catch (IOException ex) {
      throw MESSAGES.cannotParseOSGiMetadata(ex, xserviceFile);
    }
  }
Пример #23
0
 /** {@inheritDoc} */
 public ClassSpec getClassSpec(final String name) throws IOException {
   final VirtualFile file = root.getChild(name);
   if (!file.exists()) {
     return null;
   }
   final long size = file.getSize();
   final ClassSpec spec = new ClassSpec();
   final InputStream is = file.openStream();
   try {
     if (size <= (long) Integer.MAX_VALUE) {
       final int castSize = (int) size;
       byte[] bytes = new byte[castSize];
       int a = 0, res;
       while ((res = is.read(bytes, a, castSize - a)) > 0) {
         a += res;
       }
       // done
       is.close();
       spec.setBytes(bytes);
       spec.setCodeSource(new CodeSource(rootUrl, file.getCodeSigners()));
       return spec;
     } else {
       throw ServerMessages.MESSAGES.resourceTooLarge();
     }
   } finally {
     VFSUtils.safeClose(is);
   }
 }
 /**
  * Creates and returns a {@link XMLStreamReader} for the passed {@link VirtualFile ejb-jar.xml}
  *
  * @param stream The input stream
  * @param ejbJarXml
  * @return
  * @throws DeploymentUnitProcessingException
  */
 private XMLStreamReader getXMLStreamReader(
     InputStream stream, VirtualFile ejbJarXml, XMLResolver resolver)
     throws DeploymentUnitProcessingException {
   try {
     final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
     inputFactory.setXMLResolver(resolver);
     XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(stream);
     return xmlReader;
   } catch (XMLStreamException xmlse) {
     throw new DeploymentUnitProcessingException(
         "Failed to create reader for ejb-jar.xml: " + ejbJarXml.getPathName(), xmlse);
   }
 }
 /**
  * Creates a {@link ResourceRoot} for the passed {@link VirtualFile file} and adds it to the list
  * of {@link ResourceRoot}s in the {@link DeploymentUnit deploymentUnit}
  *
  * @param file The file for which the resource root will be created
  * @return Returns the created {@link ResourceRoot}
  * @throws java.io.IOException
  */
 private synchronized ResourceRoot createResourceRoot(final VirtualFile file)
     throws DeploymentUnitProcessingException {
   try {
     final Closeable closable =
         file.isFile() ? VFS.mountZip(file, file, TempFileProviderService.provider()) : null;
     final MountHandle mountHandle = new MountHandle(closable);
     final ResourceRoot resourceRoot = new ResourceRoot(file, mountHandle);
     ModuleRootMarker.mark(resourceRoot);
     ResourceRootIndexer.indexResourceRoot(resourceRoot);
     return resourceRoot;
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
  /**
   * 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);
    }
  }
Пример #27
0
 @Override
 public Closeable mountDeploymentContent(
     final VirtualFile contents, VirtualFile mountPoint, MountType type) throws IOException {
   // according to the javadoc contents can not be null
   assert contents != null : "null contents";
   switch (type) {
     case ZIP:
       return VFS.mountZip(contents, mountPoint, tempFileProvider);
     case EXPANDED:
       return VFS.mountZipExpanded(contents, mountPoint, tempFileProvider);
     case REAL:
       return VFS.mountReal(contents.getPhysicalFile(), mountPoint);
     default:
       throw ServerMessages.MESSAGES.unknownMountType(type);
   }
 }
 /**
  * Batch deployments must have a {@code META-INF/batch.xml} and/or XML configuration files in
  * {@code META-INF/batch-jobs}. They must be in an EJB JAR or a WAR.
  *
  * @param deploymentUnit the deployment unit to check
  * @return {@code true} if a {@code META-INF/batch.xml} or a non-empty {@code META-INF/batch-jobs}
  *     directory was found otherwise {@code false}
  */
 private boolean isBatchDeployment(final DeploymentUnit deploymentUnit) {
   // Section 10.7 of JSR 352 discusses valid packaging types, of which it appears EAR should be
   // one. It seems
   // though that it's of no real use as 10.5 and 10.6 seem to indicate it must be in
   // META-INF/batch-jobs of a JAR
   // and WEB-INF/classes/META-INF/batch-jobs of a WAR.
   if (DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)
       || !deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
     return false;
   }
   final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
   final VirtualFile metaInf;
   if (DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
     metaInf = root.getRoot().getChild("WEB-INF/classes/META-INF");
   } else {
     metaInf = root.getRoot().getChild("META-INF");
   }
   final VirtualFile jobXmlFile = metaInf.getChild("batch.xml");
   final VirtualFile batchJobsDir = metaInf.getChild("batch-jobs");
   return (jobXmlFile.exists()
       || (batchJobsDir.exists() && !batchJobsDir.getChildren().isEmpty()));
 }
Пример #29
0
  /** {@inheritDoc} */
  public Collection<String> getPaths() {
    final List<String> index = new ArrayList<String>();
    // First check for an index file
    final VirtualFile indexFile = VFS.getChild(root.getPathName() + ".index");
    if (indexFile.exists()) {
      try {
        final BufferedReader r = new BufferedReader(new InputStreamReader(indexFile.openStream()));
        try {
          String s;
          while ((s = r.readLine()) != null) {
            index.add(s.trim());
          }
          return index;
        } finally {
          // if exception is thrown, undo index creation
          r.close();
        }
      } catch (IOException e) {
        index.clear();
      }
    }

    FilterVirtualFileVisitor visitor =
        new FilterVirtualFileVisitor(
            new VirtualFileFilter() {
              @Override
              public boolean accepts(VirtualFile file) {
                return file.isDirectory();
              }
            },
            VisitorAttributes.RECURSE);
    try {
      root.visit(visitor);
    } catch (IOException e) {
      index.clear();
    }

    index.add("");
    for (VirtualFile dir : visitor.getMatched()) {
      index.add(dir.getPathNameRelativeTo(root));
    }

    return index;
  }
  @SuppressWarnings("unchecked")
  protected void parse(
      VFSDeploymentUnit unit, VirtualFile file, RubyRuntimeMetaData runtimeMetaData)
      throws Exception {

    Yaml yaml = new Yaml();
    try {
      Map<String, Object> config = (Map<String, Object>) yaml.load(file.openStream());

      if (config != null) {
        Object version = config.get("version");
        if ("1.8".equals("" + version)) {
          runtimeMetaData.setVersion(RubyRuntimeMetaData.Version.V1_8);
        } else if ("1.9".equals("" + version)) {
          runtimeMetaData.setVersion(RubyRuntimeMetaData.Version.V1_9);
        }
      }
    } catch (YAMLException e) {
      log.error("Error parsing ruby.yml: " + e.getMessage());
    }
  }