Skip to content

Commit

Permalink
scripts: Use main output panel for output
Browse files Browse the repository at this point in the history
Signed-off-by: ricekot <[email protected]>
  • Loading branch information
ricekot committed Dec 30, 2024
1 parent 124016c commit f2032f0
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 434 deletions.
1 change: 1 addition & 0 deletions addOns/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fields with default or missing values are omitted for the `script` job in saved Automation Framework plans.
- Depends on an updated version of the Common Library add-on.
- Depend on Passive Scanner add-on (Issue 7959).
- Use the main Output panel for script output.

### Fixed
- Correct auto-complete suggestions for parameters of Passive Rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.zaproxy.zap.extension.scripts;

import static org.zaproxy.zap.extension.scripts.ExtensionScriptsUI.extractScriptExceptionMessage;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
Expand Down Expand Up @@ -46,7 +48,6 @@
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
Expand Down Expand Up @@ -86,7 +87,6 @@ public class ConsolePanel extends AbstractPanel {
private JButton optionsButton;
private JLabel scriptTitle = null;
private CommandPanel commandPanel = null;
private OutputPanel outputPanel = null;
private KeyListener listener = null;

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

JSplitPane splitPane = new JSplitPane();
splitPane.setDividerSize(3);
splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
splitPane.setResizeWeight(0.5D);
splitPane.setTopComponent(getCommandPanel());
splitPane.setBottomComponent(getOutputPanel());

panelContent.add(this.getPanelToolbar(), LayoutHelper.getGBC(0, 0, 1, 1.0D, 0.0D));
panelContent.add(splitPane, LayoutHelper.getGBC(0, 1, 1, 1.0D, 1.0D));
panelContent.add(getCommandPanel(), LayoutHelper.getGBC(0, 1, 1, 1.0D, 1.0D));
}

private boolean isScriptUpdatedOnDisk() {
Expand Down Expand Up @@ -456,8 +449,6 @@ private void runScript() {

getRunButton().setEnabled(false);

getOutputPanel().preScriptInvoke();

// Update it, in case its been changed
script.setContents(getCommandScript());

Expand Down Expand Up @@ -546,19 +537,6 @@ public void actionPerformed(ActionEvent e) {
return commandPanel;
}

protected OutputPanel getOutputPanel() {
if (outputPanel == null) {
outputPanel = new OutputPanel(extension);
resetOutputPanel();
}
return outputPanel;
}

protected void resetOutputPanel() {
outputPanel.clear();
outputPanel.append(Constant.messages.getString("scripts.welcome.results"));
}

public String getCommandScript() {
return this.getCommandPanel().getCommandScript();
}
Expand Down Expand Up @@ -796,7 +774,12 @@ public void run() {
try {
extension.getExtScript().invokeScript(script);
} catch (Exception e) {
getOutputPanel().append(e);
if (extension.getView() != null) {
extension
.getView()
.getOutputPanel()
.append(extractScriptExceptionMessage(e), script.getName());
}
} finally {
WeakReference<ScriptExecutorThread> refScriptExecutorThread =
runnableScriptsToThreadMap.remove(script);
Expand Down
Loading

0 comments on commit f2032f0

Please sign in to comment.