Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring: Basic Changes (renaming iteration variable, extracting StringFormatter Class, adding explaining variable in JNLP's SimpleRange class, and extracting Interrupted exception logging method) #897

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
20 changes: 13 additions & 7 deletions common/src/main/java/net/adoptopenjdk/icedteaweb/ProcessUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,21 @@ public static void waitForSafely(final Process process) {
while (!pTerminated) {
try {
process.waitFor();
} catch (final InterruptedException e) {
LOG.error(IcedTeaWebConstants.DEFAULT_ERROR_MESSAGE, e);
}
try {
process.exitValue();
pTerminated = true;
} catch (final IllegalThreadStateException e) {
LOG.error(IcedTeaWebConstants.DEFAULT_ERROR_MESSAGE, e);
} catch (final InterruptedException e) {
logInterruptedException(e);
}
}
}

/**
* Logs the given InterruptedException to the error log using the default error message.
*
* @param e the InterruptedException object that occurred and will be logged
* @return This method does not have a return value as it logs the InterruptedException.
*/
private static void logInterruptedException(InterruptedException e) {
LOG.error(IcedTeaWebConstants.DEFAULT_ERROR_MESSAGE, e);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*/
class SimpleRange {

private static final String REGEXP_MODIFIER_END = REGEXP_MODIFIER + "$";
private final VersionId versionId;
private final VersionModifier modifier;

Expand Down Expand Up @@ -109,7 +110,7 @@ private static VersionModifier extractModifier(final String simpleRange) {
}

private static VersionId extractVersionId(final String simpleRange) {
final String exactId = simpleRange.replaceAll(REGEXP_MODIFIER + "$", "");
final String exactId = simpleRange.replaceAll(REGEXP_MODIFIER_END, "");
return VersionId.fromString(exactId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
*/
public abstract class BaseLogger implements Logger {

protected String expand(final String msg, final Object[] args) {
return doExpand(msg, args);
protected static String doExpand(final String msg, final Object[] args) {
return new StringFormatter().doExpand(msg, args);
}
}

static String doExpand(final String msg, final Object[] args) {
class StringFormatter {
String doExpand(final String msg, final Object[] args) {
if (msg == null) {
return "null";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void debug(final String msg) {

@Override
public void debug(final String msg, final Object... arguments) {
log(DEBUG, expand(msg, arguments), null);
log(DEBUG, doExpand(msg, arguments), null);
}

@Override
Expand All @@ -62,7 +62,7 @@ public void info(final String msg) {

@Override
public void info(final String msg, final Object... arguments) {
log(INFO, expand(msg, arguments), null);
log(INFO, doExpand(msg, arguments), null);
}

@Override
Expand All @@ -77,7 +77,7 @@ public void warn(final String msg) {

@Override
public void warn(final String msg, final Object... arguments) {
log(WARNING, expand(msg, arguments), null);
log(WARNING, doExpand(msg, arguments), null);
}

@Override
Expand All @@ -92,7 +92,7 @@ public void error(final String msg) {

@Override
public void error(final String msg, final Object... arguments) {
log(ERROR, expand(msg, arguments), null);
log(ERROR, doExpand(msg, arguments), null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ public DirectoryCheckResults(final List<DirectoryCheckResult> results) {
* @return sum of passed checks, 0-3 per result
*/
public int getPasses() {
return results.stream().mapToInt(r -> r.getPasses()).sum();
return results.stream().mapToInt(result -> result.getPasses()).sum();
}

/**
* @return sum of failed checks, 0-3 per results
*/
public int getFailures() {
return results.stream().mapToInt(r -> r.getFailures()).sum();
return results.stream().mapToInt(result -> result.getFailures()).sum();
}

/**
Expand All @@ -60,9 +60,9 @@ public String toString() {

private static String resultsToString(final List<DirectoryCheckResult> results) {
final StringBuilder sb = new StringBuilder();
for (final DirectoryCheckResult r : results) {
if (r.getFailures() > 0) {
sb.append(r.getMessage());
for (final DirectoryCheckResult result : results) {
if (result.getFailures() > 0) {
sb.append(result.getMessage());
}
}
return sb.toString();
Expand Down