geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
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 GMT
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<IModule> 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<WebApp> 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();



Mime
View raw message