Search in sources :

Example 11 with SuffixMatchFilter

use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnectorFailTooManyConnectors.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
@Test(expected = ValidateException.class)
public void testProcessConnectorFailTooManyConnectors() throws Throwable {
    // Test prep
    AnnotationRepository ar = null;
    try {
        File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
        File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
        File srcStandalone = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/rastandalone");
        final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
        final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
        final String destStandalone = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/rastandalone";
        Files.createParentDirs(new File(destStandalone + "/sample.file"));
        for (File srcFile : srcRars.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcRa16.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcStandalone.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destStandalone + "/" + srcFile.getName()));
            }
        }
        URI uri = getURI("/ra16inoutmultianno.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            System.out.println("testProcessConnectorFailTooManyConnectors: adding " + classFile.getPathName());
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Test preparation error " + e.getMessage());
    }
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNotNull(values);
    assertEquals(2, values.size());
    // Test run
    annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Example 12 with SuffixMatchFilter

use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnector.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
@Test
public void testProcessConnector() throws Throwable {
    // Test prep
    File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
    File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
    final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
    final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
    for (File srcFile : srcRars.listFiles()) {
        if (!srcFile.isDirectory()) {
            Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
        }
    }
    for (File srcFile : srcRa16.listFiles()) {
        if (!srcFile.isDirectory()) {
            Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
        }
    }
    URI uri = getURI("/ra16inoutmultianno.rar");
    final VirtualFile virtualFile = VFS.getChild(uri);
    final Indexer indexer = new Indexer();
    final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
    for (VirtualFile classFile : classChildren) {
        System.out.println("testProcessConnector: adding " + classFile.getPathName());
        InputStream inputStream = null;
        try {
            inputStream = classFile.openStream();
            indexer.index(inputStream);
        } finally {
            VFSUtils.safeClose(inputStream);
        }
    }
    final Index index = indexer.complete();
    AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNotNull(values);
    assertEquals(1, values.size());
    // Test run
    try {
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        t.printStackTrace();
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Example 13 with SuffixMatchFilter

use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.

the class KernelDeploymentParsingProcessor method parseDescriptors.

/**
 * Find and parse -jboss-beans.xml files.
 *
 * @param unit the deployment unit
 * @param root the root
 * @throws DeploymentUnitProcessingException
 *          for any error
 */
protected void parseDescriptors(DeploymentUnit unit, VirtualFile root) throws DeploymentUnitProcessingException {
    if (root == null || root.exists() == false)
        return;
    Collection<VirtualFile> beans;
    final String name = root.getName();
    if (name.endsWith("jboss-beans.xml")) {
        beans = Collections.singleton(root);
    } else {
        VirtualFileFilter filter = new SuffixMatchFilter("jboss-beans.xml");
        beans = new ArrayList<VirtualFile>();
        try {
            // try plain .jar/META-INF
            VirtualFile metainf = root.getChild("META-INF");
            if (metainf.exists())
                beans.addAll(metainf.getChildren(filter));
            // allow for WEB-INF/*-jboss-beans.xml
            VirtualFile webinf = root.getChild("WEB-INF");
            if (webinf.exists()) {
                beans.addAll(webinf.getChildren(filter));
                // allow WEB-INF/classes/META-INF
                metainf = webinf.getChild("classes/META-INF");
                if (metainf.exists())
                    beans.addAll(metainf.getChildren(filter));
            }
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException(e);
        }
    }
    for (VirtualFile beansXmlFile : beans) parseDescriptor(unit, beansXmlFile);
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) VirtualFileFilter(org.jboss.vfs.VirtualFileFilter) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) IOException(java.io.IOException)

Aggregations

VirtualFile (org.jboss.vfs.VirtualFile)13 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)13 InputStream (java.io.InputStream)11 URI (java.net.URI)11 Index (org.jboss.jandex.Index)11 Indexer (org.jboss.jandex.Indexer)11 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)11 Test (org.junit.Test)10 File (java.io.File)4 Annotation (org.jboss.jca.common.spi.annotations.repository.Annotation)4 IOException (java.io.IOException)2 Closeable (java.io.Closeable)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 MountedDeploymentOverlay (org.jboss.as.server.deployment.MountedDeploymentOverlay)1 MountHandle (org.jboss.as.server.deployment.module.MountHandle)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)1