Package org.jboss.shrinkwrap.api

Examples of org.jboss.shrinkwrap.api.Node


    protected static List<ModuleMetaData> extractModules(String host, int port, Archive<?> archive) {
        final List<ModuleMetaData> list = new ArrayList<ModuleMetaData>();
        if (archive instanceof EnterpriseArchive) {
            final EnterpriseArchive ear = (EnterpriseArchive) archive;
            final Node appXml = archive.get(ParseUtils.APPLICATION_XML);
            if (appXml != null) {
                InputStream stream = appXml.getAsset().openStream();
                try {
                    ApplicationDescriptor ad = Descriptors.importAs(ApplicationDescriptor.class).fromStream(stream);
                    List<ModuleType<ApplicationDescriptor>> allModules = ad.getAllModule();
                    for (ModuleType<ApplicationDescriptor> mt : allModules) {
                        String uri = mt.getOrCreateWeb().getWebUri();
View Full Code Here


        final String module = parseModuleRaw(war);
        return (module != null) ? module : DEFAULT;
    }

    protected static String parseModuleRaw(WebArchive war) throws Exception {
        final Node awXml = war.get(ParseUtils.APPENGINE_WEB_XML);
        if (awXml == null) {
            throw new IllegalStateException("Missing appengine-web.xml: " + war.toString(true));
        }
        final Map<String, String> results = ParseUtils.parseTokens(awXml, ParseUtils.MODULE);
        return results.get(ParseUtils.MODULE);
View Full Code Here

            throw new DeploymentException("Cannot deploy to local GAE.", e);
        }
    }

    private String readAppId(Archive<?> archive) throws IOException {
        Node webXml = archive.get("WEB-INF/appengine-web.xml");
        InputStream is = webXml.getAsset().openStream();
        try {
            StringBuilder builder = new StringBuilder();
            int x;
            boolean isAppId = false;
            StringBuilder appId = new StringBuilder();
View Full Code Here

        // Merge the auxilliary archives and collect the loadable extensions
        final Set<String> loadableExtensions = new HashSet<String>();
        final String loadableExtentionsPath = "META-INF/services/" + RemoteLoadableExtension.class.getName();
        for (Archive<?> aux : auxArchives) {
            Node node = aux.get(loadableExtentionsPath);
            if (node != null) {
                BufferedReader br = new BufferedReader(new InputStreamReader(node.getAsset().openStream()));
                try {
                    String line = br.readLine();
                    while (line != null) {
                        loadableExtensions.add(line);
                        line = br.readLine();
View Full Code Here

                        LOGGER.log(Level.SEVERE, "can't add a library to the deployment", e);
                    }
                } else if (ArchiveAsset.class.isInstance(asset)) {
                    final Archive<?> nestedArchive = ArchiveAsset.class.cast(asset).getArchive();
                    if (!isExcluded(nestedArchive.getName())) {
                        final Node bXmlNode = nestedArchive.get(META_INF + BEANS_XML);
                        if (bXmlNode != null) {
                            try {
                                beansXmlMerged.add(new AssetSource(bXmlNode.getAsset(), new URL("jar:file://!/WEB-INF/lib/" + nestedArchive.getName() + "!/META-INF/beans.xml")));
                            } catch (final MalformedURLException e) {
                                // shouldn't occur
                            }
                        }
                        archive.merge(nestedArchive);
                    }
                }
            }
        } else {
            if (isEar) { // mainly for CDi TCKs
                earMap = new HashMap<>();
                final Map<ArchivePath, Node> jars = archive.getContent(new IncludeRegExpPaths("/.*\\.jar"));
                final List<org.apache.xbean.finder.archive.Archive> archives = new ArrayList<>(jars.size());
                for (final Map.Entry<ArchivePath, Node> node : jars.entrySet()) {
                    final Asset asset = node.getValue().getAsset();
                    if (ArchiveAsset.class.isInstance(asset)) {
                        final Archive<?> libArchive = ArchiveAsset.class.cast(asset).getArchive();
                        if (!isExcluded(libArchive.getName())) {
                            final List<Class<?>> earClasses = new ArrayList<>();
                            final List<String> earClassNames = new ArrayList<>();
                            final Map<ArchivePath, Node> content = libArchive.getContent(new IncludeRegExpPaths(".*.class"));
                            for (final Map.Entry<ArchivePath, Node> classNode : content.entrySet()) {
                                final String classname = name(classNode.getKey().get());
                                try {
                                    earClasses.add(parent.loadClass(classname));
                                    earClassNames.add(classname);
                                } catch (final ClassNotFoundException e) {
                                    LOGGER.fine("Can't load class " + classname);
                                } catch (final NoClassDefFoundError ncdfe) {
                                    // no-op
                                }
                            }
                            try { // ends with !/META-INF/beans.xml to force it to be used as a cdi module
                                earMap.put(new URL("jar:file://!/lib/" + archive.getName() + (libArchive.get(META_INF + BEANS_XML) != null ? "!/META-INF/beans.xml" : "")), earClassNames);
                            } catch (final MalformedURLException e) {
                                // no-op
                            }
                            archives.add(new ClassesArchive(earClasses));
                        }
                    } // else TODO
                }
                earArchive = new CompositeArchive(archives);
            }

            prefix = META_INF;
        }

        final URL[] urls = additionalPaths.toArray(new URL[additionalPaths.size()]);

        final ClassLoader loader;
        if (!WEB_INF.equals(prefix)) {
            loader = new SWClassLoader("", new URLClassLoader(urls, parent), archive);
        } else {
            loader = new SWClassLoader(WEB_INF_CLASSES, new URLClassLoaderFirst(urls, parent), archive);
        }
        final URLClassLoader tempClassLoader = ClassLoaderUtil.createTempClassLoader(loader);

        final AppModule appModule = new AppModule(loader, archive.getName());
        if (WEB_INF.equals(prefix)) {
            appModule.setDelegateFirst(false);
            appModule.setStandloneWebModule();

            final WebModule webModule = new WebModule(new WebApp(), contextRoot(archive.getName()), loader, "", appModule.getModuleId());
            webModule.setUrls(additionalPaths);
            appModule.getWebModules().add(webModule);
        } else if (isEar) { // mainly for CDi TCKs
            final FinderFactory.OpenEJBAnnotationFinder earLibFinder = new FinderFactory.OpenEJBAnnotationFinder(new SimpleWebappAggregatedArchive(earArchive, earMap));
            appModule.setEarLibFinder(earLibFinder);

            final EjbModule earCdiModule = new EjbModule(appModule.getClassLoader(), DeploymentLoader.EAR_SCOPED_CDI_BEANS + appModule.getModuleId(), new EjbJar(), new OpenejbJar());
            earCdiModule.setBeans(new Beans());
            earCdiModule.setFinder(earLibFinder);
            earCdiModule.setEjbJar(new EmptyEjbJar());
            appModule.getEjbModules().add(earCdiModule);

            for (final Map.Entry<ArchivePath, Node> node : archive.getContent(new IncludeRegExpPaths("/.*\\.war")).entrySet()) {
                final Asset asset = node.getValue().getAsset();
                if (ArchiveAsset.class.isInstance(asset)) {
                    final Archive<?> webArchive = ArchiveAsset.class.cast(asset).getArchive();
                    if (WebArchive.class.isInstance(webArchive)) {
                        /* TODO: libs
                        final Map<ArchivePath, Node> libs = archive.getContent(new IncludeRegExpPaths("/WEB-INF/lib/.*\\.jar"));
                        */

                        final Map<String, Object> altDD = new HashMap<String, Object>();
                        final Node beansXml = findBeansXml(webArchive, new ArrayList<AssetSource>(), WEB_INF, altDD);
                        final SWClassLoader webLoader = new SWClassLoader(WEB_INF_CLASSES, parent, webArchive);
                        final FinderFactory.OpenEJBAnnotationFinder finder = new FinderFactory.OpenEJBAnnotationFinder(
                                finderArchive(beansXml, webArchive, webLoader, Collections.<URL>emptyList()));

                        final WebModule webModule = new WebModule(new WebApp(), contextRoot(webArchive.getName()), loader, "", appModule.getModuleId());
                        webModule.setUrls(Collections.<URL>emptyList());
                        webModule.setScannableUrls(Collections.<URL>emptyList());
                        webModule.setFinder(finder);

                        final EjbModule ejbModule = new EjbModule(webLoader, webModule.getModuleId(), null, new EjbJar(), new OpenejbJar());
                        ejbModule.getAltDDs().putAll(altDD);
                        ejbModule.setFinder(finder);
                        ejbModule.setClassLoader(webLoader);
                        ejbModule.setWebapp(true);

                        appModule.getEjbModules().add(ejbModule);
                        appModule.getWebModules().add(webModule);

                        addPersistenceXml(archive, WEB_INF, appModule);
                        addOpenEJbJarXml(archive, WEB_INF, ejbModule);
                        addValidationXml(archive, WEB_INF, new HashMap<String, Object>(), ejbModule);
                        addResourcesXml(archive, WEB_INF, ejbModule);
                        addEnvEntries(archive, WEB_INF, appModule, ejbModule);
                    }
                }
            }
        }

        if (isEar) { // adding the test class as lib class can break test if tested against the web part of the ear
            return appModule;
        }

        // add the test as a managed bean to be able to inject into it easily
        final Map<String, Object> testDD;
        if (javaClass != null) {
            final EjbJar ejbJar = new EjbJar();
            final OpenejbJar openejbJar = new OpenejbJar();
            final String ejbName = appModule.getModuleId() + "_" + javaClass.getName();
            final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(ejbName, javaClass.getName(), true));
            bean.localBean();
            bean.setTransactionType(TransactionType.BEAN);
            final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
            ejbDeployment.setDeploymentId(ejbName);
            final EjbModule e = new EjbModule(ejbJar, openejbJar);
            e.getProperties().setProperty("openejb.cdi.activated", "false");
            e.setBeans(new Beans());
            e.setClassLoader(tempClassLoader);
            appModule.getEjbModules().add(e);
            testDD = e.getAltDDs();
        } else {
            testDD = new HashMap<>(); // ignore
        }

        final EjbJar ejbJar;
        final Node ejbJarXml = archive.get(prefix.concat(EJB_JAR_XML));
        if (ejbJarXml != null) {
            try {
                ejbJar = ReadDescriptors.readEjbJar(ejbJarXml.getAsset().openStream());
            } catch (final OpenEJBException e) {
                throw new OpenEJBRuntimeException(e);
            }
        } else {
            ejbJar = new EjbJar();
        }

        if (ejbJar.getModuleName() == null) {
            final String name = archive.getName();
            if (name.endsWith("ar") && name.length() > 4) {
                ejbJar.setModuleName(name.substring(0, name.length() - ".jar".length()));
            } else {
                ejbJar.setModuleName(name);
            }
        }

        final EjbModule ejbModule = new EjbModule(ejbJar);
        ejbModule.setClassLoader(tempClassLoader);

        final Node beansXml = findBeansXml(archive, beansXmlMerged, prefix, ejbModule.getAltDDs());
        final org.apache.xbean.finder.archive.Archive finderArchive = finderArchive(beansXml, archive, tempClassLoader, additionalPaths);
        ejbModule.setFinder(new FinderFactory.ModuleLimitedFinder(new FinderFactory.OpenEJBAnnotationFinder(finderArchive)));
        if (appModule.isWebapp()) { // war
            appModule.getWebModules().iterator().next().setFinder(ejbModule.getFinder());
        }
View Full Code Here

        return appModule;
    }

    private static Node findBeansXml(final Archive<?> archive, final List<AssetSource> beansXmlMerged, final String prefix, final Map<String, Object> altDD) {
        Node beansXml = archive.get(prefix.concat(BEANS_XML));
        if (beansXml == null && WEB_INF.equals(prefix)) {
            beansXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(BEANS_XML));
        }
        if (beansXml != null) {
            try {
                beansXmlMerged.add(new AssetSource(beansXml.getAsset(), new URL("jar:file://!/WEB-INF/classes/beans.xml")));
            } catch (final MalformedURLException e) {
                // shouldn't occur
            }
            altDD.put(BEANS_XML, beansXmlMerged);
        }
View Full Code Here

        }
        return beansXml;
    }

    private static void addPersistenceXml(final Archive<?> archive, final String prefix, final AppModule appModule) {
        Node persistenceXml = archive.get(prefix.concat(PERSISTENCE_XML));
        if (persistenceXml == null && WEB_INF.equals(prefix)) {
            persistenceXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(PERSISTENCE_XML));
        }
        if (persistenceXml != null) {
            final Asset asset = persistenceXml.getAsset();
            if (UrlAsset.class.isInstance(asset)) {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(URL.class, "url", asset)));
            } else if (FileAsset.class.isInstance(asset)) {
                try {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(get(File.class, "file", asset).toURI().toURL()));
                } catch (final MalformedURLException e) {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
                }
            } else if (ClassLoaderAsset.class.isInstance(asset)) {
                final URL url = get(ClassLoader.class, "classLoader", asset).getResource(get(String.class, "resourceName", asset));
                if (url != null) {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(url));
                } else {
                    appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
                }
            } else {
                appModule.getAltDDs().put(PERSISTENCE_XML, Arrays.asList(new AssetSource(persistenceXml.getAsset(), null)));
            }
        }
    }
