jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1818757 - in /jmeter/trunk: src/core/org/apache/jmeter/gui/ src/core/org/apache/jmeter/gui/action/ src/core/org/apache/jmeter/testelement/ xdocs/
Date Wed, 20 Dec 2017 09:21:43 GMT
Author: pmouawad
Date: Wed Dec 20 09:21:43 2017
New Revision: 1818757

URL: http://svn.apache.org/viewvc?rev=1818757&view=rev
Log:
Bug 61920 - Plugins : Add ability to listen to Test Plan loading/closing
Contributed by  Peter Doornbosch
This closes #361
Bugzilla Id: 61920

Added:
    jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/gui/GuiPackage.java
    jmeter/trunk/src/core/org/apache/jmeter/gui/action/Remove.java
    jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/GuiPackage.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/GuiPackage.java?rev=1818757&r1=1818756&r2=1818757&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/GuiPackage.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/GuiPackage.java Wed Dec 20 09:21:43 2017
@@ -139,6 +139,9 @@ public final class GuiPackage implements
     /** GUI Logging Event Bus. */
     private GuiLogEventBus logEventBus = new GuiLogEventBus();
 
+    /** Listeners for events on test plan */
+    private List<TestPlanListener> testPlanListeners = Collections.synchronizedList(new
ArrayList<>());
+
     /**
      * Private constructor to permit instantiation only from within this class.
      * Use {@link #getInstance()} to retrieve a singleton instance.
@@ -695,6 +698,7 @@ public final class GuiPackage implements
         } catch (IllegalStateException e1) {
             log.error("Failure setting file server's base dir", e1);
         }
+        testPlanListeners.stream().forEach(TestPlanListener::testPlanLoaded);
     }
 
     public String getTestPlanFile() {
@@ -706,9 +710,11 @@ public final class GuiPackage implements
      * Clears the test plan file name.
      */
     public void clearTestPlan() {
+        testPlanListeners.stream().forEach(TestPlanListener::beforeTestPlanCleared);
         getTreeModel().clearTestPlan();
         nodesToGui.clear();
         setTestPlanFile(null);
+        testPlanListeners.stream().forEach(TestPlanListener::afterTestPlanCleared);
         undoHistory.clear();
         undoHistory.add(this.treeModel, "Initial Tree");
     }
@@ -969,4 +975,21 @@ public final class GuiPackage implements
             return shouldSaveBeforeRunByPreference();
         }
     }
+
+    /**
+     * Adds a test plan listener.
+     * @param listener
+     */
+    public void addTestPlanListener(TestPlanListener listener) {
+        testPlanListeners.add(listener);
+    }
+
+    /**
+     * Removes a test plan listener.
+     * @param listener
+     */
+    public void removeTestPlanListener(TestPlanListener listener) {
+        testPlanListeners.remove(listener);
+    }
+
 }

Added: jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java?rev=1818757&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java Wed Dec 20 09:21:43
2017
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.jmeter.gui;
+
+/**
+ * Implement this interface to be informed about Test plan being cleared
+ * to react to such events.
+ * @since 4.0
+ *
+ */
+public interface TestPlanListener {
+    /**
+     * Called before current test plan is cleared
+     */
+    void beforeTestPlanCleared();
+    
+    /**
+     * Called after current test plan has been cleared
+     */
+    void afterTestPlanCleared();
+
+    /**
+     * Called after a new test plan has been loaded
+     */
+    void testPlanLoaded();
+}

Propchange: jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/src/core/org/apache/jmeter/gui/TestPlanListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/action/Remove.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/action/Remove.java?rev=1818757&r1=1818756&r2=1818757&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/action/Remove.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/action/Remove.java Wed Dec 20 09:21:43 2017
@@ -89,6 +89,7 @@ public class Remove extends AbstractActi
         if (testElement.canRemove()) {
             GuiPackage.getInstance().getTreeModel().removeNodeFromParent(node);
             GuiPackage.getInstance().removeNode(testElement);
+            testElement.removed();
         } else {
             String message = testElement.getClass().getName() + " is busy";
             JOptionPane.showMessageDialog(null, message, "Cannot remove item", JOptionPane.ERROR_MESSAGE);

Modified: jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java?rev=1818757&r1=1818756&r2=1818757&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/testelement/TestElement.java Wed Dec 20 09:21:43
2017
@@ -332,4 +332,12 @@ public interface TestElement extends Clo
      *            to be associated
      */
     void setComment(String comment);
+
+    /**
+     * Called when the test element is removed from the test plan.
+     * Must not throw any exception
+     */
+    default void removed() {
+        // NOOP
+    }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1818757&r1=1818756&r2=1818757&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Wed Dec 20 09:21:43 2017
@@ -187,6 +187,7 @@ Summary
     <li><pr>352</pr> Menu bar - added mnemonics to more menu items. Contributed
by Graham Russell (graham at ham1.co.uk)</li>
     <li><pr>353</pr> Re-wrote some existing tests in Spock. Contributed
by Graham Russell (graham at ham1.co.uk)</li>
     <li><bug>61919</bug>UX : Reorder Menus. Contributed by Graham Russell
(graham at ham1.co.uk)</li>
+    <li><bug>61920</bug>Plugins : Add ability to listen to Test Plan loading/closing.
Contributed by Peter Doornbosch (https://bitbucket.org/pjtr/)</li>
 </ul>
 
 <ch_section>Non-functional changes</ch_section>
@@ -288,6 +289,7 @@ Summary
     <li>Benny van Wijngaarden (benny at smaragd-it.nl)</li>
     <li>Matthew Buckett (https://github.com/buckett)</li>
     <li>Helly Guo (https://github.com/hellyguo)</li>
+    <li>Peter Doornbosch (https://bitbucket.org/pjtr/)</li>
 </ul>
 <p>We also thank bug reporters who helped us improve JMeter. <br/>
 For this release we want to give special thanks to the following reporters for the clear
reports and tests made after our fixes:</p>



Mime
View raw message