Author: vyemialyanchyk
Date: 2010-07-14 09:24:36 -0400 (Wed, 14 Jul 2010)
New Revision: 23403
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test2.xml
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test2.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test1.xml
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test2.xml
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/ConsolePluginAllTests.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/launchcfg/TestConsoleConfigurationPreferences.java
Log:
https://jira.jboss.org/browse/JBIDE-6595 - fix for (5), (6), (7), (8), (9), (10)
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -27,6 +27,7 @@
public static final String ENTITYRESOLVER = "entityResolver"; //$NON-NLS-1$
public static final String NAMINGSTRATEGY = "namingStrategy"; //$NON-NLS-1$
public static final String PERSISTENCEUNIT = "persistenceUnit"; //$NON-NLS-1$
+ public static final String PREFERBASICCOMPOSITEIDS =
"preferBasicCompositeIds"; //$NON-NLS-1$
public static final String DETECTMANYTOMANY = "detectManyToMany";
//$NON-NLS-1$
public static final String DETECTONTTOONE = "detectOneToOne"; //$NON-NLS-1$
public static final String DETECTOPTIMISTICLOCK = "detectOptimisticLock";
//$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationFactory.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -207,7 +207,7 @@
overrides.put("hibernate.ejb.naming_strategy", prefs.getNamingStrategy());
//$NON-NLS-1$
}
if (StringHelper.isNotEmpty(prefs.getDialectName())) {
- overrides.put("hibernate.dialect", prefs.getDialectName()); //$NON-NLS-1$
+ overrides.put(Environment.DIALECT, prefs.getDialectName());
}
if (!includeMappings) {
overrides.put("hibernate.archive.autodetection", "none");
//$NON-NLS-1$//$NON-NLS-2$
@@ -274,7 +274,7 @@
localCfg = configureConnectionProfile(localCfg);
// replace dialect if it is set in preferences
if (StringHelper.isNotEmpty(prefs.getDialectName())) {
- localCfg.setProperty("hibernate.dialect", prefs.getDialectName());
//$NON-NLS-1$
+ localCfg.setProperty(Environment.DIALECT, prefs.getDialectName());
}
return localCfg;
}
@@ -367,15 +367,14 @@
}
private Configuration configureConnectionProfile(Configuration localCfg) {
- String connectionProfile = prefs.getConnectionProfileName();
- if (connectionProfile == null) {
+ String connProfileName = prefs.getConnectionProfileName();
+ if (connProfileName == null) {
return localCfg;
}
IConnectionProfile profile = ProfileManager.getInstance().getProfileByName(
- connectionProfile);
+ connProfileName);
if (profile != null) {
- DriverInstance driverInstance =
- ConnectionProfileUtil.getDriverDefinition(prefs.getConnectionProfileName());
+ DriverInstance driverInstance =
ConnectionProfileUtil.getDriverDefinition(connProfileName);
final Properties cpProperties = profile.getProperties(profile.getProviderId());
final Properties invokeProperties = localCfg.getProperties();
// set this property to null!
@@ -405,7 +404,7 @@
} else {
String out = NLS.bind(
ConsoleMessages.ConsoleConfiguration_connection_profile_not_found,
- connectionProfile);
+ connProfileName);
throw new HibernateConsoleRuntimeException(out);
}
return localCfg;
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-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -87,7 +87,7 @@
File[] mappingFiles = prefs.getMappingFiles();
if (mappingFiles.length > 0) {
Element fileset = root.addElement("fileset"); //$NON-NLS-1$
- fileset.addAttribute("dir", "./src"); //$NON-NLS-1$ //$NON-NLS-2$
+ fileset.addAttribute("dir", "."); //$NON-NLS-1$ //$NON-NLS-2$
fileset.addAttribute("id", "id"); //$NON-NLS-1$ //$NON-NLS-2$
for (int i = 0; i < mappingFiles.length; i++) {
Element include = fileset.addElement("include"); //$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -22,7 +22,6 @@
package org.hibernate.console;
import java.io.File;
-import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
@@ -46,6 +45,7 @@
import org.hibernate.console.execution.ExecutionContextHolder;
import org.hibernate.console.execution.ExecutionContext.Command;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import org.hibernate.console.preferences.PreferencesClassPathUtils;
public class ConsoleConfiguration implements ExecutionContextHolder {
@@ -117,61 +117,9 @@
configuration = buildWith(null, true);
fireConfigurationBuilt();
}
-
- /*
- * get custom classpath URLs
- */
- protected URL[] getCustomClassPathURLs() {
- URL[] customClassPathURLsTmp = prefs.getCustomClassPathURLS();
- URL[] customClassPathURLs = null;
- String driverURL =
ConnectionProfileUtil.getConnectionProfileDriverURL(prefs.getConnectionProfileName());
- URL[] urls = null;
- if (driverURL != null) {
- String[] driverURLParts = driverURL.split(";"); //$NON-NLS-1$
- urls = new URL[driverURLParts.length];
- for (int i = 0; i < driverURLParts.length; i++) {
- try {
- urls[i] = new URL("file:/" + driverURLParts[i].trim()); //$NON-NLS-1$
- } catch (MalformedURLException e) {
- urls[i] = null;
- }
- }
- }
- // should DTP connection profile driver jar file be inserted
- int insertItems = ( urls != null ) ? urls.length : 0;
- if (insertItems > 0) {
- insertItems = 0;
- for (int i = 0; i < urls.length; i++) {
- if (urls[i] == null) {
- continue;
- }
- int j = 0;
- for (; j < customClassPathURLsTmp.length; j++) {
- if (customClassPathURLsTmp[j].equals(urls[i])) {
- break;
- }
- }
- if (j == customClassPathURLsTmp.length) {
- urls[insertItems++] = urls[i];
- }
- }
- }
- if (insertItems > 0) {
- customClassPathURLs = new URL[customClassPathURLsTmp.length + insertItems];
- System.arraycopy(customClassPathURLsTmp, 0,
- customClassPathURLs, 0, customClassPathURLsTmp.length);
- // insert DTP connection profile driver jar file URL after the default classpath
entries
- for (int i = 0; i < insertItems; i++) {
- customClassPathURLs[customClassPathURLsTmp.length + i] = urls[i];
- }
- } else {
- customClassPathURLs = customClassPathURLsTmp;
- }
- return customClassPathURLs;
- }
protected ConsoleConfigClassLoader createClassLoader() {
- final URL[] customClassPathURLs = getCustomClassPathURLs();
+ final URL[] customClassPathURLs =
PreferencesClassPathUtils.getCustomClassPathURLs(prefs);
ConsoleConfigClassLoader classLoader = AccessController.doPrivileged(new
PrivilegedAction<ConsoleConfigClassLoader>() {
public ConsoleConfigClassLoader run() {
return new ConsoleConfigClassLoader(customClassPathURLs, getParentClassLoader()) {
Added:
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
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/preferences/PreferencesClassPathUtils.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2010 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.console.preferences;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.hibernate.console.ConnectionProfileUtil;
+
+/**
+ * Utils class to extract classpath urls from ConsoleConfigurationPreferences
+ */
+public class PreferencesClassPathUtils {
+ /*
+ * get custom classpath URLs
+ */
+ public static URL[] getCustomClassPathURLs(ConsoleConfigurationPreferences prefs) {
+ URL[] customClassPathURLsTmp = prefs.getCustomClassPathURLS();
+ URL[] customClassPathURLs = null;
+ String driverURL =
ConnectionProfileUtil.getConnectionProfileDriverURL(prefs.getConnectionProfileName());
+ URL[] urls = null;
+ if (driverURL != null) {
+ String[] driverURLParts = driverURL.split(";"); //$NON-NLS-1$
+ urls = new URL[driverURLParts.length];
+ for (int i = 0; i < driverURLParts.length; i++) {
+ try {
+ urls[i] = new URL("file:/" + driverURLParts[i].trim()); //$NON-NLS-1$
+ } catch (MalformedURLException e) {
+ urls[i] = null;
+ }
+ }
+ }
+ // should DTP connection profile driver jar file be inserted
+ int insertItems = ( urls != null ) ? urls.length : 0;
+ if (insertItems > 0) {
+ insertItems = 0;
+ for (int i = 0; i < urls.length; i++) {
+ if (urls[i] == null) {
+ continue;
+ }
+ int j = 0;
+ for (; j < customClassPathURLsTmp.length; j++) {
+ if (customClassPathURLsTmp[j].equals(urls[i])) {
+ break;
+ }
+ }
+ if (j == customClassPathURLsTmp.length) {
+ urls[insertItems++] = urls[i];
+ }
+ }
+ }
+ if (insertItems > 0) {
+ customClassPathURLs = new URL[customClassPathURLsTmp.length + insertItems];
+ System.arraycopy(customClassPathURLsTmp, 0,
+ customClassPathURLs, 0, customClassPathURLsTmp.length);
+ // insert DTP connection profile driver jar file URL after the default classpath
entries
+ for (int i = 0; i < insertItems; i++) {
+ customClassPathURLs[customClassPathURLsTmp.length + i] = urls[i];
+ }
+ } else {
+ customClassPathURLs = customClassPathURLsTmp;
+ }
+ return customClassPathURLs;
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -42,36 +42,34 @@
public class ExportAntCodeGenWizardPage extends WizardNewFileCreationPage implements
Listener {
protected ComboDialogField consoleConfigurationName;
-
+
/**
- * Creates a new file creation (Ant code generation) wizard page.
- * If the initial resource selection contains exactly one
- * container resource then it will be used as
- * the default container resource.
+ * Creates a new file creation (Ant code generation) wizard page. If the initial
resource
+ * selection contains exactly one container resource then it will be used as the
default
+ * container resource.
*
* @param pageName
* the name of the page
* @param selection
* the current resource selection
*/
- public ExportAntCodeGenWizardPage(String pageName,
- IStructuredSelection selection) {
+ public ExportAntCodeGenWizardPage(String pageName, IStructuredSelection selection) {
super(pageName, selection);
setPageComplete(false);
}
- /**
- * @see #setControl(Control)
- */
+ /**
+ * @see #setControl(Control)
+ */
protected void setControl(Control newControl) {
newControl.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
| GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
super.setControl(newControl);
- }
+ }
- /**
- * @see #createControl(Composite)
- */
+ /**
+ * @see #createControl(Composite)
+ */
public void createControl(Composite parent) {
initializeDialogUnits(parent);
Composite topLevel = new Composite(parent, SWT.NONE);
@@ -80,7 +78,7 @@
layout.marginWidth = 0;
topLevel.setLayout(layout);
topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
- | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+ | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
topLevel.setFont(parent.getFont());
setControlCombo(topLevel);
super.createControl(topLevel);
@@ -89,8 +87,8 @@
protected void setControlCombo(Control newControl) {
consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
- consoleConfigurationName.setLabelText(
- HibernateConsoleMessages.ExportAntCodeGenWizardPage_hibernate_code_generation_configurations);
+ consoleConfigurationName
+ .setLabelText(HibernateConsoleMessages.ExportAntCodeGenWizardPage_hibernate_code_generation_configurations);
ILaunchConfiguration[] launchCfgs;
try {
launchCfgs = LaunchHelper.findFilteredCodeGenerationConfigs();
@@ -109,12 +107,12 @@
}
};
consoleConfigurationName.setDialogFieldListener(fieldlistener);
- consoleConfigurationName.doFillIntoGrid((Composite)newControl, 2);
- }
+ consoleConfigurationName.doFillIntoGrid((Composite) newControl, 2);
+ }
- /**
- * @see #validatePage()
- */
+ /**
+ * @see #validatePage()
+ */
protected boolean validatePage() {
boolean res = super.validatePage();
if (res) {
@@ -125,7 +123,7 @@
}
return res;
}
-
+
public ILaunchConfiguration getSelectedLaunchConfig() {
ILaunchConfiguration[] launchCfgs;
try {
@@ -149,13 +147,15 @@
Element rootBuildXml = cgfXML.createRoot();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ConfigurationXMLFactory.dump(baos, rootBuildXml);
+ String baosResult = CodeGenXMLFactory.replaceString(baos.toString(),
+ cgfXML.getPropFileContentStubUID(), cgfXML.getPropFileContentPreSave());
//
ByteArrayInputStream bais = null;
try {
- bais = new ByteArrayInputStream(baos.toString().getBytes("UTF-8"));
//$NON-NLS-1$
+ bais = new ByteArrayInputStream(baosResult.getBytes("UTF-8"));
//$NON-NLS-1$
} catch (UnsupportedEncodingException uec) {
HibernateConsolePlugin.getDefault()
- .logErrorMessage("Problems converting to UTF-8", uec); //$NON-NLS-1$
+ .logErrorMessage("Problems converting to UTF-8", uec); //$NON-NLS-1$
bais = new ByteArrayInputStream(baos.toString().getBytes());
}
return bais;
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -17,18 +17,27 @@
*/
public class CGS {
//
+ public static final String ID = "id"; //$NON-NLS-1$
public static final String NAME = "name"; //$NON-NLS-1$
+ public static final String DEPENDS = "depends"; //$NON-NLS-1$
public static final String KEY = "key"; //$NON-NLS-1$
public static final String VALUE = "value"; //$NON-NLS-1$
public static final String LOCATION = "location"; //$NON-NLS-1$
public static final String DEFAULT = "default"; //$NON-NLS-1$
+ public static final String PATH = "path"; //$NON-NLS-1$
+ public static final String PATHELEMENT = "pathelement"; //$NON-NLS-1$
public static final String PROPERTY = "property"; //$NON-NLS-1$
public static final String PROJECT = "project"; //$NON-NLS-1$
public static final String TARGET = "target"; //$NON-NLS-1$
public static final String TASKDEF = "taskdef"; //$NON-NLS-1$
public static final String CLASSNAME = "classname"; //$NON-NLS-1$
+ public static final String CLASSPATH = "classpath"; //$NON-NLS-1$
+ public static final String CLASSPATHREF = "classpathref"; //$NON-NLS-1$
public static final String DESTDIR = "destdir"; //$NON-NLS-1$
+ public static final String TEMPLATEPATH = "templatepath"; //$NON-NLS-1$
public static final String EJB3 = "ejb3"; //$NON-NLS-1$
public static final String JDK5 = "jdk5"; //$NON-NLS-1$
public static final String HIBERNATETOOL = "hibernatetool"; //$NON-NLS-1$
+ public static final String ECHO = "echo"; //$NON-NLS-1$
+ public static final String FILE = "file"; //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.hibernate.eclipse.launch;
+import java.net.URISyntaxException;
+import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -21,15 +23,21 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.datatools.connectivity.IConnectionProfile;
+import org.eclipse.datatools.connectivity.ProfileManager;
+import org.eclipse.datatools.connectivity.drivers.DriverInstance;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.hibernate.cfg.Environment;
import org.hibernate.console.CFS;
import org.hibernate.console.ConfigurationXMLFactory;
import org.hibernate.console.ConnectionProfileUtil;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.console.KnownConfigurations;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
+import org.hibernate.console.preferences.PreferencesClassPathUtils;
import org.hibernate.eclipse.console.model.impl.ExporterFactory;
import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.util.StringHelper;
/**
* XML document part creation factory,
@@ -39,6 +47,12 @@
* @author Vitali Yemialyanchyk
*/
public class CodeGenXMLFactory {
+
+ public static final String NL = System.getProperty("line.separator");
//$NON-NLS-1$
+ public static final long versionUID4PropFile = 1841714864553304000L;
+
+ protected String propFileContentPreSave = null;
+
protected ILaunchConfiguration lc = null;
public CodeGenXMLFactory(ILaunchConfiguration lc) {
@@ -60,6 +74,7 @@
if (attributes.isReverseEngineer()) {
props.setProperty(CFS.ISREVENG, Boolean.toString(attributes.isReverseEngineer()));
props.setProperty(CFS.PACKAGENAME, attributes.getPackageName());
+ props.setProperty(CFS.PREFERBASICCOMPOSITEIDS,
Boolean.toString(attributes.isPreferBasicCompositeIds()));
props.setProperty(CFS.DETECTMANYTOMANY,
Boolean.toString(attributes.detectManyToMany()));
props.setProperty(CFS.DETECTONTTOONE, Boolean.toString(attributes.detectOneToOne()));
props.setProperty(CFS.DETECTOPTIMISTICLOCK,
Boolean.toString(attributes.detectOptimisticLock()));
@@ -74,30 +89,134 @@
consoleConfigPrefs, props);
Element rootConsoleConfig = csfXML.createRoot();
//
+ String defaultTargetName = "JdbcCodeGen"; //$NON-NLS-1$
Element root = DocumentFactory.getInstance().createElement(CGS.PROJECT);
root.addAttribute(CGS.NAME, "CodeGen"); //$NON-NLS-1$
- String defaultTargetName = "JdbcCodeGen"; //$NON-NLS-1$
root.addAttribute(CGS.DEFAULT, defaultTargetName);
+ //
+ String location = getResLocation(attributes.getOutputPath());
Element el = root.addElement(CGS.PROPERTY);
el.addAttribute(CGS.NAME, "build.dir"); //$NON-NLS-1$
- String location = getResLocation(attributes.getOutputPath());
el.addAttribute(CGS.LOCATION, location);
- el = root.addElement(CGS.PROPERTY);
- el.addAttribute(CGS.NAME, "jdbc.driver"); //$NON-NLS-1$
- String driverURL =
getConnectionProfileDriverURL(consoleConfigPrefs.getConnectionProfileName());
- el.addAttribute(CGS.LOCATION, driverURL);
//
+ String hibernatePropFile = null;
+ String generateHibernatePropeties = null;
+ String connProfileName = consoleConfigPrefs.getConnectionProfileName();
+ if (!isEmpty(connProfileName)) {
+ IConnectionProfile profile =
ProfileManager.getInstance().getProfileByName(connProfileName);
+ if (profile != null) {
+ StringBuilder propFileContent = new StringBuilder();
+ DriverInstance driverInstance =
ConnectionProfileUtil.getDriverDefinition(connProfileName);
+ final Properties cpProperties = profile.getProperties(profile.getProviderId());
+ //
+ /** /
+ String driverURL = getConnectionProfileDriverURL(connProfileName);
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, "jdbc.driver"); //$NON-NLS-1$
+ el.addAttribute(CGS.LOCATION, driverURL);
+ /**/
+ //
+ String driverClass =
driverInstance.getProperty("org.eclipse.datatools.connectivity.db.driverClass");
//$NON-NLS-1$
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, Environment.DRIVER);
+ el.addAttribute(CGS.VALUE, driverClass);
+ addIntoPropFileContent(propFileContent, Environment.DRIVER);
+ //
+ String url =
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.URL");
//$NON-NLS-1$
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, Environment.URL);
+ el.addAttribute(CGS.VALUE, url);
+ addIntoPropFileContent(propFileContent, Environment.URL);
+ //
+ String user =
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.username");
//$NON-NLS-1$
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, Environment.USER);
+ el.addAttribute(CGS.VALUE, user);
+ addIntoPropFileContent(propFileContent, Environment.USER);
+ //
+ String pass =
cpProperties.getProperty("org.eclipse.datatools.connectivity.db.password");
//$NON-NLS-1$
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, Environment.PASS);
+ el.addAttribute(CGS.VALUE, pass);
+ addIntoPropFileContent(propFileContent, Environment.PASS);
+ //
+ String dialectName = consoleConfigPrefs.getDialectName();
+ if (StringHelper.isNotEmpty(dialectName)) {
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, Environment.DIALECT);
+ el.addAttribute(CGS.VALUE, dialectName);
+ addIntoPropFileContent(propFileContent, Environment.DIALECT);
+ }
+ //
+ hibernatePropFile = "hibernatePropFile"; //$NON-NLS-1$
+ el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, hibernatePropFile);
+ el.addAttribute(CGS.VALUE,
"${java.io.tmpdir}${ant.project.name}-hibernate.properties"); //$NON-NLS-1$
+ //
+ generateHibernatePropeties = "generateHibernatePropeties"; //$NON-NLS-1$
+ Element target = root.addElement(CGS.TARGET);
+ target.addAttribute(CGS.NAME, generateHibernatePropeties);
+ //
+ hibernatePropFile = "${" + hibernatePropFile + "}"; //$NON-NLS-1$
//$NON-NLS-2$
+ Element echo = target.addElement(CGS.ECHO);
+ echo.addAttribute(CGS.FILE, hibernatePropFile);
+ echo.addText(getPropFileContentStubUID());
+ //echo.addText(propFileContent.toString());
+ propFileContentPreSave = propFileContent.toString();
+ }
+ }
+ // all jars from libraries should be here
+ String toolslibID = "toolslib"; //$NON-NLS-1$
+ Element toolslib = root.addElement(CGS.PATH);
+ toolslib.addAttribute(CGS.ID, toolslibID);
+ final URL[] customClassPathURLs =
PreferencesClassPathUtils.getCustomClassPathURLs(consoleConfigPrefs);
+ for (int i = 0; i < customClassPathURLs.length; i++) {
+ if (customClassPathURLs[i] == null) {
+ continue;
+ }
+ // what is right here: CGS.PATH or CGS.PATHELEMENT?
+ //
http://www.redhat.com/docs/en-US/JBoss_Developer_Studio/en/hibernatetools...
+ // use CGS.PATH - so may be error in documentation?
+ Element pathItem = toolslib.addElement(CGS.PATH);
+ //Element pathItem = toolslib.addElement(CGS.PATHELEMENT);
+ String strPathItem = customClassPathURLs[i].getPath();
+ try {
+ strPathItem = (new java.io.File(customClassPathURLs[i].toURI())).getPath();
+ } catch (URISyntaxException e) {
+ // ignore
+ }
+ pathItem.addAttribute(CGS.LOCATION, strPathItem);
+ }
+ //
Element target = root.addElement(CGS.TARGET);
target.addAttribute(CGS.NAME, defaultTargetName);
+ if (!isEmpty(generateHibernatePropeties)) {
+ target.addAttribute(CGS.DEPENDS, generateHibernatePropeties);
+ }
//
Element taskdef = target.addElement(CGS.TASKDEF);
taskdef.addAttribute(CGS.NAME, CGS.HIBERNATETOOL);
taskdef.addAttribute(CGS.CLASSNAME,
"org.hibernate.tool.ant.HibernateToolTask"); //$NON-NLS-1$
+ taskdef.addAttribute(CGS.CLASSPATHREF, toolslibID);
//
Element hibernatetool = target.addElement(CGS.HIBERNATETOOL);
hibernatetool.addAttribute(CGS.DESTDIR, "${build.dir}"); //$NON-NLS-1$
+ String templatePath = getResLocation(attributes.getTemplatePath());
+ if (attributes.isUseOwnTemplates()) {
+ hibernatetool.addAttribute(CGS.TEMPLATEPATH, templatePath);
+ }
+ //
+ if (StringHelper.isNotEmpty(hibernatePropFile)) {
+ rootConsoleConfig.addAttribute(CFS.PROPERTYFILE, hibernatePropFile);
+ }
+ // add hibernate console configuration
hibernatetool.content().add(rootConsoleConfig);
//
+ // the path there are user classes
+ Element classpath = hibernatetool.addElement(CGS.CLASSPATH);
+ Element path = classpath.addElement(CGS.PATH);
+ path.addAttribute(CGS.LOCATION, "${build.dir}"); //$NON-NLS-1$
+ //
Properties globalProps = new Properties();
globalProps.put(CGS.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
globalProps.put(CGS.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
@@ -144,6 +263,10 @@
return root;
}
+ public void addIntoPropFileContent(StringBuilder pfc, String str) {
+ pfc.append(NL + str + "=${" + str + "}"); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
public ConsoleConfigurationPreferences getConsoleConfigPreferences(String
consoleConfigName) {
ConsoleConfiguration consoleConfig =
KnownConfigurations.getInstance().find(consoleConfigName);
return consoleConfig.getPreferences();
@@ -159,13 +282,41 @@
final IResource outputPathRes = findResource(path);
String location = ""; //$NON-NLS-1$
if (outputPathRes != null) {
- location = outputPathRes.getLocation().toString();
+ location = outputPathRes.getLocation().toOSString();
}
return location;
}
public String getConnectionProfileDriverURL(String connectionProfile) {
String driverURL =
ConnectionProfileUtil.getConnectionProfileDriverURL(connectionProfile);
+ if (driverURL == null) {
+ driverURL = ""; //$NON-NLS-1$
+ }
return driverURL;
}
+
+ public boolean isEmpty(String str) {
+ return (str == null || str.length() == 0);
+ }
+
+ public String getPropFileContentStubUID() {
+ return Long.toHexString(versionUID4PropFile);
+ }
+
+ public String getPropFileContentPreSave() {
+ return propFileContentPreSave;
+ }
+
+ public static String replaceString(String input, String repl, String with) {
+ final StringBuffer tmp = new StringBuffer();
+ int startIdx = 0;
+ int idxOld = 0;
+ while ((idxOld = input.indexOf(repl, startIdx)) >= 0) {
+ tmp.append(input.substring(startIdx, idxOld));
+ tmp.append(with);
+ startIdx = idxOld + repl.length();
+ }
+ tmp.append(input.substring(startIdx));
+ return tmp.toString();
+ }
}
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test1.xml
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test1.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -0,0 +1,32 @@
+<project name="CodeGen" default="JdbcCodeGen">
+ <property name="build.dir" location="ResLocation/test"/>
+ <path id="toolslib">
+ <path location="ejb3-persistence.jar"/>
+ <path location="hibernate3.jar"/>
+ <path location="hsqldb.jar"/>
+ </path>
+ <target name="JdbcCodeGen">
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
+ <hibernatetool destdir="${build.dir}">
+ <jpaconfiguration namingStrategy="testNamingStrategy"
persistenceUnit="testPersistenceUnit">
+ <fileset dir="." id="id">
+ <include name="xxx.hbm.xml"/>
+ <include name="yyy.hbm.xml"/>
+ </fileset>
+ </jpaconfiguration>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
+ <hbm2doc/>
+ <hbm2cfgxml/>
+ <hbm2hbmxml/>
+ <hbmtemplate>
+ <property key="jdk5" value="true"/>
+ <property key="ejb3" value="true"/>
+ </hbmtemplate>
+ <hbm2java jdk5="true" ejb3="true"/>
+ <hbm2ddl/>
+ <hbm2dao jdk5="true" ejb3="true"/>
+ </hibernatetool>
+ </target>
+</project>
\ No newline at end of file
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test2.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test2.xml
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenJpa_test2.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -0,0 +1,23 @@
+<project name="CodeGen" default="JdbcCodeGen">
+ <property name="build.dir" location="ResLocation/test"/>
+ <path id="toolslib">
+ <path location="ejb3-persistence.jar"/>
+ <path location="hibernate3.jar"/>
+ <path location="hsqldb.jar"/>
+ </path>
+ <target name="JdbcCodeGen">
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
+ <hibernatetool destdir="${build.dir}">
+ <jpaconfiguration namingStrategy="testNamingStrategy"
persistenceUnit="testPersistenceUnit">
+ <fileset dir="." id="id">
+ <include name="xxx.hbm.xml"/>
+ <include name="yyy.hbm.xml"/>
+ </fileset>
+ </jpaconfiguration>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
+ <hbm2java jdk5="true" ejb3="true"/>
+ </hibernatetool>
+ </target>
+</project>
\ No newline at end of file
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test1.xml 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test1.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -1,10 +1,13 @@
<project name="CodeGen" default="JdbcCodeGen">
<property name="build.dir" location="ResLocation/test"/>
- <property name="jdbc.driver" location="TestDriverPath.jar"/>
+ <path id="toolslib"/>
<target name="JdbcCodeGen">
- <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
<hibernatetool destdir="${build.dir}">
<jdbcconfiguration configurationFile="project\src\hibernate.cfg.xml"
detectManyToMany="true" detectOneToOne="true"
detectOptimisticLock="true" revEngFile="ResLocation/test"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
<hbm2doc/>
<hbm2cfgxml/>
<hbm2hbmxml/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test2.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test2.xml 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGenReveng_test2.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -1,10 +1,13 @@
<project name="CodeGen" default="JdbcCodeGen">
<property name="build.dir" location="ResLocation/test"/>
- <property name="jdbc.driver" location="TestDriverPath.jar"/>
+ <path id="toolslib"/>
<target name="JdbcCodeGen">
- <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
<hibernatetool destdir="${build.dir}">
<jdbcconfiguration configurationFile="project\src\hibernate.cfg.xml"
detectManyToMany="true" detectOneToOne="true"
detectOptimisticLock="true" revEngFile="ResLocation/test"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
<hbm2java/>
</hibernatetool>
</target>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test1.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test1.xml 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test1.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -1,10 +1,13 @@
<project name="CodeGen" default="JdbcCodeGen">
<property name="build.dir" location="ResLocation/test"/>
- <property name="jdbc.driver" location="TestDriverPath.jar"/>
+ <path id="toolslib"/>
<target name="JdbcCodeGen">
- <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
<hibernatetool destdir="${build.dir}">
<configuration configurationFile="project\src\hibernate.cfg.xml"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
<hbm2doc/>
<hbm2cfgxml/>
<hbm2hbmxml/>
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test2.xml
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test2.xml 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/specimen/AntCodeGen_test2.xml 2010-07-14
13:24:36 UTC (rev 23403)
@@ -1,10 +1,13 @@
<project name="CodeGen" default="JdbcCodeGen">
<property name="build.dir" location="ResLocation/test"/>
- <property name="jdbc.driver" location="TestDriverPath.jar"/>
+ <path id="toolslib"/>
<target name="JdbcCodeGen">
- <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"/>
+ <taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
<hibernatetool destdir="${build.dir}">
<configuration configurationFile="project\src\hibernate.cfg.xml"/>
+ <classpath>
+ <path location="${build.dir}"/>
+ </classpath>
<hbm2java/>
</hibernatetool>
</target>
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-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/CodeGenXMLFactoryTest.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -15,6 +15,9 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -44,6 +47,7 @@
public class CodeGenXMLFactoryTest extends TestCase {
public static final String SPECIMEN_PATH =
"res/specimen/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
+ public static final String PROJECT_LIB_PATH =
"res/project/lib/".replaceAll("//", File.separator); //$NON-NLS-1$
//$NON-NLS-2$
public static final String HBMTEMPLATE0 = "hbm2java"; //$NON-NLS-1$
public static final String HBMTEMPLATE0_PROPERTIES =
HibernateLaunchConstants.ATTR_EXPORTERS
@@ -57,14 +61,70 @@
}
}
+ public class TestConsoleConfigPref2 extends TestConsoleConfigurationPreferences {
+ public File getConfigXMLFile() {
+ return null;
+ }
+
+ public File[] getMappingFiles() {
+ File[] files = new File[2];
+ files[0] = new File("xxx.hbm.xml"); //$NON-NLS-1$
+ files[1] = new File("yyy.hbm.xml"); //$NON-NLS-1$
+ return files;
+ }
+
+ public URL[] getCustomClassPathURLS() {
+ URL[] urls = new URL[4];
+ try {
+ urls[0] = new File("ejb3-persistence.jar").toURL(); //$NON-NLS-1$
+ urls[1] = new File("hibernate3.jar").toURL(); //$NON-NLS-1$
+ urls[2] = new File("hsqldb.jar").toURL(); //$NON-NLS-1$
+ urls[3] = null;
+ } catch (IOException e) {
+ }
+ return urls;
+ }
+ public String getEntityResolverName() {
+ return ""; //$NON-NLS-1$
+ }
+
+ public ConfigurationMode getConfigurationMode() {
+ return ConfigurationMode.JPA;
+ }
+
+ public String getNamingStrategy() {
+ return "testNamingStrategy"; //$NON-NLS-1$
+ }
+
+ public String getPersistenceUnitName() {
+ return "testPersistenceUnit"; //$NON-NLS-1$
+ }
+
+ public String getConnectionProfileName() {
+ return "jdbc:mysql://localhost:3306/jpa"; //$NON-NLS-1$
+ }
+
+ public String getDialectName() {
+ return "testDialect"; //$NON-NLS-1$
+ }
+ }
+
public class CodeGenXMLFactory4Test extends CodeGenXMLFactory {
+
+ protected boolean jpa = false;
- public CodeGenXMLFactory4Test(ILaunchConfiguration lc) {
+ public CodeGenXMLFactory4Test(ILaunchConfiguration lc, boolean jpa) {
super(lc);
+ this.jpa = jpa;
}
public ConsoleConfigurationPreferences getConsoleConfigPreferences(String
consoleConfigName) {
- ConsoleConfigurationPreferences pref = new TestConsoleConfigPref();
+ ConsoleConfigurationPreferences pref;
+ if (jpa) {
+ pref = new TestConsoleConfigPref2();
+ } else {
+ pref = new TestConsoleConfigPref();
+ }
return pref;
}
@@ -78,36 +138,66 @@
}
public void testCodeGenXMLFactoryRevengAll() {
- String codeGen = codeGenXMLFactory(true, true);
+ String codeGen = codeGenXMLFactory(true, true, false);
String specimen = getSpecimen("AntCodeGenReveng_test1.xml"); //$NON-NLS-1$
assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCodeGenXMLFactoryRevengOne() {
- String codeGen = codeGenXMLFactory(true, false);
+ String codeGen = codeGenXMLFactory(true, false, false);
String specimen = getSpecimen("AntCodeGenReveng_test2.xml"); //$NON-NLS-1$
assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCodeGenXMLFactoryAll() {
- String codeGen = codeGenXMLFactory(false, true);
+ String codeGen = codeGenXMLFactory(false, true, false);
String specimen = getSpecimen("AntCodeGen_test1.xml"); //$NON-NLS-1$
assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCodeGenXMLFactoryOne() {
- String codeGen = codeGenXMLFactory(false, false);
+ String codeGen = codeGenXMLFactory(false, false, false);
String specimen = getSpecimen("AntCodeGen_test2.xml"); //$NON-NLS-1$
assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
}
- public String codeGenXMLFactory(boolean reveng, boolean exportersAll) {
+ public void testCodeGenXMLFactoryJpaAll() {
+ String codeGen = codeGenXMLFactory(false, true, true);
+ codeGen = updatePaths(codeGen);
+ String specimen = getSpecimen("AntCodeGenJpa_test1.xml"); //$NON-NLS-1$
+ assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testCodeGenXMLFactoryJpaOne() {
+ String codeGen = codeGenXMLFactory(false, false, true);
+ codeGen = updatePaths(codeGen);
+ String specimen = getSpecimen("AntCodeGenJpa_test2.xml"); //$NON-NLS-1$
+ assertEquals(specimen.trim(), codeGen.trim().replaceAll("\n",
"\r\n")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public String updatePaths(String codeGen) {
+ String repl = ""; //$NON-NLS-1$
+ try {
+ URI uri = new File("").toURL().toURI(); //$NON-NLS-1$
+ repl = (new File(uri)).getPath();
+ } catch (MalformedURLException e) {
+ } catch (URISyntaxException e) {
+ }
+ codeGen = CodeGenXMLFactory.replaceString(codeGen, repl + File.separator,
""); //$NON-NLS-1$
+ return codeGen;
+ }
+
+ public String codeGenXMLFactory(boolean reveng, boolean exportersAll, boolean jpa) {
Map<String, ExporterDefinition> exDefinitions =
ExtensionManager.findExporterDefinitionsAsMap();
Map<String, Object> testLCAttr = new HashMap<String, Object>();
String tmp = "12345678901234567890"; //$NON-NLS-1$
testLCAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR, tmp);
testLCAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR, tmp);
testLCAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS, tmp);
+ if (jpa) {
+ testLCAttr.put(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS, true);
+ testLCAttr.put(HibernateLaunchConstants.ATTR_ENABLE_JDK5, true);
+ }
List<String> exportersList = new ArrayList<String>();
if (exportersAll) {
exportersList.clear();
@@ -130,7 +220,7 @@
testLCAttr.put(HBMTEMPLATE0_PROPERTIES, expProps2);
testLCAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, reveng);
TestLaunchConfig testLC = new TestLaunchConfig(testLCAttr);
- CodeGenXMLFactory cgfXML = new CodeGenXMLFactory4Test(testLC);
+ CodeGenXMLFactory cgfXML = new CodeGenXMLFactory4Test(testLC, jpa);
Element rootBuildXml = cgfXML.createRoot();
ConfigurationXMLFactory.dump(System.out, rootBuildXml);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -166,8 +256,11 @@
File resourceFolder = resourcePath.toFile();
URL entry = HibernateConsoleTestPlugin.getDefault().getBundle().getEntry(
strResPath);
- URL resProject = FileLocator.resolve(entry);
- String tplPrjLcStr = FileLocator.resolve(resProject).getFile();
+ String tplPrjLcStr = strResPath;
+ if (entry != null) {
+ URL resProject = FileLocator.resolve(entry);
+ tplPrjLcStr = FileLocator.resolve(resProject).getFile();
+ }
resourceFolder = new File(tplPrjLcStr);
return resourceFolder;
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsolePluginAllTests.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsolePluginAllTests.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/ConsolePluginAllTests.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -30,6 +30,8 @@
suite.addTestSuite(QueryPageViewerTest.class);
suite.addTestSuite(HBMInfoExtractorTest.class);
+
+ suite.addTestSuite(CodeGenXMLFactoryTest.class);
// core tests
//Properties properties = new Properties();
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/launchcfg/TestConsoleConfigurationPreferences.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/launchcfg/TestConsoleConfigurationPreferences.java 2010-07-14
10:13:42 UTC (rev 23402)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/launchcfg/TestConsoleConfigurationPreferences.java 2010-07-14
13:24:36 UTC (rev 23403)
@@ -8,6 +8,7 @@
import junit.framework.Assert;
import org.eclipse.core.runtime.FileLocator;
+import org.hibernate.cfg.Environment;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.eclipse.console.test.ConsoleTestMessages;
import org.hibernate.eclipse.console.test.HibernateConsoleTestPlugin;
@@ -48,7 +49,7 @@
public Properties getProperties() {
Properties p = new Properties();
- p.setProperty("hibernate.dialect",
"org.hibernate.dialect.HSQLDialect"); //$NON-NLS-1$ //$NON-NLS-2$
+ p.setProperty(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect");
//$NON-NLS-1$
return p;
}
@@ -73,17 +74,14 @@
}
public String getNamingStrategy() {
- // TODO Auto-generated method stub
return null;
}
public String getPersistenceUnitName() {
- // TODO Auto-generated method stub
return null;
}
public String getConnectionProfileName() {
- // TODO Auto-generated method stub
return null;
}
@@ -92,7 +90,6 @@
* @see
org.hibernate.console.preferences.ConsoleConfigurationPreferences#getDialectName()
*/
public String getDialectName() {
- // TODO Auto-generated method stub
return null;
}