Search in sources :

Example 11 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class PreviewServer method getModuleRootURL.

/**
 * Return the root URL of this module.
 *
 * @param module a module
 * @return java.net.URL
 */
public URL getModuleRootURL(IModule module) {
    try {
        String base = "http://localhost";
        int port = getPort();
        URL url = null;
        if (port == 80)
            url = new URL(base + "/");
        else
            url = new URL(base + ":" + port + "/");
        String type = module.getModuleType().getId();
        if ("wst.web".equals(type)) {
            IStaticWeb staticWeb = (IStaticWeb) module.loadAdapter(IStaticWeb.class, null);
            return new URL(url, staticWeb.getContextRoot());
        } else if ("jst.web".equals(type)) {
            IWebModule webModule = (IWebModule) module.loadAdapter(IWebModule.class, null);
            return new URL(url, webModule.getContextRoot());
        }
        return url;
    } catch (Exception e) {
        Trace.trace(Trace.SEVERE, "Could not get root URL", e);
        return null;
    }
}
Also used : IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) IWebModule(org.eclipse.jst.server.core.IWebModule) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException)

Example 12 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class WarModuleAssembler method assemble.

public IPath assemble(IProgressMonitor monitor) throws CoreException {
    IPath parent = copyModule(fModule, monitor);
    IWebModule webModule = (IWebModule) fModule.loadAdapter(IWebModule.class, monitor);
    IModule[] childModules = webModule.getModules();
    for (int i = 0; i < childModules.length; i++) {
        IModule module = childModules[i];
        String uri = webModule.getURI(module);
        if (uri == null) {
            // The bad memories of WTP 1.0
            // $NON-NLS-1$
            IStatus status = new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, "unable to assemble module null uri", null);
            throw new CoreException(status);
        }
        IJ2EEModule jeeModule = (IJ2EEModule) module.loadAdapter(IJ2EEModule.class, monitor);
        if (jeeModule != null && jeeModule.isBinary()) {
            // Binary module
            ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
            IModuleResource[] resources = pm.members();
            publishHelper.publishToPath(resources, parent.append(uri), monitor);
        } else {
            // Project module
            packModule(module, uri, parent);
        }
    }
    return parent;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) IPath(org.eclipse.core.runtime.IPath) IWebModule(org.eclipse.jst.server.core.IWebModule) ProjectModule(org.eclipse.wst.server.core.util.ProjectModule) CoreException(org.eclipse.core.runtime.CoreException)

Example 13 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class J2EEUtil method fillCache.

private static void fillCache(IProgressMonitor monitor) {
    earCache = new HashMap<IModule, List<IModule>>();
    earCache2 = new HashMap<IJ2EEModule, List<IModule>>();
    webCache = new HashMap<IModule, List<IModule>>();
    IModule[] modules = ServerUtil.getModules(EAR_MODULE);
    if (modules != null) {
        for (IModule module2 : modules) {
            IEnterpriseApplication ear = (IEnterpriseApplication) module2.loadAdapter(IEnterpriseApplication.class, monitor);
            if (ear != null) {
                IModule[] modules2 = ear.getModules();
                if (modules2 != null) {
                    for (IModule mm : modules2) {
                        List<IModule> m = earCache.get(mm);
                        if (m == null) {
                            m = new ArrayList<IModule>(2);
                            earCache.put(mm, m);
                        }
                        m.add(module2);
                        IJ2EEModule mod = (IJ2EEModule) mm.loadAdapter(IJ2EEModule.class, monitor);
                        if (mod != null) {
                            m = earCache2.get(mod);
                            if (m == null) {
                                m = new ArrayList<IModule>(2);
                                earCache2.put(mod, m);
                            }
                            m.add(module2);
                        }
                    }
                }
            }
        }
    }
    modules = ServerUtil.getModules(WEB_MODULE);
    if (modules != null) {
        for (IModule module2 : modules) {
            IWebModule web = (IWebModule) module2.loadAdapter(IWebModule.class, monitor);
            if (web != null) {
                IModule[] modules2 = web.getModules();
                if (modules2 != null) {
                    for (IModule mm : modules2) {
                        List<IModule> m = webCache.get(mm);
                        if (m == null) {
                            m = new ArrayList<IModule>(2);
                            webCache.put(mm, m);
                        }
                        m.add(module2);
                    }
                }
            }
        }
    }
}
Also used : IModule(org.eclipse.wst.server.core.IModule) IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) List(java.util.List) ArrayList(java.util.ArrayList) IWebModule(org.eclipse.jst.server.core.IWebModule) IEnterpriseApplication(org.eclipse.jst.server.core.IEnterpriseApplication)

