Author: vyemialyanchyk
Date: 2010-07-09 13:26:36 -0400 (Fri, 09 Jul 2010)
New Revision: 23353
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/EFS.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java
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/CodeGenerationLaunchDelegate.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
Log:
https://jira.jboss.org/browse/JBIDE-6595 - fix for (1), (2), (3), (4), partially (9)
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/CFS.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * XML Ant code generation strings
+ *
+ * @author vitali
+ */
+public class CFS {
+ //
+ public static final String JDBCCONFIGURATION = "jdbcconfiguration";
//$NON-NLS-1$
+ public static final String ANNOTATIONCONFIGURATION =
"annotationconfiguration"; //$NON-NLS-1$
+ public static final String JPACONFIGURATION = "jpaconfiguration";
//$NON-NLS-1$
+ public static final String CONFIGURATION = "configuration"; //$NON-NLS-1$
+ //
+ public static final String CONFIGURATIONFILE = "configurationFile";
//$NON-NLS-1$
+ public static final String PROPERTYFILE = "propertyFile"; //$NON-NLS-1$
+ 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 DETECTMANYTOMANY = "detectManyToMany";
//$NON-NLS-1$
+ public static final String DETECTONTTOONE = "detectOneToOne"; //$NON-NLS-1$
+ public static final String DETECTOPTIMISTICLOCK = "detectOptimisticLock";
//$NON-NLS-1$
+ public static final String PACKAGENAME = "packageName"; //$NON-NLS-1$
+ public static final String REVENGFILE = "revEngFile"; //$NON-NLS-1$
+ public static final String REVERSESTRATEGY = "reverseStrategy"; //$NON-NLS-1$
+ public static final String ISREVENG = "isRevEng"; //$NON-NLS-1$
+}
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-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.hibernate.console;
+import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;
@@ -43,85 +44,75 @@
return prefs;
}
- public Document createXML(boolean includeMappings) {
+ public Document createXML() {
Document res = DocumentFactory.getInstance().createDocument();
- Element root = createRoot(includeMappings);
+ Element root = createRoot();
res.setRootElement(root);
return res;
}
- public Element createRoot(boolean includeMappings) {
+ public Element createRoot() {
Properties properties = prefs.getProperties();
- Element root = createRoot(properties, includeMappings);
+ Element root = createRoot(properties);
return root;
}
- protected Element createRoot(Properties properties, boolean includeMappings) {
+ protected Element createRoot(Properties properties) {
String rootName = null;
- Boolean jdbcConfig = Boolean.valueOf(additional.getProperty("isRevEng",
"false")); //$NON-NLS-1$ //$NON-NLS-2$
+ Boolean jdbcConfig = Boolean.valueOf(additional.getProperty(CFS.ISREVENG,
"false")); //$NON-NLS-1$
if (jdbcConfig) {
- rootName = "jdbcconfiguration"; //$NON-NLS-1$
+ rootName = CFS.JDBCCONFIGURATION;
} else if (prefs.getConfigurationMode().equals(ConfigurationMode.ANNOTATIONS)) {
- rootName = "annotationconfiguration"; //$NON-NLS-1$
+ rootName = CFS.ANNOTATIONCONFIGURATION;
} else if (prefs.getConfigurationMode().equals(ConfigurationMode.JPA)) {
- rootName = "jpaconfiguration"; //$NON-NLS-1$
+ rootName = CFS.JPACONFIGURATION;
} else if (prefs.getConfigurationMode().equals(ConfigurationMode.CORE)) {
- rootName = "configuration"; //$NON-NLS-1$
+ rootName = CFS.CONFIGURATION;
} else {
rootName = "undef"; //$NON-NLS-1$
}
Element root = DocumentFactory.getInstance().createElement(rootName);
- final String configurationFile = getPreferences().getConfigXMLFile() == null ? null :
- getPreferences().getConfigXMLFile().toString();
- if (!StringHelper.isEmpty(configurationFile)) {
- root.addAttribute("configurationFile", configurationFile); //$NON-NLS-1$
- }
- final String propertyFile = getPreferences().getPropertyFile() == null ? null :
- getPreferences().getPropertyFile().toString();
- if (!StringHelper.isEmpty(propertyFile)) {
- root.addAttribute("propertyFile", propertyFile); //$NON-NLS-1$
- }
- final String entityResolver = getPreferences().getEntityResolverName();
- if (!StringHelper.isEmpty(entityResolver)) {
- root.addAttribute("entityResolver", entityResolver); //$NON-NLS-1$
- }
- final String persistenceUnit = getPreferences().getPersistenceUnitName();
- if (!StringHelper.isEmpty(persistenceUnit)) {
- root.addAttribute("persistenceUnit", persistenceUnit); //$NON-NLS-1$
- }
- final String detectManyToMany = additional.getProperty("detectManyToMany",
""); //$NON-NLS-1$ //$NON-NLS-2$
- if (!StringHelper.isEmpty(detectManyToMany)) {
- root.addAttribute("detectManyToMany", detectManyToMany); //$NON-NLS-1$
- }
- final String detectOneToOne = additional.getProperty("detectOneToOne",
""); //$NON-NLS-1$ //$NON-NLS-2$
- if (!StringHelper.isEmpty(detectOneToOne)) {
- root.addAttribute("detectOneToOne", detectOneToOne); //$NON-NLS-1$
- }
- final String detectOptimisticLock =
additional.getProperty("detectOptimisticLock", ""); //$NON-NLS-1$
//$NON-NLS-2$
- if (!StringHelper.isEmpty(detectOptimisticLock)) {
- root.addAttribute("detectOptimisticLock", detectOptimisticLock);
//$NON-NLS-1$
- }
- final String packageName = additional.getProperty("packageName",
""); //$NON-NLS-1$ //$NON-NLS-2$
- if (!StringHelper.isEmpty(packageName)) {
- root.addAttribute("packageName", packageName); //$NON-NLS-1$
- }
- final String revEngFile = additional.getProperty("revEngFile", "");
//$NON-NLS-1$ //$NON-NLS-2$
- if (!StringHelper.isEmpty(revEngFile)) {
- root.addAttribute("revEngFile", revEngFile); //$NON-NLS-1$
- }
- final String reverseStrategy = additional.getProperty("reverseStrategy",
""); //$NON-NLS-1$ //$NON-NLS-2$
- if (!StringHelper.isEmpty(reverseStrategy)) {
- root.addAttribute("reverseStrategy", reverseStrategy); //$NON-NLS-1$
- }
- if (includeMappings) {
+ updateAttr(root, file2Str(getPreferences().getConfigXMLFile()),
CFS.CONFIGURATIONFILE);
+ updateAttr(root, file2Str(getPreferences().getPropertyFile()), CFS.PROPERTYFILE);
+ updateAttr(root, getPreferences().getEntityResolverName(), CFS.ENTITYRESOLVER);
+ updateAttr(root, getPreferences().getNamingStrategy(), CFS.NAMINGSTRATEGY);
+ updateAttr(root, getPreferences().getPersistenceUnitName(), CFS.PERSISTENCEUNIT);
+ updateAttr(root, additional, CFS.DETECTMANYTOMANY);
+ updateAttr(root, additional, CFS.DETECTONTTOONE);
+ updateAttr(root, additional, CFS.DETECTOPTIMISTICLOCK);
+ updateAttr(root, additional, CFS.PACKAGENAME);
+ updateAttr(root, additional, CFS.REVENGFILE);
+ updateAttr(root, additional, CFS.REVERSESTRATEGY);
+ // includeMappings
+ 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("id", "id"); //$NON-NLS-1$ //$NON-NLS-2$
- Element include = fileset.addElement("include"); //$NON-NLS-1$
- include.addAttribute("name", "**/*"); //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < mappingFiles.length; i++) {
+ Element include = fileset.addElement("include"); //$NON-NLS-1$
+ include.addAttribute("name", mappingFiles[i].getAbsolutePath());
//$NON-NLS-1$
+ }
}
return root;
}
+
+ public static String file2Str(File file) {
+ return file == null ? null : file.toString();
+ }
+
+ public static void updateAttr(Element el, String val, String prName) {
+ if (!StringHelper.isEmpty(val)) {
+ el.addAttribute(prName, val);
+ }
+ }
+
+ public static void updateAttr(Element el, Properties prs, String prName) {
+ final String val = prs.getProperty(prName, ""); //$NON-NLS-1$
+ if (!StringHelper.isEmpty(val)) {
+ el.addAttribute(prName, val);
+ }
+ }
public static void dump(OutputStream os, Element element) {
try {
@@ -138,6 +129,5 @@
// ignore
}
}
-
}
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/EFS.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/EFS.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/EFS.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * 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.eclipse.console.model.impl;
+
+/**
+ * ExporterFactory strings
+ *
+ * @author vitali
+ */
+public class EFS {
+ //
+ public static final String OUTPUTDIR = "outputdir"; //$NON-NLS-1$
+ public static final String TEMPLATE_PATH = "template_path"; //$NON-NLS-1$
+ public static final String FILE_PATTERN = "file_pattern"; //$NON-NLS-1$
+ public static final String TEMPLATE_NAME = "template_name"; //$NON-NLS-1$
+ public static final String FOR_EACH = "for_each"; //$NON-NLS-1$
+ public static final String EXPORTTODATABASE = "exportToDatabase";
//$NON-NLS-1$
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -155,10 +155,11 @@
/** Method that resolves an expression through eclipses built-in variable manager.
* @throws CoreException if expression could not be evaluated. */
- private String resolve(String expression) throws CoreException {
- if(expression==null) return null;
+ public static String resolve(String expression) throws CoreException {
+ if (expression == null) {
+ return null;
+ }
IStringVariableManager variableManager =
VariablesPlugin.getDefault().getStringVariableManager();
-
return variableManager.performStringSubstitution(expression, false);
}
@@ -172,30 +173,30 @@
Exporter exporter = getExporterDefinition().createExporterInstance();
-
+ Properties extract = new Properties();
Properties props = new Properties();
props.putAll(globalProperties);
props.putAll(getProperties());
-
+
exporter.setProperties(props);
exporter.setArtifactCollector(collector);
+ extractExporterProperties(exporterId, props, extract);
+
String outputPath = defaultOutputDirectory;
- if(props.containsKey("outputdir")) { //$NON-NLS-1$
- outputPath = props.getProperty("outputdir"); //$NON-NLS-1$
- // done to avoid validation check in hibernate tools templates
- props.remove("outputdir"); //$NON-NLS-1$
+ if (extract.containsKey(EFS.OUTPUTDIR)) {
+ outputPath = extract.getProperty(EFS.OUTPUTDIR);
}
String resolvedOutputDir = resolve(outputPath);
String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
- if(outputPath != null && loc == null) {
+ if (outputPath != null && loc == null) {
String out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_output_dir_in_does_not_exist,
- resolvedOutputDir, getExporterDefinition().getDescription());
+ resolvedOutputDir, getExporterDefinition().getDescription());
throw new HibernateConsoleRuntimeException(out);
}
- if(StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
outputDirectories.add(loc);
exporter.setOutputDirectory(new File(loc));
}
@@ -203,15 +204,15 @@
exporter.setConfiguration(cfg);
List<String> templatePathList = new ArrayList<String>();
- if(props.containsKey("template_path")) { //$NON-NLS-1$
- String resolveTemplatePath = resolve(props.getProperty("template_path"));
//$NON-NLS-1$
+ if (extract.containsKey(EFS.TEMPLATE_PATH)) {
+ String resolveTemplatePath = resolve(extract.getProperty(EFS.TEMPLATE_PATH));
StringTokenizer st = new StringTokenizer(resolveTemplatePath, ";");
//$NON-NLS-1$
String out = ""; //$NON-NLS-1$
while (st.hasMoreTokens()) {
String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
- if(locationAsStringPath==null) {
+ if (locationAsStringPath == null) {
out +=
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
- resolveTemplatePath, getExporterDefinition().getDescription()) +
'\n';
+ resolveTemplatePath, getExporterDefinition().getDescription()) +
'\n';
} else {
templatePathList.add(locationAsStringPath);
}
@@ -220,50 +221,76 @@
out = out.substring(0, out.length() - 1);
throw new HibernateConsoleRuntimeException(out);
}
- props.remove("template_path"); // done to avoid validation check in
hibernate tools templates //$NON-NLS-1$
}
- if (StringHelper.isNotEmpty(customTemplatePath)){
+
+ if (StringHelper.isNotEmpty(customTemplatePath)) {
String resolvedCustomTemplatePath = resolve(customTemplatePath);
StringTokenizer st = new StringTokenizer(resolvedCustomTemplatePath, ";");
//$NON-NLS-1$
String out = ""; //$NON-NLS-1$
while (st.hasMoreTokens()) {
String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
- if(locationAsStringPath != null) {
+ if (locationAsStringPath != null) {
templatePathList.add(locationAsStringPath);
} else {
out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
- resolvedCustomTemplatePath, getExporterDefinition().getDescription());
+ resolvedCustomTemplatePath, getExporterDefinition().getDescription());
}
}
- if (!("".equals(out))){ //$NON-NLS-1$
+ if (!("".equals(out))) { //$NON-NLS-1$
out = out.substring(0, out.length() - 1);
throw new HibernateConsoleRuntimeException(out);
}
}
-
exporter.setTemplatePath(templatePathList.toArray(new
String[templatePathList.size()]));
-
-
// special handling for GenericExporter (TODO: be delegated via plugin.xml)
- if(getExporterDefinition().getId().equals("org.hibernate.tools.hbmtemplate"))
{ //$NON-NLS-1$
+ if (exporterId.equals("org.hibernate.tools.hbmtemplate")) { //$NON-NLS-1$
GenericExporter ge = (GenericExporter) exporter;
-
- ge.setFilePattern(props.getProperty("file_pattern", null)); //$NON-NLS-1$
- props.remove("file_pattern"); //$NON-NLS-1$
- ge.setTemplateName(props.getProperty("template_name",null)); //$NON-NLS-1$
- props.remove("template_name"); //$NON-NLS-1$
- ge.setForEach(props.getProperty("for_each",null)); //$NON-NLS-1$
- props.remove("for_each"); //$NON-NLS-1$
-
+ ge.setFilePattern(extract.getProperty(EFS.FILE_PATTERN));
+ ge.setTemplateName(extract.getProperty(EFS.TEMPLATE_NAME));
+ ge.setForEach(extract.getProperty(EFS.FOR_EACH));
}
// special handling for Hbm2DDLExporter
- if(getExporterDefinition().getId().equals("org.hibernate.tools.hbm2ddl")) {
//$NON-NLS-1$
+ if (exporterId.equals("org.hibernate.tools.hbm2ddl")) { //$NON-NLS-1$
Hbm2DDLExporter ddlExporter = (Hbm2DDLExporter) exporter;
//avoid users to delete their databases with a single click
- ddlExporter.setExport(Boolean.getBoolean(props.getProperty("exportToDatabase",
Boolean.toString(false)))); //$NON-NLS-1$
- props.remove("exportToDatabase"); //$NON-NLS-1$
+ ddlExporter.setExport(Boolean.getBoolean(extract.getProperty(EFS.EXPORTTODATABASE)));
}
return exporter;
}
+ /**
+ * Extract and update GUI specific exporter properties
+ *
+ * @param exporterId
+ * @param props - properties which values remain
+ * @param extract - separated updated properties
+ * @throws CoreException
+ */
+ public static void extractExporterProperties(
+ String exporterId, Properties props, Properties extract) throws CoreException {
+ if (props.containsKey(EFS.OUTPUTDIR)) {
+ extract.put(EFS.OUTPUTDIR, resolve(props.getProperty(EFS.OUTPUTDIR)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(EFS.OUTPUTDIR);
+ }
+ if (props.containsKey(EFS.TEMPLATE_PATH)) {
+ extract.put(EFS.TEMPLATE_PATH, resolve(props.getProperty(EFS.TEMPLATE_PATH)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(EFS.TEMPLATE_PATH);
+ }
+ if (exporterId.equals("org.hibernate.tools.hbmtemplate")) { //$NON-NLS-1$
+ extract.put(EFS.FILE_PATTERN, props.getProperty(EFS.FILE_PATTERN, null));
+ props.remove(EFS.FILE_PATTERN);
+ extract.put(EFS.TEMPLATE_NAME, props.getProperty(EFS.TEMPLATE_NAME, null));
+ props.remove(EFS.TEMPLATE_NAME);
+ extract.put(EFS.FOR_EACH, props.getProperty(EFS.FOR_EACH, null));
+ props.remove(EFS.FOR_EACH);
+
+ }
+ // special handling for Hbm2DDLExporter
+ if (exporterId.equals("org.hibernate.tools.hbm2ddl")) { //$NON-NLS-1$
+ extract.put(EFS.EXPORTTODATABASE, props.getProperty(EFS.EXPORTTODATABASE,
Boolean.toString(false)));
+ props.remove(EFS.EXPORTTODATABASE);
+ }
+ }
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -22,12 +22,13 @@
package org.hibernate.eclipse.console.model.impl;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.launch.CGS;
public class ExporterProperty
{
private static ExporterProperty[] globalProperties = new ExporterProperty[] {
- new ExporterProperty ("jdk5",
HibernateConsoleMessages.ExporterProperty_use_java5_syntax, "false", false),
//$NON-NLS-1$ //$NON-NLS-2$
- new ExporterProperty ("ejb3",
HibernateConsoleMessages.ExporterProperty_generate_ejb3_annotations, "false",
false) //$NON-NLS-1$ //$NON-NLS-2$
+ new ExporterProperty (CGS.JDK5,
HibernateConsoleMessages.ExporterProperty_use_java5_syntax, "false", false),
//$NON-NLS-1$
+ new ExporterProperty (CGS.EJB3,
HibernateConsoleMessages.ExporterProperty_generate_ejb3_annotations, "false",
false) //$NON-NLS-1$
};
private String defaultValue;
Added:
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
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CGS.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.eclipse.launch;
+
+/**
+ * XML Ant code generation strings
+ *
+ * @author vitali
+ */
+public class CGS {
+ //
+ public static final String NAME = "name"; //$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 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 DESTDIR = "destdir"; //$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$
+}
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-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -22,6 +22,7 @@
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfiguration;
+import org.hibernate.console.CFS;
import org.hibernate.console.ConfigurationXMLFactory;
import org.hibernate.console.ConnectionProfileUtil;
import org.hibernate.console.ConsoleConfiguration;
@@ -57,49 +58,49 @@
}
Properties props = new Properties();
if (attributes.isReverseEngineer()) {
- props.setProperty("isRevEng",
Boolean.toString(attributes.isReverseEngineer())); //$NON-NLS-1$
- props.setProperty("packageName", attributes.getPackageName());
//$NON-NLS-1$
- props.setProperty("detectManyToMany",
Boolean.toString(attributes.detectManyToMany())); //$NON-NLS-1$
- props.setProperty("detectOneToOne",
Boolean.toString(attributes.detectOneToOne())); //$NON-NLS-1$
- props.setProperty("detectOptimisticLock",
Boolean.toString(attributes.detectOptimisticLock())); //$NON-NLS-1$
- props.setProperty("reverseStrategy", attributes.getRevengStrategy());
//$NON-NLS-1$
+ props.setProperty(CFS.ISREVENG, Boolean.toString(attributes.isReverseEngineer()));
+ props.setProperty(CFS.PACKAGENAME, attributes.getPackageName());
+ props.setProperty(CFS.DETECTMANYTOMANY,
Boolean.toString(attributes.detectManyToMany()));
+ props.setProperty(CFS.DETECTONTTOONE, Boolean.toString(attributes.detectOneToOne()));
+ props.setProperty(CFS.DETECTOPTIMISTICLOCK,
Boolean.toString(attributes.detectOptimisticLock()));
+ props.setProperty(CFS.REVERSESTRATEGY, attributes.getRevengStrategy());
String revEngFile = getResLocation(attributes.getRevengSettings());
- props.setProperty("revEngFile", revEngFile); //$NON-NLS-1$
+ props.setProperty(CFS.REVENGFILE, revEngFile);
}
String consoleConfigName = attributes.getConsoleConfigurationName();
ConsoleConfigurationPreferences consoleConfigPrefs =
getConsoleConfigPreferences(consoleConfigName);
ConfigurationXMLFactory csfXML = new ConfigurationXMLFactory(
consoleConfigPrefs, props);
- Element rootConsoleConfig = csfXML.createRoot(false);
+ Element rootConsoleConfig = csfXML.createRoot();
//
- Element root = DocumentFactory.getInstance().createElement("project");
//$NON-NLS-1$
- root.addAttribute("name", "CodeGen"); //$NON-NLS-1$ //$NON-NLS-2$
+ Element root = DocumentFactory.getInstance().createElement(CGS.PROJECT);
+ root.addAttribute(CGS.NAME, "CodeGen"); //$NON-NLS-1$
String defaultTargetName = "JdbcCodeGen"; //$NON-NLS-1$
- root.addAttribute("default", defaultTargetName); //$NON-NLS-1$
- Element el = root.addElement("property"); //$NON-NLS-1$
- el.addAttribute("name", "build.dir"); //$NON-NLS-1$ //$NON-NLS-2$
+ root.addAttribute(CGS.DEFAULT, defaultTargetName);
+ Element el = root.addElement(CGS.PROPERTY);
+ el.addAttribute(CGS.NAME, "build.dir"); //$NON-NLS-1$
String location = getResLocation(attributes.getOutputPath());
- el.addAttribute("location", location); //$NON-NLS-1$
- el = root.addElement("property"); //$NON-NLS-1$
- el.addAttribute("name", "jdbc.driver"); //$NON-NLS-1$
//$NON-NLS-2$
+ 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("location", driverURL); //$NON-NLS-1$
+ el.addAttribute(CGS.LOCATION, driverURL);
//
- Element target = root.addElement("target"); //$NON-NLS-1$
- target.addAttribute("name", defaultTargetName); //$NON-NLS-1$
+ Element target = root.addElement(CGS.TARGET);
+ target.addAttribute(CGS.NAME, defaultTargetName);
//
- Element taskdef = target.addElement("taskdef"); //$NON-NLS-1$
- taskdef.addAttribute("name", "hibernatetool"); //$NON-NLS-1$
//$NON-NLS-2$
- taskdef.addAttribute("classname",
"org.hibernate.tool.ant.HibernateToolTask"); //$NON-NLS-1$ //$NON-NLS-2$
+ Element taskdef = target.addElement(CGS.TASKDEF);
+ taskdef.addAttribute(CGS.NAME, CGS.HIBERNATETOOL);
+ taskdef.addAttribute(CGS.CLASSNAME,
"org.hibernate.tool.ant.HibernateToolTask"); //$NON-NLS-1$
//
- Element hibernatetool = target.addElement("hibernatetool"); //$NON-NLS-1$
- hibernatetool.addAttribute("destdir", "${build.dir}");
//$NON-NLS-1$ //$NON-NLS-2$
+ Element hibernatetool = target.addElement(CGS.HIBERNATETOOL);
+ hibernatetool.addAttribute(CGS.DESTDIR, "${build.dir}"); //$NON-NLS-1$
hibernatetool.content().add(rootConsoleConfig);
//
Properties globalProps = new Properties();
- globalProps.put("ejb3", "" + attributes.isEJB3Enabled());
//$NON-NLS-1$ //$NON-NLS-2$
- globalProps.put("jdk5", "" + attributes.isJDK5Enabled());
//$NON-NLS-1$//$NON-NLS-2$
+ globalProps.put(CGS.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
+ globalProps.put(CGS.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
ExporterFactory ef = iter.next();
@@ -112,6 +113,13 @@
Properties expProps = new Properties();
expProps.putAll(globalProps);
expProps.putAll(ef.getProperties());
+ Properties extract = new Properties();
+ try {
+ ExporterFactory.extractExporterProperties(ef.getId(), expProps, extract);
+ } catch (CoreException e) {
+ // ignore
+ }
+ expProps.putAll(extract);
for (Map.Entry<String, ExporterProperty> name2prop : defExpProps.entrySet()) {
Object val = expProps.get(name2prop.getKey());
if (val == null || 0 ==
val.toString().compareTo(name2prop.getValue().getDefaultValue())) {
@@ -122,14 +130,14 @@
if ("hbmtemplate".compareToIgnoreCase(expName) == 0 ) { //$NON-NLS-1$
Element property = null;
if (attributes.isJDK5Enabled()) {
- property = exporter.addElement("property"); //$NON-NLS-1$
- property.addAttribute("key", "jdk5"); //$NON-NLS-1$
//$NON-NLS-2$
- property.addAttribute("value", "" + attributes.isJDK5Enabled());
//$NON-NLS-1$ //$NON-NLS-2$
+ property = exporter.addElement(CGS.PROPERTY);
+ property.addAttribute(CGS.KEY, CGS.JDK5);
+ property.addAttribute(CGS.VALUE, "" + attributes.isJDK5Enabled());
//$NON-NLS-1$
}
if (attributes.isEJB3Enabled()) {
- property = exporter.addElement("property"); //$NON-NLS-1$
- property.addAttribute("key", "ejb3"); //$NON-NLS-1$
//$NON-NLS-2$
- property.addAttribute("value", "" + attributes.isEJB3Enabled());
//$NON-NLS-1$ //$NON-NLS-2$
+ property = exporter.addElement(CGS.PROPERTY);
+ property.addAttribute(CGS.KEY, CGS.EJB3);
+ property.addAttribute(CGS.VALUE, "" + attributes.isEJB3Enabled());
//$NON-NLS-1$
}
}
}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -225,8 +225,8 @@
// Global properties
Properties props = new Properties();
- props.put("ejb3", ""+attributes.isEJB3Enabled());
//$NON-NLS-1$ //$NON-NLS-2$
- props.put("jdk5", ""+attributes.isJDK5Enabled());
//$NON-NLS-1$//$NON-NLS-2$
+ props.put(CGS.EJB3, "" + attributes.isEJB3Enabled());
//$NON-NLS-1$
+ props.put(CGS.JDK5, "" + attributes.isJDK5Enabled());
//$NON-NLS-1$
for (int i = 0; i < exporterFactories.length; i++)
{
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterSettingsTab.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -88,6 +88,7 @@
import org.hibernate.eclipse.console.ExtensionManager;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.EFS;
import org.hibernate.eclipse.console.model.impl.ExporterDefinition;
import org.hibernate.eclipse.console.model.impl.ExporterFactory;
import org.hibernate.eclipse.console.utils.EclipseImages;
@@ -798,7 +799,7 @@
// hard-coded checks: this should be delegated to extension point that knows about the
different exporters.
//Iterator iterator = observableFactoryList.getList().iterator(); // check all
exporters
for (ExporterFactory ef : selectedExporters) {// check only selected exporters
- String str = ef.getProperties().get("outputdir"); //$NON-NLS-1$
+ String str = ef.getProperties().get(EFS.OUTPUTDIR);
String msg = null;
if(str!=null) {
msg = PathHelper.checkDirectory(str,
HibernateConsoleMessages.ExporterSettingsTab_output_directory_for + " " +
ef.getExporterDefinition().getDescription(), true); //$NON-NLS-1$
@@ -808,7 +809,7 @@
}
}
- str = ef.getProperties().get("template_path"); //$NON-NLS-1$
+ str = ef.getProperties().get(EFS.TEMPLATE_PATH);
if(str!=null) {
msg = PathHelper.checkDirectory(str,
HibernateConsoleMessages.ExporterSettingsTab_template_directory_for + " " +
ef.getExporterDefinition().getDescription(), true); //$NON-NLS-1$
if(msg!=null) {
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -40,6 +40,9 @@
*/
package org.hibernate.eclipse.launch;
+import org.hibernate.console.CFS;
+import org.hibernate.eclipse.console.model.impl.EFS;
+
public class HibernateLaunchConstants
{
public static final String ATTR_PREFIX = "org.hibernate.tools.";
//$NON-NLS-1$
@@ -48,13 +51,13 @@
public static final String ATTR_EXPORTERS = ATTR_PREFIX + "exporters";
//$NON-NLS-1$
public static final String ATTR_CONSOLE_CONFIGURATION_NAME = ATTR_PREFIX +
"configurationname"; //$NON-NLS-1$
- public static final String ATTR_OUTPUT_DIR = ATTR_PREFIX + "outputdir";
//$NON-NLS-1$
+ public static final String ATTR_OUTPUT_DIR = ATTR_PREFIX + EFS.OUTPUTDIR;
public static final String ATTR_REVERSE_ENGINEER = ATTR_PREFIX +
"schema2hbm"; //$NON-NLS-1$
- public static final String ATTR_REVERSE_ENGINEER_SETTINGS = ATTR_PREFIX +
"revengfile"; //$NON-NLS-1$
+ public static final String ATTR_REVERSE_ENGINEER_SETTINGS = ATTR_PREFIX +
CFS.REVENGFILE;
public static final String ATTR_REVERSE_ENGINEER_STRATEGY = ATTR_PREFIX +
"revengstrategy"; //$NON-NLS-1$
public static final String ATTR_USE_OWN_TEMPLATES = ATTR_PREFIX +
"useOwnTemplates"; //$NON-NLS-1$
- public static final String ATTR_ENABLE_EJB3_ANNOTATIONS = ATTR_PREFIX +
"ejb3"; //$NON-NLS-1$
- public static final String ATTR_ENABLE_JDK5 = ATTR_PREFIX + "jdk5";
//$NON-NLS-1$
+ public static final String ATTR_ENABLE_EJB3_ANNOTATIONS = ATTR_PREFIX + CGS.EJB3;
+ public static final String ATTR_ENABLE_JDK5 = ATTR_PREFIX + CGS.JDK5;
public static final String ATTR_PACKAGE_NAME = ATTR_PREFIX + "package";
//$NON-NLS-1$
public static final String ATTR_ENABLE_TEMPLATE_DIR = ATTR_PREFIX +
"templatepathenabled"; //$NON-NLS-1$
public static final String ATTR_TEMPLATE_DIR = ATTR_PREFIX + "templatepath";
//$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2010-07-09
16:35:32 UTC (rev 23352)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2010-07-09
17:26:36 UTC (rev 23353)
@@ -50,6 +50,7 @@
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.EFS;
import org.hibernate.eclipse.console.utils.LaunchHelper;
import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
@@ -126,7 +127,7 @@
@SuppressWarnings("unchecked")
private static boolean isExportersAffected(ILaunchConfiguration config,
IPath oldPath) throws CoreException {
- String[] k = new String[]{"outputdir"}; //$NON-NLS-1$
+ String[] k = new String[]{EFS.OUTPUTDIR};
List<String> exporterNames =
config.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.EMPTY_LIST);
for (String exporterName : exporterNames) {
Map<String, String> props =
config.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + '.' +
@@ -229,7 +230,7 @@
@SuppressWarnings("unchecked")
private static void updateExporters(IPath oldPath, IPath newPath,
ILaunchConfigurationWorkingCopy wc) throws CoreException {
- String[] keys = new String[]{"outputdir"}; //$NON-NLS-1$
+ String[] keys = new String[]{EFS.OUTPUTDIR};
List<String> exporterNames =
wc.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.EMPTY_LIST);
for (String exporterName : exporterNames) {
String exporterProp = HibernateLaunchConstants.ATTR_EXPORTERS + '.' +