Skip to content

Commit be910a9

Browse files
More code cleanup and refactoring (#245)
* 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.
1 parent 47a13f2 commit be910a9

File tree

181 files changed

+3437
-1375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+3437
-1375
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
3+
package gov.nist.secauto.metaschema.cli.processor;
4+
5+
import gov.nist.secauto.metaschema.core.util.IVersionInfo;
6+
7+
/**
8+
* Provides version information for this library.
9+
* <p>
10+
* This class exposes build-time metadata including version numbers, build
11+
* timestamps, and Git repository information.
12+
*/
13+
public class ProcessorVersion implements IVersionInfo {
14+
15+
private static final String NAME = "${project.name}";
16+
private static final String VERSION = "${project.version}";
17+
private static final String BUILD_TIMESTAMP = "${timestamp}";
18+
private static final String COMMIT = "@git.commit.id.abbrev@";
19+
private static final String BRANCH = "@git.branch@";
20+
private static final String CLOSEST_TAG = "@git.closest.tag.name@";
21+
private static final String ORIGIN = "@git.remote.origin.url@";
22+
23+
@Override
24+
public String getName() {
25+
return NAME;
26+
}
27+
28+
@Override
29+
public String getVersion() {
30+
return VERSION;
31+
}
32+
33+
@Override
34+
public String getBuildTimestamp() {
35+
return BUILD_TIMESTAMP;
36+
}
37+
38+
@Override
39+
public String getGitOriginUrl() {
40+
return ORIGIN;
41+
}
42+
43+
@Override
44+
public String getGitCommit() {
45+
return COMMIT;
46+
}
47+
48+
@Override
49+
public String getGitBranch() {
50+
return BRANCH;
51+
}
52+
53+
@Override
54+
public String getGitClosestTag() {
55+
return CLOSEST_TAG;
56+
}
57+
}

cli-processor/src/main/java-templates/gov/nist/secauto/metaschema/cli/processor/Version.java

-40
This file was deleted.

cli-processor/src/main/java/gov/nist/secauto/metaschema/cli/processor/AbstractExitStatus.java

+49-17
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
import edu.umd.cs.findbugs.annotations.Nullable;
1414
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
1515

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

@@ -61,8 +69,16 @@ public ExitStatus withThrowable(@NonNull Throwable throwable) {
6169
@Nullable
6270
protected abstract String getMessage();
6371

64-
@Override
65-
public void generateMessage(boolean showStackTrace) {
72+
/**
73+
* Determines the appropriate LogBuilder based on the exit code status. For
74+
* non-positive exit codes (success/info), returns an INFO level builder. For
75+
* positive exit codes (errors), returns an ERROR level builder.
76+
*
77+
* @return the appropriate LogBuilder based on exit status, or {@code null} if
78+
* logging is disabled at the determined level
79+
*/
80+
@Nullable
81+
private LogBuilder getLogBuilder() {
6682
LogBuilder logBuilder = null;
6783
if (getExitCode().getStatusCode() <= 0) {
6884
if (LOGGER.isInfoEnabled()) {
@@ -71,25 +87,41 @@ public void generateMessage(boolean showStackTrace) {
7187
} else if (LOGGER.isErrorEnabled()) {
7288
logBuilder = LOGGER.atError();
7389
}
90+
return logBuilder;
91+
}
7492

75-
if (logBuilder != null) {
76-
if (showStackTrace && throwable != null) {
77-
Throwable throwable = getThrowable();
78-
logBuilder.withThrowable(throwable);
79-
}
93+
/**
94+
* Generates and logs a message based on the current exit status. The message is
95+
* logged at either INFO level (for success/info status) or ERROR level (for
96+
* error status).
97+
*
98+
* @param showStackTrace
99+
* if {@code true} and a throwable is present, includes the stack trace
100+
* in the log
101+
*/
102+
@Override
103+
public void generateMessage(boolean showStackTrace) {
104+
LogBuilder logBuilder = getLogBuilder();
105+
if (logBuilder == null) {
106+
return;
107+
}
80108

81-
String message = getMessage();
82-
if (message == null && throwable != null) {
83-
message = throwable.getLocalizedMessage();
84-
}
109+
boolean useStackTrace = showStackTrace && throwable != null;
110+
if (useStackTrace) {
111+
logBuilder.withThrowable(throwable);
112+
}
85113

86-
if (message != null && !message.isEmpty()) {
87-
logBuilder.log(message);
88-
} else if (showStackTrace && throwable != null) {
89-
// log the throwable
90-
logBuilder.log();
91-
}
114+
String message = getMessage();
115+
if (throwable != null && message == null) {
116+
message = throwable.getLocalizedMessage();
92117
}
118+
119+
if (message != null && !message.isEmpty()) {
120+
logBuilder.log(message);
121+
} else if (useStackTrace) {
122+
// log the throwable
123+
logBuilder.log();
124+
} // else avoid an empty log line
93125
}
94126

95127
}

0 commit comments

Comments
 (0)