From 1ba0ebfe95170c1b0e16a3db28808c0e4366dbd4 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Wed, 10 Aug 2016 22:39:49 -0400 Subject: [PATCH 1/4] Eclipse Launcher Updates - Store the password in secure storage - Add a debug logger - Lots of documentation updates --- .../html-src/eclipseui/eclipseui.html | 2 + .../html-src/eclipseui/usingTheLauncher.html | 77 +++++++++++++++ .../toc_eclipseui.xml | 2 + .../META-INF/MANIFEST.MF | 4 +- .../eclipse/ui/ant/DebugBuildListener.java | 64 ++++++++++++ .../eclipse/ui/launcher/AntFileGenerator.java | 5 +- .../GeneratorLaunchConfigurationDelegate.java | 16 ++- .../ui/launcher/GeneratorLaunchConstants.java | 15 +-- .../ui/launcher/tabs/LauncherUtils.java | 99 +++++++++++++++++++ .../ui/launcher/tabs/SqlScriptComposite.java | 28 +++++- .../ui/launcher/tabs/SqlScriptTab.java | 6 ++ 11 files changed, 303 insertions(+), 15 deletions(-) create mode 100644 eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html create mode 100644 eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java diff --git a/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/eclipseui.html b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/eclipseui.html index 45c372d42d..0a832ad953 100644 --- a/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/eclipseui.html +++ b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/eclipseui.html @@ -46,6 +46,8 @@

MyBatis Generator Launch Configuration

with the normal Eclipse launch support. You can also add entries to the generator's classpath through the same launch configuration support. This should make it easier to access JDBC drivers, or to access your own generator plugins.

+

See the page Using the Launcher for more +information about using the launcher.

Integrated Ant Task

See the page Using the Integrated Ant Task for more diff --git a/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html new file mode 100644 index 0000000000..547f0b317d --- /dev/null +++ b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html @@ -0,0 +1,77 @@ + + + + + Using the Launcher + + + +

Using the Launcher

+

The MyBatis Generator feature includes a custom launcher for +running MyBatis generator. The launcher leverages Eclipse's launch support +and enables you to create any number of custom launches. The launcher has far +more capability than the previous popup menu action. Further, the launch support +does not alter the Eclipse IDE classpath - which could happen inadvertently with +the prior popup menu action.

+

On this page we will cover some of the technical internals of the launcher. +We assume you are familiar with how the Eclipse launch support works in general. +If you are not familiar with Eclipse launching, just know that launch configurations +can be accessed with the Run>Run Configurations... or Run>Debug Configurations... +menu options.

+ +

Launcher Internals

+

Internally the launcher uses the MyBatis Generator Ant task to run the generator. The +launcher creates an Ant build script based on attributes in the launch +configuration and then uses Eclipse's Ant support to run the script.

+

The launch configuration allows you to specify a SQL script to run +before the generator is run. This can be useful when using in-memory databases +and is used during testing of the feature. Running a SQL script is accomplished +by using Ant's built in +SQL task to run a script you specify. See the Ant documentation for details +about the capabilities of the SQL task.

+ +

Working with the Classpath

+

The launcher allows you to add entries to the runtime classpath +of the launch. This can be used to add JDBC drivers to the classpath, and could +also be used to add Eclipse projects to the classpath. If you are developing a +plugin, you could add your plugin project to the classpath to test your plugin.

+

If you are developing a plugin, you do not need to add MyBatis Generator +itself to the launch classpath as it will already be added by the launcher.

+

Adding entries to the launcher classpath is generally preferable to using +a <classPathEntry> configuration element in the generator +configuration file. However, if you use a dependency JAR that relies on native code +(such as some DB2 drivers) it would be better to use the +<classPathEntry> configuration element. This because native +code can only be loaded by a single classloader and it is likely that +the generator classloader will be garbage collected before the launch classloader.

+ +

What's Different in a Debug Launch?

+

If you launch in debug mode, rather than run mode, the launcher will +launch Ant in debug mode and will log all messages to +a new Eclipse console called "MyBatis Generator". This can be useful when +using an SQL script as you will be able to see the script progress in the +console. You will also see many Ant configuration messages.