View Full Code Here

            }
        }
    }

    private static void addOpenEJbJarXml(final Archive<?> archive, final String prefix, final EjbModule ejbModule) {
        final Node openejbJarXml = archive.get(prefix.concat(OPENEJB_JAR_XML));
        if (openejbJarXml != null) {
            ejbModule.getAltDDs().put(OPENEJB_JAR_XML, new AssetSource(openejbJarXml.getAsset(), null));
        }
    }
View Full Code Here

            ejbModule.getAltDDs().put(OPENEJB_JAR_XML, new AssetSource(openejbJarXml.getAsset(), null));
        }
    }

    private static void addValidationXml(final Archive<?> archive, final String prefix, final Map<String, Object> testDD, final EjbModule ejbModule) {
        Node validationXml = archive.get(prefix.concat(VALIDATION_XML));
        // bval tcks
        if (validationXml == null && WEB_INF == prefix) { // we can use == here
            validationXml = archive.get(WEB_INF_CLASSES.concat(META_INF).concat(VALIDATION_XML));
        }
        if (validationXml != null) {
            testDD.put(VALIDATION_XML, new AssetSource(validationXml.getAsset(), null)); // use same config otherwise behavior is weird
            ejbModule.getAltDDs().put(VALIDATION_XML, new AssetSource(validationXml.getAsset(), null));
        }
    }
View Full Code Here

            ejbModule.getAltDDs().put(VALIDATION_XML, new AssetSource(validationXml.getAsset(), null));
        }
    }

    private static void addResourcesXml(final Archive<?> archive, final String prefix, final EjbModule ejbModule) {
        final Node resourcesXml = archive.get(prefix.concat(RESOURCES_XML));
        if (resourcesXml != null) {
            ejbModule.getAltDDs().put(RESOURCES_XML, new AssetSource(resourcesXml.getAsset(), null));
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.shrinkwrap.api.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.