Search in sources :

Example 11 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class AbstractModulesRegistryImpl method getModules.

/**
 * Returns the list of shared Modules registered in this instance.
 *
 * <p>
 * The returned list will not include the modules defined in the ancestor
 * {@link AbstractModulesRegistryImpl}s.
 *
 * @return an umodifiable list of loaded modules
 */
public Collection<HK2Module> getModules() {
    // make a copy to avoid synchronizing since this API can be called while
    // modules are added or removed by other threads.
    Map<Integer, Repository> repos = new TreeMap<Integer, Repository>();
    repos.putAll(repositories);
    // force repository extraction
    Set<Integer> keys = repos.keySet();
    TreeSet<Integer> sortedKeys = new TreeSet<Integer>();
    sortedKeys.addAll(keys);
    for (Integer key : sortedKeys) {
        Repository repo = repos.get(key);
        for (ModuleDefinition moduleDef : repo.findAll()) {
            if (modules.get(AbstractFactory.getInstance().createModuleId(moduleDef)) == null) {
                HK2Module newModule = newModule(moduleDef);
                if (newModule != null) {
                    // When some module can't get installed,
                    // don't halt proceeding, instead continue
                    add(newModule);
                // don't resolve such modules, we just want to know about them
                }
            }
        }
    }
    return modules.values();
}
Also used : ModuleDefinition(com.sun.enterprise.module.ModuleDefinition) Repository(com.sun.enterprise.module.Repository) HK2Module(com.sun.enterprise.module.HK2Module) TreeSet(java.util.TreeSet) TreeMap(java.util.TreeMap)

Example 12 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class AbstractModulesRegistryImpl method dumpState.

public void dumpState(PrintStream writer) {
    StringBuilder sb = new StringBuilder("Registry Info:: Total repositories: " + repositories.size() + ", Total modules = " + modules.size() + "\n");
    for (Repository repo : repositories.values()) {
        sb.append("Attached repository: [" + repo + "]\n");
    }
    for (HK2Module module : getModules()) {
        sb.append("Registered Module: [" + module + "]\n");
    }
    writer.println(sb);
}
Also used : Repository(com.sun.enterprise.module.Repository) HK2Module(com.sun.enterprise.module.HK2Module)

Example 13 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class Utils method identifyCyclicDependency.

public static void identifyCyclicDependency(ModuleImpl m, Logger logger) {
    StringBuffer tree = new StringBuffer();
    tree.append(m.getName());
    Vector<HK2Module> traversed = new Vector<HK2Module>();
    boolean success = traverseAndFind(m, m, traversed);
    if (success) {
        traversed.remove(0);
        for (HK2Module mod : traversed) {
            tree.append("-->" + mod.getName());
        }
        tree.append("-->" + m.getName());
        logger.log(Level.SEVERE, "Cyclic dependency : " + tree.toString());
    }
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) Vector(java.util.Vector)

Example 14 with HK2Module

use of com.sun.enterprise.module.HK2Module in project glassfish-hk2 by eclipse-ee4j.

the class Utils method traverseAndFind.

private static boolean traverseAndFind(HK2Module toTraverse, ModuleImpl toFind, Vector<HK2Module> traversed) {
    traversed.add(toTraverse);
    for (ModuleDependency md : toTraverse.getModuleDefinition().getDependencies()) {
        ModulesRegistry registry = toTraverse.getRegistry();
        for (HK2Module mod : registry.getModules()) {
            if (mod.getName().equals(md.getName())) {
                if (mod != null) {
                    if (mod.getName().equals(toFind.getName())) {
                        return true;
                    }
                    if (traverseAndFind(mod, toFind, traversed)) {
                        return true;
                    }
                }
            }
        }
    }
    traversed.remove(toTraverse);
    return false;
}
Also used : ModuleDependency(com.sun.enterprise.module.ModuleDependency) HK2Module(com.sun.enterprise.module.HK2Module) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry)

Example 15 with HK2Module

use of com.sun.enterprise.module.HK2Module in project Payara by payara.

the class ASClassLoaderUtil method getModulesClasspath.

private static synchronized String getModulesClasspath(ServiceLocator habitat) {
    synchronized (ASClassLoaderUtil.class) {
        if (modulesClassPath == null) {
            final StringBuilder tmpString = new StringBuilder();
            ModulesRegistry mr = habitat.getService(ModulesRegistry.class);
            if (mr != null) {
                for (HK2Module module : mr.getModules()) {
                    for (URI uri : module.getModuleDefinition().getLocations()) {
                        if (uri.toString().startsWith("reference:")) {
                            try {
                                // OSGi modules can have "reference:" prepended to them if they're exploded, except
                                // there doesn't appear to be an actual FileSystemProvider for this type
                                tmpString.append(new URI(uri.toString().substring("reference:".length())));
                                tmpString.append(File.pathSeparator);
                            } catch (URISyntaxException use) {
                                deplLogger.log(Level.WARNING, "Error truncating URI with prefix of \"reference:\"", use);
                            }
                        } else if (uri.toString().startsWith("jardir:")) {
                            // OSGi fileinstall created modules can have a "jardir:" schema for directory
                            // structures, but there is no FileSystemProvider for this type.
                            // Since the path is the file system path, just substitute the "file:" schema
                            tmpString.append("file:").append(uri.toString().substring("jardir:".length()));
                            tmpString.append(File.pathSeparator);
                        } else {
                            tmpString.append(Paths.get(uri).toString());
                            tmpString.append(File.pathSeparator);
                        }
                    }
                }
            }
            // set shared classpath for module so that it doesn't need to be
            // recomputed for every other invocation
            modulesClassPath = tmpString.toString();
        }
    }
    return modulesClassPath;
}
Also used : HK2Module(com.sun.enterprise.module.HK2Module) ModulesRegistry(com.sun.enterprise.module.ModulesRegistry) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

HK2Module (com.sun.enterprise.module.HK2Module)30 ModulesRegistry (com.sun.enterprise.module.ModulesRegistry)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 URL (java.net.URL)5 JarURIPattern (com.sun.enterprise.util.net.JarURIPattern)4 URI (java.net.URI)4 Pattern (java.util.regex.Pattern)4 URLClassLoader (java.net.URLClassLoader)3 ArrayList (java.util.ArrayList)3 ModuleDefinition (com.sun.enterprise.module.ModuleDefinition)2 Repository (com.sun.enterprise.module.Repository)2 ResolveError (com.sun.enterprise.module.ResolveError)2 HashMap (java.util.HashMap)2 Vector (java.util.Vector)2 ActionReport (org.glassfish.api.ActionReport)2 EngineInfo (org.glassfish.internal.data.EngineInfo)2 CacheTag (com.sun.appserv.web.taglibs.cache.CacheTag)1 InitialGroupInfoService (com.sun.corba.ee.impl.folb.InitialGroupInfoService)1 Application (com.sun.enterprise.config.serverbeans.Application)1