Search in sources :

Example 61 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class EarMetaDataParsingProcessor method handleSpecMetadata.

private EarMetaData handleSpecMetadata(VirtualFile deploymentFile, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final VirtualFile applicationXmlFile = deploymentFile.getChild(APPLICATION_XML);
    if (!applicationXmlFile.exists()) {
        return null;
    }
    InputStream inputStream = null;
    try {
        inputStream = applicationXmlFile.openStream();
        final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        inputFactory.setXMLResolver(NoopXMLResolver.create());
        XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(inputStream);
        return EarMetaDataParser.INSTANCE.parse(xmlReader, propertyReplacer);
    } catch (Exception e) {
        throw EeLogger.ROOT_LOGGER.failedToParse(e, applicationXmlFile);
    } finally {
        VFSUtils.safeClose(inputStream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStream(java.io.InputStream) XMLInputFactory(javax.xml.stream.XMLInputFactory) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 62 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class ScannerTest method testExplodedJar.

@Test
public void testExplodedJar() throws Exception {
    File explodedPar = buildExplodedPar();
    addPackageToClasspath(explodedPar);
    String dirPath = explodedPar.getAbsolutePath();
    if (dirPath.endsWith("/")) {
        dirPath = dirPath.substring(0, dirPath.length() - 1);
    }
    final VirtualFile virtualFile = VFS.getChild(dirPath);
    ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
    AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
    archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
    assertEquals(1, resultCollector.getClassDescriptorSet().size());
    assertEquals(1, resultCollector.getPackageDescriptorSet().size());
    assertEquals(1, resultCollector.getMappingFileSet().size());
    assertTrue(resultCollector.getClassDescriptorSet().contains(new ClassDescriptorImpl(Carpet.class.getName(), null)));
    for (MappingFileDescriptor mappingFileDescriptor : resultCollector.getMappingFileSet()) {
        assertNotNull(mappingFileDescriptor.getStreamAccess());
        final InputStream stream = mappingFileDescriptor.getStreamAccess().accessInputStream();
        assertNotNull(stream);
        stream.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) MappingFileDescriptor(org.hibernate.jpa.boot.spi.MappingFileDescriptor) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassDescriptorImpl(org.hibernate.jpa.boot.internal.ClassDescriptorImpl) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) Carpet(org.hibernate.jpa.test.pack.explodedpar.Carpet) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) Test(org.junit.Test)

Example 63 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class VirtualFileSystemArchiveDescriptor method processVirtualFile.

private void processVirtualFile(VirtualFile virtualFile, String path, ArchiveContext archiveContext) {
    if (path == null) {
        path = "";
    } else {
        if (!path.endsWith("/'")) {
            path = path + "/";
        }
    }
    for (VirtualFile child : virtualFile.getChildren()) {
        if (!child.exists()) {
            // should never happen conceptually, but...
            continue;
        }
        if (child.isDirectory()) {
            processVirtualFile(child, path + child.getName(), archiveContext);
            continue;
        }
        final String name = child.getPathName();
        final String relativeName = path + child.getName();
        final InputStreamAccess inputStreamAccess = new VirtualFileInputStreamAccess(name, child);
        final ArchiveEntry entry = new ArchiveEntry() {

            @Override
            public String getName() {
                return name;
            }

            @Override
            public String getNameWithinArchive() {
                return relativeName;
            }

            @Override
            public InputStreamAccess getStreamAccess() {
                return inputStreamAccess;
            }
        };
        archiveContext.obtainArchiveEntryHandler(entry).handleEntry(entry, archiveContext);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStreamAccess(org.hibernate.jpa.boot.spi.InputStreamAccess) ArchiveEntry(org.hibernate.jpa.boot.archive.spi.ArchiveEntry)

Example 64 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class CollectFiles method execute.

@Override
public void execute() throws Exception {
    VirtualFile root = VFS.getChild(this.env.getJbossHome());
    List<VirtualFile> matches = root.getChildrenRecursively(Filters.and(this.filter, this.blacklistFilter));
    // get some limit on that set, which probably would be wrong.
    if (sorter != null) {
        Collections.sort(matches, sorter);
    }
    // limit how much data we collect
    Limiter limiter = new Limiter(limit);
    Iterator<VirtualFile> iter = matches.iterator();
    while (iter.hasNext() && !limiter.isDone()) {
        VirtualFile f = iter.next();
        InputStream stream = limiter.limit(f);
        for (Sanitizer sanitizer : this.sanitizers) {
            if (sanitizer.accepts(f)) {
                stream = sanitizer.sanitize(stream);
            }
        }
        this.env.getZip().add(f, stream);
        Utils.safelyClose(stream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Sanitizer(org.jboss.as.jdr.util.Sanitizer)

Example 65 with VirtualFile

use of org.jboss.vfs.VirtualFile in project wildfly by wildfly.

the class JdrTestCase method testWildcardFilterPrefixGlob.

@Test
public void testWildcardFilterPrefixGlob() throws Exception {
    VirtualFileFilter filter = Filters.wildcard("*.txt");
    VirtualFile good = VFS.getChild("/this/is/a/test.txt");
    VirtualFile bad = VFS.getChild("/this/is/a/test.xml");
    VirtualFile wingood = VFS.getChild("/C:/this/is/a/test.txt");
    VirtualFile winbad = VFS.getChild("/C:/this/is/a/test.xml");
    assertTrue(filter.accepts(good));
    assertFalse(filter.accepts(bad));
    assertTrue(filter.accepts(wingood));
    assertFalse(filter.accepts(winbad));
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) Test(org.junit.Test)

Aggregations

VirtualFile (org.jboss.vfs.VirtualFile)93 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)36 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)29 InputStream (java.io.InputStream)28 IOException (java.io.IOException)23 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)22 Test (org.junit.Test)18 File (java.io.File)16 Closeable (java.io.Closeable)12 URI (java.net.URI)10 HashSet (java.util.HashSet)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 Index (org.jboss.jandex.Index)10 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)10 ArrayList (java.util.ArrayList)9 XMLStreamException (javax.xml.stream.XMLStreamException)9 WarMetaData (org.jboss.as.web.common.WarMetaData)9 Indexer (org.jboss.jandex.Indexer)8 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)8 XMLInputFactory (javax.xml.stream.XMLInputFactory)7