[jbosstools-commits] JBoss Tools SVN: r39939 - trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 30 09:55:06 EDT 2012


Author: dgeraskov
Date: 2012-03-30 09:55:05 -0400 (Fri, 30 Mar 2012)
New Revision: 39939

Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java
Log:
https://issues.jboss.org/browse/JBIDE-11444
Console configuration should provide persistence unit names from required projects too

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java	2012-03-30 11:56:02 UTC (rev 39938)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/ProjectUtils.java	2012-03-30 13:55:05 UTC (rev 39939)
@@ -25,8 +25,11 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
@@ -391,8 +394,42 @@
 		return res;
 	}
 	
-	@SuppressWarnings("unchecked")
-	static public String[] availablePersistenceUnits(IJavaProject javaProject) {
+	/**
+	 * Collects all persistent unit names: available in the project and required projects
+	 * @param javaProject
+	 * @return
+	 */
+	public static String[] availablePersistenceUnits(IJavaProject javaProject) {
+		if (javaProject.isOpen()){
+			Set<IJavaProject> projects = new HashSet<IJavaProject>();
+			projects.add(javaProject);
+			try {
+				String[] requiredProjectNames = javaProject.getRequiredProjectNames();
+				for (String projectName : requiredProjectNames) {
+					IProject project = findProject(projectName);
+					try {
+						if (project != null && project.isAccessible() && project.hasNature(JavaCore.NATURE_ID)){
+							projects.add(JavaCore.create(project));
+						}
+					} catch (CoreException e) {
+						HibernateConsolePlugin.getDefault().log(e);
+					}
+				}
+			} catch (JavaModelException e) {
+				HibernateConsolePlugin.getDefault().log(e);
+			}
+			Set<String> puNames = new TreeSet<String>();
+			for (IJavaProject iJavaProject : projects) {
+				for (String puName : projectPersistenceUnits(iJavaProject)) {
+					puNames.add(puName);
+				}
+			}
+			return puNames.toArray(new String[puNames.size()]);
+		}
+		return new String[0];
+	}
+	
+	private static String[] projectPersistenceUnits(IJavaProject javaProject) {
 		if (javaProject == null || javaProject.getResource() == null) {
 			return new String[0];
 		}



More information about the jbosstools-commits mailing list