Skip to content

Commit

Permalink
Code fixes and remove deprecated class usage
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr72 committed Sep 30, 2024
1 parent 7995f82 commit 40e026f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
25 changes: 13 additions & 12 deletions core/src/main/java/org/mapfish/print/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import ch.qos.logback.core.util.StatusPrinter2;
import com.google.common.annotations.VisibleForTesting;
import com.sampullara.cli.Args;
import java.io.File;
Expand Down Expand Up @@ -58,7 +58,6 @@ private Main() {
* Main method.
*
* @param args the cli arguments
* @throws Exception
*/
public static void main(final String[] args) throws Exception {
runMain(args);
Expand All @@ -69,7 +68,6 @@ public static void main(final String[] args) throws Exception {
* Runs the print.
*
* @param args the cli arguments
* @throws Exception
*/
@VisibleForTesting
public static void runMain(final String[] args) throws Exception {
Expand Down Expand Up @@ -133,17 +131,20 @@ private static void configureLogs(final String verbose) {
case LOGLEVEL_INFO:
logfile = classLoader.getResource("shell-info-log.xml");
break;
case LOGLEVEL_DEFAULT:
logfile = classLoader.getResource("shell-default-log.xml");
break;
case LOGLEVEL_VERBOSE:
logfile = classLoader.getResource("shell-verbose-log.xml");
break;
case LOGLEVEL_DEFAULT:
default:
logfile = classLoader.getResource("shell-default-log.xml");
break;
}

LoggerContext loggerContext = getLoggerContext(logfile);
new StatusPrinter2().printInCaseOfErrorsOrWarnings(loggerContext);
}

private static LoggerContext getLoggerContext(final URL logfile) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

try {
Expand All @@ -156,15 +157,15 @@ private static void configureLogs(final String verbose) {
} catch (JoranException je) {
// StatusPrinter will handle this
}
StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
return loggerContext;
}

/**
* Instead of calling system.exit an exception will be thrown. This is useful for testing so a
* test won't shutdown jvm.
* Instead of calling System.exit() an exception will be thrown. This is useful for testing so a
* test won't shut down the jvm.
*
* @param exceptionOnFailure if true then an exception will be thrown instead of system.exit being
* called.
* @param exceptionOnFailure if true then an exception will be thrown instead of System.exit()
* being called.
*/
@VisibleForTesting
static void setExceptionOnFailure(final boolean exceptionOnFailure) {
Expand Down Expand Up @@ -197,7 +198,7 @@ private void run(final CliDefinition cli) throws Exception {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Request Data: \n{}", jsonSpec.getInternalObj().toString(2));
}
this.mapPrinter.print(new HashMap<String, String>(), jsonSpec, outFile);
this.mapPrinter.print(new HashMap<>(), jsonSpec, outFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,13 @@ private class TestPrintJob extends PrintJob {
entry.configureAccess(template, context);
setSecurityContext(SecurityContextHolder.createEmptyContext());
} catch (JSONException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}

@Override
protected PrintResult withOpenOutputStream(PrintAction function) throws Exception {
return new PrintResult(42, new AbstractProcessor.Context(new HashMap()));
return new PrintResult(42, new AbstractProcessor.Context(new HashMap<>()));
}

@Override
Expand Down

0 comments on commit 40e026f

Please sign in to comment.