Skip to content

Commit 677ff14

Browse files
committed
scripts: Use main output panel for output
Signed-off-by: ricekot <git@ricekot.com>
1 parent d34418c commit 677ff14

File tree

7 files changed

+172
-434
lines changed

7 files changed

+172
-434
lines changed

addOns/scripts/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1313
- Fields with default or missing values are omitted for the `script` job in saved Automation Framework plans.
1414
- Depends on an updated version of the Common Library add-on.
1515
- Depend on Passive Scanner add-on (Issue 7959).
16+
- Use the main Output panel for script output.
1617

1718
### Fixed
1819
- Correct auto-complete suggestions for parameters of Passive Rules.

addOns/scripts/src/main/java/org/zaproxy/zap/extension/scripts/ConsolePanel.java

+9-26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package org.zaproxy.zap.extension.scripts;
2121

22+
import static org.zaproxy.zap.extension.scripts.ExtensionScriptsUI.extractScriptExceptionMessage;
23+
2224
import java.awt.BorderLayout;
2325
import java.awt.GridBagLayout;
2426
import java.awt.Toolkit;
@@ -46,7 +48,6 @@
4648
import javax.swing.JLabel;
4749
import javax.swing.JOptionPane;
4850
import javax.swing.JPanel;
49-
import javax.swing.JSplitPane;
5051
import javax.swing.JToolBar;
5152
import javax.swing.KeyStroke;
5253
import javax.swing.border.EmptyBorder;
@@ -86,7 +87,6 @@ public class ConsolePanel extends AbstractPanel {
8687
private JButton optionsButton;
8788
private JLabel scriptTitle = null;
8889
private CommandPanel commandPanel = null;
89-
private OutputPanel outputPanel = null;
9090
private KeyListener listener = null;
9191

9292
private ScriptWrapper script = null;
@@ -135,15 +135,8 @@ public ConsolePanel(ExtensionScriptsUI extension) {
135135
panelContent = new JPanel(new GridBagLayout());
136136
this.add(panelContent, BorderLayout.CENTER);
137137

138-
JSplitPane splitPane = new JSplitPane();
139-
splitPane.setDividerSize(3);
140-
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
141-
splitPane.setResizeWeight(0.5D);
142-
splitPane.setTopComponent(getCommandPanel());
143-
splitPane.setBottomComponent(getOutputPanel());
144-
145138
panelContent.add(this.getPanelToolbar(), LayoutHelper.getGBC(0, 0, 1, 1.0D, 0.0D));
146-
panelContent.add(splitPane, LayoutHelper.getGBC(0, 1, 1, 1.0D, 1.0D));
139+
panelContent.add(getCommandPanel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 1.0D));
147140
}
148141

149142
private boolean isScriptUpdatedOnDisk() {
@@ -456,8 +449,6 @@ private void runScript() {
456449

457450
getRunButton().setEnabled(false);
458451

459-
getOutputPanel().preScriptInvoke();
460-
461452
// Update it, in case its been changed
462453
script.setContents(getCommandScript());
463454

@@ -546,19 +537,6 @@ public void actionPerformed(ActionEvent e) {
546537
return commandPanel;
547538
}
548539

549-
protected OutputPanel getOutputPanel() {
550-
if (outputPanel == null) {
551-
outputPanel = new OutputPanel(extension);
552-
resetOutputPanel();
553-
}
554-
return outputPanel;
555-
}
556-
557-
protected void resetOutputPanel() {
558-
outputPanel.clear();
559-
outputPanel.append(Constant.messages.getString("scripts.welcome.results"));
560-
}
561-
562540
public String getCommandScript() {
563541
return this.getCommandPanel().getCommandScript();
564542
}
@@ -796,7 +774,12 @@ public void run() {
796774
try {
797775
extension.getExtScript().invokeScript(script);
798776
} catch (Exception e) {
799-
getOutputPanel().append(e);
777+
if (extension.getView() != null) {
778+
extension
779+
.getView()
780+
.getOutputPanel()
781+
.append(extractScriptExceptionMessage(e), script.getName());
782+
}
800783
} finally {
801784
WeakReference<ScriptExecutorThread> refScriptExecutorThread =
802785
runnableScriptsToThreadMap.remove(script);

0 commit comments

Comments
 (0)