You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2018/12/26 17:57:10 UTC
svn commit: r1849774 - in /jmeter/trunk:
src/core/org/apache/jmeter/gui/action/Save.java xdocs/changes.xml
Author: pmouawad
Date: Wed Dec 26 17:57:10 2018
New Revision: 1849774
URL: http://svn.apache.org/viewvc?rev=1849774&view=rev
Log:
Bug 59633 Menus "Save Test Plan as", "Save as Test Fragment" and "Save Selection as ..." should use a new file name in File Dialog
Bugzilla Id: 59633
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java
jmeter/trunk/xdocs/changes.xml
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java?rev=1849774&r1=1849773&r2=1849774&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/Save.java Wed Dec 26 17:57:10 2018
@@ -145,19 +145,7 @@ public class Save extends AbstractAction
JMeterTreeNode[] nodes = GuiPackage.getInstance().getTreeListener().getSelectedNodes();
if(checkAcceptableForTestFragment(nodes)) {
// Create Test Fragment node
- TestElement element = GuiPackage.getInstance().createTestElement(TestFragmentControllerGui.class.getName());
- HashTree hashTree = new ListedHashTree();
- HashTree tfTree = hashTree.add(new JMeterTreeNode(element, null));
- for (JMeterTreeNode node : nodes) {
- // Clone deeply current node
- TreeCloner cloner = new TreeCloner(false);
- GuiPackage.getInstance().getTreeModel().getCurrentSubTree(node).traverse(cloner);
- // Add clone to tfTree
- tfTree.add(cloner.getClonedTree());
- }
-
- subTree = hashTree;
-
+ subTree = createTestFragmentNode(nodes);
} else {
JMeterUtils.reportErrorToUser(
JMeterUtils.getResString("save_as_test_fragment_error"), // $NON-NLS-1$
@@ -170,41 +158,88 @@ public class Save extends AbstractAction
}
String updateFile = GuiPackage.getInstance().getTestPlanFile();
- if (!ActionNames.SAVE.equals(e.getActionCommand()) || updateFile == null) {
- JFileChooser chooser = FileDialoger.promptToSaveFile(updateFile == null ? GuiPackage.getInstance().getTreeListener()
- .getCurrentNode().getName()
- + JMX_FILE_EXTENSION : updateFile);
- if (chooser == null) {
+ if (!ActionNames.SAVE.equals(e.getActionCommand()) // Saving existing plan
+ // New File
+ || updateFile == null) {
+ updateFile = computeFileName();
+ if(updateFile == null) {
return;
}
- updateFile = chooser.getSelectedFile().getAbsolutePath();
- // Make sure the file ends with proper extension
- if(FilenameUtils.getExtension(updateFile).isEmpty()) {
- updateFile = updateFile + JMX_FILE_EXTENSION;
- }
- // Check if the user is trying to save to an existing file
- File f = new File(updateFile);
- if(f.exists()) {
- int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
- JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$
- JMeterUtils.getResString("save?"), // $NON-NLS-1$
- JOptionPane.YES_NO_OPTION,
- JOptionPane.QUESTION_MESSAGE);
- if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) {
- return ; // Do not save, user does not want to overwrite
- }
- }
-
- if (!e.getActionCommand().equals(ActionNames.SAVE_AS)) {
+ if (e.getActionCommand().equals(ActionNames.SAVE_ALL_AS)) {
GuiPackage.getInstance().setTestPlanFile(updateFile);
}
}
ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.CHECK_DIRTY));
- // backup existing file according to jmeter/user.properties settings
+ backupAndSave(e, subTree, fullSave, updateFile);
+
+ GuiPackage.getInstance().updateCurrentGui();
+ }
+
+ /**
+ * Create TestFragment test plan from selected nodes
+ * @param nodes Array of {@link JMeterTreeNode}
+ * @return {@link HashTree} new test plan
+ */
+ private HashTree createTestFragmentNode(JMeterTreeNode[] nodes) {
+ TestElement element = GuiPackage.getInstance().createTestElement(TestFragmentControllerGui.class.getName());
+ HashTree hashTree = new ListedHashTree();
+ HashTree tfTree = hashTree.add(new JMeterTreeNode(element, null));
+ for (JMeterTreeNode node : nodes) {
+ // Clone deeply current node
+ TreeCloner cloner = new TreeCloner(false);
+ GuiPackage.getInstance().getTreeModel().getCurrentSubTree(node).traverse(cloner);
+ // Add clone to tfTree
+ tfTree.add(cloner.getClonedTree());
+ }
+ return hashTree;
+ }
+
+ /**
+ * @return String new file name or null if user want to cancel
+ */
+ private String computeFileName() {
+ JFileChooser chooser = FileDialoger.promptToSaveFile(GuiPackage.getInstance().getTreeListener()
+ .getCurrentNode().getName()
+ + JMX_FILE_EXTENSION);
+ if (chooser == null) {
+ return null;
+ }
+ String updateFile = chooser.getSelectedFile().getAbsolutePath();
+ // Make sure the file ends with proper extension
+ if(FilenameUtils.getExtension(updateFile).isEmpty()) {
+ updateFile = updateFile + JMX_FILE_EXTENSION;
+ }
+ // Check if the user is trying to save to an existing file
+ File f = new File(updateFile);
+ if(f.exists()) {
+ int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
+ JMeterUtils.getResString("save_overwrite_existing_file"), // $NON-NLS-1$
+ JMeterUtils.getResString("save?"), // $NON-NLS-1$
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.QUESTION_MESSAGE);
+ if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.NO_OPTION) {
+ return null; // Do not save, user does not want to overwrite
+ }
+ }
+ return updateFile;
+ }
+
+ /**
+ * Backup existing file according to jmeter/user.properties settings
+ * and save
+ * @param e {@link ActionEvent}
+ * @param subTree HashTree Test plan to save
+ * @param fullSave Partial or full save
+ * @param newFile File to save
+ * @throws IllegalUserActionException
+ */
+ void backupAndSave(ActionEvent e, HashTree subTree, boolean fullSave, String newFile)
+ throws IllegalUserActionException {
+ //
List<File> expiredBackupFiles = EMPTY_FILE_LIST;
if (GuiPackage.getInstance().isDirty()) {
- File fileToBackup = new File(updateFile);
+ File fileToBackup = new File(newFile);
log.debug("Test plan has changed, make backup of {}", fileToBackup);
try {
expiredBackupFiles = createBackupFile(fileToBackup);
@@ -221,10 +256,10 @@ public class Save extends AbstractAction
}
}
- try (FileOutputStream ostream = new FileOutputStream(updateFile)){
+ try (FileOutputStream ostream = new FileOutputStream(newFile)){
SaveService.saveTree(subTree, ostream);
if (fullSave) { // Only update the stored copy of the tree for a full save
- FileServer.getFileServer().setScriptName(new File(updateFile).getName());
+ FileServer.getFileServer().setScriptName(new File(newFile).getName());
subTree = GuiPackage.getInstance().getTreeModel().getTestPlan(); // refetch, because convertSubTree affects it
ActionRouter.getInstance().doActionNow(new ActionEvent(subTree, e.getID(), ActionNames.SUB_TREE_SAVED));
}
@@ -236,10 +271,8 @@ public class Save extends AbstractAction
throw ex;
} catch (Exception ex) {
log.error("Error saving tree.", ex);
- throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile, ex);
- }
-
- GuiPackage.getInstance().updateCurrentGui();
+ throw new IllegalUserActionException("Couldn't save test plan to file: " + newFile, ex);
+ }
}
/**
Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1849774&r1=1849773&r2=1849774&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Dec 26 17:57:10 2018
@@ -129,6 +129,7 @@ of previous time slot as a base. Startin
<li><bug>62925</bug>Add support for ThreadDump to the JMeter non-GUI</li>
<li><bug>62870</bug>Templates : Add ability to provide parameters. Contributed by Ubik Load Pack (support at ubikloadpack.com)</li>
<li><bug>62829</bug>Allow specifying Proxy server scheme for HTTP request sampler, Advanced tab and command line option. Contributed by Hitesh Patel (hitesh.h.patel at gmail.com)</li>
+ <li><bug>59633</bug>Menus <code>Save Test Plan as</code>, <code>Save as Test Fragment</code> and <code>Save Selection as ...</code> should use a new file name in File Dialog</li>
</ul>
<ch_section>Non-functional changes</ch_section>