Search in sources :

Example 1 with Fraction

use of org.wildfly.swarm.spi.api.Fraction in project wildfly-swarm by wildfly-swarm.

the class FractionProducingExtension method uninstalledFractionClasses.

@SuppressWarnings("unchecked")
private Set<Class<? extends Fraction>> uninstalledFractionClasses(Set<Type> installedClasses) throws ModuleLoadException, IOException, ClassNotFoundException {
    Set<String> installedClassNames = installedClasses.stream().map(Type::getTypeName).collect(Collectors.toSet());
    List<String> moduleNames = ApplicationEnvironment.get().bootstrapModules();
    ClassLoader cl = Module.getBootModuleLoader().loadModule("swarm.container").getClassLoader();
    Set<Class<? extends Fraction>> fractionClasses = new HashSet<>();
    for (String moduleName : moduleNames) {
        Module module = Module.getBootModuleLoader().loadModule(moduleName);
        InputStream indexStream = module.getClassLoader().getResourceAsStream("META-INF/jandex.idx");
        if (indexStream != null) {
            IndexReader reader = new IndexReader(indexStream);
            Index index = reader.read();
            Set<ClassInfo> impls = index.getAllKnownImplementors(DotName.createSimple(Fraction.class.getName()));
            for (ClassInfo impl : impls) {
                if (!installedClassNames.contains(impl.name().toString())) {
                    Class<? extends Fraction> fractionClass = (Class<? extends Fraction>) cl.loadClass(impl.name().toString());
                    fractionClasses.add(fractionClass);
                }
            }
        }
    }
    return fractionClasses;
}
Also used : InputStream(java.io.InputStream) Fraction(org.wildfly.swarm.spi.api.Fraction) Index(org.jboss.jandex.Index) IndexReader(org.jboss.jandex.IndexReader) Module(org.jboss.modules.Module) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 2 with Fraction

use of org.wildfly.swarm.spi.api.Fraction in project wildfly-swarm by wildfly-swarm.

the class ExtensionMarshaller method marshal.

public void marshal(List<ModelNode> list) {
    List<ModelNode> extensions = new ArrayList<>();
    Set<String> seen = new HashSet<>();
    for (Fraction each : this.fractions) {
        WildFlyExtension anno = each.getClass().getAnnotation(WildFlyExtension.class);
        if (anno != null) {
            if (anno.module() != null && !anno.module().equals("")) {
                String module = anno.module();
                if (!seen.contains(module)) {
                    ModelNode node = new ModelNode();
                    node.get(OP_ADDR).set(EXTENSION, anno.module());
                    node.get(OP).set(ADD);
                    extensions.add(node);
                    seen.add(module);
                }
            }
        }
    }
    list.addAll(0, extensions);
}
Also used : WildFlyExtension(org.wildfly.swarm.spi.api.annotations.WildFlyExtension) ArrayList(java.util.ArrayList) Fraction(org.wildfly.swarm.spi.api.Fraction) ModelNode(org.jboss.dmr.ModelNode) HashSet(java.util.HashSet)

Example 3 with Fraction

use of org.wildfly.swarm.spi.api.Fraction in project wildfly-swarm by wildfly-swarm.

the class SubsystemMarshaller method marshal.

public void marshal(List<ModelNode> list) {
    for (Fraction each : this.fractions) {
        MarshalDMR anno = each.getClass().getAnnotation(MarshalDMR.class);
        if (anno != null) {
            try {
                try (AutoCloseable handle = Performance.time("marshall " + each.getClass().getSimpleName())) {
                    LinkedList<ModelNode> subList = Marshaller.marshal(each);
                    if (!isAlreadyConfigured(subList, list)) {
                        list.addAll(subList);
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        } else {
            WildFlySubsystem subsysAnno = each.getClass().getAnnotation(WildFlySubsystem.class);
            if (subsysAnno != null) {
                PathAddress address = PathAddress.pathAddress(PathElement.pathElement(SUBSYSTEM, subsysAnno.value()));
                if (!isAlreadyConfigured(address.toModelNode(), list)) {
                    ModelNode node = new ModelNode();
                    node.get(OP_ADDR).set(address.toModelNode());
                    node.get(OP).set(ADD);
                    list.add(node);
                }
            }
        }
    }
}
Also used : MarshalDMR(org.wildfly.swarm.spi.api.annotations.MarshalDMR) PathAddress(org.jboss.as.controller.PathAddress) WildFlySubsystem(org.wildfly.swarm.spi.api.annotations.WildFlySubsystem) Fraction(org.wildfly.swarm.spi.api.Fraction) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

Fraction (org.wildfly.swarm.spi.api.Fraction)3 HashSet (java.util.HashSet)2 ModelNode (org.jboss.dmr.ModelNode)2 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 PathAddress (org.jboss.as.controller.PathAddress)1 ClassInfo (org.jboss.jandex.ClassInfo)1 Index (org.jboss.jandex.Index)1 IndexReader (org.jboss.jandex.IndexReader)1 Module (org.jboss.modules.Module)1 MarshalDMR (org.wildfly.swarm.spi.api.annotations.MarshalDMR)1 WildFlyExtension (org.wildfly.swarm.spi.api.annotations.WildFlyExtension)1 WildFlySubsystem (org.wildfly.swarm.spi.api.annotations.WildFlySubsystem)1