From 6f6954f792ad84286b9d5e32821ea36848ed0e22 Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 28 Jun 2019 16:46:57 -0400 Subject: [PATCH] Remove throws Exception, change int to long --- .../java/net/wasdev/wlp/ant/AbstractTask.java | 93 ++++++++----------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/src/main/java/net/wasdev/wlp/ant/AbstractTask.java b/src/main/java/net/wasdev/wlp/ant/AbstractTask.java index 07a41101..4be38e2a 100644 --- a/src/main/java/net/wasdev/wlp/ant/AbstractTask.java +++ b/src/main/java/net/wasdev/wlp/ant/AbstractTask.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014. + * (C) Copyright IBM Corporation 2014, 2019. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -293,31 +293,26 @@ public void doJoin() throws InterruptedException { */ public String waitForStringInLog(String regexp, long timeout, File outputFile) { - int waited = 0; - final int waitIncrement = 500; + long waited = 0; + final long waitIncrement = 500; log(MessageFormat.format(messages.getString("info.search.string"), regexp, outputFile.getAbsolutePath(), timeout / 1000)); - try { - while (waited <= timeout) { - String string = findStringInFile(regexp, outputFile); - if (string == null) { - try { - Thread.sleep(waitIncrement); - } catch (InterruptedException e) { - // Ignore and carry on - } - waited += waitIncrement; - } else { - return string; + while (waited <= timeout) { + String string = findStringInFile(regexp, outputFile); + if (string == null) { + try { + Thread.sleep(waitIncrement); + } catch (InterruptedException e) { + // Ignore and carry on } + waited += waitIncrement; + } else { + return string; } - log(MessageFormat.format(messages.getString("error.serch.string.timeout"), regexp, outputFile.getAbsolutePath())); - } catch (Exception e) { - // I think we can assume if we can't read the file it doesn't - // contain our string - throw new BuildException(e); } + log(MessageFormat.format(messages.getString("error.serch.string.timeout"), regexp, outputFile.getAbsolutePath())); + return null; } @@ -331,9 +326,8 @@ public String waitForStringInLog(String regexp, long timeout, * the file to search * @return The first line which includes the pattern, or null if the pattern * isn't found or if the file doesn't exist - * @throws Exception */ - protected String findStringInFile(String regexp, File fileToSearch) throws Exception { + protected String findStringInFile(String regexp, File fileToSearch) { String foundString = null; List matches = findStringsInFileCommon(regexp, true, -1, fileToSearch); @@ -355,18 +349,21 @@ protected String findStringInFile(String regexp, File fileToSearch) throws Excep * @param msgLevel the log level for the match number message * @return List of Strings which match the pattern. No match results in an * empty list. - * @throws Exception */ private List findStringsInFileCommon(String regexp, - boolean stopOnFirst, int searchLimit, File fileToSearch, int msgLevel) - throws Exception { + boolean stopOnFirst, int searchLimit, File fileToSearch, int msgLevel) { if (fileToSearch == null) { log(messages.getString("info.file.validated")); return null; } if (!fileToSearch.exists()) { - log(MessageFormat.format(messages.getString("info.file.validate.noexist"), fileToSearch.getCanonicalPath())); + try { + log(MessageFormat.format(messages.getString("info.file.validate.noexist"), fileToSearch.getCanonicalPath())); + } catch (IOException e) { + // file doesn't exist anyways, so just print the absolute path for the message + log(MessageFormat.format(messages.getString("info.file.validate.noexist"), fileToSearch.getAbsolutePath())); + } return null; } @@ -437,11 +434,9 @@ private List findStringsInFileCommon(String regexp, * the file to search * @return List of Strings which match the pattern. No match results in an * empty list. - * @throws Exception */ protected List findStringsInFileCommon(String regexp, - boolean stopOnFirst, int searchLimit, File fileToSearch) - throws Exception { + boolean stopOnFirst, int searchLimit, File fileToSearch) { return findStringsInFileCommon(regexp, stopOnFirst, searchLimit, fileToSearch, Project.MSG_INFO); } @@ -453,9 +448,8 @@ protected List findStringsInFileCommon(String regexp, * @param fileToSearch * the file to search * @return the number of occurrences of the regular expression - * @throws Exception */ - public int countStringOccurrencesInFile(String regexp, File fileToSearch) throws Exception { + public int countStringOccurrencesInFile(String regexp, File fileToSearch) { List lines = findStringsInFileCommon(regexp, false, -1, fileToSearch, Project.MSG_VERBOSE); if (lines == null) { @@ -479,33 +473,28 @@ public int countStringOccurrencesInFile(String regexp, File fileToSearch) throws */ public String waitForUpdatedStringInLog(String regexp, long timeout, File outputFile, int previousOccurrences) { - int waited = 0; - final int waitIncrement = 500; + long waited = 0; + final long waitIncrement = 500; log(MessageFormat.format(messages.getString("info.search.string"), regexp, outputFile.getAbsolutePath(), timeout / 1000)); - try { - while (waited <= timeout) { - List matches = findStringsInFileCommon(regexp, false, -1, outputFile, Project.MSG_VERBOSE); - if (matches == null || matches.size() <= previousOccurrences) { - try { - Thread.sleep(waitIncrement); - } catch (InterruptedException e) { - // Ignore and carry on - } - waited += waitIncrement; - } else { - String line = matches.get(matches.size() - 1); - log(MessageFormat.format(messages.getString("info.match.string"), matches.size(), line), Project.MSG_INFO); - return line; + while (waited <= timeout) { + List matches = findStringsInFileCommon(regexp, false, -1, outputFile, Project.MSG_VERBOSE); + if (matches == null || matches.size() <= previousOccurrences) { + try { + Thread.sleep(waitIncrement); + } catch (InterruptedException e) { + // Ignore and carry on } + waited += waitIncrement; + } else { + String line = matches.get(matches.size() - 1); + log(MessageFormat.format(messages.getString("info.match.string"), matches.size(), line), Project.MSG_INFO); + return line; } - log(MessageFormat.format(messages.getString("error.serch.string.timeout"), regexp, outputFile.getAbsolutePath())); - } catch (Exception e) { - // I think we can assume if we can't read the file it doesn't - // contain our string - throw new BuildException(e); } + log(MessageFormat.format(messages.getString("error.serch.string.timeout"), regexp, outputFile.getAbsolutePath())); + return null; }