View | Details | Raw Unified | Return to bug 61731
Collapse All | Expand All

(-)bin/jmeter.properties (+7 lines)
Lines 208-213 Link Here
208
208
209
209
210
#---------------------------------------------------------------------------
210
#---------------------------------------------------------------------------
211
# JMX Save automatically before run
212
#---------------------------------------------------------------------------
213
#Enable auto saving of the .jmx file before start run a test plan
214
#When enabled, before the run the .jmx will be saved and also backed up to the directory pointed
215
save_automatically_before_run=false
216
217
#---------------------------------------------------------------------------
211
# JMX Backup configuration
218
# JMX Backup configuration
212
#---------------------------------------------------------------------------
219
#---------------------------------------------------------------------------
213
#Enable auto backups of the .jmx file when a test plan is saved.
220
#Enable auto backups of the .jmx file when a test plan is saved.
(-)src/core/org/apache/jmeter/gui/GuiPackage.java (-4 / +26 lines)
Lines 115-121 Link Here
115
115
116
    /** The main JMeter toolbar. */
116
    /** The main JMeter toolbar. */
117
    private JToolBar toolbar;
117
    private JToolBar toolbar;
118
118
    
119
    /**
119
    /**
120
     * The LoggerPanel menu item
120
     * The LoggerPanel menu item
121
     */
121
     */
Lines 122-127 Link Here
122
    private JCheckBoxMenuItem menuItemLoggerPanel;
122
    private JCheckBoxMenuItem menuItemLoggerPanel;
123
123
124
    /**
124
    /**
125
     * The LoggerPanel menu item
126
     */
127
    private JCheckBoxMenuItem menuItemSaveBeforeRunPanel;
128
129
    /**
125
     * Logger Panel reference
130
     * Logger Panel reference
126
     */
131
     */
127
    private LoggerPanel loggerPanel;
132
    private LoggerPanel loggerPanel;
Lines 783-791 Link Here
783
     * @param menuItemLoggerPanel The menu item LoggerPanel
788
     * @param menuItemLoggerPanel The menu item LoggerPanel
784
     */
789
     */
785
    public void setMenuItemLoggerPanel(JCheckBoxMenuItem menuItemLoggerPanel) {
790
    public void setMenuItemLoggerPanel(JCheckBoxMenuItem menuItemLoggerPanel) {
786
        this.menuItemLoggerPanel = menuItemLoggerPanel;
791
    	this.menuItemLoggerPanel = menuItemLoggerPanel;
787
    }
792
    }
788
793
        
789
    /**
794
    /**
790
     * Get the menu item LoggerPanel.
795
     * Get the menu item LoggerPanel.
791
     *
796
     *
Lines 792-801 Link Here
792
     * @return the menu item LoggerPanel
797
     * @return the menu item LoggerPanel
793
     */
798
     */
794
    public JCheckBoxMenuItem getMenuItemLoggerPanel() {
799
    public JCheckBoxMenuItem getMenuItemLoggerPanel() {
795
        return menuItemLoggerPanel;
800
    	return menuItemLoggerPanel;
796
    }
801
    }
802
    
803
    /**
804
     * Set the menu item SaveBeforeRunPanel.
805
     * @param menuItemSaveBeforeRunPanel The menu item SaveBeforeRunPanel
806
     */
807
    public void setMenuItemSaveBeforeRunPanel(JCheckBoxMenuItem menuItemSaveBeforeRunPanel) {
808
        this.menuItemSaveBeforeRunPanel = menuItemSaveBeforeRunPanel;
809
    }
797
810
798
    /**
811
    /**
812
     * Get the menu item SaveBeforeRunPanel.
813
     *
814
     * @return the menu item SaveBeforeRunPanel
815
     */
816
    public JCheckBoxMenuItem getMenuItemSaveBeforeRunPanel() {
817
        return menuItemSaveBeforeRunPanel;
818
    }
819
820
    /**
799
     * @param loggerPanel LoggerPanel
821
     * @param loggerPanel LoggerPanel
800
     */
822
     */
801
    public void setLoggerPanel(LoggerPanel loggerPanel) {
823
    public void setLoggerPanel(LoggerPanel loggerPanel) {
(-)src/core/org/apache/jmeter/gui/action/AbstractAction.java (-14 / +13 lines)
Lines 22-29 Link Here
22
import java.io.File;
22
import java.io.File;
23
import java.text.MessageFormat;
23
import java.text.MessageFormat;
24
import java.util.Iterator;
24
import java.util.Iterator;
25
import java.util.Set;
26
27
import javax.swing.JOptionPane;
25
import javax.swing.JOptionPane;
28
26
29
import org.apache.jmeter.exceptions.IllegalUserActionException;
27
import org.apache.jmeter.exceptions.IllegalUserActionException;
Lines 58-77 Link Here
58
    }
56
    }
59
57
60
    /**
58
    /**
59
     * check if should save before run
61
     * @param e the event that led to the call of this method
60
     * @param e the event that led to the call of this method
62
     */
61
     */
