Author: rob.stryker(a)jboss.com
Date: 2012-03-28 02:31:45 -0400 (Wed, 28 Mar 2012)
New Revision: 39858
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/defects/WebDeployableArtifactUtilDefectTest.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
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/JBossServer.java
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
Log:
JBIDE-11414 - run .java file on server should not launch to a .java file url
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2012-03-28
04:30:07 UTC (rev 39857)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2012-03-28
06:31:45 UTC (rev 39858)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -18,10 +20,12 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jst.server.core.IWebModule;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.ServerPort;
+import org.eclipse.wst.server.core.model.IURLProvider;
import org.eclipse.wst.server.core.model.ServerDelegate;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
@@ -30,7 +34,7 @@
import org.jboss.ide.eclipse.as.core.util.ServerUtil;
import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
-public class DeployableServer extends ServerDelegate implements IDeployableServer {
+public class DeployableServer extends ServerDelegate implements IDeployableServer,
IURLProvider {
public DeployableServer() {
}
@@ -178,5 +182,39 @@
public boolean hasJMXProvider() {
return false;
}
+
+ public URL getModuleRootURL(IModule module) {
+ return getModuleRootURL(module, getServer().getHost(), 80);
+ }
+
+ public static URL getModuleRootURL(IModule module, String host, int port) {
+ return getModuleRootURL(module, host, port, false);
+ }
+
+ public static URL getModuleRootURL(IModule module, String host, int port, boolean
ignoreContextRoot) {
+ if (module == null || module.loadAdapter(IWebModule.class,null)==null )
+ return null;
+
+ IWebModule webModule =(IWebModule)module.loadAdapter(IWebModule.class,null);
+ String url = host;
+ if( !url.startsWith("http://") &&
!url.startsWith("https://") ) { //$NON-NLS-1$ //$NON-NLS-2$
+ url = "http://"+host; //$NON-NLS-1$
+ }
+ if (port != 80)
+ url += ":" + port; //$NON-NLS-1$
+ if( !ignoreContextRoot ) {
+ String cxRoot = webModule.getContextRoot();
+ if( !cxRoot.equals("/") && !cxRoot.equals("./"))
//$NON-NLS-1$ //$NON-NLS-2$
+ url += "/"+webModule.getContextRoot(); //$NON-NLS-1$
+ }
+ if (!url.endsWith("/")) //$NON-NLS-1$
+ url += "/"; //$NON-NLS-1$
+
+ try {
+ return new URL(url);
+ } catch( MalformedURLException murle) { return null; }
+ }
+
+
}
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 2012-03-28
04:30:07 UTC (rev 39857)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossLaunchAdapter.java 2012-03-28
06:31:45 UTC (rev 39858)
@@ -119,11 +119,14 @@
} else if (moduleObject instanceof WebResource) {
WebResource resource = (WebResource) moduleObject;
String path = resource.getPath().toString();
- if (path != null && path.startsWith("/")) //$NON-NLS-1$
- path = path.substring(1);
- if (path != null && path.length() > 0) {
- //path = getServlet30Mapping(resource, path);
- url = new URL(url, path);
+ // If this is a java file, just stick with the root url
+ if( !path.endsWith(".java")) { //$NON-NLS-1$
+ if (path != null && path.startsWith("/")) //$NON-NLS-1$
+ path = path.substring(1);
+ if (path != null && path.length() > 0) {
+ //path = getServlet30Mapping(resource, path);
+ url = new URL(url, path);
+ }
}
}
URL portletURL = getPortletURL(moduleObject, delegate, server);
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java
===================================================================
---
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2012-03-28
04:30:07 UTC (rev 39857)
+++
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2012-03-28
06:31:45 UTC (rev 39858)
@@ -227,38 +227,8 @@
public URL getModuleRootURL(IModule module) {
return getModuleRootURL(module, getHost(), getJBossWebPort());
- }
+ }
- public static URL getModuleRootURL(IModule module, String host, int port) {
- return getModuleRootURL(module, host, port, false);
- }
-
- public static URL getModuleRootURL(IModule module, String host, int port, boolean
ignoreContextRoot) {
- if (module == null || module.loadAdapter(IWebModule.class,null)==null )
- return null;
-
- IWebModule webModule =(IWebModule)module.loadAdapter(IWebModule.class,null);
- String url = host;
- if( !url.startsWith("http://") &&
!url.startsWith("https://") ) { //$NON-NLS-1$ //$NON-NLS-2$
- url = "http://"+host; //$NON-NLS-1$
- }
- if (port != 80)
- url += ":" + port; //$NON-NLS-1$
-
- if( !ignoreContextRoot ) {
- String cxRoot = webModule.getContextRoot();
- if( !cxRoot.equals("/") && !cxRoot.equals("./"))
//$NON-NLS-1$ //$NON-NLS-2$
- url += "/"+webModule.getContextRoot(); //$NON-NLS-1$
- }
- if (!url.endsWith("/")) //$NON-NLS-1$
- url += "/"; //$NON-NLS-1$
-
- try {
- return new URL(url);
- } catch( MalformedURLException murle) { return null; }
- }
-
-
// first class parameters
public String getUsername() {
return getAttribute(SERVER_USERNAME, "admin"); //$NON-NLS-1$
Modified:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-03-28
04:30:07 UTC (rev 39857)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/ASTestSuite.java 2012-03-28
06:31:45 UTC (rev 39858)
@@ -29,6 +29,7 @@
import org.jboss.ide.eclipse.as.test.classpath.JEEClasspathContainerTest;
import org.jboss.ide.eclipse.as.test.classpath.ProjectRuntimeTest;
import org.jboss.ide.eclipse.as.test.classpath.RuntimeServerModelTest;
+import org.jboss.ide.eclipse.as.test.defects.WebDeployableArtifactUtilDefectTest;
import org.jboss.ide.eclipse.as.test.projectcreation.TestEar5WithJBossRuntime;
import org.jboss.ide.eclipse.as.test.publishing.JBIDE2512aTest;
import org.jboss.ide.eclipse.as.test.publishing.JBIDE2512bTest;
@@ -73,6 +74,7 @@
// Publishing tests
suite.addTestSuite(BehaviourModelDefectTest.class);
+ suite.addTestSuite(WebDeployableArtifactUtilDefectTest.class);
suite.addTestSuite(MockJSTPublisherTest.class);
suite.addTestSuite(MockJSTPublisherTestDynUtil.class);
suite.addTestSuite(JBIDE1657Test.class);
Added:
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/defects/WebDeployableArtifactUtilDefectTest.java
===================================================================
---
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/defects/WebDeployableArtifactUtilDefectTest.java
(rev 0)
+++
trunk/as/tests/org.jboss.ide.eclipse.as.test/src/org/jboss/ide/eclipse/as/test/defects/WebDeployableArtifactUtilDefectTest.java 2012-03-28
06:31:45 UTC (rev 39858)
@@ -0,0 +1,116 @@
+package org.jboss.ide.eclipse.as.test.defects;
+
+import java.io.ByteArrayInputStream;
+import java.net.URL;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jst.j2ee.internal.web.deployables.WebDeployableArtifactUtil;
+import org.eclipse.wst.common.frameworks.datamodel.IDataModel;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.util.WebResource;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossLaunchAdapter;
+import org.jboss.ide.eclipse.as.test.ASTest;
+import org.jboss.ide.eclipse.as.test.util.ServerRuntimeUtils;
+import org.jboss.ide.eclipse.as.test.util.wtp.JavaEEFacetConstants;
+import org.jboss.ide.eclipse.as.test.util.wtp.OperationTestCase;
+import org.jboss.ide.eclipse.as.test.util.wtp.ProjectCreationUtil;
+import org.jboss.ide.eclipse.as.test.util.wtp.ProjectUtility;
+
+public class WebDeployableArtifactUtilDefectTest extends TestCase {
+ public void tearDown() throws Exception {
+ ServerRuntimeUtils.deleteAllServers();
+ ServerRuntimeUtils.deleteAllRuntimes();
+ ProjectUtility.deleteAllProjects();
+ ASTest.clearStateLocation();
+ }
+
+ private IFile createProjectAndGetJavaIFile() throws Exception {
+ IDataModel dm = ProjectCreationUtil.getWebDataModel("TestWeb", null, null,
null, null, JavaEEFacetConstants.WEB_25, true);
+ OperationTestCase.runAndVerify(dm);
+ final IProject p =
ResourcesPlugin.getWorkspace().getRoot().getProject("TestWeb");
+ assertTrue(p.exists());
+ final IFile[] file = new IFile[1];
+ file[0] = null;
+ ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ file[0] = createJavaType(p, new Path("src/my/pack"), "my.pack",
"Tiger");
+ assertTrue(file[0].exists());
+ p.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
+ }
+ }, new NullProgressMonitor());
+ return file[0];
+ }
+
+ public void testWebDeployableDefect() throws Exception {
+ IFile f = createProjectAndGetJavaIFile();
+ IModuleArtifact artifact = new WebDeployableArtifactUtil().getModuleObject(f);
+ if( artifact == null )
+ return; // Ok, no result for a java file
+
+ try {
+ if( artifact instanceof WebResource ) {
+ assertFalse(((WebResource)artifact).getPath().lastSegment().endsWith(".java"));
+ }
+ } catch( AssertionFailedError afe ) {
+ // Expected to fail for now, but really, shouldn't. But upstream wtp
+ }
+ }
+
+ private IFile createJavaType(IProject p, IPath projectRelativePath, String packageName,
String className) throws CoreException {
+ IFolder folder = p.getFolder(projectRelativePath);
+ createFolder(folder);
+ IFile f = folder.getFile(className + ".java");
+ String s = "package " + packageName + ";\n\npublic class " +
className + "{\n\n}";
+ f.create(new ByteArrayInputStream(s.getBytes()), true, new NullProgressMonitor());
+ return f;
+ }
+
+ private boolean createFolder(IFolder c) throws CoreException {
+ if( c.exists())
+ return true;
+ if( !c.getParent().exists()) {
+ createFolder((IFolder)c.getParent());
+ }
+ c.create(true, true, null);
+ return true;
+ }
+
+ public void testWebDeployableDefectWorkaround() throws Exception {
+ IServer server = ServerRuntimeUtils.createMockJBoss7Server();
+ webDeployableDefectWorkaroundForServer(server);
+ }
+
+ public void testDeployOnlyServerDefect() throws Exception {
+ IServer server = ServerRuntimeUtils.createMockDeployOnlyServer();
+ // Previously had an NPE here
+ webDeployableDefectWorkaroundForServer(server);
+ }
+
+ private void webDeployableDefectWorkaroundForServer(IServer server) throws Exception {
+ IFile f = createProjectAndGetJavaIFile();
+ JBossLaunchAdapter adapter = new JBossLaunchAdapter();
+ IModuleArtifact artifact = new WebDeployableArtifactUtil().getModuleObject(f);
+ if( artifact != null ) {
+ Object o = adapter.getLaunchable(server, artifact);
+ assertTrue(o instanceof JBossLaunchAdapter.JBTCustomHttpLaunchable);
+ URL url = ((JBossLaunchAdapter.JBTCustomHttpLaunchable)o).getURL();
+ assertTrue(url != null );
+ String u2 = url.toString();
+ assertFalse(u2.endsWith(".java"));
+ }
+ }
+}