Skip to content

Commit cea9f7f

Browse files
committed
scripts: Use main output panel for script output
Signed-off-by: ricekot <git@ricekot.com>
1 parent 32891bf commit cea9f7f

File tree

8 files changed

+173
-436
lines changed

8 files changed

+173
-436
lines changed

addOns/scripts/CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ All notable changes to this add-on will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
55

66
## Unreleased
7-
7+
### Changed
8+
- Use the main Output panel for script output.
89

910
## [45.8.0] - 2025-01-10
1011
### Added

addOns/scripts/scripts.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ zapAddOn {
3030
dependencies {
3131
addOns {
3232
register("commonlib") {
33-
version.set(">=1.29.0")
33+
version.set(">=1.31.0")
3434
}
3535
register("pscan") {
3636
version.set(">= 0.1.0 & < 1.0.0")

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

+9-26
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import javax.swing.JLabel;
4747
import javax.swing.JOptionPane;
4848
import javax.swing.JPanel;
49-
import javax.swing.JSplitPane;
5049
import javax.swing.JToolBar;
5150
import javax.swing.KeyStroke;
5251
import javax.swing.border.EmptyBorder;
@@ -86,7 +85,6 @@ public class ConsolePanel extends AbstractPanel {
8685
private JButton optionsButton;
8786
private JLabel scriptTitle = null;
8887
private CommandPanel commandPanel = null;
89-
private OutputPanel outputPanel = null;
9088
private KeyListener listener = null;
9189

9290
private ScriptWrapper script = null;
@@ -135,15 +133,8 @@ public ConsolePanel(ExtensionScriptsUI extension) {
135133
panelContent = new JPanel(new GridBagLayout());
136134
this.add(panelContent, BorderLayout.CENTER);
137135

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-
145136
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));
137+
panelContent.add(getCommandPanel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 1.0D));
147138
}
148139

149140
private boolean isScriptUpdatedOnDisk() {
@@ -456,8 +447,6 @@ private void runScript() {
456447

457448
getRunButton().setEnabled(false);
458449

459-
getOutputPanel().preScriptInvoke();
460-
461450
// Update it, in case its been changed
462451
script.setContents(getCommandScript());
463452

@@ -546,19 +535,6 @@ public void actionPerformed(ActionEvent e) {
546535
return commandPanel;
547536
}
548537

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-
562538
public String getCommandScript() {
563539
return this.getCommandPanel().getCommandScript();
564540
}
@@ -796,7 +772,14 @@ public void run() {
796772
try {
797773
extension.getExtScript().invokeScript(script);
798774
} catch (Exception e) {
799-
getOutputPanel().append(e);
775+
if (extension.getView() != null) {
776+
extension
777+
.getView()
778+
.getOutputPanel()
779+
.append(
780+
ExtensionScriptsUI.extractScriptExceptionMessage(e),
781+
script.getName());
782+
}
800783
} finally {
801784
WeakReference<ScriptExecutorThread> refScriptExecutorThread =
802785
runnableScriptsToThreadMap.remove(script);

0 commit comments

Comments
 (0)