63
    protected void popupShouldSave(ActionEvent e) {
62
	protected void popupShouldSave(ActionEvent e) {
64
        log.debug("popupShouldSave");
63
		log.debug("popupShouldSave");
65
        if (GuiPackage.getInstance().getTestPlanFile() == null) {
64
		if (GuiPackage.getInstance().getTestPlanFile() == null) {
66
            if (JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
65
			if (JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(), JMeterUtils.getResString("should_save"), //$NON-NLS-1$
67
                    JMeterUtils.getResString("should_save"),  //$NON-NLS-1$
66
					JMeterUtils.getResString("warning"), //$NON-NLS-1$
68
                    JMeterUtils.getResString("warning"),  //$NON-NLS-1$
67
					JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
69
                    JOptionPane.YES_NO_OPTION,
68
				ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE));
70
                    JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
69
			}
71
                ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(),ActionNames.SAVE));
70
		} else if (JMeterUtils.shouldSaveBeforeRun()) {
72
            }
71
			ActionRouter.getInstance().doActionNow(new ActionEvent(e.getSource(), e.getID(), ActionNames.SAVE));
73
        }
72
		}
74
    }
73
	}
75
    
74
    
76
    /**
75
    /**
77
     * @param tree where check if listener has existing file
76
     * @param tree where check if listener has existing file
(-)src/core/org/apache/jmeter/gui/action/ActionNames.java (+1 lines)
Lines 108-113 Link Here
108
    public static final String VALIDATE_TG      = "validate_tg"; //$NON-NLS-1$
108
    public static final String VALIDATE_TG      = "validate_tg"; //$NON-NLS-1$
109
    public static final String ZOOM_IN          = "zoom_in"; //$NON-NLS-1$
109
    public static final String ZOOM_IN          = "zoom_in"; //$NON-NLS-1$
110
    public static final String ZOOM_OUT         = "zoom_out"; //$NON-NLS-1$
110
    public static final String ZOOM_OUT         = "zoom_out"; //$NON-NLS-1$
111
    public static final String SAVE_BEFORE_RUN         = "save_before_run"; //$NON-NLS-1$
111
112
112
    // Prevent instantiation
113
    // Prevent instantiation
113
    private ActionNames() {}
114
    private ActionNames() {}
(-)src/core/org/apache/jmeter/gui/action/SaveBeforeRun.java (+58 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.gui.action;
20
21
import java.awt.event.ActionEvent;
22
import java.util.HashSet;
23
import java.util.Set;
24
import org.apache.jmeter.gui.GuiPackage;
25
import org.apache.jmeter.util.JMeterUtils;
26
/**
27
 * 
28
 * Save Before Run Action
29
 * 
30
 * To save test plan before GUI execution
31
 * 
32
 * @author orim
33
 *
34
 */
35
public class SaveBeforeRun extends AbstractAction {
36
	private static final Set<String> commands = new HashSet<>();
37
		
38
	static {
39
		commands.add(ActionNames.SAVE_BEFORE_RUN);
40
	}
41
42
	@Override
43
	public Set<String> getActionNames() {
44
		return commands;
45
	}
46
47
	@Override
48
	public void doAction(ActionEvent e) {
49
		if (ActionNames.SAVE_BEFORE_RUN.equals(e.getActionCommand())) {
50
			// toggle boolean preference value
51
			boolean togglePreferenceValue = !JMeterUtils.shouldSaveBeforeRunByPreference();
52
			JMeterUtils.setSaveBeforeRunByPreference(togglePreferenceValue);
53
			GuiPackage guiInstance = GuiPackage.getInstance();
54
			// toggle check box
55
            guiInstance.getMenuItemSaveBeforeRunPanel().getModel().setSelected(togglePreferenceValue);
56
		}
57
	}		
58
}
(-)src/core/org/apache/jmeter/gui/util/JMeterMenuBar.java (-2 / +8 lines)
Lines 151-157 Link Here
151
    public static final String DARCULA_LAF = "Darcula"; // $NON-NLS-1$
151
    public static final String DARCULA_LAF = "Darcula"; // $NON-NLS-1$
152
152
153
    public static final String DARCULA_LAF_CLASS = "com.bulenkov.darcula.DarculaLaf"; // $NON-NLS-1$
153
    public static final String DARCULA_LAF_CLASS = "com.bulenkov.darcula.DarculaLaf"; // $NON-NLS-1$
154
154
    
155
    public JMeterMenuBar() {
155
    public JMeterMenuBar() {
156
        // List for recent files menu items
156
        // List for recent files menu items
157
        fileLoadRecentFiles = new LinkedList<>();
157
        fileLoadRecentFiles = new LinkedList<>();
Lines 369-375 Link Here
369
        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
369
        JMenuItem zoomIn = makeMenuItemRes("menu_zoom_in", ActionNames.ZOOM_IN); //$NON-NLS-1$
370
        optionsMenu.add(zoomIn);
370
        optionsMenu.add(zoomIn);
371
        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
371
        JMenuItem zoomOut = makeMenuItemRes("menu_zoom_out", ActionNames.ZOOM_OUT); //$NON-NLS-1$
372
        optionsMenu.add(zoomOut);
372
        optionsMenu.add(zoomOut);        
373
        JCheckBoxMenuItem saveBeforeRun = makeCheckBoxMenuItemRes("menu_save_before_run", ActionNames.SAVE_BEFORE_RUN); //$NON-NLS-1$
374
        saveBeforeRun.setSelected(JMeterUtils.shouldSaveBeforeRunByPreference());
375
        if (guiInstance != null) {        	
376
            guiInstance.setMenuItemSaveBeforeRunPanel(saveBeforeRun);
377
        }
378
        optionsMenu.add(saveBeforeRun);
373
379
374
        addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
380
        addPluginsMenuItems(optionsMenu, menuCreators, MENU_LOCATION.OPTIONS);
375
    }
381
    }
(-)src/core/org/apache/jmeter/resources/messages.properties (+1 lines)
Lines 689-694 Link Here
689
menu_pre_processors=Pre Processors
689
menu_pre_processors=Pre Processors
690
menu_recent=Open Recent
690
menu_recent=Open Recent
691
menu_response_based_modifiers=Response Based Modifiers
691
menu_response_based_modifiers=Response Based Modifiers
692
menu_save_before_run=Save Automatically Before Run
692
menu_search=Search
693
menu_search=Search
693
menu_search_reset=Reset Search
694
menu_search_reset=Reset Search
694
menu_tables=Table
695
menu_tables=Table
(-)src/core/org/apache/jmeter/util/JMeterUtils.java (+37 lines)
Lines 45-50 Link Here
45
import java.util.ResourceBundle;
45
import java.util.ResourceBundle;
46
import java.util.Vector;
46
import java.util.Vector;
47
import java.util.concurrent.ThreadLocalRandom;
47
import java.util.concurrent.ThreadLocalRandom;
48
import java.util.prefs.Preferences;
48
49
49
import javax.swing.ImageIcon;
50
import javax.swing.ImageIcon;
50
import javax.swing.JOptionPane;
51
import javax.swing.JOptionPane;
Lines 56-61 Link Here
56
57
57
import org.apache.commons.io.IOUtils;
58
import org.apache.commons.io.IOUtils;
58
import org.apache.jmeter.gui.GuiPackage;
59
import org.apache.jmeter.gui.GuiPackage;
60
import org.apache.jmeter.gui.action.AbstractAction;
59
import org.apache.jmeter.threads.JMeterContextService;
61
import org.apache.jmeter.threads.JMeterContextService;
60
import org.apache.jorphan.reflect.ClassFinder;
62
import org.apache.jorphan.reflect.ClassFinder;
61
import org.apache.jorphan.test.UnitTestManager;
63
import org.apache.jorphan.test.UnitTestManager;
Lines 126-131 Link Here
126
            return new Perl5Matcher();
128
            return new Perl5Matcher();
127
        }
129
        }
128
    };
130
    };
131
        
132
    private static final Preferences PREFS = Preferences.userNodeForPackage(AbstractAction.class);
133
    
134
    private static final String SBR_PREFS_KEY = "sbr";
135
    
136
    protected static final String SAVE_BEFORE_RUN = "save_automatically_before_run"; // $NON-NLS-1$
129
137
130
    /**
138
    /**
131
     * Gets Perl5Matcher for this thread.
139
     * Gets Perl5Matcher for this thread.
Lines 1265-1268 Link Here
1265
        // TODO : How much are we concerned by CVE-2013-7285 
1273
        // TODO : How much are we concerned by CVE-2013-7285 
1266
        xstream.addPermission(AnyTypePermission.ANY);
1274
        xstream.addPermission(AnyTypePermission.ANY);
1267
    }
1275
    }
1276
    
1277
    /*
1278
     * Should Save Before Run by Preference Only
1279
     */
1280
    public static boolean shouldSaveBeforeRunByPreference() {
1281
    	String sbr = PREFS.get(SBR_PREFS_KEY, null);
1282
    	// toggle boolean preference value
1283
    	return "true".equalsIgnoreCase(sbr); // $NON-NLS-1$	 
1284
    }
1285
    /*
1286
     * Should Save Before Run by Preference Only
1287
     */
1288
	public static void setSaveBeforeRunByPreference(boolean saveBeforeRun) {
1289
		PREFS.put(SBR_PREFS_KEY, saveBeforeRun ? "true" : "false"); // $NON-NLS-1$ // $NON-NLS-2$
1290
	}
1291
	
1292
	/*
1293
	 * Should Save Before Run 
1294
	 * Decide by Preference and if not exists by Property
1295
	 */
1296
	public static boolean shouldSaveBeforeRun() {
1297
		String sbr = PREFS.get(SBR_PREFS_KEY, null);
1298
        if (sbr == null) {
1299
        	// set property if no preference
1300
            return JMeterUtils.getPropDefault(SAVE_BEFORE_RUN, false);         
1301
        } else {
1302
        	return shouldSaveBeforeRunByPreference();
1303
        }
1304
	}
1268
}
1305
}

Return to bug 61731