From 9f2aca50e33a1be8154bd90b93a1f658e4b6d910 Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Tue, 8 Jan 2002 19:59:45 +0000 Subject: [PATCH] Fix bad coding style. then/else parts of if statement and loop body must always been enclosed in a block statement. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270629 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/SQLExec.java | 27 ++++++++--- .../apache/tools/ant/taskdefs/SignJar.java | 19 ++++++-- .../org/apache/tools/ant/taskdefs/Tar.java | 3 +- .../apache/tools/ant/taskdefs/UpToDate.java | 4 +- .../org/apache/tools/ant/taskdefs/War.java | 3 +- .../tools/ant/taskdefs/XSLTProcess.java | 15 ++++-- .../org/apache/tools/ant/taskdefs/Zip.java | 22 ++++++--- .../ant/taskdefs/optional/AdaptxLiaison.java | 3 +- .../tools/ant/taskdefs/optional/Rpm.java | 4 +- .../tools/ant/taskdefs/optional/Script.java | 10 ++-- .../ant/taskdefs/optional/TraXLiaison.java | 4 +- .../taskdefs/optional/XMLValidateTask.java | 25 ++++++---- .../ant/taskdefs/optional/XalanLiaison.java | 3 +- .../ant/taskdefs/optional/XslpLiaison.java | 3 +- .../optional/ejb/WebsphereDeploymentTool.java | 3 +- .../taskdefs/optional/ide/VAJAntToolGUI.java | 48 ++++++++++++------- .../ant/taskdefs/optional/net/TelnetTask.java | 27 +++++++---- .../perforce/SimpleP4OutputHandler.java | 4 +- .../optional/starteam/TreeBasedTask.java | 3 +- .../apache/tools/ant/types/Substitution.java | 3 +- 20 files changed, 161 insertions(+), 72 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java index 5d238100a..d0279d6b7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java +++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java @@ -495,7 +495,9 @@ public class SQLExec extends Task { throw new SQLException("No suitable Driver for "+url); } - if (!isValidRdbms(conn)) return; + if (!isValidRdbms(conn)) { + return; + } conn.setAutoCommit(autocommit); @@ -566,8 +568,12 @@ public class SQLExec extends Task { while ((line=in.readLine()) != null){ line = line.trim(); line = project.replaceProperties(line); - if (line.startsWith("//")) continue; - if (line.startsWith("--")) continue; + if (line.startsWith("//")) { + continue; + } + if (line.startsWith("--")) { + continue; + } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); @@ -582,7 +588,9 @@ public class SQLExec extends Task { // SQL defines "--" as a comment to EOL // and in Oracle it may contain a hint // so we cannot just remove it, instead we must end it - if (line.indexOf("--") >= 0) sql += "\n"; + if (line.indexOf("--") >= 0) { + sql += "\n"; + } if (delimiterType.equals(DelimiterType.NORMAL) && sql.endsWith(delimiter) || delimiterType.equals(DelimiterType.ROW) && line.equals(delimiter)) { @@ -606,8 +614,9 @@ public class SQLExec extends Task { * Verify if connected to the correct RDBMS **/ protected boolean isValidRdbms(Connection conn) { - if (rdbms == null && version == null) + if (rdbms == null && version == null) { return true; + } try { DatabaseMetaData dmd = conn.getMetaData(); @@ -648,7 +657,9 @@ public class SQLExec extends Task { */ protected void execSQL(String sql, PrintStream out) throws SQLException { // Check and ignore empty statements - if ("".equals(sql.trim())) return; + if ("".equals(sql.trim())) { + return; + } try { totalSql++; @@ -672,7 +683,9 @@ public class SQLExec extends Task { } catch (SQLException e) { log("Failed to execute: " + sql, Project.MSG_ERR); - if (!onError.equals("continue")) throw e; + if (!onError.equals("continue")) { + throw e; + } log(e.toString(), Project.MSG_ERR); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/SignJar.java b/src/main/org/apache/tools/ant/taskdefs/SignJar.java index f4f286943..ddcf09de8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SignJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/SignJar.java @@ -199,7 +199,9 @@ public class SignJar extends Task { throw new BuildException("storepass attribute must be set"); } - if(isUpToDate(jarSource, jarTarget)) return; + if(isUpToDate(jarSource, jarTarget)) { + return; + } final StringBuffer sb = new StringBuffer(); @@ -265,11 +267,18 @@ public class SignJar extends Task { if( null != signedjarFile ) { - if(!jarFile.exists()) return false; - if(!signedjarFile.exists()) return false; - if(jarFile.equals(signedjarFile)) return false; - if(signedjarFile.lastModified() > jarFile.lastModified()) + if(!jarFile.exists()) { + return false; + } + if(!signedjarFile.exists()) { + return false; + } + if(jarFile.equals(signedjarFile)) { + return false; + } + if(signedjarFile.lastModified() > jarFile.lastModified()) { return true; + } } else { if( lazy ) { return isSigned(jarFile); diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 360592d03..d062e35a0 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -333,8 +333,9 @@ public class Tar extends MatchingTask { tOut.closeEntry(); } finally { - if (fIn != null) + if (fIn != null) { fIn.close(); + } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java index 44206076b..6cdc7a19c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java +++ b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java @@ -155,7 +155,9 @@ public class UpToDate extends MatchingTask implements Condition { } // if not there then it can't be up to date - if (_targetFile != null && !_targetFile.exists()) return false; + if (_targetFile != null && !_targetFile.exists()) { + return false; + } Enumeration enum = sourceFileSets.elements(); boolean upToDate = true; diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java index 333116a0c..50c47c710 100644 --- a/src/main/org/apache/tools/ant/taskdefs/War.java +++ b/src/main/org/apache/tools/ant/taskdefs/War.java @@ -92,8 +92,9 @@ public class War extends Jar { */ public void setWebxml(File descr) { deploymentDescriptor = descr; - if (!deploymentDescriptor.exists()) + if (!deploymentDescriptor.exists()) { throw new BuildException("Deployment descriptor: " + deploymentDescriptor + " does not exist."); + } // Create a ZipFileSet for this file, and pass it up. ZipFileSet fs = new ZipFileSet(); diff --git a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java index 0f42cf499..a5ec7cb5a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java +++ b/src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java @@ -194,8 +194,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { dirs = scanner.getIncludedDirectories(); for (int j = 0;j < dirs.length;++j){ list=new File(baseDir,dirs[j]).list(); - for (int i = 0;i < list.length;++i) + for (int i = 0;i < list.length;++i) { process( baseDir, list[i], destDir, stylesheet ); + } } } //-- execute @@ -386,7 +387,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { } }catch (Exception ex) { log("Failed to process " + inFile, Project.MSG_INFO); - if(outFile!=null)outFile.delete(); + if(outFile!=null) { + outFile.delete(); + } throw new BuildException(ex); } } @@ -456,12 +459,16 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger { } public String getName() throws BuildException{ - if(name==null)throw new BuildException("Name attribute is missing."); + if(name==null) { + throw new BuildException("Name attribute is missing."); + } return name; } public String getExpression() throws BuildException{ - if(expression==null)throw new BuildException("Expression attribute is missing."); + if(expression==null) { + throw new BuildException("Expression attribute is missing."); + } return expression; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Zip.java b/src/main/org/apache/tools/ant/taskdefs/Zip.java index 1c2adc183..3a1b2ede9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Zip.java +++ b/src/main/org/apache/tools/ant/taskdefs/Zip.java @@ -346,8 +346,9 @@ public class Zip extends MatchingTask { // before we added any files, then we must swallow this exception. Otherwise, // the error that's reported will be the close() error, which is not the real // cause of the problem. - if (success) + if (success) { throw ex; + } } } } catch (IOException ioe) { @@ -395,15 +396,17 @@ public class Zip extends MatchingTask { */ protected void addFiles(FileScanner scanner, ZipOutputStream zOut, String prefix, String fullpath) throws IOException { - if (prefix.length() > 0 && fullpath.length() > 0) + if (prefix.length() > 0 && fullpath.length() > 0) { throw new BuildException("Both prefix and fullpath attributes may not be set on the same fileset."); + } File thisBaseDir = scanner.getBasedir(); // directories that matched include patterns String[] dirs = scanner.getIncludedDirectories(); - if (dirs.length > 0 && fullpath.length() > 0) + if (dirs.length > 0 && fullpath.length() > 0) { throw new BuildException("fullpath attribute may only be specified for filesets that specify a single file."); + } for (int i = 0; i < dirs.length; i++) { if ("".equals(dirs[i])) { continue; @@ -417,8 +420,9 @@ public class Zip extends MatchingTask { // files that matched include patterns String[] files = scanner.getIncludedFiles(); - if (files.length > 1 && fullpath.length() > 0) + if (files.length > 1 && fullpath.length() > 0) { throw new BuildException("fullpath attribute may only be specified for filesets that specify a single file."); + } for (int i = 0; i < files.length; i++) { File f = new File(thisBaseDir, files[i]); if (fullpath.length() > 0) @@ -441,8 +445,9 @@ public class Zip extends MatchingTask { ZipOutputStream zOut, String prefix, String fullpath) throws IOException { - if (prefix.length() > 0 && fullpath.length() > 0) + if (prefix.length() > 0 && fullpath.length() > 0) { throw new BuildException("Both prefix and fullpath attributes may not be set on the same fileset."); + } ZipScanner zipScanner = (ZipScanner) ds; File zipSrc = fs.getSrc(); @@ -547,7 +552,9 @@ public class Zip extends MatchingTask { } } - if (!zipFile.exists()) return false; + if (!zipFile.exists()) { + return false; + } SourceFileScanner sfs = new SourceFileScanner(this); MergingMapper mm = new MergingMapper(); @@ -571,8 +578,9 @@ public class Zip extends MatchingTask { Vector files = new Vector(); for (int i = 0; i < fileNames.length; i++) { File thisBaseDir = scanners[i].getBasedir(); - for (int j = 0; j < fileNames[i].length; j++) + for (int j = 0; j < fileNames[i].length; j++) { files.addElement(new File(thisBaseDir, fileNames[i][j])); + } } File[] toret = new File[files.size()]; files.copyInto(toret); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/AdaptxLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/AdaptxLiaison.java index 55dd3fa62..4ba4cec47 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/AdaptxLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/AdaptxLiaison.java @@ -95,8 +95,9 @@ public class AdaptxLiaison implements XSLTLiaison { } public void setOutputtype(String type) throws Exception { - if (!type.equals("xml")) + if (!type.equals("xml")) { throw new BuildException("Unsupported output type: " + type); + } } } //-- AdaptxLiaison diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java index 1b3426563..73470bbd4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java @@ -173,7 +173,9 @@ public class Rpm extends Task { Execute exe = new Execute(streamhandler, null); exe.setAntRun(project); - if (topDir == null) topDir = project.getBaseDir(); + if (topDir == null) { + topDir = project.getBaseDir(); + } exe.setWorkingDirectory(topDir); exe.setCommandline(toExecute.getCommandline()); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java index c29404ff6..1a4092d20 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java @@ -83,10 +83,13 @@ public class Script extends Task { boolean isValid = key.length()>0 && Character.isJavaIdentifierStart(key.charAt(0)); - for (int i=1; isValid && i 0) + if (getCombinedClasspath() != null && getCombinedClasspath().toString().length() > 0) { args += " -cp " + getCombinedClasspath(); + } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java index f9a404ac6..0cc0cbe34 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntToolGUI.java @@ -258,8 +258,9 @@ public class VAJAntToolGUI extends Frame { public void messageLogged(BuildEvent event) { if (event.getPriority() <= getBuildInfo().getOutputMessageLevel()) { String msg = ""; - if (event.getTask() != null) + if (event.getTask() != null) { msg = "[" + event.getTask().getTaskName() + "] "; + } getMessageTextArea().append(lineSeparator + msg + event.getMessage()); } } @@ -345,22 +346,29 @@ public class VAJAntToolGUI extends Frame { } } // MenuItems - if (e.getSource() == VAJAntToolGUI.this.getSaveMenuItem()) + if (e.getSource() == VAJAntToolGUI.this.getSaveMenuItem()) { saveBuildInfo(); - if (e.getSource() == VAJAntToolGUI.this.getAboutMenuItem()) + } + if (e.getSource() == VAJAntToolGUI.this.getAboutMenuItem()) { getAboutDialog().show(); - if (e.getSource() == VAJAntToolGUI.this.getShowLogMenuItem()) + } + if (e.getSource() == VAJAntToolGUI.this.getShowLogMenuItem()) { getMessageFrame().show(); + } /* #### About dialog #### */ - if (e.getSource() == VAJAntToolGUI.this.getAboutOkButton()) + if (e.getSource() == VAJAntToolGUI.this.getAboutOkButton()) { getAboutDialog().dispose(); + } /* #### Log frame #### */ - if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) + if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) { getMessageFrame().dispose(); - if (e.getSource() == VAJAntToolGUI.this.getMessageClearLogButton()) + } + if (e.getSource() == VAJAntToolGUI.this.getMessageClearLogButton()) { getMessageTextArea().setText(""); - if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) + } + if (e.getSource() == VAJAntToolGUI.this.getMessageOkButton()) { getMessageFrame().dispose(); + } } catch (Throwable exc) { handleException(exc); @@ -372,12 +380,15 @@ public class VAJAntToolGUI extends Frame { */ public void itemStateChanged(ItemEvent e) { try { - if (e.getSource() == VAJAntToolGUI.this.getTargetList()) + if (e.getSource() == VAJAntToolGUI.this.getTargetList()) { getBuildButton().setEnabled(true); - if (e.getSource() == VAJAntToolGUI.this.getMessageOutputLevelChoice()) + } + if (e.getSource() == VAJAntToolGUI.this.getMessageOutputLevelChoice()) { getBuildInfo().setOutputMessageLevel(getMessageOutputLevelChoice().getSelectedIndex()); - if (e.getSource() == VAJAntToolGUI.this.getTargetList()) + } + if (e.getSource() == VAJAntToolGUI.this.getTargetList()) { getBuildInfo().setTarget(getTargetList().getSelectedItem()); + } } catch (Throwable exc) { handleException(exc); @@ -388,18 +399,21 @@ public class VAJAntToolGUI extends Frame { * PropertyChangeListener method */ public void propertyChange(java.beans.PropertyChangeEvent evt) { - if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("projectName"))) + if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("projectName"))) { connectProjectNameToLabel(); - if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("buildFileName"))) + } + if (evt.getSource() == VAJAntToolGUI.this.getBuildInfo() && (evt.getPropertyName().equals("buildFileName"))) { connectBuildFileNameToTextField(); + } } /** * TextListener method */ public void textValueChanged(TextEvent e) { - if (e.getSource() == VAJAntToolGUI.this.getBuildFileTextField()) + if (e.getSource() == VAJAntToolGUI.this.getBuildFileTextField()) { connectTextFieldToBuildFileName(); + } } /** @@ -411,10 +425,12 @@ public class VAJAntToolGUI extends Frame { dispose(); System.exit(0); } - if (e.getSource() == VAJAntToolGUI.this.getAboutDialog()) + if (e.getSource() == VAJAntToolGUI.this.getAboutDialog()) { getAboutDialog().dispose(); - if (e.getSource() == VAJAntToolGUI.this.getMessageFrame()) + } + if (e.getSource() == VAJAntToolGUI.this.getMessageFrame()) { getMessageFrame().dispose(); + } } catch (Throwable exc) { handleException(exc); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java index d6583039a..0786d7e96 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java @@ -123,15 +123,18 @@ public class TelnetTask extends Task { public void execute() throws BuildException { /** A server name is required to continue */ - if (server== null) + if (server== null) { throw new BuildException("No Server Specified"); + } /** A userid and password must appear together * if they appear. They are not required. */ - if (userid == null && password != null) + if (userid == null && password != null) { throw new BuildException("No Userid Specified"); - if (password == null && userid != null) + } + if (password == null && userid != null) { throw new BuildException("No Password Specified"); + } /** Create the telnet client object */ telnet = new AntTelnetClient(); @@ -141,15 +144,17 @@ public class TelnetTask extends Task { throw new BuildException("Can't connect to "+server); } /** Login if userid and password were specified */ - if (userid != null && password != null) + if (userid != null && password != null) { login(); + } /** Process each sub command */ Enumeration tasksToRun = telnetTasks.elements(); while (tasksToRun!=null && tasksToRun.hasMoreElements()) { TelnetSubTask task = (TelnetSubTask) tasksToRun.nextElement(); - if (task instanceof TelnetRead && defaultTimeout != null) + if (task instanceof TelnetRead && defaultTimeout != null) { ((TelnetRead)task).setDefaultTimeout(defaultTimeout); + } task.execute(telnet); } } @@ -160,8 +165,9 @@ public class TelnetTask extends Task { */ private void login() { - if (addCarriageReturn) + if (addCarriageReturn) { telnet.sendString("\n", true); + } telnet.waitForString("ogin:"); telnet.sendString(userid, true); telnet.waitForString("assword:"); @@ -287,8 +293,9 @@ public class TelnetTask extends Task { */ public void setDefaultTimeout(Integer defaultTimeout) { - if (timeout == null) + if (timeout == null) { timeout = defaultTimeout; + } } } /** @@ -336,8 +343,9 @@ public class TelnetTask extends Task { is.available() == 0) { Thread.sleep(250); } - if (is.available() == 0) + if (is.available() == 0) { throw new BuildException("Response Timed-Out", getLocation()); + } sb.append((char) is.read()); } } @@ -361,8 +369,9 @@ public class TelnetTask extends Task { OutputStream os =this.getOutputStream(); try { os.write((s + "\n").getBytes()); - if (echoString) + if (echoString) { log(s, Project.MSG_INFO); + } os.flush(); } catch (Exception e) { diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java index 69b88d400..475605655 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java @@ -69,7 +69,9 @@ public class SimpleP4OutputHandler extends P4HandlerAdapter { } public void process(String line) throws BuildException { - if(parent.util.match("/^exit/",line)) return; + if(parent.util.match("/^exit/",line)) { + return; + } //Throw exception on errors (except up-to-date) //p4 -s is unpredicatable. For example a server down diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java index 84b6db0dd..121e311e2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/starteam/TreeBasedTask.java @@ -434,8 +434,9 @@ public abstract class TreeBasedTask extends StarTeamTask { if (null != this.label) { Label[] allLabels = v.getLabels(); for (int i = 0; i < allLabels.length; i++) { - if (allLabels[i].getName().equals(this.label)) + if (allLabels[i].getName().equals(this.label)) { return allLabels[i].getID(); + } } throw new BuildException("Error: label " + this.label diff --git a/src/main/org/apache/tools/ant/types/Substitution.java b/src/main/org/apache/tools/ant/types/Substitution.java index 92fbbaa5e..ed1be516c 100644 --- a/src/main/org/apache/tools/ant/types/Substitution.java +++ b/src/main/org/apache/tools/ant/types/Substitution.java @@ -93,8 +93,9 @@ public class Substitution extends DataType */ public String getExpression(Project p) { - if (isReference()) + if (isReference()) { return getRef(p).getExpression(p); + } return expression; }