Author: adietish
Date: 2010-09-07 04:33:04 -0400 (Tue, 07 Sep 2010)
New Revision: 24754
Added:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ResourceUtils.java
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ZipUtils.java
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/util/ProjectUtils.java
Log:
[JBIDE-6987] fixed the deployment assembly
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-07
07:33:12 UTC (rev 24753)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java 2010-09-07
08:33:04 UTC (rev 24754)
@@ -56,6 +56,8 @@
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.gwt.core.util.ResourceUtils;
+import org.jboss.tools.gwt.core.util.ZipUtils;
import org.jboss.tools.usage.util.StatusUtils;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -67,6 +69,8 @@
*/
public class GWTInstallFacetDelegate implements IDelegate {
+ private static final String GWTSERVLETJAR_FOLDER_PATTERN = "gwt-{0}.{1}.{2}";
+
public void execute(IProject project, IProjectFacetVersion projectFacetVersion, Object
config,
IProgressMonitor monitor) throws CoreException {
IJavaProject javaProject = JavaCore.create(project);
@@ -79,10 +83,11 @@
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);
-
+ if (dataModel.isGenerateSampleCode()) {
+ List<IPath> srcFolderPaths = ProjectUtils.getSourceFolders(javaProject);
+ createSample(srcFolderPaths, webContentPath, javaProject, monitor);
+ }
configureWebXml(project, monitor);
}
@@ -139,15 +144,15 @@
new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
if (!outputWorkspaceFolder.exists()) {
- ProjectUtils.create(outputWorkspaceFolder, monitor);
+ ResourceUtils.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)
+ private void createSample(final List<IPath> srcPaths, final IPath webContentPath,
final IJavaProject javaProject,
+ IProgressMonitor monitor)
throws CoreException {
if (srcPaths.size() <= 0) {
@@ -156,56 +161,52 @@
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 {
- try {
- /**
- * TODO: it is not secure to take the first
- * source-folder that was found (there might be several
- * of them).
- */
- unzipSrc(srcPaths.get(0), javaProject);
- unzipWebContent(webContentPath, javaProject);
- copyGwtServlet(javaProject, webContentPath, monitor);
+ javaProject.getProject().getWorkspace().run(new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ try {
+ /**
+ * TODO: it is not secure to take the first source-folder
+ * that was found (there might be several of them).
+ */
+ unzipSrc(srcPaths.get(0), javaProject);
+ unzipWebContent(webContentPath, javaProject);
+ copyGwtServlet(javaProject, webContentPath, monitor);
- } catch (IOException e) {
- throw new CoreException(StatusUtils.getErrorStatus(GWTCoreActivator.PLUGIN_ID,
+ } catch (IOException e) {
+ throw new CoreException(StatusUtils.getErrorStatus(GWTCoreActivator.PLUGIN_ID,
"Could not unzip samples", e));
- }
}
+ }
+ }, monitor);
- }, monitor);
-
- javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
- }
+ javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
private void unzipSrc(final IPath srcFolderPath, final IJavaProject javaProject) throws
IOException {
ZipInputStream inputStream = new ZipInputStream(new BufferedInputStream(
- ProjectUtils.checkedGetResourceStream(IGoogleEclipsePluginConstants.SAMPLE_HELLO_SRC_ZIP_FILENAME,
- getClass())));
- ProjectUtils.unzipToFolder(inputStream, ProjectUtils.getFile(srcFolderPath,
javaProject.getProject()));
+ getClass().getResourceAsStream(IGoogleEclipsePluginConstants.SAMPLE_HELLO_SRC_ZIP_FILENAME)));
+ ZipUtils.unzipToFolder(inputStream, ResourceUtils.getFile(srcFolderPath,
javaProject.getProject()));
}
private void unzipWebContent(IPath webContentPath, IJavaProject javaProject) throws
IOException {
ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(
- ProjectUtils.checkedGetResourceStream(
- IGoogleEclipsePluginConstants.SAMPLE_HELLO_WEBCONTENT_ZIP_FILENAME, getClass())));
- ProjectUtils.unzipToFolder(zipInputStream, ProjectUtils.getFile(webContentPath,
javaProject.getProject()));
+ getClass().getResourceAsStream(IGoogleEclipsePluginConstants.SAMPLE_HELLO_WEBCONTENT_ZIP_FILENAME)));
+ ZipUtils.unzipToFolder(zipInputStream, ResourceUtils.getFile(webContentPath,
javaProject.getProject()));
}
- private void copyGwtServlet(IJavaProject javaProject, IPath webContentPath,
IProgressMonitor monitor) throws IOException, CoreException {
+ 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)
+ 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);
+ ResourceUtils.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);
@@ -214,23 +215,17 @@
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));
+ 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();
+ return MessageFormat.format(GWTSERVLETJAR_FOLDER_PATTERN, bundleVersion.getMajor(),
bundleVersion.getMinor(),
+ bundleVersion.getMicro());
}
private Bundle getGwtSdkBundle(BundleContext bundleContext) {
@@ -252,31 +247,14 @@
* the monitor to inform on progress
*/
protected void configureWebXml(final IProject project, IProgressMonitor monitor) {
- IModelProvider modelProvider = ModelProviderManager.getModelProvider(project);
- Object modelObject = modelProvider.getModelObject();
- if (!(modelObject instanceof WebApp)) {
- // TODO log
- return;
- }
-
monitor.subTask("configuring web.xml");
- IPath webXmlPath = ProjectUtils.getWebXmlPath();
- boolean exists =
project.getProjectRelativePath().append(webXmlPath).toFile().exists();
- if (!exists) {
- webXmlPath = IModelProvider.FORCESAVE;
- }
+ IModelProvider modelProvider = ModelProviderManager.getModelProvider(project);
+ IPath webXmlPath = ProjectUtils.getWebXmlPath(project);
modelProvider.modify(new Runnable() {
public void run() {
- IModelProvider modelProvider = ModelProviderManager.getModelProvider(project);
- Object modelObject = modelProvider.getModelObject();
- if (!(modelObject instanceof WebApp)) {
- // TODO log
- return;
- }
- WebApp webApp = (WebApp) modelObject;
-
+ WebApp webApp = ProjectUtils.getWebApp(project);
Servlet servlet = createServlet(
IGoogleEclipsePluginConstants.SERVLET_NAME,
IGoogleEclipsePluginConstants.SERVLET_CLASS,
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-07
07:33:12 UTC (rev 24753)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java 2010-09-07
08:33:04 UTC (rev 24754)
@@ -11,29 +11,21 @@
package org.jboss.tools.gwt.core.util;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-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;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.model.IModelProvider;
+import org.eclipse.jst.j2ee.model.ModelProviderManager;
+import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
@@ -53,11 +45,13 @@
/** the folder that holds the web configurations and deployed classes */
public static final String WEB_INF_FOLDER = "WEB-INF";
- /** Signals the end of a stream. */
- private static final int EOS = -1;
-
- public static IPath getWebXmlPath() {
- return new Path(WEB_INF_FOLDER).append(WEB_XML_FILE);
+ public static IPath getWebXmlPath(IProject project) {
+ IPath webXmlPath = new Path(WEB_INF_FOLDER).append(WEB_XML_FILE);
+ boolean exists =
project.getProjectRelativePath().append(webXmlPath).toFile().exists();
+ if (!exists) {
+ webXmlPath = IModelProvider.FORCESAVE;
+ }
+ return webXmlPath;
}
/**
@@ -106,53 +100,6 @@
}
/**
- * Unzips the given ZipInputStream to the given folder.
- *
- * @param zipInputStream
- * the zip input stream
- * @param dirToExtractTo
- * the dir to extract to
- * @throws IOException
- * Signals that an I/O exception has occurred.
- *
- * @see ZipInputStream
- * @see File
- */
- public static final void unzipToFolder(ZipInputStream zipInputStream, File
dirToExtractTo) throws IOException {
- Assert.isLegal(zipInputStream != null);
- Assert.isLegal(!dirToExtractTo.exists() || dirToExtractTo.isDirectory());
- try {
- for (ZipEntry zipEntry = null; (zipEntry = zipInputStream.getNextEntry()) != null;) {
- File file = new File(dirToExtractTo, zipEntry.getName());
- if (zipEntry.isDirectory()) {
- if (!file.exists()) {
- file.mkdirs();
- }
- } else {
- if (!file.getParentFile().exists()) {
- file.getParentFile().mkdirs();
- }
- writeTo(zipInputStream, file);
- }
- }
- } finally {
- zipInputStream.close();
- }
- }
-
- private static void writeTo(InputStream inputStream, File file) throws IOException {
- BufferedOutputStream outputStream = new BufferedOutputStream(new
FileOutputStream(file));
- byte[] buffer = new byte[8192];
- try {
- for (int read = 0; (read = inputStream.read(buffer)) != EOS;) {
- outputStream.write(buffer, 0, read);
- }
- } finally {
- outputStream.close();
- }
- }
-
- /**
* Returns the (paths of) the source folders for the given java project. The
* paths returned are relative to the workspace.
*
@@ -177,56 +124,13 @@
return srcFolderList;
}
- /**
- * Returns a file for the given path in the given project.
- *
- * @param path
- * the path to return the file for
- * @param project
- * the project the path's located in
- * @return the file that represents the given path in the given project
- */
- public static File getFile(IPath path, IProject project) {
- 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
- * @return the input stream
- *
- * @throws AssertionFailedException
- * if the resource's not found
- */
- public static InputStream checkedGetResourceStream(String resourceName, Class<?>
clazz) {
- InputStream inputStream = clazz.getResourceAsStream(resourceName);
- Assert.isTrue(inputStream != null, MessageFormat.format("Could not find the zip
file {0}", resourceName));
- 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;
- }
+ public static WebApp getWebApp(IProject project) {
+ IModelProvider modelProvider = ModelProviderManager.getModelProvider(project);
+ Object modelObject = modelProvider.getModelObject();
+ Assert.isTrue(modelObject instanceof WebApp, MessageFormat.format(
+ "Could not get webapp model for project {0}. The given project is not a web
app.", project.getName()));
+ return (WebApp) modelObject;
}
}
Added:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ResourceUtils.java
===================================================================
---
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ResourceUtils.java
(rev 0)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ResourceUtils.java 2010-09-07
08:33:04 UTC (rev 24754)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.gwt.core.util;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+public class ResourceUtils {
+
+ /**
+ * Returns a file for the given path in the given project.
+ *
+ * @param path
+ * the path to return the file for
+ * @param project
+ * the project the path's located in
+ * @return the file that represents the given path in the given project
+ */
+ public static File getFile(IPath path, IProject project) {
+ IFolder folder = project.getWorkspace().getRoot().getFolder(path);
+ return folder.getLocation().toFile();
+ }
+
+ /**
+ * 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;
+ }
+ }
+}
Property changes on:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ResourceUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ZipUtils.java
===================================================================
---
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ZipUtils.java
(rev 0)
+++
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ZipUtils.java 2010-09-07
08:33:04 UTC (rev 24754)
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.gwt.core.util;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class ZipUtils {
+
+ /** Signals the end of a stream. */
+ private static final int EOS = -1;
+
+
+ /**
+ * Unzips the given ZipInputStream to the given folder.
+ *
+ * @param zipInputStream
+ * the zip input stream
+ * @param dirToExtractTo
+ * the dir to extract to
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ *
+ * @see ZipInputStream
+ * @see File
+ */
+ public static final void unzipToFolder(ZipInputStream zipInputStream, File
dirToExtractTo) throws IOException {
+ Assert.isLegal(zipInputStream != null);
+ Assert.isLegal(!dirToExtractTo.exists() || dirToExtractTo.isDirectory());
+ try {
+ for (ZipEntry zipEntry = null; (zipEntry = zipInputStream.getNextEntry()) != null;) {
+ File file = new File(dirToExtractTo, zipEntry.getName());
+ if (zipEntry.isDirectory()) {
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ } else {
+ if (!file.getParentFile().exists()) {
+ file.getParentFile().mkdirs();
+ }
+ writeTo(zipInputStream, file);
+ }
+ }
+ } finally {
+ zipInputStream.close();
+ }
+ }
+
+ private static void writeTo(InputStream inputStream, File file) throws IOException {
+ BufferedOutputStream outputStream = new BufferedOutputStream(new
FileOutputStream(file));
+ byte[] buffer = new byte[8192];
+ try {
+ for (int read = 0; (read = inputStream.read(buffer)) != EOS;) {
+ outputStream.write(buffer, 0, read);
+ }
+ } finally {
+ outputStream.close();
+ }
+ }
+}
Property changes on:
trunk/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ZipUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain