Author: pmouawad Date: Thu Oct 26 19:36:49 2017 New Revision: 1813453 URL: http://svn.apache.org/viewvc?rev=1813453&view=rev Log: Fix sonar warnings
Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java?rev=1813453&r1=1813452&r2=1813453&view=diff ============================================================================== --- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java (original) +++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/proxy/gui/ProxyControlGui.java Thu Oct 26 19:36:49 2017 @@ -205,11 +205,11 @@ public class ProxyControlGui extends Log private JButton restart; //+ action names - private static final String STOP = "stop"; // $NON-NLS-1$ + private static final String ACTION_STOP = "stop"; // $NON-NLS-1$ - private static final String START = "start"; // $NON-NLS-1$ + private static final String ACTION_START = "start"; // $NON-NLS-1$ - private static final String RESTART = "restart"; // $NON-NLS-1$ + private static final String ACTION_RESTART = "restart"; // $NON-NLS-1$ // This is applied to fields that should cause a restart when changed private static final String ENABLE_RESTART = "enable_restart"; // $NON-NLS-1$ @@ -239,7 +239,7 @@ public class ProxyControlGui extends Log private static final String EXCLUDE_COL = "patterns_to_exclude"; // $NON-NLS-1$ // Used by itemListener - private static final String PORTFIELD = "portField"; // $NON-NLS-1$ + private static final String PORT_FIELD_NAME = "portField"; // $NON-NLS-1$ public ProxyControlGui() { super(); @@ -251,14 +251,13 @@ public class ProxyControlGui extends Log @Override public TestElement createTestElement() { model = makeProxyControl(); - log.debug("creating/configuring model = " + model); + log.debug("creating/configuring model = {}", model); modifyTestElement(model); return model; } protected ProxyControl makeProxyControl() { - ProxyControl local = new ProxyControl(); - return local; + return new ProxyControl(); } /** {@inheritDoc} */ @@ -334,7 +333,7 @@ public class ProxyControlGui extends Log /** {@inheritDoc} */ @Override public void configure(TestElement element) { - log.debug("Configuring gui with " + element); + log.debug("Configuring gui with {}", element); super.configure(element); model = (ProxyControl) element; portField.setText(model.getPortString()); @@ -394,14 +393,14 @@ public class ProxyControlGui extends Log samplerFollowRedirects.setSelected(false); } - if (command.equals(STOP)) { + if (command.equals(ACTION_STOP)) { model.stopProxy(); stop.setEnabled(false); start.setEnabled(true); restart.setEnabled(false); - } else if (command.equals(START)) { + } else if (command.equals(ACTION_START)) { startProxy(); - } else if (command.equals(RESTART)) { + } else if (command.equals(ACTION_RESTART)) { model.stopProxy(); startProxy(); } else if (command.equals(ENABLE_RESTART)){ @@ -419,8 +418,7 @@ public class ProxyControlGui extends Log } else if (command.equals(DELETE_INCLUDE)) { deleteRowFromTable(includeModel, includeTable); } else if (command.equals(CHANGE_TARGET)) { - log.debug("Change target " + targetNodes.getSelectedItem()); - log.debug("In model " + model); + log.debug("Change target {} in model {}", targetNodes.getSelectedItem(), model); TreeNodeWrapper nw = (TreeNodeWrapper) targetNodes.getSelectedItem(); model.setTarget(nw.getTreeNode()); enableRestart(); @@ -474,10 +472,9 @@ public class ProxyControlGui extends Log protected void addSuggestedExcludes(JTable table) { GuiUtils.stopTableEditing(table); int rowCount = table.getRowCount(); - PowerTableModel model = null; String[] exclusions = SUGGESTED_EXCLUSIONS.split(";"); // $NON-NLS-1$ if (exclusions.length>0) { - model = (PowerTableModel) table.getModel(); + PowerTableModel model = (PowerTableModel) table.getModel(); if(model != null) { for (String clipboardLine : exclusions) { model.addRow(new Object[] {clipboardLine}); @@ -498,21 +495,19 @@ public class ProxyControlGui extends Log protected void addFromClipboard(JTable table) { GuiUtils.stopTableEditing(table); int rowCount = table.getRowCount(); - PowerTableModel model = null; try { String clipboardContent = GuiUtils.getPastedText(); if (clipboardContent != null) { + PowerTableModel model = null; String[] clipboardLines = clipboardContent.split(NEW_LINE); for (String clipboardLine : clipboardLines) { model = (PowerTableModel) table.getModel(); model.addRow(new Object[] {clipboardLine}); } - if (table.getRowCount() > rowCount) { - if(model != null) { - // Highlight (select) the appropriate rows. - int rowToSelect = model.getRowCount() - 1; - table.setRowSelectionInterval(rowCount, rowToSelect); - } + if (model != null && table.getRowCount() > rowCount) { + // Highlight (select) the appropriate rows. + int rowToSelect = model.getRowCount() - 1; + table.setRowSelectionInterval(rowCount, rowToSelect); } } } catch (IOException ioe) { @@ -547,7 +542,6 @@ public class ProxyControlGui extends Log // Proxy can take some while to start up; show a waiting cursor Cursor cursor = getCursor(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); - // TODO somehow show progress try { replacer.replaceValues(model); model.startProxy(); @@ -564,7 +558,7 @@ public class ProxyControlGui extends Log sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_install_as_in_doc")); // $NON-NLS-1$ sb.append("<br><b>").append(MessageFormat.format( JMeterUtils.getResString("proxy_daemon_msg_check_expiration"), - new Object[] {ProxyControl.CERT_VALIDITY})) // $NON-NLS-1$ + ProxyControl.CERT_VALIDITY)) // $NON-NLS-1$ .append("</b><br>"); sb.append("<br>").append(JMeterUtils.getResString("proxy_daemon_msg_check_details")) .append("<ul>"); // $NON-NLS-1$ @@ -609,11 +603,13 @@ public class ProxyControlGui extends Log /** {@inheritDoc} */ @Override public void keyPressed(KeyEvent e) { + // NOOP } /** {@inheritDoc} */ @Override public void keyTyped(KeyEvent e) { + // NOOP } /** {@inheritDoc} */ @@ -621,7 +617,7 @@ public class ProxyControlGui extends Log public void keyReleased(KeyEvent e) { String fieldName = e.getComponent().getName(); - if (fieldName.equals(PORTFIELD)) { + if (fieldName.equals(PORT_FIELD_NAME)) { try { Integer.parseInt(portField.getText()); } catch (NumberFormatException nfe) { @@ -702,21 +698,21 @@ public class ProxyControlGui extends Log ImageIcon startImage = JMeterUtils.getImage("toolbar/" + iconSize + "/arrow-right-3.png"); start.setIcon(startImage); start.addActionListener(this); - start.setActionCommand(START); + start.setActionCommand(ACTION_START); start.setEnabled(true); stop = new JButton(JMeterUtils.getResString("stop")); // $NON-NLS-1$ ImageIcon stopImage = JMeterUtils.getImage("toolbar/" + iconSize + "/process-stop-4.png"); stop.setIcon(stopImage); stop.addActionListener(this); - stop.setActionCommand(STOP); + stop.setActionCommand(ACTION_STOP); stop.setEnabled(false); ImageIcon restartImage = JMeterUtils.getImage("toolbar/" + iconSize + "/edit-redo-7.png"); restart = new JButton(JMeterUtils.getResString("restart")); // $NON-NLS-1$ restart.setIcon(restartImage); restart.addActionListener(this); - restart.setActionCommand(RESTART); + restart.setActionCommand(ACTION_RESTART); restart.setEnabled(false); JPanel panel = new JPanel(); @@ -732,7 +728,7 @@ public class ProxyControlGui extends Log private JPanel createPortPanel() { portField = new JTextField(ProxyControl.DEFAULT_PORT_S, 20); - portField.setName(PORTFIELD); + portField.setName(PORT_FIELD_NAME); portField.addKeyListener(this); Dimension portPreferredSize = portField.getPreferredSize(); portField.setMinimumSize(new Dimension((int) Math.round(portPreferredSize.width*0.75), portPreferredSize.height)); @@ -1086,7 +1082,7 @@ public class ProxyControlGui extends Log TreeNodeWrapper choice = null; for (int i = 0; i < targetNodesModel.getSize(); i++) { choice = (TreeNodeWrapper) targetNodesModel.getElementAt(i); - log.debug("Selecting item " + choice + " for model " + model + " in " + this); + log.debug("Selecting item {} for model {} in {}", choice, model, this); if (choice.getTreeNode() == model.getTarget()) // .equals caused NPE { break; @@ -1107,15 +1103,6 @@ public class ProxyControlGui extends Log StringBuilder name = new StringBuilder(); JMeterTreeNode cur = (JMeterTreeNode) node.getChildAt(i); TestElement te = cur.getTestElement(); - /* - * Will never be true. Probably intended to use - * org.apache.jmeter.threads.ThreadGroup rather than - * java.lang.ThreadGroup However, that does not work correctly; - * whereas treating it as a Controller does. if (te instanceof - * ThreadGroup) { name.append(parent_name); - * name.append(cur.getName()); name.append(separator); - * buildNodesModel(cur, name.toString(), level); } else - */ if (te instanceof Controller) { name.append(parentName); name.append(cur.getName());