Skip to content

Commit

Permalink
More code cleanup and refactoring (metaschema-framework#245)
Browse files Browse the repository at this point in the history
* Added missing Javadocs. Adjusted many existing Javadocs to provide more details.
* Refactored data type and atomic item implementations to move casting operations to the atomic item implementations. This creates a cleaner isolation between the type adapters and Metapath items.
* Refactored names of temporal implementation classes.
* Removed some unused constants.
* Improved date and dateTime adapter unit testing to check for ambiguity and resulting time value.
* Reformatted some code.
* Performed some light refactoring to remove unused code and to improve overall code readability to make maintenance easier.
* Added asserts to ensure HTML to Mardown conversion is tested more completely.
* Significantly improved data and date/time parsing test vectors.
* Replaced Paths.get() with Paths.get(System.getProperty(user.dir)) to be more explict. Improved value creation methods in date and date/time item classes. Added many Javadocs.
* Refactored the result type used in MetapathExpression to avoid the need for a case statement. This should result in cleaner code and better performance overall.
* Removed commented out code.
* Updated some inconsistent log4j configurations to be consistent with other configurations.
* Updated dependencies through parent POM.
  • Loading branch information
david-waltermire authored Nov 17, 2024
1 parent 47a13f2 commit be910a9
Show file tree
Hide file tree
Showing 181 changed files with 3,437 additions and 1,375 deletions.
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

0 comments on commit be910a9

Please sign in to comment.