Search in sources :

Example 1 with VirtualFile

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

the class JBossVFSv3ClassPathLocationScanner method findResourceNames.

public Set<String> findResourceNames(String location, URL locationUrl) throws IOException {
    String filePath = UrlUtils.toFilePath(locationUrl);
    String classPathRootOnDisk = filePath.substring(0, filePath.length() - location.length());
    if (!classPathRootOnDisk.endsWith("/")) {
        classPathRootOnDisk = classPathRootOnDisk + "/";
    }
    LOG.debug("Scanning starting at classpath root on JBoss VFS: " + classPathRootOnDisk);
    Set<String> resourceNames = new TreeSet<String>();
    List<VirtualFile> files = VFS.getChild(filePath).getChildrenRecursively(new VirtualFileFilter() {

        public boolean accepts(VirtualFile file) {
            return file.isFile();
        }
    });
    for (VirtualFile file : files) {
        resourceNames.add(file.getPathName().substring(classPathRootOnDisk.length()));
    }
    return resourceNames;
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) TreeSet(java.util.TreeSet)

Example 2 with VirtualFile

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

the class EEApplicationDescription method getComponents.

/**
     * Get all views in the application that have the given name and view type
     *
     * @param componentName  The name of the component
     * @param viewName       The view type
     * @param deploymentRoot The deployment root of the component doing the lookup
     * @return A set of all views for the given component name and type
     */
public Set<ViewDescription> getComponents(final String componentName, final String viewName, final VirtualFile deploymentRoot) {
    final List<ViewInformation> info = componentsByViewName.get(viewName);
    if (info == null) {
        return Collections.<ViewDescription>emptySet();
    }
    if (componentName.contains("#")) {
        final String[] parts = componentName.split("#");
        String path = parts[0];
        if (!path.startsWith("../")) {
            path = "../" + path;
        }
        final VirtualFile virtualPath = deploymentRoot.getChild(path);
        final String name = parts[1];
        final Set<ViewDescription> ret = new HashSet<ViewDescription>();
        for (ViewInformation i : info) {
            if (i.beanName.equals(name)) {
                //now we need to check the path
                if (virtualPath.equals(i.deploymentRoot)) {
                    ret.add(i.viewDescription);
                }
            }
        }
        return ret;
    } else {
        final Set<ViewDescription> all = new HashSet<ViewDescription>();
        final Set<ViewDescription> thisDeployment = new HashSet<ViewDescription>();
        for (ViewInformation i : info) {
            if (i.beanName.equals(componentName)) {
                all.add(i.viewDescription);
                if (i.deploymentRoot.equals(deploymentRoot)) {
                    thisDeployment.add(i.viewDescription);
                }
            }
        }
        if (all.size() > 1) {
            return thisDeployment;
        }
        return all;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) HashSet(java.util.HashSet)

Example 3 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.boot.archive.spi.InputStreamAccess) ArchiveEntry(org.hibernate.boot.archive.spi.ArchiveEntry)

Example 4 with VirtualFile

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

the class PersistenceUnitSearch method getPersistenceUnit.

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 JpaLogger.ROOT_LOGGER.persistenceUnitNotFound(absolutePath, puName, current);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) PersistenceUnitMetadataHolder(org.jboss.as.jpa.config.PersistenceUnitMetadataHolder) PersistenceUnitMetadata(org.jipijapa.plugin.spi.PersistenceUnitMetadata)

Example 5 with VirtualFile

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

the class ScannerTest method testZippedJar.

@Test
public void testZippedJar() throws Exception {
    File defaultPar = buildDefaultPar();
    addPackageToClasspath(defaultPar);
    final VirtualFile virtualFile = VFS.getChild(defaultPar.getAbsolutePath());
    Closeable closeable = VFS.mountZip(virtualFile, virtualFile, tempFileProvider);
    try {
        ArchiveDescriptor archiveDescriptor = VirtualFileSystemArchiveDescriptorFactory.INSTANCE.buildArchiveDescriptor(virtualFile.toURL());
        AbstractScannerImpl.ResultCollector resultCollector = new AbstractScannerImpl.ResultCollector(new StandardScanOptions());
        archiveDescriptor.visitArchive(new AbstractScannerImpl.ArchiveContextImpl(new PersistenceUnitDescriptorAdapter(), true, resultCollector));
        validateResults(resultCollector, ApplicationServer.class, Version.class);
    } finally {
        closeable.close();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) AbstractScannerImpl(org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl) Closeable(java.io.Closeable) ArchiveDescriptor(org.hibernate.jpa.boot.archive.spi.ArchiveDescriptor) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) StandardScanOptions(org.hibernate.jpa.boot.scan.internal.StandardScanOptions) 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