You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by se...@apache.org on 2013/07/10 00:14:30 UTC
svn commit: r1501588 - in
/jmeter/trunk/src/core/org/apache/jmeter/gui/action: Load.java
SelectTemplateDialog.java
Author: sebb
Date: Tue Jul 9 22:14:30 2013
New Revision: 1501588
URL: http://svn.apache.org/r1501588
Log:
Template GUI Manager silently overwrites files; does not allow for file merge
Load directly from template, but don't set the filename details
Allow Template Merge
Bugzilla Id: 55224
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/action/Load.java
jmeter/trunk/src/core/org/apache/jmeter/gui/action/SelectTemplateDialog.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Load.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/Load.java?rev=1501588&r1=1501587&r2=1501588&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/Load.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/Load.java Tue Jul 9 22:14:30 2013
@@ -102,6 +102,19 @@ public class Load implements Command {
* @param merging if true, then try to merge the file into the current GUI.
*/
static void loadProjectFile(final ActionEvent e, final File f, final boolean merging) {
+ loadProjectFile(e, f, merging, true);
+ }
+
+ /**
+ * Loads or merges a file into the current GUI, reporting any errors to the user.
+ * If the file is a complete test plan, sets the GUI test plan file name
+ *
+ * @param e the event that triggered the action
+ * @param f the file to load
+ * @param merging if true, then try to merge the file into the current GUI.
+ * @param setDetails if true, then set the file details (if not merging)
+ */
+ static void loadProjectFile(final ActionEvent e, final File f, final boolean merging, final boolean setDetails) {
ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.STOP_THREAD));
final GuiPackage guiPackage = GuiPackage.getInstance();
@@ -114,14 +127,16 @@ public class Load implements Command {
log.info("Loading file: " + f);
// TODO should this be done even if not a full test plan?
// and what if load fails?
- FileServer.getFileServer().setBaseForScript(f);
+ if(setDetails) {
+ FileServer.getFileServer().setBaseForScript(f);
+ }
}
reader = new FileInputStream(f);
final HashTree tree = SaveService.loadTree(reader);
final boolean isTestPlan = insertLoadedTree(e.getID(), tree, merging);
// don't change name if merging
- if (!merging && isTestPlan) {
+ if (!merging && isTestPlan && setDetails) {
// TODO should setBaseForScript be called here rather than above?
guiPackage.setTestPlanFile(f.getAbsolutePath());
}
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/SelectTemplateDialog.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/SelectTemplateDialog.java?rev=1501588&r1=1501587&r2=1501588&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/SelectTemplateDialog.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/SelectTemplateDialog.java Tue Jul 9 22:14:30 2013
@@ -24,13 +24,7 @@ import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
import javax.swing.AbstractAction;
import javax.swing.Action;
@@ -47,7 +41,6 @@ import javax.swing.JScrollPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-import org.apache.commons.io.IOUtils;
import org.apache.jmeter.gui.GuiPackage;
import org.apache.jmeter.gui.action.template.Template;
import org.apache.jmeter.gui.action.template.TemplateManager;
@@ -55,7 +48,6 @@ import org.apache.jmeter.swing.HtmlPane;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.gui.ComponentUtil;
import org.apache.jorphan.gui.JLabeledChoice;
-import org.apache.jorphan.util.JOrphanUtils;
/**
* Dialog used for Templates selection
@@ -128,25 +120,35 @@ public class SelectTemplateDialog extend
*/
private void checkDirtyAndLoad(final ActionEvent actionEvent)
throws HeadlessException {
+ final String selectedTemplate = templateList.getText();
+ final Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate);
+ if (template == null) {
+ return;
+ }
+ final boolean isTestPlan = template.isTestPlan();
// Check if the user wants to drop any changes
- ActionRouter.getInstance().doActionNow(new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.CHECK_DIRTY));
- GuiPackage guiPackage = GuiPackage.getInstance();
- if (guiPackage.isDirty()) {
- // Check if the user wants to create from template
- int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
- JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$
- JMeterUtils.getResString("template_load?"), // $NON-NLS-1$
- JOptionPane.YES_NO_CANCEL_OPTION,
- JOptionPane.QUESTION_MESSAGE);
- if(response == JOptionPane.YES_OPTION) {
- ActionRouter.getInstance().doActionNow(new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.SAVE));
- }
- if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.CANCEL_OPTION) {
- return; // Don't clear the plan
+ if (isTestPlan) {
+ ActionRouter.getInstance().doActionNow(new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.CHECK_DIRTY));
+ GuiPackage guiPackage = GuiPackage.getInstance();
+ if (guiPackage.isDirty()) {
+ // Check if the user wants to create from template
+ int response = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
+ JMeterUtils.getResString("cancel_new_from_template"), // $NON-NLS-1$
+ JMeterUtils.getResString("template_load?"), // $NON-NLS-1$
+ JOptionPane.YES_NO_CANCEL_OPTION,
+ JOptionPane.QUESTION_MESSAGE);
+ if(response == JOptionPane.YES_OPTION) {
+ ActionRouter.getInstance().doActionNow(new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.SAVE));
+ }
+ if (response == JOptionPane.CLOSED_OPTION || response == JOptionPane.CANCEL_OPTION) {
+ return; // Don't clear the plan
+ }
}
}
ActionRouter.getInstance().doActionNow(new ActionEvent(actionEvent.getSource(), actionEvent.getID(), ActionNames.STOP_THREAD));
- doOpen(actionEvent);
+ final File fileToCopy = new File(JMeterUtils.getJMeterHome(), template.getFileName());
+ Load.loadProjectFile(actionEvent, fileToCopy, !isTestPlan, false);
+ this.setVisible(false);
}
private void init() {
@@ -205,30 +207,4 @@ public class SelectTemplateDialog extend
: JMeterUtils.getResString("template_merge_from") );
}
- /**
- * @param e {@link ActionEvent}
- */
- private void doOpen(ActionEvent e) {
- final String selectedTemplate = templateList.getText();
- final Template template = TemplateManager.getInstance().getTemplateByName(selectedTemplate);
- final String fileName = template.getFileName();
- final File fileToCopy = new File(JMeterUtils.getJMeterHome(), fileName);
- final File targetFile = new File( System.getProperty("user.dir"),
- fileName.substring(fileName.lastIndexOf("/")));
- InputStream inputStream = null;
- OutputStream outputStream = null;
- try {
- inputStream = new BufferedInputStream(new FileInputStream(fileToCopy));
- outputStream = new BufferedOutputStream(new FileOutputStream(targetFile));
- IOUtils.copy(inputStream, outputStream);
- outputStream.close();
- Load.loadProjectFile(e, targetFile, false);
- this.setVisible(false);
- } catch (Exception e1) {
- throw new Error(e1);
- } finally {
- JOrphanUtils.closeQuietly(inputStream);
- JOrphanUtils.closeQuietly(outputStream);
- }
- }
}
\ No newline at end of file