Author: fbricon
Date: 2012-04-18 06:10:43 -0400 (Wed, 18 Apr 2012)
New Revision: 40274
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jpa/META-INF/MANIFEST.MF
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/JptUtils.java
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/MavenResourceLocator.java
Log:
JBIDE-11557 : Use reflection to make the JPA Maven configurator compatible with Juno
Modified: trunk/maven/plugins/org.jboss.tools.maven.jpa/META-INF/MANIFEST.MF
===================================================================
--- trunk/maven/plugins/org.jboss.tools.maven.jpa/META-INF/MANIFEST.MF 2012-04-18 09:09:41
UTC (rev 40273)
+++ trunk/maven/plugins/org.jboss.tools.maven.jpa/META-INF/MANIFEST.MF 2012-04-18 10:10:43
UTC (rev 40274)
@@ -8,7 +8,6 @@
org.eclipse.core.runtime,
org.jboss.tools.maven.core,
org.jboss.tools.maven.ui,
- org.jboss.tools.common.model,
org.eclipse.jst.j2ee.core,
org.eclipse.jst.j2ee,
org.eclipse.wst.common.emfworkbench.integration,
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/JptUtils.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/JptUtils.java 2012-04-18
09:09:41 UTC (rev 40273)
+++
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/JptUtils.java 2012-04-18
10:10:43 UTC (rev 40274)
@@ -10,6 +10,7 @@
************************************************************************************/
package org.jboss.tools.maven.jpa.configurators;
+import java.lang.reflect.Method;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -36,7 +37,7 @@
* @return the IFile persitence.xml handle. Can be null.
*/
public static IFile getPersistenceXml(IProject project) {
- ResourceLocator resourceLocator = JptCommonCorePlugin.getResourceLocator(project);
+ ResourceLocator resourceLocator = getResourceLocator(project);
if (resourceLocator == null) {
return null;
}
@@ -75,5 +76,30 @@
}
return JpaFacet.FACET.getVersion(version);
}
+
+ public static ResourceLocator getResourceLocator(IProject project) {
+ Method getResourceLocator;
+ try {
+ getResourceLocator =
JptCommonCorePlugin.class.getMethod("getResourceLocator", IProject.class);
+ if(getResourceLocator!=null) {
+ return (ResourceLocator)getResourceLocator.invoke(null, project);
+ }
+ } catch (NoSuchMethodException e) {
+ try {
+ Class<?> resourceLocatorManagerClass =
Class.forName("org.eclipse.jpt.common.core.internal.resource.ResourceLocatorManager");
+ Object instance = resourceLocatorManagerClass.getMethod("getInstance",
null).invoke(null, null);
+ getResourceLocator =
resourceLocatorManagerClass.getMethod("getResourceLocator", IProject.class);
+ if(getResourceLocator!=null) {
+ return (ResourceLocator)getResourceLocator.invoke(instance, project);
+ } ;
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
}
Modified:
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/MavenResourceLocator.java
===================================================================
---
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/MavenResourceLocator.java 2012-04-18
09:09:41 UTC (rev 40273)
+++
trunk/maven/plugins/org.jboss.tools.maven.jpa/src/org/jboss/tools/maven/jpa/configurators/MavenResourceLocator.java 2012-04-18
10:10:43 UTC (rev 40274)
@@ -11,6 +11,7 @@
package org.jboss.tools.maven.jpa.configurators;
import java.io.File;
+import java.lang.reflect.Method;
import java.util.List;
import org.apache.maven.model.Resource;
@@ -56,7 +57,7 @@
* Accepts all resources not under the build output and test build output
* folders
*/
- public boolean acceptResourceLocation(IProject project, IContainer container) {
+ public boolean resourceLocationIsValid(IProject project, IContainer container) {
IMavenProjectFacade mavenProjectFacade = getMavenProjectFacade(project);
boolean accept = true;
if (mavenProjectFacade != null
@@ -72,7 +73,7 @@
} else {
// Maven project not loaded yet, fallback to default behaviour.
//System.err.println(project + " not loaded");
- accept = getDelegate(project).acceptResourceLocation(project, container);
+ accept = isResourceLocationValid(getDelegate(project), project, container);
}
// Sometimes src/main/resources/META-INF is not even sent immediately to
// this method, resulting in persistence.xml not being added to the jpaFiles
@@ -208,4 +209,34 @@
IPath runtimePath = getDelegate(project).getRuntimePath(project, resourcePath);
return runtimePath;
}
+
+ /**
+ * @deprecated use {@link #acceptResourceLocation(IProject, IContainer)} instead
+ */
+ @Deprecated
+ public boolean acceptResourceLocation(IProject project, IContainer container) {
+ return resourceLocationIsValid(project, container);
+ }
+
+
+ //Ugly workaround to deal with Dali API changes in Juno and keep backward compatibility
with Indigo
+ private static boolean isResourceLocationValid(ResourceLocator resourceLocator, IProject
project, IContainer container) {
+ Method isResourceLocationIsValid = null;
+ for (Method m : resourceLocator.getClass().getMethods()) {
+ if ("isResourceLocationIsValid".equals(m.getName()) ||
"acceptResourceLocation".equals(m.getName())) {
+ isResourceLocationIsValid = m;
+ break;
+ }
+ }
+ boolean result = false;
+ if (isResourceLocationIsValid != null) {
+ try {
+ result = (Boolean)isResourceLocationIsValid.invoke(resourceLocator, project,
container);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return result;
+ }
+
}
\ No newline at end of file