Skip to content

Commit

Permalink
#196 print command
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 22, 2024
1 parent 75706b1 commit 1e3fa7c
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ControlSequenceIndicatorFormatted implements Formatted {
private final transient String pattern;

/**
* Construtor.
* Ctor.
* @param pat Pattern to be used to find replacement points
*/
public ControlSequenceIndicatorFormatted(final String pat) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jcabi/log/DecorsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ final class DecorsManager {

/**
* Storage of all found decors.
* @checkstyle LineLength (2 lines)
*/
private static final ConcurrentMap<String, Class<? extends Formattable>> DECORS =
new ConcurrentHashMap<>(0);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jcabi/log/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ public static void log(final Level level, final Object source,
* @return Output stream directly pointed to the logging facility
* @see <a href="http://stackoverflow.com/questions/17258325">some discussion</a>
* @since 0.8
* @checkstyle MagicNumberCheck (20 lines)
*/
public static OutputStream stream(final Level level, final Object source) {
// @checkstyle AnonInnerLengthCheck (50 lines)
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jcabi/log/MsDecor.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public void formatTo(final Formatter formatter, final int flags,
* Create text.
* @param precision The precision
* @return The text
* @checkstyle MagicNumber (50 lines)
*/
private String toText(final int precision) {
final double number;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/jcabi/log/NanoDecor.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public void formatTo(final Formatter formatter, final int flags,
private String toText(final int precision) {
final double number;
final String title;
// @checkstyle MagicNumber (15 lines)
if (this.nano < 1000.0) {
number = this.nano;
title = "ns";
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/jcabi/log/PreFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ final class PreFormatter {
* Pattern used for matching format string arguments.
*/
private static final Pattern PATTERN = Pattern.compile(
// @checkstyle LineLength (1 line)
"%(\\d+\\$)?(\\[([A-Za-z\\-\\.0-9]+)\\])?[\\+\\-]?(?:\\d*(?:\\.\\d+)?)?[a-zA-Z%]"
"%(\\d+\\$)?(\\[([A-Za-z\\-.0-9]+)])?[+\\-]?(?:\\d*(?:\\.\\d+)?)?[a-zA-Z%]"
);

/**
Expand Down Expand Up @@ -146,7 +145,6 @@ private void process(final CharSequence fmt, final Object... args) {
if (pos < args.length) {
throw new IllegalArgumentException(
String.format(
// @checkstyle LineLength (1 line)
"There are %d parameter(s) but only %d format argument(s) were provided.",
args.length,
pos
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/jcabi/log/SizeDecor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ final class SizeDecor implements Formattable {
private final transient Long size;

static {
// @checkstyle MagicNumber (9 lines)
SizeDecor.SUFFIXES.put(0, "b");
SizeDecor.SUFFIXES.put(1, "Kb");
SizeDecor.SUFFIXES.put(2, "Mb");
Expand Down Expand Up @@ -89,7 +88,7 @@ public void formatTo(final Formatter formatter, final int flags,
format.append('-');
}
if (width > 0) {
format.append(Integer.toString(width));
format.append(width);
}
if ((flags & FormattableFlags.UPPERCASE) == FormattableFlags
.UPPERCASE) {
Expand All @@ -111,9 +110,8 @@ public void formatTo(final Formatter formatter, final int flags,
private String formatSizeWithSuffix(final int precision) {
int power = 0;
double number = this.size;
// @checkstyle MagicNumber (2 lines)
while (number / 1024.0 >= 1.0 && power < SizeDecor.MAX_POWER) {
number = number / 1024.0;
number /= 1024.0;
power += 1;
}
final String suffix = SizeDecor.SUFFIXES.get(power);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/jcabi/log/TextDecor.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ private static String pretty(final String text) {
final int skip = text.length() - TextDecor.MAX;
final StringBuilder output = new StringBuilder(text.length());
output.append(text.substring(0, (text.length() - skip) / 2));
// @checkstyle MultipleStringLiterals (1 line)
output.append("..").append(Integer.toString(skip)).append("..");
output.append("..").append(skip).append("..");
output.append(
text.substring(text.length() - TextDecor.MAX + output.length())
);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/jcabi/log/VerboseCallable.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,25 +175,25 @@ public T call() throws Exception {
} catch (final RuntimeException ex) {
if (this.rethrow) {
Logger.warn(
this, "escalated runtime exception: %s", this.tail(ex)
this, "Escalated runtime exception: %s", this.tail(ex)
);
throw ex;
}
Logger.warn(this, "swallowed runtime exception: %s", this.tail(ex));
Logger.warn(this, "Swallowed runtime exception: %s", this.tail(ex));
// @checkstyle IllegalCatch (1 line)
} catch (final Exception ex) {
if (this.rethrow) {
Logger.warn(this, "escalated exception: %s", this.tail(ex));
Logger.warn(this, "Escalated exception: %s", this.tail(ex));
throw ex;
}
Logger.warn(this, "swallowed exception: %s", this.tail(ex));
Logger.warn(this, "Swallowed exception: %s", this.tail(ex));
// @checkstyle IllegalCatch (1 line)
} catch (final Error error) {
if (this.rethrow) {
Logger.error(this, "escalated error: %s", this.tail(error));
Logger.error(this, "Escalated error: %s", this.tail(error));
throw error;
}
Logger.error(this, "swallowed error: %s", this.tail(error));
Logger.error(this, "Swallowed error: %s", this.tail(error));
}
try {
TimeUnit.MICROSECONDS.sleep(1L);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/com/jcabi/log/VerboseProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,11 @@ public VerboseProcess(final Process prc, final Level stdout,
}
if (Level.ALL.equals(stdout)) {
throw new IllegalArgumentException(
// @checkstyle LineLength (1 line)
"stdout LEVEL can't be set to ALL because it is intended only for internal configuration"
);
}
if (Level.ALL.equals(stderr)) {
throw new IllegalArgumentException(
// @checkstyle LineLength (1 line)
"stderr LEVEL can't be set to ALL because it is intended only for internal configuration"
);
}
Expand Down Expand Up @@ -247,11 +245,11 @@ public void close() {
for (final Thread monitor : this.monitors) {
if (monitor != null) {
monitor.interrupt();
Logger.debug(this, "monitor interrupted");
Logger.debug(this, "Monitor interrupted");
}
}
this.process.destroy();
Logger.debug(this, "underlying process destroyed");
Logger.debug(this, "Underlying process destroyed");
}

/**
Expand All @@ -261,8 +259,13 @@ public void close() {
*/
private static Process start(final ProcessBuilder builder) {
if (builder == null) {
throw new IllegalArgumentException("builder can't be NULL");
throw new IllegalArgumentException("Builder can't be NULL");
}
Logger.debug(
VerboseProcess.class,
"#start(): %s",
String.join(" ", builder.command())
);
try {
final Process process = builder.start();
process.getOutputStream().close();
Expand Down Expand Up @@ -391,7 +394,7 @@ private static void close(final Closeable res) {
} catch (final IOException ex) {
Logger.error(
VerboseProcess.class,
"failed to close resource: %[exception]s",
"Failed to close resource: %[exception]s",
ex
);
}
Expand Down Expand Up @@ -456,7 +459,7 @@ public Void call() throws Exception {
if (Thread.interrupted()) {
Logger.debug(
VerboseProcess.class,
"explicitly interrupting read from buffer"
"Explicitly interrupting read from buffer"
);
break;
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/jcabi/log/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ void providesOutputStream() throws Exception {
final PrintWriter writer = new PrintWriter(
new OutputStreamWriter(stream, "UTF-8")
);
// @checkstyle LineLength (1 line)
writer.print("hello, \u20ac, how're\u040a?\nI'm fine, \u0000\u0007!\n");
writer.flush();
writer.close();
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/jcabi/log/MsDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ void testPrintsNullRight() {
private static Collection<Object[]> params() {
return Arrays.asList(
new Object[][] {
// @checkstyle LineLength (20 lines)
// @checkstyle MagicNumber (20 lines)
{13L, "13ms", 0, 0, -1},
{13L, "13.0ms", 0, 0, 1},
{1024L, "1s", 0, 0, 0},
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/jcabi/log/NanoDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ void testPrintsNullRight() {
private static Collection<Object[]> params() {
return Arrays.asList(
new Object[][] {
// @checkstyle LineLength (20 lines)
// @checkstyle MagicNumber (20 lines)
{13L, "13ns", 0, 0, -1},
{13L, "13.0ns", 0, 0, 1},
{25L, "25.00ns", 0, 0, 2},
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/jcabi/log/SecretDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ void testLogsRight(final Object list, final String text,
private static Collection<Object[]> params() {
return Arrays.asList(
new Object[][] {
// @checkstyle MagicNumber (4 lines)
{"testing", "t***g", 0, 0, 0},
{"ouch", "o***h ", FormattableFlags.LEFT_JUSTIFY, 7, 5},
{"x", " X***X", FormattableFlags.UPPERCASE, 6, 0},
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/jcabi/log/SizeDecorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ void testPrintsNullRight() {
private static Collection<Object[]> params() {
return Arrays.asList(
new Object[][] {
// @checkstyle MagicNumber (14 lines)
{1L, "1b", 0, 0, 0},
{123L, " 123b", 0, 6, 0},
{1024L, "1.000Kb", 0, 0, 3},
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/com/jcabi/log/VerboseProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ void terminatesMonitorsAndProcessIfClosedInstantly()
@Test
void terminatesMonitorsAndProcessIfClosedShortly()
throws Exception {
// @checkstyle MagicNumberCheck (1 line)
this.terminatesMonitorsAndProcessIfClosed(50L);
}

Expand Down Expand Up @@ -353,7 +352,6 @@ public void run() {
);
}
process.stdoutQuietly();
// @checkstyle MagicNumberCheck (1 line)
TimeUnit.MILLISECONDS.sleep(1000L);
Mockito.verify(
prc,
Expand Down

0 comments on commit 1e3fa7c

Please sign in to comment.