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;
}
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;
}
}
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);
}
}
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);
}
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();
}
}
Aggregations