Java Code Examples for org.jboss.vfs.VirtualFile#exists()

The following examples show how to use org.jboss.vfs.VirtualFile#exists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DriverDependenciesProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
    final ModuleLoader moduleLoader = Module.getBootModuleLoader();
    if (deploymentUnit.hasAttachment(Attachments.RESOURCE_ROOTS)) {
        final List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
        for (ResourceRoot root : resourceRoots) {
            VirtualFile child = root.getRoot().getChild(SERVICE_FILE_NAME);
            if (child.exists()) {
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, JTA, false, false, false, false));
                break;
            }
        }
    }
}
 
Example 2
Source File: ClassLoaderUtil.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
public static List<URL> loadVfs(URL resource) throws IOException
{
  List<URL> result = new LinkedList<>();

  try
  {
    VirtualFile r = VFS.getChild(resource.toURI());
    if (r.exists() && r.isDirectory())
    {
      for (VirtualFile f : r.getChildren())
      {
        result.add(f.asFileURL());
      }
    }
  }
  catch (URISyntaxException e)
  {
    System.out.println("Problem reading resource '" + resource + "':\n " + e.getMessage());
    log.error("Exception thrown", e);
  }

  return result;
}
 
Example 3
Source File: VFSResourceLoader.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
VirtualFile getExistentVirtualFile(final String name) {
    VirtualFile file;
    int version = RELEASE;
    if (multiRelease) while (version >= 9) {
        file = root.getChild(MR_PREFIX + version + "/" + name);
        if (file.exists()) {
            return file;
        }
        version --;
    }
    file = root.getChild(name);
    return file.exists() ? file : null;
}
 
Example 4
Source File: JBossAllXMLParsingProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ResourceRoot root = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    VirtualFile descriptor = null;
    for (final String loc : DEPLOYMENT_STRUCTURE_DESCRIPTOR_LOCATIONS) {
        final VirtualFile file = root.getRoot().getChild(loc);
        if (file.exists()) {
            descriptor = file;
            break;
        }
    }
    if(descriptor == null) {
        return;
    }
    final XMLMapper mapper = XMLMapper.Factory.create();
    final Map<QName, AttachmentKey<?>> namespaceAttachments = new HashMap<QName, AttachmentKey<?>>();
    for(final JBossAllXMLParserDescription<?> parser : deploymentUnit.getAttachmentList(JBossAllXMLParserDescription.ATTACHMENT_KEY)) {
        namespaceAttachments.put(parser.getRootElement(), parser.getAttachmentKey());
        mapper.registerRootElement(parser.getRootElement(), new JBossAllXMLElementReader(parser));
    }
    mapper.registerRootElement(new QName(Namespace.JBOSS_1_0.getUriString(), JBOSS), Parser.INSTANCE);
    mapper.registerRootElement(new QName(Namespace.NONE.getUriString(), JBOSS), Parser.INSTANCE);

    final JBossAllXmlParseContext context = new JBossAllXmlParseContext(deploymentUnit);
    parse(descriptor, mapper, context);

    //we use this map to detect the presence of two different but functionally equivalent namespaces
    final Map<AttachmentKey<?>, QName> usedNamespaces = new HashMap<AttachmentKey<?>, QName>();
    for(Map.Entry<QName, Object> entry : context.getParseResults().entrySet()) {
        final AttachmentKey attachmentKey = namespaceAttachments.get(entry.getKey());
        if(usedNamespaces.containsKey(attachmentKey)) {
            throw ServerLogger.ROOT_LOGGER.equivalentNamespacesInJBossXml(entry.getKey(), usedNamespaces.get(attachmentKey));
        }
        usedNamespaces.put(attachmentKey, entry.getKey());
        deploymentUnit.putAttachment(attachmentKey, entry.getValue());
    }
}
 
Example 5
Source File: ScriptProviderDeploymentProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static ScriptProviderDescriptor readScriptProviderDescriptor(VirtualFile deploymentRoot) {
    VirtualFile metadataFile = deploymentRoot.getChild("META-INF/keycloak-scripts.json");

    if (!metadataFile.exists()) {
        return null;
    }

    try (InputStream inputStream = metadataFile.openStream()) {
        return JsonSerialization.readValue(inputStream, ScriptProviderDescriptor.class);
    } catch (IOException cause) {
        throw new RuntimeException("Failed to read providers metadata", cause);
    }
}
 
Example 6
Source File: KeycloakProviderDependencyProcessor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public static KeycloakDeploymentInfo getKeycloakProviderDeploymentInfo(DeploymentUnit du) {
    KeycloakDeploymentInfo info = KeycloakDeploymentInfo.create();
    info.name(du.getName());

    final ResourceRoot resourceRoot = du.getAttachment(Attachments.DEPLOYMENT_ROOT);
    if (resourceRoot != null) {
        final VirtualFile deploymentRoot = resourceRoot.getRoot();
        if (deploymentRoot != null && deploymentRoot.exists()) {
            if (deploymentRoot.getChild("META-INF/keycloak-themes.json").exists() && deploymentRoot.getChild("theme").exists()) {
                info.themes();
            }

            if (deploymentRoot.getChild("theme-resources").exists()) {
                info.themeResources();
            }

            VirtualFile services = deploymentRoot.getChild("META-INF/services");
            if(services.exists()) {
                try {
                    List<VirtualFile> archives = services.getChildren(new AbstractVirtualFileFilterWithAttributes() {
                        @Override
                        public boolean accepts(VirtualFile file) {
                            return file.getName().startsWith("org.keycloak");
                        }
                    });
                    if (!archives.isEmpty()) {
                        info.services();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    return info;
}
 
Example 7
Source File: ScriptProviderDeploymentProcessor.java    From keycloak with Apache License 2.0 4 votes vote down vote up
static void deploy(DeploymentUnit deploymentUnit, KeycloakDeploymentInfo info) {
    ResourceRoot resourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);

    if (resourceRoot == null) {
        return;
    }

    VirtualFile jarFile = resourceRoot.getRoot();

    if (jarFile == null || !jarFile.exists() || !jarFile.getName().endsWith(".jar")) {
        return;
    }

    ScriptProviderDescriptor descriptor = readScriptProviderDescriptor(jarFile);

    if (descriptor == null) {
        return;
    }

    for (Map.Entry<String, List<ScriptProviderMetadata>> entry : descriptor.getProviders().entrySet()) {
        for (ScriptProviderMetadata metadata : entry.getValue()) {
            String fileName = metadata.getFileName();

            if (fileName == null) {
                throw new RuntimeException("You must provide the script file name");
            }

            try (InputStream in = jarFile.getChild(fileName).openStream()) {
                metadata.setCode(StreamUtil.readString(in, StandardCharsets.UTF_8));
            } catch (IOException cause) {
                throw new RuntimeException("Failed to read script file [" + fileName + "]", cause);
            }

            metadata.setId(new StringBuilder("script").append("-").append(fileName).toString());

            String name = metadata.getName();

            if (name == null) {
                name = fileName;
            }

            metadata.setName(name);

            PROVIDERS.get(entry.getKey()).accept(info, metadata);
        }
    }
}