Java Code Examples for org.jboss.modules.ResourceLoaders#createJarResourceLoader()

The following examples show how to use org.jboss.modules.ResourceLoaders#createJarResourceLoader() . 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: WildFlySwarmApplicationConf.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
void apply(ModuleSpec.Builder builder) throws IOException {

    int slashLoc = this.path.lastIndexOf('/');
    String name = this.path;

    if (slashLoc > 0) {
        name = this.path.substring(slashLoc + 1);
    }

    String ext = ".jar";
    int dotLoc = name.lastIndexOf('.');
    if (dotLoc > 0) {
        ext = name.substring(dotLoc);
        name = name.substring(0, dotLoc);
    }

    File tmp = TempFileManager.INSTANCE.newTempFile(name, ext);

    try (InputStream artifactIn = getClass().getClassLoader().getResourceAsStream(this.path)) {
        Files.copy(artifactIn, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }
    final String jarName = tmp.getName().toString();
    final JarFile jarFile = new JarFile(tmp);
    final ResourceLoader jarLoader = ResourceLoaders.createJarResourceLoader(jarName,
            jarFile);
    builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(jarLoader));

    if (".war".equals(ext)) {
        final ResourceLoader warLoader = ResourceLoaders.createJarResourceLoader(jarName,
                jarFile,
                "WEB-INF/classes");
        builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(warLoader));
    }
}
 
Example 2
Source File: Seam2Processor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (deploymentUnit.getParent() != null) {
        return;
    }

    final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
    deploymentUnits.add(deploymentUnit);
    deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));

    for (DeploymentUnit unit : deploymentUnits) {

        final ResourceRoot mainRoot = unit.getAttachment(Attachments.DEPLOYMENT_ROOT);
        if (mainRoot == null)
            continue;

        VirtualFile root = mainRoot.getRoot();
        for (String path : SEAM_FILES) {
            if (root.getChild(path).exists()) {
                final ModuleSpecification moduleSpecification = deploymentUnit
                        .getAttachment(Attachments.MODULE_SPECIFICATION);
                final ModuleLoader moduleLoader = Module.getBootModuleLoader();
                moduleSpecification.addSystemDependency(new ModuleDependency(moduleLoader, VFS_MODULE, false, false, false,
                        false)); // for VFS scanner

                try {
                    ResourceLoader resourceLoader = ResourceLoaders.createJarResourceLoader(SEAM_INT_JAR, new JarFile(
                            getSeamIntResourceRoot().getRoot().getPathName()));
                    moduleSpecification.addResourceLoader(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader));
                } catch (Exception e) {
                    throw new DeploymentUnitProcessingException(e);
                }

                unit.addToAttachmentList(Attachments.RESOURCE_ROOTS, getSeamIntResourceRoot());
                return;
            }
        }
    }
}
 
Example 3
Source File: JBossModuleUtils.java    From Nicobar with Apache License 2.0 5 votes vote down vote up
/**
 * Populates a {@link ModuleSpec} with runtime resources, dependencies and properties from the
 * {@link ScriptCompilerPluginSpec}
 * Helpful when creating a {@link ModuleSpec} from a ScriptLibPluginSpec
 *
 * @param moduleSpecBuilder builder to populate
 * @param pluginSpec {@link ScriptCompilerPluginSpec} to copy from
 * @param latestRevisionIds used to lookup the latest dependencies. see {@link JBossModuleLoader#getLatestRevisionIds()}
 */
public static void populateCompilerModuleSpec(ModuleSpec.Builder moduleSpecBuilder, ScriptCompilerPluginSpec pluginSpec, Map<ModuleId, ModuleIdentifier> latestRevisionIds) throws ModuleLoadException {
    Objects.requireNonNull(moduleSpecBuilder, "moduleSpecBuilder");
    Objects.requireNonNull(pluginSpec, "pluginSpec");
    Objects.requireNonNull(latestRevisionIds, "latestRevisionIds");
    Set<Path> pluginRuntime = pluginSpec.getRuntimeResources();
    for (Path resourcePath : pluginRuntime) {
        File file = resourcePath.toFile();
        String pathString = resourcePath.toString();
        ResourceLoader rootResourceLoader = null;
        if (file.isDirectory()) {
            rootResourceLoader = ResourceLoaders.createFileResourceLoader(pathString, file);
        } else if (pathString.endsWith(".jar")) {
            try {
                rootResourceLoader = ResourceLoaders.createJarResourceLoader(pathString, new JarFile(file));
            } catch (IOException e) {
                throw new ModuleLoadException(e);
            }
        }
        if (rootResourceLoader != null) {
            moduleSpecBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(rootResourceLoader));
        }
    }
    moduleSpecBuilder.addDependency(JRE_DEPENDENCY_SPEC);
    moduleSpecBuilder.addDependency(NICOBAR_CORE_DEPENDENCY_SPEC);
    moduleSpecBuilder.addDependency(DependencySpec.createLocalDependencySpec());
    // add dependencies to the module spec
    Set<ModuleId> dependencies = pluginSpec.getModuleDependencies();
    for (ModuleId scriptModuleId : dependencies) {
        ModuleIdentifier latestIdentifier = latestRevisionIds.get(scriptModuleId);
        if (latestIdentifier == null) {
            throw new ModuleLoadException("Cannot find dependent module: " + scriptModuleId);
        }

        moduleSpecBuilder.addDependency(DependencySpec.createModuleDependencySpec(latestIdentifier, true, false));
    }

    Map<String, String> pluginMetadata = pluginSpec.getPluginMetadata();
    addPropertiesToSpec(moduleSpecBuilder, pluginMetadata);
}
 
Example 4
Source File: MavenArtifactUtil.java    From thorntail with Apache License 2.0 3 votes vote down vote up
/**
 * A utility method to create a Maven artifact resource loader for the given artifact coordinates.
 *
 * @param rootName the resource root name to use (must not be {@code null})
 * @param coordinates the artifact coordinates to use (must not be {@code null})
 * @param mavenResolver the Maven resolver to use (must not be {@code null})
 * @return the resource loader
 * @throws IOException if the artifact could not be resolved
 */
public static ResourceLoader createMavenArtifactLoader(final MavenResolver mavenResolver, final ArtifactCoordinates coordinates, final String rootName) throws IOException {
    File fp = mavenResolver.resolveJarArtifact(coordinates);
    if (fp == null) return null;
    JarFile jarFile = JDKSpecific.getJarFile(fp, true);
    return ResourceLoaders.createJarResourceLoader(rootName, jarFile);
}