[jbosstools-commits] JBoss Tools SVN: r23969 - in trunk/hibernatetools: plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Aug 6 09:18:58 EDT 2010


Author: vyemialyanchyk
Date: 2010-08-06 09:18:57 -0400 (Fri, 06 Aug 2010)
New Revision: 23969

Added:
   trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml
   trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test2.xml
Modified:
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
   trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java
   trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
Log:
https://jira.jboss.org/browse/JBIDE-6750 - fixed

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java	2010-08-06 12:31:01 UTC (rev 23968)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java	2010-08-06 13:18:57 UTC (rev 23969)
@@ -41,10 +41,6 @@
 		this.additional = additional;
 	}
 
-	public ConsoleConfigurationPreferences getPreferences() {
-		return prefs;
-	}
-
 	public Document createXML() {
 		Document res = DocumentFactory.getInstance().createDocument();
 		Element root = createRoot();
@@ -53,13 +49,12 @@
 	}
 
 	public Element createRoot() {
+		if (prefs == null) {
+			return null;
+		}
+		@SuppressWarnings("unused")
 		Properties properties = prefs.getProperties();
-		Element root = createRoot(properties);
-		return root;
-	}
-
-	protected Element createRoot(Properties properties) {
-		String rootName = null;
+		String rootName = "undef"; //$NON-NLS-1$
 		Boolean jdbcConfig = Boolean.valueOf(additional.getProperty(ConfigurationXMLStrings.ISREVENG, "false")); //$NON-NLS-1$
 		if (jdbcConfig) {
 			rootName = ConfigurationXMLStrings.JDBCCONFIGURATION;
@@ -69,15 +64,13 @@
 			rootName = ConfigurationXMLStrings.JPACONFIGURATION;
 		} else if (prefs.getConfigurationMode().equals(ConfigurationMode.CORE)) {
 			rootName = ConfigurationXMLStrings.CONFIGURATION;
-		} else {
-			rootName = "undef"; //$NON-NLS-1$
 		}
 		Element root = DocumentFactory.getInstance().createElement(rootName);
-		updateAttr(root, file2Str(getPreferences().getConfigXMLFile()), ConfigurationXMLStrings.CONFIGURATIONFILE);
-		updateAttr(root, file2Str(getPreferences().getPropertyFile()), ConfigurationXMLStrings.PROPERTYFILE);
-		updateAttr(root, getPreferences().getEntityResolverName(), ConfigurationXMLStrings.ENTITYRESOLVER);
-		updateAttr(root, getPreferences().getNamingStrategy(), ConfigurationXMLStrings.NAMINGSTRATEGY);
-		updateAttr(root, getPreferences().getPersistenceUnitName(), ConfigurationXMLStrings.PERSISTENCEUNIT);
+		updateAttr(root, file2Str(prefs.getConfigXMLFile()), ConfigurationXMLStrings.CONFIGURATIONFILE);
+		updateAttr(root, file2Str(prefs.getPropertyFile()), ConfigurationXMLStrings.PROPERTYFILE);
+		updateAttr(root, prefs.getEntityResolverName(), ConfigurationXMLStrings.ENTITYRESOLVER);
+		updateAttr(root, prefs.getNamingStrategy(), ConfigurationXMLStrings.NAMINGSTRATEGY);
+		updateAttr(root, prefs.getPersistenceUnitName(), ConfigurationXMLStrings.PERSISTENCEUNIT);
 		updateAttr(root, additional, ConfigurationXMLStrings.DETECTMANYTOMANY);
 		updateAttr(root, additional, ConfigurationXMLStrings.DETECTONTTOONE);
 		updateAttr(root, additional, ConfigurationXMLStrings.DETECTOPTIMISTICLOCK);

Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java	2010-08-06 12:31:01 UTC (rev 23968)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java	2010-08-06 13:18:57 UTC (rev 23969)
@@ -23,9 +23,11 @@
 	 * get custom classpath URLs 
 	 */
 	public static URL[] getCustomClassPathURLs(ConsoleConfigurationPreferences prefs) {
-		URL[] customClassPathURLsTmp = prefs.getCustomClassPathURLS();
+		URL[] customClassPathURLsTmp = prefs == null ? new URL[0] :
+			prefs.getCustomClassPathURLS();
 		URL[] customClassPathURLs = null;
-		String driverURL = ConnectionProfileUtil.getConnectionProfileDriverURL(prefs.getConnectionProfileName());
+		String driverURL = prefs == null ? null :
+			ConnectionProfileUtil.getConnectionProfileDriverURL(prefs.getConnectionProfileName());
 		URL[] urls = null;
 		if (driverURL != null) {
 			String[] driverURLParts = driverURL.split(";"); //$NON-NLS-1$

Added: trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml	                        (rev 0)
+++ trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test1.xml	2010-08-06 13:18:57 UTC (rev 23969)
@@ -0,0 +1,35 @@
+<project name="CodeGen" default="hibernateAntCodeGeneration">
+  <property name="build.dir" location="reslocation/test"/>
+  <path id="toolslib"/>
+  <target name="hibernateAntCodeGeneration">
+    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib"/>
+    <hibernatetool destdir="${build.dir}">
+      <classpath>
+        <path location="${build.dir}"/>
+      </classpath>
+      <hbm2doc>
+        <property key="ejb3" value="false"/>
+        <property key="jdk5" value="false"/>
+      </hbm2doc>
+      <hbm2cfgxml>
+        <property key="jdk5" value="false"/>
+      </hbm2cfgxml>
+      <hbm2hbmxml>
+        <property key="ejb3" value="false"/>
+        <property key="jdk5" value="false"/>
+      </hbm2hbmxml>
+      <hbmtemplate>
+        <property key="ejb3" value="false"/>
+        <property key="jdk5" value="false"/>
+      </hbmtemplate>
+      <hbm2java destdir="outputdir/test">
+        <property key="keyXXX" value="valueYYY"/>
+      </hbm2java>
+      <hbm2ddl>
+        <property key="ejb3" value="false"/>
+        <property key="jdk5" value="false"/>
+      </hbm2ddl>
+      <hbm2dao/>
+    </hibernatetool>
+  </target>
+</project>
\ No newline at end of file

Added: trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test2.xml
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test2.xml	                        (rev 0)
+++ trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/sample/AntCodeGenNullable_test2.xml	2010-08-06 13:18:57 UTC (rev 23969)
@@ -0,0 +1,15 @@
+<project name="CodeGen" default="hibernateAntCodeGeneration">
+  <property name="build.dir" location="reslocation/test"/>
+  <path id="toolslib"/>
+  <target name="hibernateAntCodeGeneration">
+    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib"/>
+    <hibernatetool destdir="${build.dir}">
+      <classpath>
+        <path location="${build.dir}"/>
+      </classpath>
+      <hbm2java destdir="outputdir/test">
+        <property key="keyXXX" value="valueYYY"/>
+      </hbm2java>
+    </hibernatetool>
+  </target>
+</project>
\ No newline at end of file

Modified: trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java	2010-08-06 12:31:01 UTC (rev 23968)
+++ trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java	2010-08-06 13:18:57 UTC (rev 23969)
@@ -108,21 +108,27 @@
 		}
 	}
 
+	public enum ETestCase {
+		simple,
+		jpa,
+		nullable,
+	}
+	
 	public class CodeGenXMLFactory4Test extends CodeGenXMLFactory {
 		
-		protected boolean jpa = false;
+		protected ETestCase testCase = ETestCase.simple;
 
-		public CodeGenXMLFactory4Test(ILaunchConfiguration lc, boolean jpa) {
+		public CodeGenXMLFactory4Test(ILaunchConfiguration lc, ETestCase testCase) {
 			super(lc);
-			this.jpa = jpa;
+			this.testCase = testCase;
 		}
 
 		public ConsoleConfigurationPreferences getConsoleConfigPreferences(String consoleConfigName) {
-			ConsoleConfigurationPreferences pref;
-			if (jpa) {
+			ConsoleConfigurationPreferences pref = null;
+			if (testCase == ETestCase.simple) {
+				pref = new TestConsoleConfigPref();
+			} else if (testCase == ETestCase.jpa) {
 				pref = new TestConsoleConfigPref2();
-			} else {
-				pref = new TestConsoleConfigPref();
 			}
 			return pref;
 		}
@@ -137,42 +143,56 @@
 	}
 
 	public void testCodeGenXMLFactoryRevengAll() {
-		String codeGen = codeGenXMLFactory(true, true, false);
+		String codeGen = codeGenXMLFactory(true, true, ETestCase.simple);
 		String specimen = getSample("AntCodeGenReveng_test1.xml"); //$NON-NLS-1$
 		assertEquals(specimen.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public void testCodeGenXMLFactoryRevengOne() {
-		String codeGen = codeGenXMLFactory(true, false, false);
+		String codeGen = codeGenXMLFactory(true, false, ETestCase.simple);
 		String sample = getSample("AntCodeGenReveng_test2.xml"); //$NON-NLS-1$
 		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public void testCodeGenXMLFactoryAll() {
-		String codeGen = codeGenXMLFactory(false, true, false);
+		String codeGen = codeGenXMLFactory(false, true, ETestCase.simple);
 		String sample = getSample("AntCodeGen_test1.xml"); //$NON-NLS-1$
 		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public void testCodeGenXMLFactoryOne() {
-		String codeGen = codeGenXMLFactory(false, false, false);
+		String codeGen = codeGenXMLFactory(false, false, ETestCase.simple);
 		String sample = getSample("AntCodeGen_test2.xml"); //$NON-NLS-1$
 		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public void testCodeGenXMLFactoryJpaAll() {
-		String codeGen = codeGenXMLFactory(false, true, true);
+		String codeGen = codeGenXMLFactory(false, true, ETestCase.jpa);
 		codeGen = updatePaths(codeGen);
 		String sample = getSample("AntCodeGenJpa_test1.xml"); //$NON-NLS-1$
 		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
 
 	public void testCodeGenXMLFactoryJpaOne() {
-		String codeGen = codeGenXMLFactory(false, false, true);
+		String codeGen = codeGenXMLFactory(false, false, ETestCase.jpa);
 		codeGen = updatePaths(codeGen);
 		String sample = getSample("AntCodeGenJpa_test2.xml"); //$NON-NLS-1$
 		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
 	}
+
+	public void testCodeGenXMLFactoryNullableAll() {
+		String codeGen = codeGenXMLFactory(false, true, ETestCase.nullable);
+		codeGen = updatePaths(codeGen);
+		String sample = getSample("AntCodeGenNullable_test1.xml"); //$NON-NLS-1$
+		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+	public void testCodeGenXMLFactoryNullableOne() {
+		String codeGen = codeGenXMLFactory(false, false, ETestCase.nullable);
+		codeGen = updatePaths(codeGen);
+		String sample = getSample("AntCodeGenNullable_test2.xml"); //$NON-NLS-1$
+		assertEquals(sample.trim(), codeGen.replaceAll("\n", "\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
+	}
 	
 	public String updatePaths(String codeGen) {
 		String repl = ""; //$NON-NLS-1$
@@ -185,14 +205,14 @@
 		return codeGen.replace(repl + File.separator, ""); //$NON-NLS-1$
 	}
 
-	public String codeGenXMLFactory(boolean reveng, boolean exportersAll, boolean jpa) {
+	public String codeGenXMLFactory(boolean reveng, boolean exportersAll, ETestCase testCase) {
 		Map<String, ExporterDefinition> exDefinitions = ExtensionManager.findExporterDefinitionsAsMap();
 		Map<String, Object> testLaunchConfigAttr = new HashMap<String, Object>();
 		String tmp = "12345678901234567890"; //$NON-NLS-1$
 		testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, tmp);
 		testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR, tmp);
 		testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS, tmp);
-		if (jpa) {
+		if (testCase == ETestCase.jpa) {
 			testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
 			testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
 		}
@@ -225,7 +245,7 @@
 		testLaunchConfigAttr.put(HBMTEMPLATE0_PROPERTIES, expProps2);
 		testLaunchConfigAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, reveng);
 		TestLaunchConfig testLaunchConfig = new TestLaunchConfig(testLaunchConfigAttr);
-		CodeGenXMLFactory codeGenFactory = new CodeGenXMLFactory4Test(testLaunchConfig, jpa);
+		CodeGenXMLFactory codeGenFactory = new CodeGenXMLFactory4Test(testLaunchConfig, testCase);
 		return codeGenFactory.createCodeGenXML();
 	}
 



More information about the jbosstools-commits mailing list