Author: snjeza
Date: 2010-08-18 20:23:20 -0400 (Wed, 18 Aug 2010)
New Revision: 24283
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossLaunchAdapter.java
Log:
https://jira.jboss.org/browse/JBIDE-3908 when a portlet project is deployed to AS, the
target url is not correct
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossLaunchAdapter.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossLaunchAdapter.java 2010-08-19
00:21:09 UTC (rev 24282)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossLaunchAdapter.java 2010-08-19
00:23:20 UTC (rev 24283)
@@ -10,19 +10,27 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jst.server.core.EJBBean;
import org.eclipse.jst.server.core.JndiLaunchable;
import org.eclipse.jst.server.core.JndiObject;
import org.eclipse.jst.server.core.Servlet;
+import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework;
+import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.model.IURLProvider;
import org.eclipse.wst.server.core.model.LaunchableAdapterDelegate;
@@ -30,13 +38,30 @@
import org.eclipse.wst.server.core.util.HttpLaunchable;
import org.eclipse.wst.server.core.util.WebResource;
import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
public class JBossLaunchAdapter extends LaunchableAdapterDelegate {
+ private static final String SIMPLE_PORTAL_PATH = "simple-portal";
//$NON-NLS-1$
+ private static final String JBOSS_PORTLET = "jboss.portlet"; //$NON-NLS-1$
+ private static final String PORTAL_PATH = "portal"; //$NON-NLS-1$
+
private static final String JAVA_NAMING_PROVIDER_URL_PROPKEY =
IJBossServerConstants.NAMING_FACTORY_PROVIDER_URL;
private static final String JAVA_NAMING_FACTORY_INITIAL_PROPKEY =
IJBossServerConstants.NAMING_FACTORY_KEY;
+
+ private static final String SERVER_DEFAULT_DEPLOY_JBOSS_PORTAL_SAR =
"deploy/jboss-portal.sar"; //$NON-NLS-1$
+
+ private static final String SERVER_DEFAULT_DEPLOY_JBOSS_PORTAL_HA_SAR =
"deploy/jboss-portal-ha.sar"; //$NON-NLS-1$
+
+ private static final String SERVER_DEFAULT_DEPLOY_SIMPLE_PORTAL =
"deploy/simple-portal"; //$NON-NLS-1$
+
+ private static final String SERVER_DEFAULT_DEPLOY_SIMPLE_PORTAL_SAR =
"deploy/simple-portal.sar"; //$NON-NLS-1$
+
+ private static final String SERVER_DEFAULT_DEPLOY_GATEIN =
"deploy/gatein.ear"; //$NON-NLS-1$
+
+
public JBossLaunchAdapter() {
- // TODO Auto-generated constructor stub
+
}
/*
@@ -48,7 +73,7 @@
if (!(delegate instanceof JBossServer ))
return null;
if ((moduleObject instanceof Servlet) ||(moduleObject instanceof WebResource))
- return prepareHttpLaunchable(moduleObject, delegate);
+ return prepareHttpLaunchable(moduleObject, delegate, server);
if((moduleObject instanceof EJBBean) || (moduleObject instanceof JndiObject))
return prepareJndiLaunchable(moduleObject,delegate);
@@ -85,9 +110,10 @@
/**
* @param moduleObject
* @param delegate
+ * @param server
* @return object
*/
- private Object prepareHttpLaunchable(IModuleArtifact moduleObject, ServerDelegate
delegate) {
+ private Object prepareHttpLaunchable(IModuleArtifact moduleObject, ServerDelegate
delegate, IServer server) {
try {
URL url = ((IURLProvider) delegate).getModuleRootURL(moduleObject.getModule());
@@ -103,15 +129,82 @@
} else if (moduleObject instanceof WebResource) {
WebResource resource = (WebResource) moduleObject;
String path = resource.getPath().toString();
- if (path != null && path.startsWith("/") && path.length()
> 0) //$NON-NLS-1$
+ if (path != null && path.startsWith("/")) //$NON-NLS-1$
path = path.substring(1);
- if (path != null && path.length() > 0)
+ if (path != null && path.length() > 0) {
+ //path = getServlet30Mapping(resource, path);
url = new URL(url, path);
- }
+ }
+ }
+ URL portletURL = getPortletURL(moduleObject, delegate, server);
+ if (portletURL != null) {
+ url = portletURL;
+ }
return new HttpLaunchable(url);
} catch (MalformedURLException e) {
return null; // no launchable available.
}
}
+ private URL getPortletURL(IModuleArtifact moduleObject, ServerDelegate delegate, IServer
server) {
+ IModule module = moduleObject.getModule();
+ if (module != null && server != null) {
+ IProject project = module.getProject();
+ if (project != null) {
+ try {
+ if (FacetedProjectFramework.hasProjectFacet(project, JBOSS_PORTLET)) {
+ IRuntime runtime = server.getRuntime();
+ if (runtime == null || runtime.getLocation() == null) {
+ return null;
+ }
+ IJBossServerRuntime jbossRuntime =
(IJBossServerRuntime)runtime.loadAdapter(IJBossServerRuntime.class, new
NullProgressMonitor());
+ if (jbossRuntime != null) {
+ String urlString = "http://" + server.getHost(); //$NON-NLS-1$
+ if (delegate instanceof JBossServer) {
+ JBossServer jBossServer = (JBossServer) delegate;
+ urlString = urlString + ":" + jBossServer.getJBossWebPort() +
"/"; //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ return null;
+ }
+ URL url = new URL(urlString);
+ IPath jbossLocation = runtime.getLocation();
+ IPath configPath =
jbossLocation.append(IJBossServerConstants.SERVER).append(jbossRuntime.getJBossConfiguration());
+ File configFile = configPath.toFile();
+ // JBoss Portal server
+ if (exists(configFile, SERVER_DEFAULT_DEPLOY_JBOSS_PORTAL_SAR)) {
+ return new URL(url,PORTAL_PATH);
+ }
+ // JBoss Portal clustering server
+ if (exists(configFile,
+ SERVER_DEFAULT_DEPLOY_JBOSS_PORTAL_HA_SAR)) {
+ return new URL(url,PORTAL_PATH);
+ }
+ // JBoss portletcontainer
+ if (exists(configFile,SERVER_DEFAULT_DEPLOY_SIMPLE_PORTAL) ||
+ exists(configFile,SERVER_DEFAULT_DEPLOY_SIMPLE_PORTAL_SAR)) {
+ return new URL(url,SIMPLE_PORTAL_PATH);
+ }
+ // GateIn Portal Server
+ if (exists(configFile, SERVER_DEFAULT_DEPLOY_GATEIN)) {
+ return new URL(url,PORTAL_PATH);
+ }
+ }
+ }
+ } catch (MalformedURLException e) {
+ // ignore
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ }
+ return null;
+ }
+
+ private static boolean exists(final File location,String portalDir) {
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ portalDir = portalDir.replace("/", "\\"); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+ File file = new File(location,portalDir);
+ return file.exists();
+ }
}