Author: vyemialyanchyk
Date: 2010-08-05 08:11:46 -0400 (Thu, 05 Aug 2010)
New Revision: 23936
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java
Log:
https://jira.jboss.org/browse/JBIDE-6723 - fixed - ant exporters attributes description in
xml
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/ant-tasks-description.xml 2010-08-05
12:11:46 UTC (rev 23936)
@@ -0,0 +1,55 @@
+<ant-tasks>
+ <task name="hbm2doc" id="org.hibernate.tools.hbm2doc">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ </task>
+ <task name="hbm2cfgxml" id="org.hibernate.tools.hbm2cfgxml">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <attribute name="ejb3" gui-name="ejb3"
default="false"/>
+ </task>
+ <task name="hbm2hbmxml" id="org.hibernate.tools.hbm2hbmxml">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ </task>
+ <task name="hbmtemplate"
id="org.hibernate.tools.hbmtemplate">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <attribute name="filepattern" gui-name="file_pattern"
default=""/>
+ <attribute name="foreach" gui-name="for_each"
default=""/>
+ <attribute name="template" gui-name="template_name"
default=""/>
+ <attribute name="exporterclass" gui-name="exporterclass"
default=""/>
+ </task>
+ <task name="hbm2java" id="org.hibernate.tools.hbm2java">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <attribute name="jdk5" gui-name="jdk5"
default="false"/>
+ <attribute name="ejb3" gui-name="ejb3"
default="false"/>
+ </task>
+ <task name="hbm2ddl" id="org.hibernate.tools.hbm2ddl">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <attribute name="export" gui-name="exportToDatabase"
default="true"/>
+ <attribute name="update" gui-name="schemaUpdate"
default="false"/>
+ <attribute name="drop" gui-name="drop"
default="false"/>
+ <attribute name="create" gui-name="create"
default="true"/>
+ <attribute name="outputfilename" gui-name="outputfilename"
default=""/>
+ <attribute name="delimiter" gui-name="delimiter"
default=";"/>
+ <attribute name="format" gui-name="format"
default="false"/>
+ <attribute name="haltonerror" gui-name="haltonerror"
default="false"/>
+ <attribute name="console" gui-name="scriptToConsole"
default="true"/>
+ </task>
+ <task name="hbm2dao" id="org.hibernate.tools.hbm2dao">
+ <attribute name="destdir" gui-name="outputdir"
default=""/>
+ <attribute name="templatepath" gui-name="template_path"
default=""/>
+ <attribute name="templateprefix" gui-name="templateprefix"
default=""/>
+ <attribute name="jdk5" gui-name="jdk5"
default="false"/>
+ <attribute name="ejb3" gui-name="ejb3"
default="false"/>
+ </task>
+</ant-tasks>
\ No newline at end of file
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2010-08-05
12:11:15 UTC (rev 23935)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/plugin.xml 2010-08-05
12:11:46 UTC (rev 23936)
@@ -552,7 +552,7 @@
name="dot.executable"
type="string"
value="dot.exe"/>
- <property
+ <property
description="Output directory"
name="outputdir"
type="directory"
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-08-05
12:11:15 UTC (rev 23935)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-08-05
12:11:46 UTC (rev 23936)
@@ -13,10 +13,12 @@
import java.io.ByteArrayOutputStream;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import org.dom4j.DocumentFactory;
import org.dom4j.Element;
@@ -37,7 +39,7 @@
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.eclipse.launch.ExportersXMLAttributeDescription.AttributeDescription;
import org.hibernate.util.StringHelper;
/**
@@ -60,7 +62,9 @@
* this is necessary to proper content formating
*/
protected String propFileContentPreSave = ""; //$NON-NLS-1$
-
+ /**
+ * generate Ant scrip from this launch configuration
+ */
protected ILaunchConfiguration lc = null;
public CodeGenXMLFactory(ILaunchConfiguration lc) {
@@ -225,7 +229,11 @@
Element path = classpath.addElement(CodeGenerationStrings.PATH);
path.addAttribute(CodeGenerationStrings.LOCATION, "${build.dir}");
//$NON-NLS-1$
//
+ Map<String, Map<String, AttributeDescription>> exportersDescr =
+ ExportersXMLAttributeDescription.getExportersDescription();
+ //
Properties globalProps = new Properties();
+ // obligatory global properties
globalProps.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled());
//$NON-NLS-1$
globalProps.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled());
//$NON-NLS-1$
List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
@@ -234,39 +242,65 @@
if (!ef.isEnabled(lc)) {
continue;
}
- Map<String, ExporterProperty> defExpProps = ef.getDefaultExporterProperties();
+ //Map<String, ExporterProperty> defExpProps =
ef.getDefaultExporterProperties();
+ //String expId = ef.getId();
String expName = ef.getExporterTag();
+ // mapping: guiName -> AttributeDescription
+ Map<String, AttributeDescription> attributesDescrGui =
exportersDescr.get(expName);
+ // construct new mapping: name -> AttributeDescription
+ Map<String, AttributeDescription> attributesDescrAnt = new TreeMap<String,
AttributeDescription>();
+ for (AttributeDescription ad : attributesDescrGui.values()) {
+ attributesDescrAnt.put(ad.name, ad);
+ }
+ //
Element exporter = hibernatetool.addElement(expName);
Properties expProps = new Properties();
expProps.putAll(globalProps);
expProps.putAll(ef.getProperties());
- Properties extract = new Properties();
+ //
+ Properties extractGUISpecial = new Properties();
try {
- ExporterFactory.extractExporterProperties(ef.getId(), expProps, extract);
+ ExporterFactory.extractExporterProperties(ef.getId(), expProps, extractGUISpecial);
} 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())) {
+ // convert gui special properties names into Ant names
+ for (Map.Entry<Object, Object> propEntry : extractGUISpecial.entrySet()) {
+ Object key = propEntry.getKey();
+ Object val = propEntry.getValue();
+ AttributeDescription ad = attributesDescrGui.get(key);
+ if (ad == null) {
+ expProps.put(key, val);
continue;
}
- exporter.addAttribute(name2prop.getKey(), val.toString());
+ expProps.put(ad.name, val);
}
- if ("hbmtemplate".compareToIgnoreCase(expName) == 0 ) { //$NON-NLS-1$
- Element property = null;
- if (attributes.isJDK5Enabled()) {
- property = exporter.addElement(CodeGenerationStrings.PROPERTY);
- property.addAttribute(CodeGenerationStrings.KEY, CodeGenerationStrings.JDK5);
- property.addAttribute(CodeGenerationStrings.VALUE, "" +
attributes.isJDK5Enabled()); //$NON-NLS-1$
+ // list2Remove - list to collect properties which put into attributes,
+ // all other properties be ordinal property definition
+ List<Object> list2Remove = new ArrayList<Object>();
+ for (Map.Entry<Object, Object> propEntry : expProps.entrySet()) {
+ Object key = propEntry.getKey();
+ Object val = propEntry.getValue();
+ AttributeDescription ad = attributesDescrAnt.get(key);
+ if (ad == null) {
+ continue;
}
- if (attributes.isEJB3Enabled()) {
- property = exporter.addElement(CodeGenerationStrings.PROPERTY);
- property.addAttribute(CodeGenerationStrings.KEY, CodeGenerationStrings.EJB3);
- property.addAttribute(CodeGenerationStrings.VALUE, "" +
attributes.isEJB3Enabled()); //$NON-NLS-1$
+ list2Remove.add(key);
+ if (val == null || 0 == val.toString().compareTo(ad.defaultValue)) {
+ continue;
}
+ exporter.addAttribute(ad.name, val.toString());
}
+ for (Object obj : list2Remove) {
+ expProps.remove(obj);
+ }
+ for (Map.Entry<Object, Object> propEntry : expProps.entrySet()) {
+ Object key = propEntry.getKey();
+ Object val = propEntry.getValue();
+ Element property = exporter.addElement(CodeGenerationStrings.PROPERTY);
+ property.addAttribute(CodeGenerationStrings.KEY, key.toString());
+ property.addAttribute(CodeGenerationStrings.VALUE, "" + val);
//$NON-NLS-1$
+ }
}
return root;
}
@@ -288,7 +322,7 @@
public String getResLocation(String path) {
final IResource outputPathRes = findResource(path);
- String location = ""; //$NON-NLS-1$
+ String location = path == null ? "" : path; //$NON-NLS-1$
if (outputPathRes != null) {
location = outputPathRes.getLocation().toOSString();
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExportersXMLAttributeDescription.java 2010-08-05
12:11:46 UTC (rev 23936)
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 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;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.dom4j.Document;
+import org.dom4j.DocumentException;
+import org.dom4j.DocumentHelper;
+import org.dom4j.Element;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+
+/**
+ * Ant Hibernate Exporters tasks attribute description.
+ *
+ * @author Vitali Yemialyanchyk
+ */
+public class ExportersXMLAttributeDescription {
+
+ /**
+ * path to file to store description
+ */
+ public static final String ANT_TASKS_DESCRIPTION_PATH =
"ant-tasks-description.xml".replaceAll("//", File.separator);
//$NON-NLS-1$ //$NON-NLS-2$
+
+ public static class AttributeDescription {
+ public String name;
+ public String guiName;
+ public String defaultValue;
+ }
+
+ private static Map<String, Map<String, AttributeDescription>>
mapExporter2AttributeDescr = null;
+
+ private static void initExportersDescriptionmap() {
+ if (mapExporter2AttributeDescr != null) {
+ return;
+ }
+ mapExporter2AttributeDescr = new TreeMap<String, Map<String,
AttributeDescription>>();
+ Document doc = getDocument();
+ if (doc == null) {
+ return;
+ }
+ Element root = doc.getRootElement();
+ @SuppressWarnings("rawtypes")
+ Iterator itTask = root.elementIterator("task"); //$NON-NLS-1$
+ while (itTask.hasNext()) {
+ Element elTask = (Element)itTask.next();
+ Map<String, AttributeDescription> attributes = new TreeMap<String,
AttributeDescription>();
+ @SuppressWarnings("rawtypes")
+ Iterator itAttribute = elTask.elementIterator("attribute"); //$NON-NLS-1$
+ while (itAttribute.hasNext()) {
+ Element elAttribute = (Element)itAttribute.next();
+ AttributeDescription ad = new AttributeDescription();
+ ad.name = elAttribute.attributeValue("name"); //$NON-NLS-1$
+ ad.guiName = elAttribute.attributeValue("gui-name"); //$NON-NLS-1$
+ ad.defaultValue = elAttribute.attributeValue("default"); //$NON-NLS-1$
+ attributes.put(ad.guiName, ad);
+ }
+ //String taskId = elTask.attributeValue("id"); //$NON-NLS-1$
+ String taskName = elTask.attributeValue("name"); //$NON-NLS-1$
+ mapExporter2AttributeDescr.put(taskName, attributes);
+ }
+ }
+
+ /**
+ * get map with core description
+ *
+ * @return
+ */
+ public static Map<String, Map<String, AttributeDescription>>
getExportersDescription() {
+ initExportersDescriptionmap();
+ Map<String, Map<String, AttributeDescription>> res =
+ new TreeMap<String, Map<String, AttributeDescription>>();
+ res.putAll(mapExporter2AttributeDescr);
+ return res;
+ }
+
+ private static Document getDocument() {
+ File resourceFile = null;
+ try {
+ resourceFile = getResourceItem(ANT_TASKS_DESCRIPTION_PATH);
+ } catch (IOException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("getResource: ", e);
//$NON-NLS-1$
+ }
+ if (resourceFile == null || !resourceFile.exists()) {
+ return null;
+ }
+ StringBuffer cbuf = new StringBuffer((int) resourceFile.length());
+ try {
+ String ls = System.getProperties().getProperty("line.separator",
"\n"); //$NON-NLS-1$//$NON-NLS-2$
+ BufferedReader in = new BufferedReader(new FileReader(resourceFile));
+ String str;
+ while ((str = in.readLine()) != null) {
+ cbuf.append(str + ls);
+ }
+ in.close();
+ } catch (IOException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("IOException: ", e);
//$NON-NLS-1$
+ }
+ Document res = null;
+ try {
+ res = DocumentHelper.parseText(cbuf.toString());
+ } catch (DocumentException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("DocumentException: ",
e); //$NON-NLS-1$
+ }
+ return res;
+ }
+
+ private static File getResourceItem(String strResPath) throws IOException {
+ IPath resourcePath = new Path(strResPath);
+ File resourceFile = resourcePath.toFile();
+ URL entry = HibernateConsolePlugin.getDefault().getBundle().getEntry(
+ strResPath);
+ if (entry != null) {
+ URL resProject = FileLocator.resolve(entry);
+ strResPath = FileLocator.resolve(resProject).getFile();
+ }
+ resourceFile = new File(strResPath);
+ return resourceFile;
+ }
+}