Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorpfullbright2010-07-14 22:20:23 +0000
committerpfullbright2010-07-14 22:20:23 +0000
commitfc708cc05c58e6348d210418c52ec1b9e8c34b0b (patch)
treee85a848d6a11295be70af5cf2f6c8cbb31846b47 /jpa
parent218c6e4d50a647757330d65329584983c0aa5976 (diff)
downloadwebtools.dali-fc708cc05c58e6348d210418c52ec1b9e8c34b0b.tar.gz
webtools.dali-fc708cc05c58e6348d210418c52ec1b9e8c34b0b.tar.xz
webtools.dali-fc708cc05c58e6348d210418c52ec1b9e8c34b0b.zip
bug 309030 - fixed resource resolution/creation for plug-in projects
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core.properties1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java76
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/operations/AbstractJpaFileCreationDataModelProvider.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java5
6 files changed, 81 insertions, 38 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
index 0f45878634..5680244f70 100644
--- a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF
@@ -22,6 +22,7 @@ Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jst.common.project.facet.core;bundle-version="[1.3.100,2.0.0)",
org.eclipse.jst.j2ee;bundle-version="[1.1.200,1.2.0)",
org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,1.3.0)",
+ org.eclipse.pde.core;bundle-version="[3.6.0,4.0.0)";resolution:=optional,
org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.emfworkbench.integration;bundle-version="[1.1.200,2.0.0)",
org.eclipse.wst.common.frameworks;bundle-version="[1.1.200,1.3.0)",
diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core.properties
index 9eeede567a..923fca3bfa 100644
--- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_core.properties
@@ -15,7 +15,6 @@ VALIDATE_SOURCE_FOLDER_NOT_SPECIFIED=Source folder must be specified
VALIDATE_SOURCE_FOLDER_ILLEGAL=Source folder path is illegal
VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST=Source folder ''{0}'' does not exist
VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT=Source folder ''{0}'' is not in project ''{1}''
-VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER=Source folder ''{0}'' is not an actual source folder
VALIDATE_FILE_PATH_NOT_SPECIFIED=File path must be specified
VALIDATE_FILE_ALREADY_EXISTS=File already exists at this location
VALIDATE_FILE_VERSION_NOT_SUPPORTED=File version not supported
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
index e33e50703a..c298021783 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
@@ -24,6 +24,7 @@ import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IResourceProxy;
import org.eclipse.core.resources.IResourceProxyVisitor;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -78,9 +79,13 @@ import org.eclipse.jpt.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.utility.internal.iterables.SubIterableWrapper;
import org.eclipse.jpt.utility.internal.iterables.TransformationIterable;
import org.eclipse.jst.j2ee.model.internal.validation.ValidationCancelledException;
+import org.eclipse.pde.core.project.IBundleProjectDescription;
+import org.eclipse.pde.core.project.IBundleProjectService;
import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* JPA project. Holds all the JPA stuff.
@@ -189,8 +194,8 @@ public abstract class AbstractJpaProject
* generated.
*/
protected String metamodelSourceFolderName;
-
-
+
+
// ********** constructor/initialization **********
protected AbstractJpaProject(JpaProject.Config config) {
@@ -515,8 +520,8 @@ public abstract class AbstractJpaProject
* Return the new JPA file, null if it was not created.
*/
protected JpaFile addJpaFile_(IFile file) {
- if ( ! this.getJavaProject().isOnClasspath(file)) {
- return null; // the file must be on the Java classpath
+ if (! getJavaProject().isOnClasspath(file) && ! isInBundleRoot(file)) {
+ return null; // the file must be on the Java classpath or in the bundle root
}
JpaFile jpaFile = null;
@@ -535,7 +540,64 @@ public abstract class AbstractJpaProject
this.jpaFiles.add(jpaFile);
return jpaFile;
}
-
+
+ /**
+ * Returns <code>true</code> if the given resource is within the PDE bundle root folder,
+ * and <code>false</code> otherwise.
+ *
+ * @param resource a resource
+ * @return <code>true</code> if the given resource is within the bundle root, and
+ * <code>false</code> otherwise
+ */
+ private boolean isInBundleRoot(IResource resource) {
+ IFolder folder = getBundleRoot(project);
+ if (folder != null) {
+ return folder.getFullPath().isPrefixOf(resource.getFullPath());
+ }
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> if the given resource is within the PDE bundle root folder,
+ * and <code>false</code> otherwise.
+ *
+ * @param resource a resource
+ * @return <code>true</code> if the given resource is within the bundle root, and
+ * <code>false</code> otherwise
+ */
+ public static IFolder getBundleRoot(IProject project) {
+ try {
+ if (project.hasNature("org.eclipse.pde.PluginNature")) {
+ IBundleProjectService service = getBundleProjectService();
+ if (service != null) {
+ IBundleProjectDescription description = service.getDescription(project);
+ if (description != null) {
+ IPath path = description.getBundleRoot();
+ if (path != null) {
+ return project.getFolder(path);
+ }
+ }
+ }
+ }
+ }
+ catch (CoreException ce) {
+ // ignore, PDE bundle root not set
+ }
+ return null;
+ }
+
+ private static IBundleProjectService getBundleProjectService() {
+ BundleContext context = JptCorePlugin.instance().getBundle().getBundleContext();
+ ServiceReference reference = context.getServiceReference(IBundleProjectService.class.getName());
+ if (reference == null)
+ return null;
+ IBundleProjectService service = (IBundleProjectService) context.getService(reference);
+ if (service != null)
+ context.ungetService(reference);
+
+ return service;
+ }
+
/**
* Remove the JPA file corresponding to the specified IFile, if it exists.
* Return true if a JPA File was removed, false otherwise
@@ -1206,7 +1268,7 @@ public abstract class AbstractJpaProject
*/
protected boolean jpaFileIsAlive(JpaFile jpaFile) {
IFile file = jpaFile.getFile();
- return this.getJavaProject().isOnClasspath(file) &&
+ return (this.getJavaProject().isOnClasspath(file) || isInBundleRoot(file)) &&
file.exists();
}
@@ -1463,7 +1525,7 @@ public abstract class AbstractJpaProject
}
protected void externalProjectChanged(IResourceDelta delta) {
- if (this.getJavaProject().isOnClasspath(delta.getResource())) {
+ if (this.getJavaProject().isOnClasspath(delta.getResource()) || isInBundleRoot(delta.getResource())) {
ResourceDeltaVisitor resourceDeltaVisitor = this.buildExternalResourceDeltaVisitor();
resourceDeltaVisitor.visitDelta(delta);
// force an "update" here since adding and/or removing an external Java type
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java
index ec15ff5a9c..3f2de58caf 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JptCoreMessages.java
@@ -23,7 +23,6 @@ public class JptCoreMessages {
public static String VALIDATE_SOURCE_FOLDER_ILLEGAL;
public static String VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST;
public static String VALIDATE_SOURCE_FOLDER_NOT_IN_PROJECT;
- public static String VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER;
public static String VALIDATE_FILE_PATH_NOT_SPECIFIED;
public static String VALIDATE_FILE_ALREADY_EXISTS;
public static String VALIDATE_FILE_VERSION_NOT_SUPPORTED;
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 3600851036..dada8fad7a 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
@@ -18,12 +18,11 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
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.AbstractJpaProject;
import org.eclipse.jpt.core.internal.JptCoreMessages;
import org.eclipse.jpt.utility.Filter;
import org.eclipse.jpt.utility.internal.ArrayTools;
@@ -169,11 +168,6 @@ public abstract class AbstractJpaFileCreationDataModelProvider
IStatus.ERROR, JptCorePlugin.PLUGIN_ID,
NLS.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_DOES_NOT_EXIST, sourceFolderPath));
}
- if (getVerifiedJavaSourceFolder() == null) {
- return new Status(
- IStatus.ERROR, JptCorePlugin.PLUGIN_ID,
- NLS.bind(JptCoreMessages.VALIDATE_SOURCE_FOLDER_NOT_SOURCE_FOLDER, sourceFolderPath));
- }
String filePath = getStringProperty(FILE_PATH);
if (StringTools.stringIsEmpty(filePath)) {
return new Status(
@@ -235,14 +229,17 @@ public abstract class AbstractJpaFileCreationDataModelProvider
}
/**
- * Return a best guess java source folder for the specified project
+ * Return a best guess source folder for the specified project
*/
- // Copied from NewJavaClassDataModelProvider
protected IFolder getDefaultSourceFolder() {
IProject project = getProject();
if (project == null) {
return null;
}
+ IFolder folder = AbstractJpaProject.getBundleRoot(project);
+ if (folder != null) {
+ return folder;
+ }
IPackageFragmentRoot[] sources = J2EEProjectUtilities.getSourceContainers(project);
// Try and return the first source folder
if (sources.length > 0) {
@@ -313,26 +310,6 @@ public abstract class AbstractJpaFileCreationDataModelProvider
return folder;
}
- /**
- * Return the source folder, provided it is verified to be an actual java
- * source folder
- */
- protected IFolder getVerifiedJavaSourceFolder() {
- IFolder folder = getVerifiedSourceFolder();
- if (folder == null) {
- return null;
- }
- IJavaProject jProject = JavaCore.create(getProject());
- if (jProject == null) {
- return null;
- }
- IPackageFragmentRoot packageFragmentRoot = jProject.getPackageFragmentRoot(folder);
- if (packageFragmentRoot == null || ! packageFragmentRoot.exists()) {
- return null;
- }
- return folder;
- }
-
protected IFile getExistingFile() {
IFolder folder = getVerifiedSourceFolder();
if (folder == null) {
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java
index 7ad77b4cd3..090223a148 100644
--- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/orm/MappingFileWizardPage.java
@@ -26,6 +26,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.Window;
+import org.eclipse.jpt.core.internal.AbstractJpaProject;
import org.eclipse.jpt.core.internal.operations.OrmFileCreationDataModelProperties;
import org.eclipse.jpt.core.internal.utility.jdt.JDTTools;
import org.eclipse.jpt.ui.JptUiPlugin;
@@ -271,6 +272,10 @@ public class MappingFileWizardPage extends DataModelWizardPage
if (JDTTools.packageFragmentRootIsSourceFolder(javaProject.getPackageFragmentRoot(folder))) {
return true;
}
+ // add bundle root, if it exists
+ if (element.equals(AbstractJpaProject.getBundleRoot(project))) {
+ return true;
+ }
}
return false;
}

Back to the top