[jbosstools-commits] JBoss Tools SVN: r24108 - in trunk/hibernatetools/plugins: org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Aug 12 11:47:05 EDT 2010
Author: vyemialyanchyk
Date: 2010-08-12 11:47:05 -0400 (Thu, 12 Aug 2010)
New Revision: 24108
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/CodeGenXMLFactory.java
trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
Log:
https://jira.jboss.org/browse/JBIDE-6809 - fixed
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-08-12 15:46:46 UTC (rev 24107)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConfigurationXMLFactory.java 2010-08-12 15:47:05 UTC (rev 24108)
@@ -21,6 +21,8 @@
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences;
import org.hibernate.console.preferences.ConsoleConfigurationPreferences.ConfigurationMode;
import org.hibernate.util.StringHelper;
@@ -33,8 +35,18 @@
* @author Vitali Yemialyanchyk
*/
public class ConfigurationXMLFactory {
+
protected ConsoleConfigurationPreferences prefs;
protected Properties additional;
+ /**
+ * place to generate Ant script file (all paths in script should be
+ * relative to this place)
+ */
+ protected IPath pathPlace2Generate = null;
+ /**
+ * workspace path
+ */
+ protected IPath pathWorkspacePath = null;
public ConfigurationXMLFactory(ConsoleConfigurationPreferences prefs, Properties additional) {
this.prefs = prefs;
@@ -66,8 +78,12 @@
rootName = ConfigurationXMLStrings.CONFIGURATION;
}
Element root = DocumentFactory.getInstance().createElement(rootName);
- updateAttr(root, file2Str(prefs.getConfigXMLFile()), ConfigurationXMLStrings.CONFIGURATIONFILE);
- updateAttr(root, file2Str(prefs.getPropertyFile()), ConfigurationXMLStrings.PROPERTYFILE);
+ String tmp = file2Str(prefs.getConfigXMLFile());
+ tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath);
+ updateAttr(root, tmp, ConfigurationXMLStrings.CONFIGURATIONFILE);
+ tmp = file2Str(prefs.getPropertyFile());
+ tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath);
+ updateAttr(root, tmp, ConfigurationXMLStrings.PROPERTYFILE);
updateAttr(root, prefs.getEntityResolverName(), ConfigurationXMLStrings.ENTITYRESOLVER);
updateAttr(root, prefs.getNamingStrategy(), ConfigurationXMLStrings.NAMINGSTRATEGY);
updateAttr(root, prefs.getPersistenceUnitName(), ConfigurationXMLStrings.PERSISTENCEUNIT);
@@ -85,14 +101,21 @@
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$
- include.addAttribute("name", mappingFiles[i].getAbsolutePath()); //$NON-NLS-1$
+ tmp = mappingFiles[i].getAbsolutePath();
+ tmp = new Path(tmp).toString();
+ tmp = makePathRelative(tmp, pathPlace2Generate, pathWorkspacePath);
+ include.addAttribute("name", tmp); //$NON-NLS-1$
}
}
return root;
}
public static String file2Str(File file) {
- return file == null ? null : file.getPath();
+ String res = file == null ? null : file.getPath();
+ if (res != null) {
+ res = new Path(res).toString();
+ }
+ return res;
}
public static void updateAttr(Element el, String val, String prName) {
@@ -131,4 +154,35 @@
}
}
}
+
+ public static String makePathRelative(String strPathItem, final IPath pathPlace2Generate, final IPath pathWorkspacePath) {
+ if (strPathItem != null && pathPlace2Generate != null && pathWorkspacePath != null) {
+ IPath tmpPath = new Path(strPathItem);
+ if (pathWorkspacePath.isPrefixOf(tmpPath)) {
+ tmpPath = tmpPath.makeRelativeTo(pathPlace2Generate);
+ strPathItem = pathPlace2Generate.toString();
+ String tmp = tmpPath.toString();
+ if (tmp.length() > 0) {
+ strPathItem += IPath.SEPARATOR + tmp;
+ }
+ }
+ }
+ return strPathItem;
+ }
+
+ public void setPlace2Generate(IPath pathPlace2Generate) {
+ this.pathPlace2Generate = pathPlace2Generate;
+ }
+
+ public IPath getPlace2Generate() {
+ return pathPlace2Generate;
+ }
+
+ public void setWorkspacePath(IPath pathWorkspacePath) {
+ this.pathWorkspacePath = pathWorkspacePath;
+ }
+
+ public IPath getWorkspacePath() {
+ return pathWorkspacePath;
+ }
}
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-08-12 15:46:46 UTC (rev 24107)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java 2010-08-12 15:47:05 UTC (rev 24108)
@@ -217,6 +217,11 @@
String externalPropFileName = CodeGenXMLFactory.propFileNameSuffix;
externalPropFileName = getFileName() + "." + externalPropFileName; //$NON-NLS-1$
codeGenXMLFactory.setExternalPropFileName(externalPropFileName);
+ codeGenXMLFactory.setPlace2Generate(getContainerFullPath().toString());
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace != null && workspace.getRoot() != null && workspace.getRoot().getLocation() != null) {
+ codeGenXMLFactory.setWorkspacePath(workspace.getRoot().getLocation().toString());
+ }
String buildXml = codeGenXMLFactory.createCodeGenXML();
return new ByteArrayInputStream(buildXml.getBytes());
}
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-12 15:46:46 UTC (rev 24107)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-08-12 15:47:05 UTC (rev 24108)
@@ -27,6 +27,8 @@
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
import org.eclipse.datatools.connectivity.drivers.DriverInstance;
@@ -52,12 +54,18 @@
*/
public class CodeGenXMLFactory {
+ public static final String varBuildDir = "build.dir"; //$NON-NLS-1$
+ public static final String varCurrentDir = "current.dir"; //$NON-NLS-1$
+ public static final String varWorkspaceDir = "workspace.dir"; //$NON-NLS-1$
+
public static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
/**
* UUID to make a stub for propFileContentPreSave,
* before formatting
*/
public static final long versionUID4PropFile = 1841714864553304000L;
+ public static final long place2GenerateUID = 3855319363698081943L;
+ public static final long workspacePathUID = 2720818065195124531L;
/**
*/
public static final String propFileNameSuffix = "hibernate.properties"; //$NON-NLS-1$
@@ -79,6 +87,15 @@
* file name for generated properties file
*/
protected String externalPropFileName = propFileNameSuffix;
+ /**
+ * place to generate Ant script file (all paths in script should be
+ * relative to this place)
+ */
+ protected String place2Generate = ""; //$NON-NLS-1$
+ /**
+ * workspace path
+ */
+ protected String workspacePath = ""; //$NON-NLS-1$
public CodeGenXMLFactory(ILaunchConfiguration lc) {
this.lc = lc;
@@ -107,21 +124,39 @@
String revEngFile = getResLocation(attributes.getRevengSettings());
props.setProperty(ConfigurationXMLStrings.REVENGFILE, revEngFile);
}
+ //
+ final IPath pathPlace2Generate = isEmpty(place2Generate) ? null : new Path(getResLocation(place2Generate));
+ final IPath pathWorkspacePath = isEmpty(workspacePath) ? null : new Path(getResLocation(workspacePath));
+ //
String consoleConfigName = attributes.getConsoleConfigurationName();
ConsoleConfigurationPreferences consoleConfigPrefs =
getConsoleConfigPreferences(consoleConfigName);
final ConfigurationXMLFactory configurationXMLFactory = new ConfigurationXMLFactory(
consoleConfigPrefs, props);
+ configurationXMLFactory.setPlace2Generate(pathPlace2Generate);
+ configurationXMLFactory.setWorkspacePath(pathWorkspacePath);
Element rootConsoleConfig = configurationXMLFactory.createRoot();
//
String defaultTargetName = "hibernateAntCodeGeneration"; //$NON-NLS-1$
- Element root = DocumentFactory.getInstance().createElement(CodeGenerationStrings.PROJECT);
+ Element el, root = DocumentFactory.getInstance().createElement(CodeGenerationStrings.PROJECT);
root.addAttribute(CodeGenerationStrings.NAME, "CodeGen"); //$NON-NLS-1$
root.addAttribute(CodeGenerationStrings.DEFAULT, defaultTargetName);
//
+ if (!isEmpty(place2Generate)) {
+ el = root.addElement(CodeGenerationStrings.PROPERTY);
+ el.addAttribute(CodeGenerationStrings.NAME, varCurrentDir);
+ el.addAttribute(CodeGenerationStrings.LOCATION, getPlace2GenerateUID());
+ }
+ if (!isEmpty(workspacePath)) {
+ el = root.addElement(CodeGenerationStrings.PROPERTY);
+ el.addAttribute(CodeGenerationStrings.NAME, varWorkspaceDir);
+ el.addAttribute(CodeGenerationStrings.LOCATION, getWorkspacePathUID());
+ }
+ //
String location = getResLocation(attributes.getOutputPath());
- Element el = root.addElement(CodeGenerationStrings.PROPERTY);
- el.addAttribute(CodeGenerationStrings.NAME, "build.dir"); //$NON-NLS-1$
+ location = ConfigurationXMLFactory.makePathRelative(location, pathPlace2Generate, pathWorkspacePath);
+ el = root.addElement(CodeGenerationStrings.PROPERTY);
+ el.addAttribute(CodeGenerationStrings.NAME, varBuildDir);
el.addAttribute(CodeGenerationStrings.LOCATION, location);
//
String hibernatePropFile = null;
@@ -204,7 +239,7 @@
Element target = root.addElement(CodeGenerationStrings.TARGET);
target.addAttribute(CodeGenerationStrings.NAME, generateHibernatePropeties);
//
- hibernatePropFile = "${" + hibernatePropFile + "}"; //$NON-NLS-1$ //$NON-NLS-2$
+ hibernatePropFile = getVar(hibernatePropFile);
Element echo = target.addElement(CodeGenerationStrings.ECHO);
echo.addAttribute(CodeGenerationStrings.FILE, hibernatePropFile);
echo.addText(getPropFileContentStubUID());
@@ -231,6 +266,8 @@
} catch (URISyntaxException e) {
// ignore
}
+ strPathItem = new Path(strPathItem).toString();
+ strPathItem = ConfigurationXMLFactory.makePathRelative(strPathItem, pathPlace2Generate, pathWorkspacePath);
pathItem.addAttribute(CodeGenerationStrings.LOCATION, strPathItem);
}
//
@@ -246,7 +283,7 @@
taskdef.addAttribute(CodeGenerationStrings.CLASSPATHREF, toolslibID);
//
Element hibernatetool = target.addElement(CodeGenerationStrings.HIBERNATETOOL);
- hibernatetool.addAttribute(CodeGenerationStrings.DESTDIR, "${build.dir}"); //$NON-NLS-1$
+ hibernatetool.addAttribute(CodeGenerationStrings.DESTDIR, getVar(varBuildDir));
String templatePath = getResLocation(attributes.getTemplatePath());
if (attributes.isUseOwnTemplates()) {
hibernatetool.addAttribute(CodeGenerationStrings.TEMPLATEPATH, templatePath);
@@ -262,7 +299,7 @@
// the path there are user classes
Element classpath = hibernatetool.addElement(CodeGenerationStrings.CLASSPATH);
Element path = classpath.addElement(CodeGenerationStrings.PATH);
- path.addAttribute(CodeGenerationStrings.LOCATION, "${build.dir}"); //$NON-NLS-1$
+ path.addAttribute(CodeGenerationStrings.LOCATION, getVar(varBuildDir));
//
Map<String, Map<String, AttributeDescription>> exportersDescr =
ExportersXMLAttributeDescription.getExportersDescription();
@@ -363,8 +400,12 @@
return driverClass;
}
+ public String getVar(String str) {
+ return "${" + str + "}"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
public void addIntoPropFileContent(StringBuilder pfc, String str) {
- pfc.append(NL + str + "=${" + str + "}"); //$NON-NLS-1$ //$NON-NLS-2$
+ pfc.append(NL + str + "=" + getVar(str)); //$NON-NLS-1$
}
public void addIntoPropFileContent(StringBuilder pfc, String name, String value) {
@@ -389,7 +430,9 @@
final IResource outputPathRes = findResource(path);
String location = path == null ? "" : path; //$NON-NLS-1$
if (outputPathRes != null) {
- location = outputPathRes.getLocation().toOSString();
+ location = outputPathRes.getLocation().toString();
+ } else {
+ location = new Path(location).toString();
}
return location;
}
@@ -406,10 +449,18 @@
return (str == null || str.length() == 0);
}
- public String getPropFileContentStubUID() {
+ public static String getPropFileContentStubUID() {
return Long.toHexString(versionUID4PropFile);
}
+ public static String getPlace2GenerateUID() {
+ return Long.toHexString(place2GenerateUID);
+ }
+
+ public static String getWorkspacePathUID() {
+ return Long.toHexString(workspacePathUID);
+ }
+
public String getPropFileContentPreSave() {
return propFileContentPreSave == null ? "" : propFileContentPreSave; //$NON-NLS-1$
}
@@ -418,8 +469,18 @@
Element rootBuildXml = createRoot();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ConfigurationXMLFactory.dump(baos, rootBuildXml);
- String res = baos.toString().replace(
- getPropFileContentStubUID(), getPropFileContentPreSave()).trim();
+ String res = baos.toString().trim();
+ //place2Generate, workspacePath
+ if (!isEmpty(place2Generate)) {
+ String location = getResLocation(place2Generate);
+ res = res.replace(location, getVar(varCurrentDir));
+ res = res.replace(getPlace2GenerateUID(), location);
+ }
+ if (!isEmpty(workspacePath)) {
+ String location = getResLocation(workspacePath);
+ res = res.replace(getWorkspacePathUID(), location);
+ }
+ res = res.replace(getPropFileContentStubUID(), getPropFileContentPreSave());
return res;
}
@@ -435,4 +496,20 @@
return externalPropFileName;
}
+ public void setPlace2Generate(String place2Generate) {
+ this.place2Generate = place2Generate;
+ }
+
+ public String getPlace2Generate() {
+ return place2Generate;
+ }
+
+ public void setWorkspacePath(String workspacePath) {
+ this.workspacePath = workspacePath;
+ }
+
+ public String getWorkspacePath() {
+ return workspacePath;
+ }
+
}
More information about the jbosstools-commits
mailing list