Skip to content
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
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