Author: adietish
Date: 2010-09-06 04:03:22 -0400 (Mon, 06 Sep 2010)
New Revision: 24730
Modified:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/IGoogleEclipsePluginConstants.java
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java
Log:
[JBIDE-6987] gwt-servlet.jar now gets copied to the new project WEB-INF/lib. Still
missing: add it to the deployment
Modified:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java
===================================================================
---
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java 2010-09-06
07:17:50 UTC (rev 24729)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java 2010-09-06
08:03:22 UTC (rev 24730)
@@ -11,7 +11,11 @@
package org.jboss.tools.gwt.core;
import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.text.MessageFormat;
import java.util.List;
import java.util.zip.ZipInputStream;
@@ -19,13 +23,13 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.Assert;
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.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IScopeContext;
@@ -48,50 +52,56 @@
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.log.LogHelper;
+import org.jboss.tools.common.model.project.ProjectHome;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.gwt.core.internal.GWTCoreActivator;
import org.jboss.tools.gwt.core.util.ProjectUtils;
import org.jboss.tools.usage.util.StatusUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
import org.osgi.service.prefs.BackingStoreException;
/**
- * @author adietish
+ * @author Andre Dietisheim
*/
public class GWTInstallFacetDelegate implements IDelegate {
public void execute(IProject project, IProjectFacetVersion projectFacetVersion, Object
config,
IProgressMonitor monitor) throws CoreException {
- try {
- IJavaProject javaProject = JavaCore.create(project);
+ IJavaProject javaProject = JavaCore.create(project);
- addNature(javaProject, monitor);
- addClasspathContainer(javaProject, monitor);
+ addGwtNature(javaProject, monitor);
+ addClasspathContainer(javaProject, monitor);
- IPath webContentPath = ProjectUtils.getWebContentRootPath(javaProject.getProject());
- Assert.isTrue(webContentPath != null && !webContentPath.isEmpty(),
- MessageFormat
- .format("no web content folder was found in project {0}",
javaProject.getElementName()));
+ IPath webContentPath = getWebContentFolder(project, monitor);
- createWebApplicationPreferences(project, webContentPath, javaProject, monitor);
- configureOutputFolder(webContentPath, javaProject, monitor);
+ createWebApplicationPreferences(project, webContentPath, javaProject, monitor);
+ configureOutputFolder(webContentPath, javaProject, monitor);
- List<IPath> srcFolderPaths = ProjectUtils.getSourceFolders(javaProject);
- GWTInstallDataModelProvider dataModel = (GWTInstallDataModelProvider) config;
- createSample(srcFolderPaths, webContentPath, dataModel, javaProject, monitor);
+ List<IPath> srcFolderPaths = ProjectUtils.getSourceFolders(javaProject);
+ GWTInstallDataModelProvider dataModel = (GWTInstallDataModelProvider) config;
+ createSample(srcFolderPaths, webContentPath, dataModel, javaProject, monitor);
- configureWebXml(project, monitor);
- } catch (Exception e) {
- throw new CoreException(StatusUtils.getErrorStatus(GWTCoreActivator.PLUGIN_ID,
"Could not create gwt facet.", e));
- }
+ configureWebXml(project, monitor);
}
- private void addNature(IJavaProject javaProject, IProgressMonitor monitor) throws
CoreException {
- monitor.subTask("adding gwt nature");
+ private IPath getWebContentFolder(IProject project, IProgressMonitor monitor) throws
CoreException {
+ IPath webContentPath = ProjectHome.getFirstWebContentPath(project);
+ Assert.isTrue(webContentPath != null && !webContentPath.isEmpty(),
+ MessageFormat
+ .format("No web content folder was found in project {0}",
project.getName()));
+ return webContentPath;
+ }
+ private void addGwtNature(IJavaProject javaProject, IProgressMonitor monitor) throws
CoreException {
+ monitor.subTask("Adding GWT nature");
+
EclipseUtil.addNatureToProject(javaProject.getProject(),
IGoogleEclipsePluginConstants.GWT_NATURE);
}
private void addClasspathContainer(IJavaProject javaProject, IProgressMonitor monitor)
throws CoreException {
- monitor.subTask("adding gwt container to classpath");
+ monitor.subTask("Adding gwt container to classpath");
IClasspathEntry entry = JavaCore.newContainerEntry(new
Path(IGoogleEclipsePluginConstants.GWT_CONTAINER_ID),
false);
@@ -99,43 +109,55 @@
}
private void createWebApplicationPreferences(IProject project, IPath webContentPath,
- IJavaProject javaProject, IProgressMonitor monitor) throws BackingStoreException,
CoreException {
- monitor.subTask("creating web application preferences");
+ IJavaProject javaProject, IProgressMonitor monitor) throws CoreException {
+ try {
+ monitor.subTask("creating web application preferences");
- IScopeContext projectScope = new ProjectScope(project);
- IEclipsePreferences preferences =
projectScope.getNode(IGoogleEclipsePluginConstants.GDT_PLUGIN_ID);
+ IScopeContext projectScope = new ProjectScope(project);
+ IEclipsePreferences preferences =
projectScope.getNode(IGoogleEclipsePluginConstants.GDT_PLUGIN_ID);
- preferences.put(IGoogleEclipsePluginConstants.WAR_SRCDIR_KEY,
- webContentPath.makeRelativeTo(javaProject.getPath()).toString());
- preferences.put(IGoogleEclipsePluginConstants.WAR_SRCDIR_ISOUTPUT_KEY,
- IGoogleEclipsePluginConstants.WAR_SRCDIR_ISOUTPUT_DEFAULTVALUE);
- preferences.flush();
+ preferences.put(IGoogleEclipsePluginConstants.WAR_SRCDIR_KEY,
+ webContentPath.makeRelativeTo(project.getFullPath()).toString());
+ preferences.put(IGoogleEclipsePluginConstants.WAR_SRCDIR_ISOUTPUT_KEY,
+ IGoogleEclipsePluginConstants.WAR_SRCDIR_ISOUTPUT_DEFAULTVALUE);
+ preferences.flush();
+ } catch (BackingStoreException e) {
+ throw new CoreException(StatusUtils.getErrorStatus(GWTCoreActivator.PLUGIN_ID,
+ "Could not save project preferences", e));
+ }
}
- private void configureOutputFolder(IPath webContentProjectPath, IJavaProject
javaProject, IProgressMonitor monitor)
+ private void configureOutputFolder(IPath webContentProjectPath, final IJavaProject
javaProject,
+ IProgressMonitor monitor)
throws CoreException, JavaModelException {
- monitor.subTask("configuring output folder");
+ IProject project = javaProject.getProject();
+ monitor.subTask("Configuring output folder");
IPath outputFolderProjectPath = webContentProjectPath.append(new Path(
IGoogleEclipsePluginConstants.OUTPUT_FOLDER_DEFAULTVALUE));
- IFolder outputWorkspaceFolder =
javaProject.getProject().getWorkspace().getRoot().getFolder(
- outputFolderProjectPath);
- if (!outputWorkspaceFolder.exists()) {
- outputWorkspaceFolder.create(true, true, monitor);
- }
- javaProject.setOutputLocation(outputWorkspaceFolder.getFullPath(), new
NullProgressMonitor());
+ final IFolder outputWorkspaceFolder =
project.getWorkspace().getRoot().getFolder(outputFolderProjectPath);
+ project.getWorkspace().run(
+ new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ if (!outputWorkspaceFolder.exists()) {
+ ProjectUtils.create(outputWorkspaceFolder, monitor);
+ }
+ javaProject.setOutputLocation(outputWorkspaceFolder.getFullPath(), monitor);
+ }
+ }, monitor);
}
private void createSample(final List<IPath> srcPaths, final IPath webContentPath,
GWTInstallDataModelProvider dataModel, final IJavaProject javaProject,
IProgressMonitor monitor)
- throws IOException, CoreException {
+ throws CoreException {
if (srcPaths.size() <= 0) {
- LogHelper.logWarning(GWTCoreActivator.PLUGIN_ID, MessageFormat.format("no source
folders were found in project {0}", javaProject.getElementName()));
+ LogHelper.logWarning(GWTCoreActivator.PLUGIN_ID,
+ MessageFormat.format("No source folders were found in project {0}",
javaProject.getElementName()));
return;
}
if (dataModel.isGenerateSampleCode()) {
- monitor.subTask("creating sample code");
+ monitor.subTask("Creating sample code");
javaProject.getProject().getWorkspace().run(new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
@@ -147,9 +169,11 @@
*/
unzipSrc(srcPaths.get(0), javaProject);
unzipWebContent(webContentPath, javaProject);
+ copyGwtServlet(javaProject, webContentPath, monitor);
} catch (IOException e) {
- LogHelper.logError(GWTCoreActivator.PLUGIN_ID, "Could not create gwt
facet", e);
+ throw new CoreException(StatusUtils.getErrorStatus(GWTCoreActivator.PLUGIN_ID,
+ "Could not unzip samples", e));
}
}
@@ -173,6 +197,51 @@
ProjectUtils.unzipToFolder(zipInputStream, ProjectUtils.getFile(webContentPath,
javaProject.getProject()));
}
+ private void copyGwtServlet(IJavaProject javaProject, IPath webContentPath,
IProgressMonitor monitor) throws IOException, CoreException {
+ FileUtil.copy(getGwtServletJar(), getGwtServletDestination(javaProject, webContentPath,
monitor));
+ }
+
+ private FileOutputStream getGwtServletDestination(IJavaProject javaProject, IPath
webContentPath, IProgressMonitor monitor)
+ throws CoreException, FileNotFoundException {
+ IPath webInfLibPath = webContentPath.append(new
Path(IGoogleEclipsePluginConstants.WEB_INF_LIB));
+ IWorkspaceRoot workspaceRoot = javaProject.getProject().getWorkspace().getRoot();
+ ProjectUtils.create(workspaceRoot.getFolder(webInfLibPath), monitor);
+ IPath gwtServletFilePath =
webInfLibPath.append(IGoogleEclipsePluginConstants.GWT_SERVLET_NAME);
+ File file = new File(workspaceRoot.getFile(gwtServletFilePath).getLocationURI());
+ return new FileOutputStream(file);
+ }
+
+ private InputStream getGwtServletJar() throws CoreException, IOException {
+ Bundle gwtBundle =
getGwtSdkBundle(GWTCoreActivator.getDefault().getBundle().getBundleContext());
+ Assert.isTrue(gwtBundle != null,
+ MessageFormat.format("GWT SDK bundle was not found. Could not copy {0}",
IGoogleEclipsePluginConstants.GWT_SERVLET_NAME));
+ String gwtSdkVersion = getGwtServletFolder(gwtBundle);
+ IPath gwtServletPath = new
Path(gwtSdkVersion).append(IGoogleEclipsePluginConstants.GWT_SERVLET_NAME);
+ return gwtBundle.getEntry(gwtServletPath.toFile().toString()).openStream();
+ }
+
+ private String getGwtServletFolder(Bundle bundle) {
+ Version bundleVersion = bundle.getVersion();
+ return new StringBuilder()
+ .append("gwt")
+ .append("-")
+ .append(bundleVersion.getMajor())
+ .append(".")
+ .append(bundleVersion.getMinor())
+ .append(".")
+ .append(bundleVersion.getMicro())
+ .toString();
+ }
+
+ private Bundle getGwtSdkBundle(BundleContext bundleContext) {
+ for (Bundle bundle : bundleContext.getBundles()) {
+ if
(bundle.getSymbolicName().contains(IGoogleEclipsePluginConstants.GWT_SDK_BUNDLENAME)) {
+ return bundle;
+ }
+ }
+ return null;
+ }
+
/**
* Configures the web xml. Adds the gwt servlet, servlet mapping and welcome
* page.
Modified:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/IGoogleEclipsePluginConstants.java
===================================================================
---
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/IGoogleEclipsePluginConstants.java 2010-09-06
07:17:50 UTC (rev 24729)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/IGoogleEclipsePluginConstants.java 2010-09-06
08:03:22 UTC (rev 24730)
@@ -55,4 +55,11 @@
public static final String SERVLET_MAPPING = "/gwt_jboss/greet";
//$NON-NLS-1$
public static final String WELCOME_FILE = "Gwt_jboss.html"; //$NON-NLS-1$
+
+ public static final String GWT_SDK_BUNDLENAME =
"com.google.gwt.eclipse.sdkbundle"; //$NON-NLS-1$
+
+ public static final String GWT_SERVLET_NAME = "gwt-servlet.jar";
//$NON-NLS-1$
+
+ public static final String WEB_INF_LIB = "/WEB-INF/lib"; //$NON-NLS-1$;
+
}
Modified:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java
===================================================================
---
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java 2010-09-06
07:17:50 UTC (rev 24729)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java 2010-09-06
08:03:22 UTC (rev 24730)
@@ -24,8 +24,10 @@
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.AssertionFailedException;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
@@ -54,7 +56,7 @@
/** Signals the end of a stream. */
private static final int EOS = -1;
- public static IPath getWebXmlPath() {
+ public static IPath getWebXmlPath() {
return new Path(WEB_INF_FOLDER).append(WEB_XML_FILE);
}
@@ -188,14 +190,16 @@
IFolder folder = project.getWorkspace().getRoot().getFolder(path);
return folder.getLocation().toFile();
}
-
+
/**
* Returns a resource as stream while checking whether the resource exists.
- *
- * @param resourceName the resource name
+ *
+ * @param resourceName
+ * the resource name
* @return the input stream
*
- * @throws AssertionFailedException if the resource's not found
+ * @throws AssertionFailedException
+ * if the resource's not found
*/
public static InputStream checkedGetResourceStream(String resourceName, Class<?>
clazz) {
InputStream inputStream = clazz.getResourceAsStream(resourceName);
@@ -203,5 +207,26 @@
return inputStream;
}
+ /**
+ * Creates the given resource and all its parents (recursively)
+ *
+ * @param resource
+ * @param monitor
+ * @throws CoreException
+ */
+ public static void create(IResource resource, IProgressMonitor monitor) throws
CoreException {
+ if (resource.exists())
+ return;
+ create(resource.getParent(), monitor);
+ switch (resource.getType()) {
+ case IResource.FOLDER:
+ ((IFolder) resource).create(IResource.NONE, true, null);
+ break;
+ case IResource.PROJECT:
+ ((IProject) resource).create(monitor);
+ ((IProject) resource).open(monitor);
+ break;
+ }
+ }
}