+ +

How Passwords are Stored

+

If you specify a password for connecting to a database with the Ant script, you +have options on how that password is stored.

+

If you select the check box specifying that +credentials should be stored in secure storage, then the user ID and password will +be stored in Eclipse's internal secure storage system. The password will be encrypted +using Eclipse's default support. The password will be in clear text in the generated Ant +script while the launch is running, but the generated Ant file will be deleted after the +launch completes.

+

If you do not select the check box specifying that +credentials should be stored in secure storage, then the user ID and password will +be stored in clear text in the Eclipse launch configuration. The password will also +be in clear text in the generated Ant script while the launch is running, and the +generated Ant file will not be deleted after the launch completes.

+

Launch configuration files are stored in
+<workspace-directory>/.metadata/.plugins/org.eclipse.debug.core/.launches +

+

The generated Ant files are stored in
+<workspace-directory>/.metadata/.plugins/org.mybatis.generator.eclipse.ui/.generatedAntScripts +

+ + diff --git a/eclipse/org.mybatis.generator.eclipse.doc/toc_eclipseui.xml b/eclipse/org.mybatis.generator.eclipse.doc/toc_eclipseui.xml index 62ef539d0f..04d824e25e 100644 --- a/eclipse/org.mybatis.generator.eclipse.doc/toc_eclipseui.xml +++ b/eclipse/org.mybatis.generator.eclipse.doc/toc_eclipseui.xml @@ -6,6 +6,8 @@ + + diff --git a/eclipse/org.mybatis.generator.eclipse.ui/META-INF/MANIFEST.MF b/eclipse/org.mybatis.generator.eclipse.ui/META-INF/MANIFEST.MF index fdc1646482..f0ca94abe1 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/META-INF/MANIFEST.MF +++ b/eclipse/org.mybatis.generator.eclipse.ui/META-INF/MANIFEST.MF @@ -20,7 +20,9 @@ Require-Bundle: org.eclipse.ui, org.eclipse.jdt.launching;bundle-version="3.8.0", org.eclipse.jdt.debug.ui;bundle-version="3.7.101", org.eclipse.core.expressions, - org.eclipse.core.variables;bundle-version="3.2.800" + org.eclipse.core.variables;bundle-version="3.2.800", + org.eclipse.equinox.security;bundle-version="1.2.100", + org.eclipse.ui.console;bundle-version="3.6.100" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: org.mybatis.generator.eclipse.ui, diff --git a/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java b/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java new file mode 100644 index 0000000000..6f2ca98cbc --- /dev/null +++ b/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java @@ -0,0 +1,64 @@ +package org.mybatis.generator.eclipse.ui.ant; + +import java.io.IOException; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildListener; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IOConsole; +import org.eclipse.ui.console.IOConsoleOutputStream; + +public class DebugBuildListener implements BuildListener { + private IOConsole console = new IOConsole("MyBatis Generator", null); //$NON-NLS-1$ + private IOConsoleOutputStream outputStream = console.newOutputStream(); + + public DebugBuildListener() { + ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] {console}); + } + + @Override + public void buildStarted(BuildEvent event) { + writeMessage("MyBatis Generator Started"); //$NON-NLS-1$ + } + + @Override + public void buildFinished(BuildEvent event) { + writeMessage("MyBatis Generator Finished"); //$NON-NLS-1$ + } + + @Override + public void targetStarted(BuildEvent event) { + writeMessage("Target " + event.getTarget().getName() + " - Started"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public void targetFinished(BuildEvent event) { + writeMessage("Target " + event.getTarget().getName() + " - Finished"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public void taskStarted(BuildEvent event) { + writeMessage("Task " + event.getTask().getTaskName() + " - Started"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public void taskFinished(BuildEvent event) { + writeMessage("Task " + event.getTask().getTaskName() + " - Finished"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + @Override + public void messageLogged(BuildEvent event) { + writeMessage(" " + event.getMessage()); //$NON-NLS-1$ + } + + private void writeMessage(String message) { + try { + outputStream.write(message); + outputStream.write('\n'); + outputStream.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/AntFileGenerator.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/AntFileGenerator.java index 998c11041d..f4075f9995 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/AntFileGenerator.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/AntFileGenerator.java @@ -23,6 +23,7 @@ import org.mybatis.generator.api.dom.xml.Attribute; import org.mybatis.generator.api.dom.xml.Document; import org.mybatis.generator.api.dom.xml.XmlElement; +import org.mybatis.generator.eclipse.ui.launcher.tabs.LauncherUtils; import org.mybatis.generator.internal.util.StringUtility; /** @@ -74,8 +75,8 @@ private void addSqlTaskIfNecessary(XmlElement parent) { sqlTask.addAttribute(new Attribute("driver", getTextOrBlank(configuration, ATTR_SQL_SCRIPT_DRIVER_CLASS))); //$NON-NLS-1$ sqlTask.addAttribute(new Attribute("url", getTextOrBlank(configuration, ATTR_SQL_SCRIPT_CONNECTION_URL))); //$NON-NLS-1$ - sqlTask.addAttribute(new Attribute("userid", getTextOrBlank(configuration, ATTR_SQL_SCRIPT_USERID))); //$NON-NLS-1$ - sqlTask.addAttribute(new Attribute("password", getTextOrBlank(configuration, ATTR_SQL_SCRIPT_PASSWORD))); //$NON-NLS-1$ + sqlTask.addAttribute(new Attribute("userid", LauncherUtils.getUserId(configuration))); //$NON-NLS-1$ + sqlTask.addAttribute(new Attribute("password", LauncherUtils.getPassword(configuration))); //$NON-NLS-1$ sqlTask.addAttribute(new Attribute("src", sqlFileFullPath)); //$NON-NLS-1$ parent.addElement(sqlTask); diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java index 40b333ec74..76328b8129 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.tools.ant.Project; import org.eclipse.ant.core.AntCorePlugin; import org.eclipse.ant.core.AntCorePreferences; import org.eclipse.ant.core.AntRunner; @@ -38,6 +39,7 @@ import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; import org.mybatis.generator.eclipse.ui.Activator; import org.mybatis.generator.eclipse.ui.Messages; +import org.mybatis.generator.eclipse.ui.launcher.tabs.LauncherUtils; /** * This launcher works by invoking the AntRunner on a generated ant script for the generator. @@ -58,16 +60,28 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun throws CoreException { AntRunner antRunner = new AntRunner(); + String buildFile; try { - antRunner.setBuildFileLocation(generateAntScript(configuration)); + buildFile = generateAntScript(configuration); } catch (IOException e) { Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.LAUNCH_ERROR_ERROR_GENERATING_ANT_FILE, e); throw new CoreException(status); } + antRunner.setBuildFileLocation(buildFile); modifyAntClasspathIfNecessary(configuration, antRunner); + if ("debug".equals(mode)) { //$NON-NLS-1$ + antRunner.setMessageOutputLevel(Project.MSG_DEBUG); + antRunner.setArguments("-debug"); //$NON-NLS-1$ + antRunner.addBuildListener("org.mybatis.generator.eclipse.ui.ant.DebugBuildListener"); //$NON-NLS-1$ + } antRunner.run(monitor); + + if (LauncherUtils.getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS)) { + File file = new File(buildFile); + file.delete(); + } } private void modifyAntClasspathIfNecessary(ILaunchConfiguration configuration, AntRunner antRunner) throws CoreException { diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConstants.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConstants.java index 709c499774..511eee0523 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConstants.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConstants.java @@ -15,12 +15,15 @@ */ package org.mybatis.generator.eclipse.ui.launcher; +import org.mybatis.generator.eclipse.ui.Activator; + public interface GeneratorLaunchConstants { - public static final String ATTR_CONFIGURATION_FILE_NAME = "MyBatis.Generator.ConfigTab.FileName"; //$NON-NLS-1$ + public static final String ATTR_CONFIGURATION_FILE_NAME = Activator.PLUGIN_ID + ".CONFIG_TAB.FILE_NAME"; //$NON-NLS-1$ - public static final String ATTR_SQL_SCRIPT_FILE_NAME = "MyBatis.Generator.SQLTab.ScriptFileName"; //$NON-NLS-1$ - public static final String ATTR_SQL_SCRIPT_DRIVER_CLASS = "MyBatis.Generator.SQLTab.DriverClass"; //$NON-NLS-1$ - public static final String ATTR_SQL_SCRIPT_CONNECTION_URL = "MyBatis.Generator.SQLTab.ConnectionURL"; //$NON-NLS-1$ - public static final String ATTR_SQL_SCRIPT_USERID = "MyBatis.Generator.SQLTab.UserID"; //$NON-NLS-1$ - public static final String ATTR_SQL_SCRIPT_PASSWORD = "MyBatis.Generator.SQLTab.Password"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_FILE_NAME = Activator.PLUGIN_ID + ".SQL_TAB.FILE_NAME"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_DRIVER_CLASS = Activator.PLUGIN_ID + ".SQL_TAB.DRIVER_CLASS"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_CONNECTION_URL = Activator.PLUGIN_ID + ".SQL_TAB.CONNECTION_URL"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_USERID = Activator.PLUGIN_ID + ".SQL_TAB.USER_ID"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_PASSWORD = Activator.PLUGIN_ID + ".SQL_TAB.PASSWORD"; //$NON-NLS-1$ + public static final String ATTR_SQL_SCRIPT_SECURE_CREDENTIALS = Activator.PLUGIN_ID + ".SQL_TAB.SECURE_CREDENTIALS"; //$NON-NLS-1$ } diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java index e11b23cbef..6a5ff1d6e2 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java @@ -16,7 +16,16 @@ package org.mybatis.generator.eclipse.ui.launcher.tabs; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; +import org.eclipse.equinox.security.storage.ISecurePreferences; +import org.eclipse.equinox.security.storage.SecurePreferencesFactory; +import org.eclipse.equinox.security.storage.StorageException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Shell; +import org.mybatis.generator.eclipse.ui.Activator; +import org.mybatis.generator.eclipse.ui.launcher.GeneratorLaunchConstants; public class LauncherUtils { @@ -31,4 +40,94 @@ public static String getTextOrBlank(ILaunchConfiguration configuration, String a return text; } + + public static String getTextOrBlank(ISecurePreferences node, String attribute) { + String text; + + try { + text = node.get(attribute, ""); //$NON-NLS-1$ + } catch (StorageException e) { + text = ""; //$NON-NLS-1$ + } + + return text; + } + + public static boolean getBooleanOrFalse(ILaunchConfiguration configuration, String attribute) { + boolean answer; + + try { + answer = configuration.getAttribute(attribute, false); + } catch (CoreException e) { + answer = false; + } + + return answer; + } + + public static void setPassword(ILaunchConfigurationWorkingCopy configuration, String password, Shell shell) { + boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS); + if (secure) { + ISecurePreferences node = getSecurePreferencesNode(); + try { + node.put("password", password, true); //$NON-NLS-1$ + } catch (StorageException e) { + logException(shell, e); + } + } else { + configuration.setAttribute(GeneratorLaunchConstants.ATTR_SQL_SCRIPT_PASSWORD, password); + } + } + + public static String getPassword(ILaunchConfiguration configuration) { + boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS); + String password; + if (secure) { + ISecurePreferences node = getSecurePreferencesNode(); + password = getTextOrBlank(node, "password"); //$NON-NLS-1$ + } else { + password = getTextOrBlank(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_PASSWORD); + } + return password; + } + + public static void setUserId(ILaunchConfigurationWorkingCopy configuration, String userId, Shell shell) { + boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS); + if (secure) { + ISecurePreferences node = getSecurePreferencesNode(); + try { + node.put("user", userId, false); //$NON-NLS-1$ + } catch (StorageException e) { + logException(shell, e); + } + } else { + configuration.setAttribute(GeneratorLaunchConstants.ATTR_SQL_SCRIPT_USERID, userId); + } + } + + public static String getUserId(ILaunchConfiguration configuration) { + boolean secure = getBooleanOrFalse(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_SECURE_CREDENTIALS); + String userId; + if (secure) { + ISecurePreferences node = getSecurePreferencesNode(); + userId = getTextOrBlank(node, "user"); //$NON-NLS-1$ + } else { + userId = getTextOrBlank(configuration, GeneratorLaunchConstants.ATTR_SQL_SCRIPT_USERID); + } + return userId; + } + + private static void logException(Shell shell, StorageException e) { + MessageDialog.openError(shell, + "Secure Storage Error", + "Error writing to secure storage. See error log for more details."); + Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, "Error writing to secure storage", e); + Activator.getDefault().getLog().log(status); + } + + private static ISecurePreferences getSecurePreferencesNode() { + ISecurePreferences root = SecurePreferencesFactory.getDefault(); + ISecurePreferences node = root.node("/org.mybatis.generator/sqlscript"); //$NON-NLS-1$ + return node; + } } diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java index 36c584453a..3f440488c6 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java @@ -15,6 +15,7 @@ */ package org.mybatis.generator.eclipse.ui.launcher.tabs; +import static org.mybatis.generator.eclipse.ui.launcher.tabs.LauncherUtils.getBooleanOrFalse; import static org.mybatis.generator.eclipse.ui.launcher.tabs.LauncherUtils.getTextOrBlank; import static org.mybatis.generator.internal.util.StringUtility.stringHasValue; @@ -31,8 +32,11 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; @@ -51,6 +55,7 @@ public class SqlScriptComposite extends AbstractGeneratorComposite { private Text txtJdbcURL; private Text txtUserID; private Text txtPassword; + private Button btnSecureStorage; private SqlScriptTab sqlScriptTab; /** @@ -132,7 +137,7 @@ public void modifyText(ModifyEvent e) { lblPassword.setText(Messages.SQL_SCRIPT_TAB_PASSWORD_LABEL); new Label(group, SWT.NONE); - txtPassword = new Text(group, SWT.BORDER); + txtPassword = new Text(group, SWT.PASSWORD | SWT.BORDER); txtPassword.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { sqlScriptTab.updateLaunchConfigurationDialog(); @@ -142,6 +147,16 @@ public void modifyText(ModifyEvent e) { gd_txtPassword.horizontalIndent = 30; txtPassword.setLayoutData(gd_txtPassword); new Label(group, SWT.NONE); + + btnSecureStorage = new Button(group, SWT.CHECK); + btnSecureStorage.setText("Store Credentials in Secure Storage"); + btnSecureStorage.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + sqlScriptTab.updateLaunchConfigurationDialog(); + } + }); + new Label(group, SWT.NONE); } public boolean isValid() { @@ -180,16 +195,19 @@ public void initializeFrom(ILaunchConfiguration configuration) { txtFileName.setText(getTextOrBlank(configuration, ATTR_SQL_SCRIPT_FILE_NAME)); txtJdbcDriver.setText(getTextOrBlank(configuration, ATTR_SQL_SCRIPT_DRIVER_CLASS)); txtJdbcURL.setText(getTextOrBlank(configuration, ATTR_SQL_SCRIPT_CONNECTION_URL)); - txtUserID.setText(getTextOrBlank(configuration, ATTR_SQL_SCRIPT_USERID)); - txtPassword.setText(getTextOrBlank(configuration, ATTR_SQL_SCRIPT_PASSWORD)); + btnSecureStorage.setSelection(getBooleanOrFalse(configuration, ATTR_SQL_SCRIPT_SECURE_CREDENTIALS)); + + txtUserID.setText(LauncherUtils.getUserId(configuration)); + txtPassword.setText(LauncherUtils.getPassword(configuration)); } public void performApply(ILaunchConfigurationWorkingCopy configuration) { configuration.setAttribute(ATTR_SQL_SCRIPT_FILE_NAME, txtFileName.getText()); configuration.setAttribute(ATTR_SQL_SCRIPT_DRIVER_CLASS, txtJdbcDriver.getText()); configuration.setAttribute(ATTR_SQL_SCRIPT_CONNECTION_URL, txtJdbcURL.getText()); - configuration.setAttribute(ATTR_SQL_SCRIPT_USERID, txtUserID.getText()); - configuration.setAttribute(ATTR_SQL_SCRIPT_PASSWORD, txtPassword.getText()); + configuration.setAttribute(ATTR_SQL_SCRIPT_SECURE_CREDENTIALS, btnSecureStorage.getSelection()); + LauncherUtils.setUserId(configuration, txtUserID.getText(), sqlScriptTab.getShell()); + LauncherUtils.setPassword(configuration, txtPassword.getText(), sqlScriptTab.getShell()); } @Override diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptTab.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptTab.java index f9806c2afe..d39d0294e1 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptTab.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptTab.java @@ -20,6 +20,7 @@ import org.eclipse.debug.ui.AbstractLaunchConfigurationTab; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Shell; import org.mybatis.generator.eclipse.ui.Messages; public class SqlScriptTab extends AbstractLaunchConfigurationTab { @@ -66,4 +67,9 @@ public boolean isValid(ILaunchConfiguration launchConfig) { public void setErrorMessage(String message) { super.setErrorMessage(message); } + + @Override + public Shell getShell() { + return super.getShell(); + } } From 2fa3eb08323712576a3b301b6e0a649a39735768 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Fri, 12 Aug 2016 17:28:34 -0400 Subject: [PATCH 2/4] Small update to launcher docs and code --- .../html-src/eclipseui/usingTheLauncher.html | 4 ++++ .../ui/launcher/GeneratorLaunchConfigurationDelegate.java | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html index 547f0b317d..fdf6581317 100644 --- a/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html +++ b/eclipse/org.mybatis.generator.eclipse.doc/html-src/eclipseui/usingTheLauncher.html @@ -52,6 +52,10 @@

What's Different in a Debug Launch?

a new Eclipse console called "MyBatis Generator". This can be useful when using an SQL script as you will be able to see the script progress in the console. You will also see many Ant configuration messages.

+

Currently the launcher does not support breakpoints in dependent projects. +If you are developing a plugin you may add the plugin project to the launcher +classpath and the plugin will be executed, but any breakpoints set in +plugin code will be ignored. This is a limitation of Ant support.

How Passwords are Stored

If you specify a password for connecting to a database with the Ant script, you diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java index 76328b8129..04e5b1d41d 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/GeneratorLaunchConfigurationDelegate.java @@ -36,6 +36,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; import org.eclipse.jdt.launching.AbstractJavaLaunchConfigurationDelegate; import org.mybatis.generator.eclipse.ui.Activator; import org.mybatis.generator.eclipse.ui.Messages; @@ -70,7 +71,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun antRunner.setBuildFileLocation(buildFile); modifyAntClasspathIfNecessary(configuration, antRunner); - if ("debug".equals(mode)) { //$NON-NLS-1$ + if (ILaunchManager.DEBUG_MODE.equals(mode)) { antRunner.setMessageOutputLevel(Project.MSG_DEBUG); antRunner.setArguments("-debug"); //$NON-NLS-1$ antRunner.addBuildListener("org.mybatis.generator.eclipse.ui.ant.DebugBuildListener"); //$NON-NLS-1$ From 6a77034f18bac5dd014872666a971a2b6448cfd6 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sun, 14 Aug 2016 17:50:08 -0400 Subject: [PATCH 3/4] i18n and license header updates --- .../eclipse/ui/ant/DebugBuildListener.java | 15 +++++++++++++++ .../mybatis/generator/eclipse/ui/Messages.java | 6 +++++- .../eclipse/ui/launcher/tabs/LauncherUtils.java | 8 +++++--- .../ui/launcher/tabs/SqlScriptComposite.java | 2 +- .../generator/eclipse/ui/messages.properties | 5 +++++ .../eclipse/ui/wizards/NewConfigFileWizard.java | 12 ------------ .../ui/wizards/NewConfigFileWizardPage1.java | 2 +- 7 files changed, 32 insertions(+), 18 deletions(-) diff --git a/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java b/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java index 6f2ca98cbc..bd69b836bc 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/antsrc/org/mybatis/generator/eclipse/ui/ant/DebugBuildListener.java @@ -1,3 +1,18 @@ +/** + * Copyright 2006-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.mybatis.generator.eclipse.ui.ant; import java.io.IOException; diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/Messages.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/Messages.java index 0048e7756d..0c1bb60282 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/Messages.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/Messages.java @@ -19,7 +19,6 @@ public class Messages extends NLS { - public static String FILE_PICKER_BROWSE_FILE_SYSTEM; public static String FILE_PICKER_BROWSE_WORKSPACE; public static String FILE_PICKER_FILE_DOESNT_EXIST; @@ -42,11 +41,16 @@ public class Messages extends NLS { public static String SQL_SCRIPT_TAB_PASSWORD_LABEL; public static String SQL_SCRIPT_TAB_JDBC_DRIVER_REQUIRED; public static String SQL_SCRIPT_TAB_JDBC_URL_REQUIRED; + public static String SQL_SCRIPT_TAB_SECURE_STORAGE; public static String LAUNCH_CONFIGURATION_SELECTOR_TITLE; public static String LAUNCH_CONFIGURATION_SELECTOR_MESSAGE; public static String LAUNCH_ERROR_ERROR_GENERATING_ANT_FILE; + public static String SECURE_STORAGE_ERROR_DIALOG_TITLE; + public static String SECURE_STORAGE_ERROR_DIALOG_MESSAGE; + public static String SECURE_STORAGE_ERROR_LOG_MESSAGE; + static { NLS.initializeMessages("org.mybatis.generator.eclipse.ui.messages", Messages.class); //$NON-NLS-1$ } diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java index 6a5ff1d6e2..a84d8a3bf4 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/LauncherUtils.java @@ -25,6 +25,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.widgets.Shell; import org.mybatis.generator.eclipse.ui.Activator; +import org.mybatis.generator.eclipse.ui.Messages; import org.mybatis.generator.eclipse.ui.launcher.GeneratorLaunchConstants; public class LauncherUtils { @@ -119,9 +120,10 @@ public static String getUserId(ILaunchConfiguration configuration) { private static void logException(Shell shell, StorageException e) { MessageDialog.openError(shell, - "Secure Storage Error", - "Error writing to secure storage. See error log for more details."); - Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, "Error writing to secure storage", e); + Messages.SECURE_STORAGE_ERROR_DIALOG_TITLE, + Messages.SECURE_STORAGE_ERROR_DIALOG_MESSAGE); + Status status = new Status(Status.ERROR, Activator.PLUGIN_ID, + Messages.SECURE_STORAGE_ERROR_LOG_MESSAGE, e); Activator.getDefault().getLog().log(status); } diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java index 3f440488c6..c958ae2838 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/launcher/tabs/SqlScriptComposite.java @@ -149,7 +149,7 @@ public void modifyText(ModifyEvent e) { new Label(group, SWT.NONE); btnSecureStorage = new Button(group, SWT.CHECK); - btnSecureStorage.setText("Store Credentials in Secure Storage"); + btnSecureStorage.setText(Messages.SQL_SCRIPT_TAB_SECURE_STORAGE); btnSecureStorage.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/messages.properties b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/messages.properties index 3987062bfc..2ec96844f4 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/messages.properties +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/messages.properties @@ -36,7 +36,12 @@ SQL_SCRIPT_TAB_USERID_LABEL=User ID SQL_SCRIPT_TAB_PASSWORD_LABEL=Password SQL_SCRIPT_TAB_JDBC_DRIVER_REQUIRED=JDBC Driver Class is required if you specify a file name SQL_SCRIPT_TAB_JDBC_URL_REQUIRED=JDBC connection URL is required if you specify a file name +SQL_SCRIPT_TAB_SECURE_STORAGE=Store Credentials in Secure Storage LAUNCH_CONFIGURATION_SELECTOR_TITLE=Select a Launch Configuration LAUNCH_CONFIGURATION_SELECTOR_MESSAGE=Select existing configuration: LAUNCH_ERROR_ERROR_GENERATING_ANT_FILE=Exception generating Ant file + +SECURE_STORAGE_ERROR_DIALOG_TITLE=Secure Storage Error +SECURE_STORAGE_ERROR_DIALOG_MESSAGE=Error writing to secure storage. See error log for more details. +SECURE_STORAGE_ERROR_LOG_MESSAGE=Error writing to secure storage diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizard.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizard.java index e8dd6b7403..59180a60fe 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizard.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizard.java @@ -47,15 +47,6 @@ import org.mybatis.generator.codegen.XmlConstants; import org.mybatis.generator.eclipse.ui.Activator; -/** - * This is a sample new wizard. Its role is to create a new file resource in the - * provided container. If the container resource (a folder or a project) is - * selected in the workspace when the wizard is opened, it will accept it as the - * target container. The wizard creates one file with the extension "mpe". If a - * sample multi-page editor (also available as a template) is registered for the - * same extension, it will be able to open it. - */ - public class NewConfigFileWizard extends Wizard implements INewWizard { private NewConfigFileWizardPage1 page; private ISelection selection; @@ -71,7 +62,6 @@ public NewConfigFileWizard() { /** * Adding the page to the wizard. */ - public void addPages() { page = new NewConfigFileWizardPage1(selection); addPage(page); @@ -114,7 +104,6 @@ public void run(IProgressMonitor monitor) * or just replace its contents, and open the editor on the newly created * file. */ - private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException { // create a sample file @@ -155,7 +144,6 @@ public void run() { /** * We will initialize file contents with a sample text. */ - private InputStream openContentStream() { Document document = new Document(XmlConstants.MYBATIS_GENERATOR_CONFIG_PUBLIC_ID, diff --git a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizardPage1.java b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizardPage1.java index 1a0b26ce79..a0042c913a 100644 --- a/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizardPage1.java +++ b/eclipse/org.mybatis.generator.eclipse.ui/src/org/mybatis/generator/eclipse/ui/wizards/NewConfigFileWizardPage1.java @@ -135,7 +135,7 @@ private void initialize() { locationText.setText(container.getFullPath().toString()); } } - fileText.setText("generatorConfig.xml"); + fileText.setText("generatorConfig.xml"); //$NON-NLS-1$ } /** From 26919d120b36176861f823982631da0d39439c68 Mon Sep 17 00:00:00 2001 From: Jeff Butler Date: Sun, 14 Aug 2016 17:52:04 -0400 Subject: [PATCH 4/4] Update docs for new version --- .../src/site/xhtml/running/runningWithMaven.xhtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/mybatis-generator-core/src/site/xhtml/running/runningWithMaven.xhtml b/core/mybatis-generator-core/src/site/xhtml/running/runningWithMaven.xhtml index 0e3d53a7e0..eba4af74d8 100644 --- a/core/mybatis-generator-core/src/site/xhtml/running/runningWithMaven.xhtml +++ b/core/mybatis-generator-core/src/site/xhtml/running/runningWithMaven.xhtml @@ -39,7 +39,7 @@ in a Maven build can be very simple. The minimum configuration is shown below:< <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> - <version>1.3.3</version> + <version>1.3.4</version> </plugin> ... </plugins> @@ -83,7 +83,7 @@ the goal to execute automatically. An example of this is shown below:

<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> - <version>1.3.3</version> + <version>1.3.4</version> <executions> <execution> <id>Generate MyBatis Artifacts</id> @@ -124,7 +124,7 @@ file and may be used in the normal way. For example:

<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> - <version>1.3.3</version> + <version>1.3.4</version> <executions> <execution> <id>Generate MyBatis Artifacts</id>