Author: adietish
Date: 2010-09-03 12:07:40 -0400 (Fri, 03 Sep 2010)
New Revision: 24705
Modified:
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/META-INF/MANIFEST.MF
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java
Log:
[JBIDE-6954] various cleanups, proper exception handling now
Modified:
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/META-INF/MANIFEST.MF
===================================================================
---
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/META-INF/MANIFEST.MF 2010-09-03
16:03:16 UTC (rev 24704)
+++
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/META-INF/MANIFEST.MF 2010-09-03
16:07:40 UTC (rev 24705)
@@ -26,4 +26,5 @@
Export-Package: org.jboss.tools.gwt.core,
org.jboss.tools.gwt.core.util
Bundle-ActivationPolicy: lazy
+Import-Package: org.jboss.tools.common.model.project
Modified:
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java
===================================================================
---
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java 2010-09-03
16:03:16 UTC (rev 24704)
+++
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/GWTInstallFacetDelegate.java 2010-09-03
16:07:40 UTC (rev 24705)
@@ -25,7 +25,6 @@
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;
@@ -44,54 +43,64 @@
import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.jst.javaee.web.WebFactory;
import org.eclipse.jst.javaee.web.WelcomeFileList;
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.common.project.facet.core.IDelegate;
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.gwt.core.internal.GWTCoreActivator;
import org.jboss.tools.gwt.core.util.ProjectUtils;
import org.jboss.tools.usage.util.StatusUtils;
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()));
+ addModuleCoreNature(project, monitor);
+ 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 addModuleCoreNature(IProject project, IProgressMonitor monitor) throws
CoreException {
+ monitor.subTask("Adding module core nature");
+
+ ModuleCoreNature.addModuleCoreNatureIfNecessary(project, monitor);
+ }
+
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 +108,52 @@
}
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");
- 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());
+ IProject project = javaProject.getProject();
+ monitor.subTask("Configuring output folder");
+ IPath outputFolderProjectPath = webContentProjectPath.append(new
Path(IGoogleEclipsePluginConstants.OUTPUT_FOLDER_DEFAULTVALUE));
+ 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 {
@@ -149,7 +167,8 @@
unzipWebContent(webContentPath, javaProject);
} 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));
}
}
Modified:
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java
===================================================================
---
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java 2010-09-03
16:03:16 UTC (rev 24704)
+++
branches/jbosstools-3.2.0.M2/gwt/plugins/org.jboss.tools.gwt.core/src/org/jboss/tools/gwt/core/util/ProjectUtils.java 2010-09-03
16:07:40 UTC (rev 24705)
@@ -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;
@@ -81,27 +83,6 @@
javaProject.setRawClasspath(newClasspath, monitor);
}
- /**
- * Returns the path of the web content folder in the given project. The path
- * returned is relative to the workspace.
- *
- * @param project
- * the project to return the web content folder for
- * @return the path of the web content folder (relative to the workspace)
- */
- public static IPath getWebContentRootPath(IProject project) {
- if (!ModuleCoreNature.isFlexibleProject(project)) {
- return project.getFullPath();
- }
- IPath path = null;
- IVirtualComponent component = ComponentCore.createComponent(project);
- if (component != null && component.exists()) {
- path = component.getRootFolder().getWorkspaceRelativePath();
- } else {
- path = project.getFullPath();
- }
- return path;
- }
/**
* Unzips the given ZipInputStream to the given folder.
@@ -203,5 +184,27 @@
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;
+ }
+ }
+
}