Author: vyemialyanchyk
Date: 2010-09-08 13:07:38 -0400 (Wed, 08 Sep 2010)
New Revision: 24817
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationProcessListener.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationUtils.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF
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/console/model/impl/ExporterFactory.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/CodeGenerationSettingsTab.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java
Log:
https://jira.jboss.org/browse/JBIDE-6423 - fixed;
https://jira.jboss.org/browse/JBIDE-6648
- fixed
Modified: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF 2010-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/META-INF/MANIFEST.MF 2010-09-08
17:07:38 UTC (rev 24817)
@@ -76,6 +76,11 @@
org.eclipse.datatools.connectivity,
org.eclipse.jpt.core,
org.eclipse.jpt.db,
- org.eclipse.jdt
+ org.eclipse.jdt,
+ org.apache.ant;bundle-version="1.7.1",
+ org.eclipse.ant.core;bundle-version="3.2.200",
+ org.eclipse.ant.launching;bundle-version="1.0.0",
+ org.eclipse.ant.ui;bundle-version="3.5.0",
+ org.eclipse.core.externaltools;bundle-version="1.0.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
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-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/codegen/ExportAntCodeGenWizardPage.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -214,8 +214,7 @@
return null;
}
codeGenXMLFactory = new CodeGenXMLFactory(lc);
- String externalPropFileName = CodeGenXMLFactory.propFileNameSuffix;
- externalPropFileName = getFileName() + "." + externalPropFileName;
//$NON-NLS-1$
+ String externalPropFileName =
CodeGenXMLFactory.getExternalPropFileNameStandard(getFileName());
codeGenXMLFactory.setExternalPropFileName(externalPropFileName);
codeGenXMLFactory.setPlace2Generate(getContainerFullPath().toString());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
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-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -166,6 +166,36 @@
IStringVariableManager variableManager =
VariablesPlugin.getDefault().getStringVariableManager();
return variableManager.performStringSubstitution(expression, false);
}
+
+ /**
+ * ExporterFactory update a collection of output directories,
+ * true if new output directory was added into the set of outputDirs.
+ *
+ * @param defOutDir
+ * @param globalProps
+ * @param outputDirs
+ * @return true if new output directory added
+ * @throws CoreException
+ */
+ public boolean collectOutputDirectories(String defOutDir, final Properties globalProps,
+ Set<String> outputDirs) throws CoreException {
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProps);
+ props.putAll(getProperties());
+ extractExporterProperties(exporterId, props, extract);
+ String outputPath = defOutDir;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ boolean res = false;
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ res = outputDirs.add(loc);
+ }
+ return res;
+ }
/**
* Creates exporter with the specified settings; also resolves any relevant properties
via Eclipse VariablesPlugin.
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-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenXMLFactory.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -516,4 +516,9 @@
return workspacePath;
}
+ public static String getExternalPropFileNameStandard(String fileName) {
+ String externalPropFileName = CodeGenXMLFactory.propFileNameSuffix;
+ externalPropFileName = fileName + "." + externalPropFileName; //$NON-NLS-1$
+ return externalPropFileName;
+ }
}
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-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationLaunchDelegate.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -22,6 +22,9 @@
package org.hibernate.eclipse.launch;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.util.HashSet;
import java.util.Iterator;
@@ -30,12 +33,16 @@
import java.util.Properties;
import java.util.Set;
+import org.eclipse.ant.internal.launching.launchConfigurations.AntLaunchDelegate;
+import org.eclipse.ant.launching.IAntLaunchConstants;
+import org.eclipse.core.externaltools.internal.IExternalToolConstants;
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.manipulation.FileBufferOperationRunner;
import org.eclipse.core.filebuffers.manipulation.MultiTextEditWithProgress;
import org.eclipse.core.filebuffers.manipulation.TextFileBufferOperation;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Assert;
@@ -46,14 +53,17 @@
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.model.IProcess;
import org.eclipse.debug.ui.RefreshTab;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.ToolFactory;
import org.eclipse.jdt.core.formatter.CodeFormatter;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jface.text.DocumentRewriteSessionType;
import org.eclipse.jface.text.IDocument;
import org.eclipse.osgi.util.NLS;
@@ -77,8 +87,10 @@
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
-public class CodeGenerationLaunchDelegate extends
- LaunchConfigurationDelegate {
+@SuppressWarnings("restriction")
+public class CodeGenerationLaunchDelegate extends AntLaunchDelegate {
+
+ protected IPath path2GenBuildXml = null;
private static final class FormatGeneratedCode extends TextFileBufferOperation {
private FormatGeneratedCode(String name) {
@@ -115,28 +127,136 @@
}
}
+ /**
+ * Create file with file name fileName and content fileContent
+ *
+ * @param fileName - file name
+ * @param fileContent - file content
+ * @throws IOException
+ */
+ protected void createFile(String fileName, String fileContent) throws IOException {
+ FileOutputStream fos = null;
+ try {
+ File ff = new File(fileName);
+ if (!ff.exists()) {
+ ff.createNewFile();
+ }
+ fos = new FileOutputStream(fileName);
+ fos.write(fileContent.getBytes());
+ fos.flush();
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {}
+ }
+ }
+ }
+
+ /**
+ * Create temporary build.xml and then erase it after code generation complete
+ *
+ * @param lc
+ * @throws IOException
+ * @throws UnsupportedEncodingException
+ */
+ protected void createBuildXmlFile(ILaunchConfiguration lc, String fileName) throws
UnsupportedEncodingException, IOException {
+ CodeGenXMLFactory codeGenXMLFactory = new CodeGenXMLFactory(lc);
+ String externalPropFileName =
CodeGenXMLFactory.getExternalPropFileNameStandard(fileName);
+ codeGenXMLFactory.setExternalPropFileName(externalPropFileName);
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ if (workspace != null && workspace.getRoot() != null &&
workspace.getRoot().getLocation() != null) {
+ codeGenXMLFactory.setWorkspacePath(workspace.getRoot().getLocation().toString());
+ }
+ String buildXml = codeGenXMLFactory.createCodeGenXML();
+ createFile(fileName, buildXml);
+ final String propFileContentPreSave = codeGenXMLFactory.getPropFileContentPreSave();
+ createFile(externalPropFileName, propFileContentPreSave);
+ }
+
+ /**
+ * Update launch configuration with attributes required for external process codegen.
+ *
+ * @param lc
+ * @return
+ * @throws CoreException
+ */
+ public ILaunchConfiguration updateLaunchConfig(ILaunchConfiguration lc) throws
CoreException {
+ ILaunchConfigurationWorkingCopy lcwc = lc.getWorkingCopy();
+ String fileName = null;
+ try {
+ fileName = getPath2GenBuildXml().toString();
+ } catch (IOException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ }
+ // setup location of Ant build.xml file
+ lcwc.setAttribute(IExternalToolConstants.ATTR_LOCATION, fileName);
+ // setup Ant runner main type
+ lcwc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
+ IAntLaunchConstants.MAIN_TYPE_NAME);
+ // setup ant remote process factory
+ lcwc.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID,
"org.eclipse.ant.ui.remoteAntProcessFactory"); //$NON-NLS-1$
+ // refresh whole workspace
+ //lcwc.setAttribute(RefreshUtil.ATTR_REFRESH_SCOPE, RefreshUtil.MEMENTO_WORKSPACE);
+ return lcwc;
+ }
+ public ILaunch getLaunch(ILaunchConfiguration configuration, String mode)
+ throws CoreException {
+ configuration = updateLaunchConfig(configuration);
+ return super.getLaunch(configuration, mode);
+ }
+
public void launch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(configuration);
Assert.isNotNull(monitor);
- try {
- ExporterAttributes attributes = new ExporterAttributes(configuration);
-
- List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
- for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
+ ExporterAttributes attributes = new ExporterAttributes(configuration);
+ List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
+ for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
+ ExporterFactory exFactory = iter.next();
+ if (!exFactory.isEnabled(configuration)) {
+ iter.remove();
+ }
+ }
+ if (attributes.isUseExternalProcess()) {
+ // create temporary build.xml and then erase it after code generation complete
+ String fileName = null;
+ try {
+ fileName = getPath2GenBuildXml().toString();
+ createBuildXmlFile(configuration, fileName);
+ } catch (UnsupportedEncodingException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ } catch (IOException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ }
+ configuration = updateLaunchConfig(configuration);
+ super.launch(configuration, mode, launch, monitor);
+ //
+ final Properties props = new Properties();
+ props.put(CodeGenerationStrings.EJB3, "" +
attributes.isEJB3Enabled()); //$NON-NLS-1$
+ props.put(CodeGenerationStrings.JDK5, "" +
attributes.isJDK5Enabled()); //$NON-NLS-1$
+ Set<String> outputDirs = new HashSet<String>();
+ for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
ExporterFactory exFactory = iter.next();
- if(!exFactory.isEnabled(configuration)) {
- iter.remove();
- }
+ exFactory.collectOutputDirectories(attributes.getOutputPath(),
+ props, outputDirs);
}
-
+ //
+ final IProcess[] processes = launch.getProcesses();
+ // codegen listener to erase build.xml file after codegen process complete
+ CodeGenerationProcessListener refresher = new CodeGenerationProcessListener(
+ processes[0], fileName, outputDirs);
+ refresher.startBackgroundRefresh();
+ return;
+ }
+ try {
Set<String> outputDirectories = new HashSet<String>();
ExporterFactory[] exporters = exporterFactories.toArray( new
ExporterFactory[exporterFactories.size()] );
ArtifactCollector collector = runExporters(attributes, exporters,
outputDirectories, monitor);
for (String path : outputDirectories) {
- refreshOutputDir( path );
+ CodeGenerationUtils.refreshOutputDir(path);
}
RefreshTab.refreshResources(configuration, monitor);
@@ -186,18 +306,6 @@
}
- private void refreshOutputDir(String outputdir) {
- IResource bufferRes = PathHelper.findMember(ResourcesPlugin.getWorkspace().getRoot(),
outputdir);
-
- if (bufferRes != null && bufferRes.isAccessible()) {
- try {
- bufferRes.refreshLocal(IResource.DEPTH_INFINITE, null);
- } catch (CoreException e) {
- //ignore, maybe merge into possible existing status.
- }
- }
- }
-
private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final
IProgressMonitor monitor)
throws CoreException
{
@@ -381,4 +489,12 @@
throws CoreException {
throw new CoreException(new Status(IStatus.ERROR, HibernateConsolePlugin.ID, code,
message, exception));
}
+
+ public IPath getPath2GenBuildXml() throws IOException {
+ if (path2GenBuildXml != null) {
+ return path2GenBuildXml;
+ }
+ path2GenBuildXml = new Path(File.createTempFile("build_",
"xml").getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
+ return path2GenBuildXml;
+ }
}
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationProcessListener.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationProcessListener.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationProcessListener.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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;
+
+import java.io.File;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.model.IProcess;
+
+/**
+ * Refreshes resources as specified by a launch configuration, when
+ * an associated process terminates.
+ *
+ * Here the listener intended to delete temporary generated Ant build.xml file.
+ *
+ * @author Vitali Yemialyanchyk
+ */
+public class CodeGenerationProcessListener implements IDebugEventSetListener {
+
+ protected IProcess process;
+ protected String fileName;
+ protected Set<String> outputDirs;
+
+ public CodeGenerationProcessListener(IProcess process, String fileName,
+ Set<String> outputDirs) {
+ this.process = process;
+ this.fileName = fileName;
+ this.outputDirs = outputDirs;
+ }
+
+ /**
+ * If the process has already terminated, resource refreshing is done
+ * immediately in the current thread. Otherwise, refreshing is done when the
+ * process terminates.
+ */
+ public void startBackgroundRefresh() {
+ synchronized (process) {
+ if (process.isTerminated()) {
+ refresh();
+ } else {
+ DebugPlugin.getDefault().addDebugEventListener(this);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
+ */
+ public void handleDebugEvents(DebugEvent[] events) {
+ for (int i = 0; i < events.length; i++) {
+ DebugEvent event = events[i];
+ if (event.getSource() == process && event.getKind() == DebugEvent.TERMINATE)
{
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ refresh();
+ break;
+ }
+ }
+ }
+
+ /**
+ * Submits a job to do the refresh, i.e. delete temporary build.xml and
+ * it's parent directory.
+ */
+ protected void refresh() {
+ // erase file fileName
+ IPath path2File = new Path(fileName);
+ File file = path2File.toFile();
+ file.delete();
+ //
+ String externalPropFileName =
CodeGenXMLFactory.getExternalPropFileNameStandard(fileName);
+ path2File = new Path(externalPropFileName);
+ file = path2File.toFile();
+ file.delete();
+ for (String path : outputDirs) {
+ CodeGenerationUtils.refreshOutputDir(path);
+ }
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java 2010-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationSettingsTab.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -92,8 +92,8 @@
private SelectionButtonDialogField useOwnTemplates;
private DirectoryBrowseField templatedir;
+ private SelectionButtonDialogField useExternalProcess;
-
public CodeGenerationSettingsTab() {
super();
}
@@ -113,6 +113,16 @@
layout.numColumns = 4;
layout.verticalSpacing = 10;
+ IDialogFieldListener fieldlistener = new IDialogFieldListener() {
+ public void dialogFieldChanged(DialogField field) {
+ dialogChanged();
+ }
+ };
+
+ useExternalProcess = new SelectionButtonDialogField(SWT.CHECK);
+ useExternalProcess.setDialogFieldListener(fieldlistener);
+ useExternalProcess.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_use_generation_in_external_process);
+
consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
ConsoleConfiguration[] cfg = LaunchHelper.findFilteredSortedConsoleConfigs();
@@ -124,12 +134,6 @@
}
consoleConfigurationName.setItems(names);
- IDialogFieldListener fieldlistener = new IDialogFieldListener() {
- public void dialogFieldChanged(DialogField field) {
- dialogChanged();
- }
- };
-
consoleConfigurationName.setDialogFieldListener(fieldlistener);
outputdir = new StringButtonDialogField(new IStringButtonAdapter() {
@@ -242,6 +246,7 @@
useOwnTemplates.attachDialogField(templatedir);
reverseengineer.attachDialogFields(new DialogField[] { packageName,
preferRawCompositeIds, reverseEngineeringSettings, reverseEngineeringStrategy,
autoManyToMany, autoOneToOne, autoVersioning });
+ useExternalProcess.doFillIntoGrid(container, 4);
consoleConfigurationName.doFillIntoGrid(container, 4);
Control[] controls = outputdir.doFillIntoGrid(container, 4);
// Hack to tell the text field to stretch!
@@ -280,12 +285,20 @@
outputdir.setEnabled(!configSelected);
reverseengineer.setEnabled(!configSelected);
useOwnTemplates.setEnabled(!configSelected);
+ useExternalProcess.setEnabled(!configSelected);
+ boolean useExternalProcessFlag = useExternalProcess.isSelected();
+ preferRawCompositeIds.setEnabled(reverseengineer.isSelected() &&
+ !configSelected && !useExternalProcessFlag);
+ if (useExternalProcessFlag) {
+ preferRawCompositeIds.setSelection(true);
+ }
+
if (configSelected) {
updateStatus(HibernateConsoleMessages.CodeGenerationSettingsTab_console_cfg_must_be_specified);
return;
}
-
+
String msg = PathHelper.checkDirectory(outputdir.getText(),
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, true);
if (msg!=null) {
@@ -377,7 +390,7 @@
public String getConfigurationName() {
String text = consoleConfigurationName.getText();
- return NULL_CONFIG.equals(text) ? "" : text;
+ return NULL_CONFIG.equals(text) ? "" : text; //$NON-NLS-1$
}
@@ -424,27 +437,29 @@
}
public void initializeFrom(ILaunchConfiguration configuration) {
+ ExporterAttributes attributes = null;
try {
- ExporterAttributes attributes = new ExporterAttributes(configuration);
- if ( consoleConfigurationName.getText() !=
attributes.getConsoleConfigurationName()){
- consoleConfigurationName.selectItem(0);//NULL_CONFIG
- consoleConfigurationName.setText(attributes.getConsoleConfigurationName());
- }
-
- preferRawCompositeIds.setSelection(attributes.isPreferBasicCompositeIds());
- autoManyToMany.setSelection( attributes.detectManyToMany() );
- autoVersioning.setSelection( attributes.detectOptimisticLock() );
- autoOneToOne.setSelection( attributes.detectOneToOne());
- outputdir.setText(safeText(attributes.getOutputPath()));
- reverseengineer.setSelection(attributes.isReverseEngineer());
- reverseEngineeringSettings.setText(safeText(attributes.getRevengSettings()));
- reverseEngineeringStrategy.setText(safeText(attributes.getRevengStrategy()));
- useOwnTemplates.setSelection(attributes.isUseOwnTemplates());
- packageName.setText(safeText(attributes.getPackageName()));
- templatedir.setText(safeText(attributes.getTemplatePath()));
+ attributes = new ExporterAttributes(configuration);
} catch (CoreException ce) {
- HibernateConsolePlugin.getDefault().logErrorMessage(HibernateConsoleMessages.CodeGenerationSettingsTab_problems_when_reading,
ce);
+ HibernateConsolePlugin.getDefault().logErrorMessage(
+ HibernateConsoleMessages.CodeGenerationSettingsTab_problems_when_reading, ce);
}
+ if (attributes == null) {
+ return;
+ }
+ consoleConfigurationName.setText(attributes.getConsoleConfigurationName());
+ preferRawCompositeIds.setSelection(attributes.isPreferBasicCompositeIds());
+ autoManyToMany.setSelection( attributes.detectManyToMany() );
+ autoVersioning.setSelection( attributes.detectOptimisticLock() );
+ autoOneToOne.setSelection( attributes.detectOneToOne());
+ outputdir.setText(safeText(attributes.getOutputPath()));
+ reverseengineer.setSelection(attributes.isReverseEngineer());
+ reverseEngineeringSettings.setText(safeText(attributes.getRevengSettings()));
+ reverseEngineeringStrategy.setText(safeText(attributes.getRevengStrategy()));
+ useOwnTemplates.setSelection(attributes.isUseOwnTemplates());
+ packageName.setText(safeText(attributes.getPackageName()));
+ templatedir.setText(safeText(attributes.getTemplatePath()));
+ useExternalProcess.setSelection(attributes.isUseExternalProcess());
}
private String safeText(String text) {
@@ -453,29 +468,30 @@
private String strOrNull(String text) {
if(text==null || text.trim().length()==0) {
- return null;
- } else {
- return text;
+ text = null;
}
+ return text;
}
- public void performApply(ILaunchConfigurationWorkingCopy configuration) {
- configuration.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
strOrNull(outputdir.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
preferRawCompositeIds.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY,
autoManyToMany.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE,
autoOneToOne.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING,
autoVersioning.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER,
isReverseEngineerEnabled());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
strOrNull(reverseEngineeringStrategy.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
strOrNull(reverseEngineeringSettings.getText()));
+ public void performApply(ILaunchConfigurationWorkingCopy config) {
+ config.setAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
strOrNull(outputdir.getText()));
+ config.setAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
preferRawCompositeIds.isSelected());
+ config.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY,
autoManyToMany.isSelected());
+ config.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE,
autoOneToOne.isSelected());
+ config.setAttribute(HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING,
autoVersioning.isSelected());
+ config.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER,
isReverseEngineerEnabled());
+ config.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
strOrNull(reverseEngineeringStrategy.getText()));
+ config.setAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
strOrNull(reverseEngineeringSettings.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,
useOwnTemplates.isSelected());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
strOrNull(templatedir.getText()));
+ config.setAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,
useOwnTemplates.isSelected());
+ config.setAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
strOrNull(templatedir.getText()));
- configuration.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
getConfigurationName());
- configuration.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,
getOutputPackage());
+ config.setAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,
getConfigurationName());
+ config.setAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME, getOutputPackage());
+ config.setAttribute(HibernateLaunchConstants.ATTR_USE_EXTERNAL_PROCESS,
useExternalProcess.isSelected());
+
}
public String getName() {
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationUtils.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationUtils.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/CodeGenerationUtils.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -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;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Utility class for code generation.
+ */
+public class CodeGenerationUtils {
+
+ public static void refreshOutputDir(String outputdir) {
+ IResource bufferRes = PathHelper.findMember(ResourcesPlugin.getWorkspace().getRoot(),
+ outputdir);
+
+ if (bufferRes != null && bufferRes.isAccessible()) {
+ try {
+ bufferRes.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException e) {
+ // ignore, maybe merge into possible existing status.
+ }
+ }
+ }
+}
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java 2010-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ExporterAttributes.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -65,6 +65,7 @@
public class ExporterAttributes
{
private boolean reverseEngineer, useOwnTemplates, enableJDK5, enableEJB3,
preferBasicCompositeIds;
+ private boolean useExternalProcess;
private String consoleConfigurationName;
private String revengSettings;
private String revengStrategy;
@@ -95,6 +96,7 @@
revengSettings =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
""); //$NON-NLS-1$
revengStrategy =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
""); //$NON-NLS-1$
useOwnTemplates =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,false);
+ useExternalProcess =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_EXTERNAL_PROCESS, false);
enableJDK5 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5,false);
enableEJB3 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,false);
packageName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,"");
//$NON-NLS-1$
@@ -336,6 +338,16 @@
{
this.useOwnTemplates = useOwnTemplates;
}
+
+ public boolean isUseExternalProcess()
+ {
+ return useExternalProcess;
+ }
+
+ public void setUseExternalProcess(boolean useExternalProcess)
+ {
+ this.useExternalProcess = useExternalProcess;
+ }
public List<ExporterFactory> getExporterFactories() {
return exporterFactories;
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-09-08
16:02:20 UTC (rev 24816)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/HibernateLaunchConstants.java 2010-09-08
17:07:38 UTC (rev 24817)
@@ -56,6 +56,7 @@
public static final String ATTR_REVERSE_ENGINEER_SETTINGS = ATTR_PREFIX +
ConfigurationXMLStrings.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_USE_EXTERNAL_PROCESS = ATTR_PREFIX +
"useExternalProcess"; //$NON-NLS-1$
public static final String ATTR_ENABLE_EJB3_ANNOTATIONS = ATTR_PREFIX +
CodeGenerationStrings.EJB3;
public static final String ATTR_ENABLE_JDK5 = ATTR_PREFIX +
CodeGenerationStrings.JDK5;
public static final String ATTR_PACKAGE_NAME = ATTR_PREFIX + "package";
//$NON-NLS-1$