use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.
the class AnnotationsTestCase method testProcessConnectorFailNoConnector.
/**
* Process: Connector -- verification of the processConnector method
*
* @throws Throwable throwable exception
*/
@Ignore("JBJCA-1435: The current validation in IronJacamar is not correct, the testcase here is.")
@Test(expected = ValidateException.class)
public void testProcessConnectorFailNoConnector() 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");
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() && !"BaseResourceAdapter.class".equals(srcFile.getName())) {
Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
}
}
for (File srcFile : srcRa16.listFiles()) {
if (!srcFile.isDirectory() && !"TestResourceAdapter.class".equals(srcFile.getName())) {
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("testProcessConnectorFailNoConnector: 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);
assertNull(values);
// Test run
annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
}
use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.
the class EarStructureProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit)) {
return;
}
final ResourceRoot deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile virtualFile = deploymentRoot.getRoot();
// Make sure we don't index or add this as a module root
deploymentRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
ModuleRootMarker.mark(deploymentRoot, false);
String libDirName = DEFAULT_LIB_DIR;
// its possible that the ear metadata could come for jboss-app.xml
final boolean appXmlPresent = deploymentRoot.getRoot().getChild("META-INF/application.xml").exists();
final EarMetaData earMetaData = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earMetaData != null) {
final String xmlLibDirName = earMetaData.getLibraryDirectory();
if (xmlLibDirName != null) {
if (xmlLibDirName.length() == 1 && xmlLibDirName.charAt(0) == '/') {
throw EeLogger.ROOT_LOGGER.rootAsLibraryDirectory();
}
libDirName = xmlLibDirName;
}
}
// Process all the children
Map<String, MountedDeploymentOverlay> overlays = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_OVERLAY_LOCATIONS);
try {
final VirtualFile libDir;
// process the lib directory
if (!libDirName.isEmpty()) {
libDir = virtualFile.getChild(libDirName);
if (libDir.exists()) {
List<VirtualFile> libArchives = libDir.getChildren(CHILD_ARCHIVE_FILTER);
for (final VirtualFile child : libArchives) {
String relativeName = child.getPathNameRelativeTo(deploymentRoot.getRoot());
MountedDeploymentOverlay overlay = overlays.get(relativeName);
final MountHandle mountHandle;
if (overlay != null) {
overlay.remountAsZip(false);
mountHandle = new MountHandle(null);
} else {
final Closeable closable = child.isFile() ? mount(child, false) : null;
mountHandle = new MountHandle(closable);
}
final ResourceRoot childResource = new ResourceRoot(child, mountHandle);
if (child.getName().toLowerCase(Locale.ENGLISH).endsWith(JAR_EXTENSION)) {
ModuleRootMarker.mark(childResource);
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, childResource);
}
}
}
} else {
libDir = null;
}
// scan the ear looking for wars and jars
final List<VirtualFile> childArchives = new ArrayList<VirtualFile>(virtualFile.getChildren(new SuffixMatchFilter(CHILD_ARCHIVE_EXTENSIONS, new VisitorAttributes() {
@Override
public boolean isLeavesOnly() {
return false;
}
@Override
public boolean isRecurse(VirtualFile file) {
// don't recurse into /lib
if (file.equals(libDir)) {
return false;
}
for (String suffix : CHILD_ARCHIVE_EXTENSIONS) {
if (file.getName().endsWith(suffix)) {
// don't recurse into sub deployments
return false;
}
}
return true;
}
})));
// if there is no application.xml then look in the ear root for modules
if (!appXmlPresent) {
for (final VirtualFile child : childArchives) {
final boolean isWarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(WAR_EXTENSION);
final boolean isRarFile = child.getName().toLowerCase(Locale.ENGLISH).endsWith(RAR_EXTENSION);
this.createResourceRoot(deploymentUnit, child, isWarFile || isRarFile, isWarFile);
}
} else {
final Set<VirtualFile> subDeploymentFiles = new HashSet<VirtualFile>();
// otherwise read from application.xml
for (final ModuleMetaData module : earMetaData.getModules()) {
if (module.getFileName().endsWith(".xml")) {
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
final VirtualFile moduleFile = virtualFile.getChild(module.getFileName());
if (!moduleFile.exists()) {
throw EeLogger.ROOT_LOGGER.cannotProcessEarModule(virtualFile, module.getFileName());
}
if (libDir != null) {
VirtualFile moduleParentFile = moduleFile.getParent();
if (moduleParentFile != null && libDir.equals(moduleParentFile)) {
throw EeLogger.ROOT_LOGGER.earModuleChildOfLibraryDirectory(libDirName, module.getFileName());
}
}
// maintain this in a collection of subdeployment virtual files, to be used later
subDeploymentFiles.add(moduleFile);
final boolean webArchive = module.getType() == ModuleType.Web;
final ResourceRoot childResource = this.createResourceRoot(deploymentUnit, moduleFile, true, webArchive);
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.MODULE_META_DATA, module);
if (!webArchive) {
ModuleRootMarker.mark(childResource);
}
final String alternativeDD = module.getAlternativeDD();
if (alternativeDD != null && alternativeDD.trim().length() > 0) {
final VirtualFile alternateDeploymentDescriptor = deploymentRoot.getRoot().getChild(alternativeDD);
if (!alternateDeploymentDescriptor.exists()) {
throw EeLogger.ROOT_LOGGER.alternateDeploymentDescriptor(alternateDeploymentDescriptor, moduleFile);
}
switch(module.getType()) {
case Client:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Connector:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CONNECTOR_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Ejb:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Web:
childResource.putAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_WEB_DEPLOYMENT_DESCRIPTOR, alternateDeploymentDescriptor);
break;
case Service:
throw EeLogger.ROOT_LOGGER.unsupportedModuleType(module.getFileName());
}
}
}
// now check the rest of the archive for any other jar/sar files
for (final VirtualFile child : childArchives) {
if (subDeploymentFiles.contains(child)) {
continue;
}
final String fileName = child.getName().toLowerCase(Locale.ENGLISH);
if (fileName.endsWith(SAR_EXTENSION) || fileName.endsWith(JAR_EXTENSION)) {
this.createResourceRoot(deploymentUnit, child, false, false);
}
}
}
} catch (IOException e) {
throw EeLogger.ROOT_LOGGER.failedToProcessChild(e, virtualFile);
}
}
use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.
the class AnnotationsTestCase method testProcessAuthenticationMechanism.
/**
* Process: AuthenticationMechanism -- verification of the
* processAuthenticationMechanism method
*
* @throws Throwable throwable exception
*/
@Test
public void testProcessAuthenticationMechanism() throws Throwable {
try {
URI uri = getURI("/ra16annoauthmech.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) {
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());
annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
} catch (Throwable t) {
fail(t.getMessage());
}
}
use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.
the class AnnotationsTestCase method testProcessAdministeredObject.
/**
* Process: AdministeredObject -- verification of the
* processAdministeredObject method
*
* @throws Throwable throwable exception
*/
@Test
public void testProcessAdministeredObject() throws Throwable {
try {
URI uri = getURI("/ra16annoadminobj.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) {
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());
annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
} catch (Throwable t) {
fail(t.getMessage());
}
}
use of org.jboss.vfs.util.SuffixMatchFilter in project wildfly by wildfly.
the class AnnotationsTestCase method testProcessConnectorManualSpecConnector.
/**
* Process: Connector -- verification of the processConnector method
*
* @throws Throwable throwable exception
*/
public void testProcessConnectorManualSpecConnector() 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");
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() && !"TestResourceAdapter.class".equals(srcFile.getName())) {
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("testProcessConnectorFailNoConnector: 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);
assertNull(values);
// Test run
annotations.process(ar, "org.jboss.as.connector.deployers.spec.rars.BaseResourceAdapter", Thread.currentThread().getContextClassLoader());
}
Aggregations