Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpfullbright2011-02-11 22:24:38 +0000
committerpfullbright2011-02-11 22:24:38 +0000
commit3631ad6e4ea4d14fddfbbaf1694683df803bbfe9 (patch)
tree75ddbc1f8a0bb1a04b0e74d61365d341919316b4
parenteb70500b638d1d02984e90a349f774137573fcfa (diff)
downloadwebtools.dali-3631ad6e4ea4d14fddfbbaf1694683df803bbfe9.tar.gz
webtools.dali-3631ad6e4ea4d14fddfbbaf1694683df803bbfe9.tar.xz
webtools.dali-3631ad6e4ea4d14fddfbbaf1694683df803bbfe9.zip
bug 336553 - fixed file creation in projects with locations other than workspaceR2_3_3
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java20
3 files changed, 29 insertions, 25 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
index cbed042a7e..294f28f531 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java
@@ -15,7 +15,6 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
@@ -26,6 +25,7 @@ import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.internal.AbstractJpaProject;
import org.eclipse.jpt.core.internal.JptCoreMessages;
+import org.eclipse.jpt.core.internal.utility.PlatformTools;
import org.eclipse.jpt.utility.Filter;
import org.eclipse.jpt.utility.internal.ArrayTools;
import org.eclipse.jpt.utility.internal.CollectionTools;
@@ -262,13 +262,11 @@ public abstract class AbstractJpaFileCreationDataModelProvider
if (project == null) {
return false;
}
- try {
- IWorkspaceRoot root = project.getWorkspace().getRoot();
- return root.getContainerForLocation(root.getLocation().append(new Path(containerPath))) == null;
- }
- catch (IllegalArgumentException e) {
+ IContainer container = PlatformTools.getContainer(new Path(containerPath));
+ if (container == null) {
return true;
}
+ return false;
}
/**
@@ -279,14 +277,8 @@ public abstract class AbstractJpaFileCreationDataModelProvider
if (project == null) {
return false;
}
- IFolder folder;
- try {
- folder = project.getWorkspace().getRoot().getFolder(new Path(folderPath));
- }
- catch (IllegalArgumentException e) {
- return false;
- }
- return ! project.equals(folder.getProject());
+ IContainer container = PlatformTools.getContainer(new Path(folderPath));
+ return ! project.equals(container.getProject());
}
/**
@@ -299,14 +291,7 @@ public abstract class AbstractJpaFileCreationDataModelProvider
if (project == null) {
return null;
}
- IContainer container;
- try {
- IWorkspaceRoot root = project.getWorkspace().getRoot();
- container = root.getContainerForLocation(root.getLocation().append(new Path(folderPath)));
- }
- catch (IllegalArgumentException e) {
- return null;
- }
+ IContainer container = PlatformTools.getContainer(new Path(folderPath));
if (container == null || ! container.exists()) {
return null;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java
index 922308d027..1a20efd62f 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationOperation.java
@@ -14,7 +14,6 @@ import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -24,6 +23,7 @@ import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jem.util.emf.workbench.ProjectUtilities;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.internal.utility.PlatformTools;
import org.eclipse.jpt.core.resource.AbstractXmlResourceProvider;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
@@ -88,8 +88,7 @@ public abstract class AbstractJpaFileCreationOperation
// Get the source folder name from the data model
String folderPath = model.getStringProperty(SOURCE_FOLDER);
IProject project = getProject();
- IWorkspaceRoot root = project.getWorkspace().getRoot();
- IContainer container = root.getContainerForLocation(root.getLocation().append(new Path(folderPath)));
+ IContainer container = PlatformTools.getContainer(new Path(folderPath));
boolean createVirtualReference = ComponentCore.createFolder(project, new Path("")).exists();
if (container instanceof IFolder) {
IFolder folder = (IFolder) container;
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java
index 1974095648..43f461e4f0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java
@@ -11,8 +11,13 @@ package org.eclipse.jpt.core.internal.utility;
import java.io.IOException;
import java.io.InputStream;
+import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
@@ -24,6 +29,21 @@ import org.eclipse.jpt.core.JptCorePlugin;
public class PlatformTools {
/**
+ * Return the {@link IContainer} with the workspace relative "full" path
+ */
+ public static IContainer getContainer(IPath fullContainerPath) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ // changed to handle non-workspace projects
+ String projectName = fullContainerPath.segment(0).toString();
+ IPath projectRelativePath = fullContainerPath.removeFirstSegments(1);
+ IProject project = root.getProject(projectName);
+ if (projectRelativePath.isEmpty()) {
+ return project;
+ }
+ return project.getFolder(projectRelativePath);
+ }
+
+ /**
* Return the specified file's content type,
* using the Eclipse platform's content type manager.
*/

Back to the top