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

More code cleanup and refactoring #245

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fc1413e
Added missing Javadocs.
david-waltermire Nov 11, 2024
d73da15
Refactored data type and atomic item implementations to move casting …
david-waltermire Nov 12, 2024
2e7ed2e
Added more Javadocs.
david-waltermire Nov 14, 2024
69d9925
Refactored names of temporal implementation classes. Adjusted Javadoc…
david-waltermire Nov 14, 2024
6504a02
Removed some unused constants and added more Javadocs.
david-waltermire Nov 14, 2024
f7c0a9c
Addressed code review comments.
david-waltermire Nov 14, 2024
9a4237f
Improved date and dateTime adapter unit testing to check for ambiguit…
david-waltermire Nov 14, 2024
1b2312f
Code formatting.
david-waltermire Nov 14, 2024
f727af5
Added a bunch of Javadocs. Performed some light refactoring.
david-waltermire Nov 15, 2024
e266feb
Added asserts to properly test HTML to Mardown conversion.
david-waltermire Nov 16, 2024
cd5c5a3
Significantly improved data and date/time parsing test vectors.
david-waltermire Nov 16, 2024
a5fc87c
Replaced Paths.get() with Paths.get(System.getProperty(user.dir)) to …
david-waltermire Nov 16, 2024
9e7ae7a
Refactored the result type used in MetapathExpression to avoid the ne…
david-waltermire Nov 16, 2024
ba9208b
More light refactoring and Javadoc improvements.
david-waltermire Nov 16, 2024
2142d52
Added a todo to do more refactoring later.
david-waltermire Nov 16, 2024
3ece9b1
Removed commented out code.
david-waltermire Nov 16, 2024
84966f3
More adjustments based on code review.
david-waltermire Nov 16, 2024
7978ff0
Adjustments to catch actually thrown exceptions.
david-waltermire Nov 16, 2024
1c403cf
Updated the log4j configuration to be consistent with other configura…
david-waltermire Nov 16, 2024
04bea0d
Updated dependencies through parent POM.
david-waltermire Nov 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@


package gov.nist.secauto.metaschema.cli.processor;

import gov.nist.secauto.metaschema.core.util.IVersionInfo;

/**
* Provides version information for this library.
* <p>
* This class exposes build-time metadata including version numbers, build
* timestamps, and Git repository information.
*/
public class ProcessorVersion implements IVersionInfo {

private static final String NAME = "${project.name}";
private static final String VERSION = "${project.version}";
private static final String BUILD_TIMESTAMP = "${timestamp}";
private static final String COMMIT = "@git.commit.id.abbrev@";
private static final String BRANCH = "@git.branch@";
private static final String CLOSEST_TAG = "@git.closest.tag.name@";
private static final String ORIGIN = "@git.remote.origin.url@";

@Override
public String getName() {
return NAME;
}

@Override
public String getVersion() {
return VERSION;
}

@Override
public String getBuildTimestamp() {
return BUILD_TIMESTAMP;
}

@Override
public String getGitOriginUrl() {
return ORIGIN;
}

@Override
public String getGitCommit() {
return COMMIT;
}

@Override
public String getGitBranch() {
return BRANCH;
}

@Override
public String getGitClosestTag() {
return CLOSEST_TAG;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Records information about the exit status of a CLI command.
* <p>
* This abstract class provides base functionality for handling CLI command exit
* statuses, including error logging and throwable management. Implementing
* classes must provide the {@link #getMessage()} implementation to define the
* status message content.
*/
public abstract class AbstractExitStatus implements ExitStatus {
private static final Logger LOGGER = LogManager.getLogger(AbstractExitStatus.class);

Expand Down Expand Up @@ -61,8 +69,16 @@ public ExitStatus withThrowable(@NonNull Throwable throwable) {
@Nullable
protected abstract String getMessage();

@Override
public void generateMessage(boolean showStackTrace) {
/**
* Determines the appropriate LogBuilder based on the exit code status. For
* non-positive exit codes (success/info), returns an INFO level builder. For
* positive exit codes (errors), returns an ERROR level builder.
*
* @return the appropriate LogBuilder based on exit status, or {@code null} if
* logging is disabled at the determined level
*/
@Nullable
private LogBuilder getLogBuilder() {
LogBuilder logBuilder = null;
if (getExitCode().getStatusCode() <= 0) {
if (LOGGER.isInfoEnabled()) {
Expand All @@ -71,25 +87,41 @@ public void generateMessage(boolean showStackTrace) {
} else if (LOGGER.isErrorEnabled()) {
logBuilder = LOGGER.atError();
}
return logBuilder;
}

if (logBuilder != null) {
if (showStackTrace && throwable != null) {
Throwable throwable = getThrowable();
logBuilder.withThrowable(throwable);
}
/**
* Generates and logs a message based on the current exit status. The message is
* logged at either INFO level (for success/info status) or ERROR level (for
* error status).
*
* @param showStackTrace
* if {@code true} and a throwable is present, includes the stack trace
* in the log
*/
@Override
public void generateMessage(boolean showStackTrace) {
LogBuilder logBuilder = getLogBuilder();
if (logBuilder == null) {
return;
}

String message = getMessage();
if (message == null && throwable != null) {
message = throwable.getLocalizedMessage();
}
boolean useStackTrace = showStackTrace && throwable != null;
if (useStackTrace) {
logBuilder.withThrowable(throwable);
}

if (message != null && !message.isEmpty()) {
logBuilder.log(message);
} else if (showStackTrace && throwable != null) {
// log the throwable
logBuilder.log();
}
String message = getMessage();
if (throwable != null && message == null) {
message = throwable.getLocalizedMessage();
}

if (message != null && !message.isEmpty()) {
logBuilder.log(message);
} else if (useStackTrace) {
// log the throwable
logBuilder.log();
} // else avoid an empty log line
}

}
Loading
Loading