Skip to content

Commit f6b3d33

Browse files
committed
scripts: Use main output panel for output
Signed-off-by: ricekot <[email protected]>
1 parent bdf2d49 commit f6b3d33

File tree

9 files changed

+214
-435
lines changed

9 files changed

+214
-435
lines changed

addOns/commonlib/src/main/java/org/zaproxy/addon/commonlib/ui/TabbedOutputPanel.java

+17
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,23 @@ public void clear(String sourceName) {
378378
}
379379
}
380380

381+
/**
382+
* Sets the selected output tab, creating it if it doesn't exist.
383+
*
384+
* @param sourceName the name of the corresponding output source
385+
*/
386+
public void setSelectedOutputTab(String sourceName) {
387+
addNewOutputSource(sourceName);
388+
tabbedPanel.getTabList().stream()
389+
.filter(t -> t.getName().equals(sourceName))
390+
.findFirst()
391+
.ifPresent(
392+
component -> {
393+
tabbedPanel.setVisible(component, true);
394+
tabbedPanel.setSelectedComponent(component);
395+
});
396+
}
397+
381398
private void doAppend(ZapTextArea txtOutput, String message) {
382399
if (Model.getSingleton()
383400
.getOptionsParam()

addOns/scripts/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
### Fixed
88
- Remove unnecessary custom parameter handling.
99

10+
### Changed
11+
- Use the main Output panel for script output.
12+
1013
## [45.8.0] - 2025-01-10
1114
### Added
1215
- Report indirect script errors while the Automation Framework plans are running (Issue 8586).

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

+16-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;
@@ -56,6 +55,8 @@
5655
import org.parosproxy.paros.Constant;
5756
import org.parosproxy.paros.control.Control;
5857
import org.parosproxy.paros.extension.AbstractPanel;
58+
import org.parosproxy.paros.view.OutputPanel;
59+
import org.zaproxy.addon.commonlib.ui.TabbedOutputPanel;
5960
import org.zaproxy.zap.ZAP;
6061
import org.zaproxy.zap.extension.script.ScriptWrapper;
6162
import org.zaproxy.zap.utils.DisplayUtils;
@@ -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() {
@@ -455,8 +448,11 @@ private void runScript() {
455448
}
456449

457450
getRunButton().setEnabled(false);
458-
459-
getOutputPanel().preScriptInvoke();
451+
OutputPanel outputPanel = extension.getView().getOutputPanel();
452+
outputPanel.setTabFocus();
453+
if (outputPanel instanceof TabbedOutputPanel tabbedOutputPanel) {
454+
tabbedOutputPanel.setSelectedOutputTab(script.getName());
455+
}
460456

461457
// Update it, in case its been changed
462458
script.setContents(getCommandScript());
@@ -546,19 +542,6 @@ public void actionPerformed(ActionEvent e) {
546542
return commandPanel;
547543
}
548544

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-
562545
public String getCommandScript() {
563546
return this.getCommandPanel().getCommandScript();
564547
}
@@ -796,7 +779,14 @@ public void run() {
796779
try {
797780
extension.getExtScript().invokeScript(script);
798781
} catch (Exception e) {
799-
getOutputPanel().append(e);
782+
if (extension.getView() != null) {
783+
extension
784+
.getView()
785+
.getOutputPanel()
786+
.append(
787+
ExtensionScriptsUI.extractScriptExceptionMessage(e),
788+
script.getName());
789+
}
800790
} finally {
801791
WeakReference<ScriptExecutorThread> refScriptExecutorThread =
802792
runnableScriptsToThreadMap.remove(script);

0 commit comments

Comments
 (0)