Example 14 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class TomcatServer method modifyModules.

/**
 * @see ServerDelegate#modifyModules(IModule[], IModule[], IProgressMonitor)
 */
public void modifyModules(IModule[] add, IModule[] remove, IProgressMonitor monitor) throws CoreException {
    IStatus status = canModifyModules(add, remove);
    if (status == null || !status.isOK())
        throw new CoreException(status);
    TomcatConfiguration config = getTomcatConfiguration();
    if (add != null) {
        int size = add.length;
        for (int i = 0; i < size; i++) {
            IModule module3 = add[i];
            IWebModule module = (IWebModule) module3.loadAdapter(IWebModule.class, monitor);
            String contextRoot = module.getContextRoot();
            if (contextRoot != null && !contextRoot.startsWith("/") && contextRoot.length() > 0)
                contextRoot = "/" + contextRoot;
            String docBase = config.getDocBasePrefix() + module3.getName();
            WebModule module2 = new WebModule(contextRoot, docBase, module3.getId(), isModulesReloadableByDefault());
            config.addWebModule(-1, module2);
        }
    }
    if (remove != null) {
        int size2 = remove.length;
        for (int j = 0; j < size2; j++) {
            IModule module3 = remove[j];
            String memento = module3.getId();
            List modules = getTomcatConfiguration().getWebModules();
            int size = modules.size();
            for (int i = 0; i < size; i++) {
                WebModule module = (WebModule) modules.get(i);
                if (memento.equals(module.getMemento()))
                    config.removeWebModule(i);
            }
        }
    }
// config.save(config.getFolder(), monitor);
}
Also used : List(java.util.List) IWebModule(org.eclipse.jst.server.core.IWebModule) IWebModule(org.eclipse.jst.server.core.IWebModule)

Example 15 with IWebModule

use of org.eclipse.jst.server.core.IWebModule in project webtools.servertools by eclipse.

the class PublishOperation2 method execute.

/**
 * @see PublishOperation#execute(IProgressMonitor, IAdaptable)
 */
public void execute(IProgressMonitor monitor, IAdaptable info) throws CoreException {
    List<IStatus> status = new ArrayList<IStatus>();
    // If parent web module
    if (module.length == 1) {
        publishDir(module[0], status, monitor);
    } else // Else a child module
    {
        Properties p = server.loadModulePublishLocations();
        // Try to determine the URI for the child module
        IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, monitor);
        String childURI = null;
        if (webModule != null) {
            childURI = webModule.getURI(module[1]);
        }
        // Try to determine if child is binary
        IJ2EEModule childModule = (IJ2EEModule) module[1].loadAdapter(IJ2EEModule.class, monitor);
        boolean isBinary = false;
        if (childModule != null) {
            isBinary = childModule.isBinary();
        }
        if (isBinary) {
            publishArchiveModule(childURI, p, status, monitor);
        } else {
            publishJar(childURI, p, status, monitor);
        }
        server.saveModulePublishLocations(p);
    }
    throwException(status);
    server.setModulePublishState2(module, IServer.PUBLISH_STATE_NONE);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) ArrayList(java.util.ArrayList) IWebModule(org.eclipse.jst.server.core.IWebModule) Properties(java.util.Properties)

Aggregations

IWebModule (org.eclipse.jst.server.core.IWebModule)16 IJ2EEModule (org.eclipse.jst.server.core.IJ2EEModule)6 IModule (org.eclipse.wst.server.core.IModule)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 CoreException (org.eclipse.core.runtime.CoreException)4 Properties (java.util.Properties)3 IStatus (org.eclipse.core.runtime.IStatus)3 IOException (java.io.IOException)2 URL (java.net.URL)2 Status (org.eclipse.core.runtime.Status)2 WebModule (org.eclipse.jst.server.tomcat.core.internal.WebModule)2 IStaticWeb (org.eclipse.wst.server.core.util.IStaticWeb)2 File (java.io.File)1 IPath (org.eclipse.core.runtime.IPath)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 IEnterpriseApplication (org.eclipse.jst.server.core.IEnterpriseApplication)1 IMemento (org.eclipse.jst.server.preview.adapter.internal.IMemento)1 XMLMemento (org.eclipse.jst.server.preview.adapter.internal.XMLMemento)1