[jbosstools-commits] JBoss Tools SVN: r40946 - in trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console: workbench and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri May 11 04:01:16 EDT 2012


Author: dgeraskov
Date: 2012-05-11 04:01:15 -0400 (Fri, 11 May 2012)
New Revision: 40946

Added:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/Messages.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ProjectCompilerVersionChecker.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/messages.properties
Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/ExecuteQueryAction.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java
Log:
https://issues.jboss.org/browse/JBIDE-11773
Warn user about the problem with JDK levels

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/ExecuteQueryAction.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/ExecuteQueryAction.java	2012-05-11 06:33:15 UTC (rev 40945)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/actions/ExecuteQueryAction.java	2012-05-11 08:01:15 UTC (rev 40946)
@@ -31,6 +31,7 @@
 import org.hibernate.eclipse.console.HibernateConsolePlugin;
 import org.hibernate.eclipse.console.QueryEditor;
 import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.workbench.ProjectCompilerVersionChecker;
 
 /**
  * @author max
@@ -65,21 +66,23 @@
 		if (cfg != null) {
 			//keep states of ConsoleConfiguration and HibernateExtension synchronized
 			if (!(cfg.isSessionFactoryCreated() && cfg.getHibernateExtension().isSessionFactoryCreated())) {
-				if (queryEditor.askUserForConfiguration(cfg.getName())) {
-					if (!(cfg.hasConfiguration() && cfg.getHibernateExtension().hasConfiguration())) {
-	    				try {
-	    					cfg.build();
-	    				} catch (HibernateException he) {
-	    					HibernateConsolePlugin.getDefault().showError(
-	    						HibernateConsolePlugin.getShell(), 
-	    						HibernateConsoleMessages.LoadConsoleCFGCompletionProposal_could_not_load_configuration +
-	    						' ' + cfg.getName(), he);
-	    				}
+				if (ProjectCompilerVersionChecker.validateProjectComplianceLevel(cfg)){
+					if (queryEditor.askUserForConfiguration(cfg.getName())) {
+						if (!(cfg.hasConfiguration() && cfg.getHibernateExtension().hasConfiguration())) {
+		    				try {
+		    					cfg.build();
+		    				} catch (HibernateException he) {
+		    					HibernateConsolePlugin.getDefault().showError(
+		    						HibernateConsolePlugin.getShell(), 
+		    						HibernateConsoleMessages.LoadConsoleCFGCompletionProposal_could_not_load_configuration +
+		    						' ' + cfg.getName(), he);
+		    				}
+						}
+						if (cfg.hasConfiguration() && cfg.getHibernateExtension().hasConfiguration()) {
+							cfg.buildSessionFactory();
+							queryEditor.executeQuery(cfg);
+						}
 					}
-					if (cfg.hasConfiguration() && cfg.getHibernateExtension().hasConfiguration()) {
-						cfg.buildSessionFactory();
-						queryEditor.executeQuery(cfg);
-					}
 				}
 			} else {
 				queryEditor.executeQuery(cfg);

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java	2012-05-11 06:33:15 UTC (rev 40945)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ConsoleConfigurationWorkbenchAdapter.java	2012-05-11 08:01:15 UTC (rev 40946)
@@ -32,8 +32,11 @@
 
 public class ConsoleConfigurationWorkbenchAdapter extends BasicWorkbenchAdapter {
 
-	public Object[] getChildren(Object o) {
+	public Object[] getChildren(Object o) {		
 		final ConsoleConfiguration ccfg = getConsoleConfiguration( o );
+		if (!ProjectCompilerVersionChecker.validateProjectComplianceLevel(ccfg)){
+			return new Object[0];
+		}
 		//String sfError = null;
 		if(!ccfg.hasConfiguration()) {
 			ccfg.build();

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/Messages.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/Messages.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/Messages.java	2012-05-11 08:01:15 UTC (rev 40946)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.workbench;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author Dmitry Geraskov (geraskov at gmail.com)
+ *
+ */
+public class Messages extends NLS {
+	private static final String BUNDLE_NAME = "org.hibernate.eclipse.console.workbench.messages"; //$NON-NLS-1$
+	public static String ProjectCompilerVersionChecker_title;
+	public static String ProjectCompilerVersionChecker_message;
+	static {
+		// initialize resource bundle
+		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+	}
+
+	private Messages() {
+	}
+}

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ProjectCompilerVersionChecker.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ProjectCompilerVersionChecker.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/ProjectCompilerVersionChecker.java	2012-05-11 08:01:15 UTC (rev 40946)
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ *     Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.workbench;
+
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Display;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.eclipse.console.utils.ProjectUtils;
+
+/**
+ * @author Dmitry Geraskov (geraskov at gmail.com)
+ *
+ */
+ at SuppressWarnings("restriction")
+public class ProjectCompilerVersionChecker {
+	
+	/**
+	 * 
+	 * @param ccfg
+	 * @return false if Projects jdk version is bigger than Eclipse jdk version
+	 */
+	public static boolean validateProjectComplianceLevel(final ConsoleConfiguration ccfg){
+		IJavaProject[] javaProjects = ProjectUtils.findJavaProjects(ccfg);
+		if (javaProjects.length > 0){
+			for (final IJavaProject iJavaProject : javaProjects) {
+				if (iJavaProject.exists()) {
+					String projectTarget = iJavaProject.getOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, true);
+					String eclipseCompilerVersion = System.getProperty("java.specification.version"); //$NON-NLS-1$
+					long projectJdkLevel = CompilerOptions.versionToJdkLevel(projectTarget);
+					long eclipseJdkLevel = CompilerOptions.versionToJdkLevel(eclipseCompilerVersion);
+					if (eclipseJdkLevel <= projectJdkLevel){
+						Display.getDefault().syncExec(new Runnable(){
+							@Override
+							public void run() {
+								MessageDialog.openWarning(null, Messages.ProjectCompilerVersionChecker_title, 
+										NLS.bind(Messages.ProjectCompilerVersionChecker_message, iJavaProject.getElementName()));
+							}
+						});
+						return false;
+					}
+				}
+			}
+		}
+		return true;
+	}
+}

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/messages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/messages.properties	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/messages.properties	2012-05-11 08:01:15 UTC (rev 40946)
@@ -0,0 +1,2 @@
+ProjectCompilerVersionChecker_title=Wrong Compiler Settings
+ProjectCompilerVersionChecker_message=Project ''{0}'' has higher compiler option than running Eclipse. Hibernate plugins unable to load its classes. Please decrease the compiler option or run the Eclipse with higher JDK level



More information about the jbosstools-commits mailing list