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;
}
}
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;
}
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);
}
}
}
}
}
}
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);
}
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);
}
Aggregations