Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 4401 invoked from network); 14 Feb 2011 17:50:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2011 17:50:41 -0000 Received: (qmail 87230 invoked by uid 500); 14 Feb 2011 17:50:41 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 87100 invoked by uid 500); 14 Feb 2011 17:50:39 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 87093 invoked by uid 99); 14 Feb 2011 17:50:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 17:50:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 17:50:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4F7552388906; Mon, 14 Feb 2011 17:50:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1070594 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: GeronimoServer.java GeronimoServerDelegate.java GeronimoUtils.java Date: Mon, 14 Feb 2011 17:50:17 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110214175017.4F7552388906@eris.apache.org> Author: gawor Date: Mon Feb 14 17:50:16 2011 New Revision: 1070594 URL: http://svn.apache.org/viewvc?rev=1070594&view=rev Log: GERONIMODEVTOOLS-710: context root with regular and bundle web applications Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServer.java geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServer.java URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServer.java?rev=1070594&r1=1070593&r2=1070594&view=diff ============================================================================== --- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServer.java (original) +++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServer.java Mon Feb 14 17:50:16 2011 @@ -58,13 +58,6 @@ public class GeronimoServer extends Gero deploymentFactory = new DeploymentFactoryImpl(); } - /* (non-Javadoc) - * @see org.apache.geronimo.st.v30.core.GenericGeronimoServer#getContextRoot(org.eclipse.wst.server.core.IModule) - */ - public String getContextRoot(IModule module) throws Exception { - return GeronimoUtils.getContextRoot(module); - } - /* * (non-Javadoc) * Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java?rev=1070594&r1=1070593&r2=1070594&view=diff ============================================================================== --- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java (original) +++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerDelegate.java Mon Feb 14 17:50:16 2011 @@ -28,6 +28,7 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; +import org.apache.geronimo.st.v30.core.GeronimoUtils; import org.apache.geronimo.st.v30.core.internal.Trace; import org.apache.geronimo.st.v30.core.osgi.AriesHelper; import org.apache.geronimo.st.v30.core.osgi.OsgiConstants; @@ -100,9 +101,6 @@ abstract public class GeronimoServerDele public static final String CLEAN_OSGI_BUNDLE_CACHE = "--clean"; - public abstract String getContextRoot(IModule module) throws Exception ; - - /** * Determines whether the specified module modifications can be made to the server at this time * @@ -261,35 +259,59 @@ abstract public class GeronimoServerDele public URL getModuleRootURL(IModule module) { Trace.tracePoint("Entry", "GeronimoServerDelegate.getModuleRootURL", module); - try { - if (module == null - || module.loadAdapter(IWebModule.class, null) == null) - return null; - - String host = getServer().getHost(); - String url = "http://" + host; - int port = 0; - - port = Integer.parseInt(getHTTPPort()); - port = ServerMonitorManager.getInstance().getMonitoredPort(getServer(), port, "web"); - if (port != 80) - url += ":" + port; - - String moduleId = getContextRoot(module); - if (!moduleId.startsWith("/")) - url += "/"; - url += moduleId; - - if (!url.endsWith("/")) - url += "/"; - - Trace.tracePoint("Exit ", "GeronimoServerDelegate.getModuleRootURL", new URL(url)); - return new URL(url); - } catch (Exception e) { - Trace.trace(Trace.SEVERE, "Could not get root URL", e); - return null; + if (module == null) { + return null; + } + + String contextRoot = null; + + if (GeronimoUtils.isBundleModule(module)) { + // bundle - might be WAB + Manifest manifest = GeronimoUtils.getBundleManifest(module); + if (manifest != null) { + contextRoot = manifest.getMainAttributes().getValue("Web-ContextPath"); + } + } else if (module.loadAdapter(IWebModule.class, null) != null) { + // regular WAR file + List parents = getApplicationModules(module); + if (parents.isEmpty()) { + // standalone module - get context-root from geronimo-web.xml + contextRoot = GeronimoUtils.getContextRoot(module, true); + } else if (parents.size() == 1) { + // one parent - get context-root from EAR descriptor + contextRoot = GeronimoUtils.getContextRoot(module, false); + } } + + if (contextRoot != null) { + try { + String host = getServer().getHost(); + String url = "http://" + host; + int port = Integer.parseInt(getHTTPPort()); + port = ServerMonitorManager.getInstance().getMonitoredPort(getServer(), port, "web"); + if (port != 80) { + url += ":" + port; + } + String moduleId = contextRoot; + if (!moduleId.startsWith("/")) { + url += "/"; + } + url += moduleId; + + if (!url.endsWith("/")) { + url += "/"; + } + + Trace.tracePoint("Exit ", "GeronimoServerDelegate.getModuleRootURL", new URL(url)); + return new URL(url); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could not get root URL", e); + return null; + } + } + + return null; } Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java?rev=1070594&r1=1070593&r2=1070594&view=diff ============================================================================== --- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java (original) +++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoUtils.java Mon Feb 14 17:50:16 2011 @@ -16,6 +16,10 @@ */ package org.apache.geronimo.st.v30.core; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.jar.Manifest; + import javax.enterprise.deploy.shared.ModuleType; import javax.xml.bind.JAXBElement; @@ -87,7 +91,7 @@ public class GeronimoUtils { } public static boolean isBundleModule(IModule module) { - return OsgiConstants.COMPOSITE_BUNDLE.equals(module.getModuleType().getId()); + return OsgiConstants.BUNDLE.equals(module.getModuleType().getId()); } public static ModuleType getJSR88ModuleType(IModule module) { @@ -231,18 +235,49 @@ public class GeronimoUtils { return ComponentCore.createComponent(module.getProject()); } - public static String getContextRoot(IModule module) throws Exception{ - String contextRoot = null; - - J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module.loadAdapter(J2EEFlexProjDeployable.class, null); - contextRoot = ((IWebModule) j2eeModule).getContextRoot(); - - if (contextRoot == null) + public static Manifest getBundleManifest(IModule module) { + IVirtualComponent component = getVirtualComponent(module); + IPath manifestPath = component.getRootFolder().getUnderlyingFolder().getProjectRelativePath().append("META-INF").append("MANIFEST.MF"); + IFile manifestFile = component.getProject().getFile(manifestPath); + Manifest manifest = null; + InputStream in = null; + try { + in = manifestFile.getContents(); + manifest = new Manifest(in); + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could load manifest file", e); + } finally { + if (in != null) { + try { in.close(); } catch (Exception ee) {} + } + } + return manifest; + } + + public static String getContextRoot(IModule module, boolean standalone) { + String contextRoot = null; + if (standalone) { + try { + JAXBElement plan = getWebDeploymentPlan(module); + if (plan != null) { + contextRoot = plan.getValue().getContextRoot(); + } + } catch (Exception e) { + Trace.trace(Trace.SEVERE, "Could load geronimo-web.xml", e); + } + } else { + // TODO: this does not seem to pick up changes if application.xml is updated with a new context-root + J2EEFlexProjDeployable j2eeModule = (J2EEFlexProjDeployable) module.loadAdapter(J2EEFlexProjDeployable.class, null); + contextRoot = ((IWebModule) j2eeModule).getContextRoot(); + } + + if (contextRoot == null) { contextRoot = getId(module); - + } + return contextRoot; } - + public static String getId(IModule module) { // use the module ID String moduleId = module.getId();