Skip to content

Commit fa7d062

Browse files
committed
chore: v1.2.2
1 parent be9caad commit fa7d062

File tree

4 files changed

+48
-37
lines changed

4 files changed

+48
-37
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.exadmin</groupId>
88
<artifactId>cyberferret</artifactId>
9-
<version>1.2.1</version>
9+
<version>1.2.2</version>
1010
<name>cyber-ferret</name>
1111

1212
<properties>

src/main/java/com/github/exadmin/cyberferret/CyberFerretApp.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,15 @@
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010

11-
import java.io.IOException;
12-
import java.io.InputStream;
1311
import java.nio.file.Paths;
14-
import java.util.Properties;
1512

1613
import static com.github.exadmin.cyberferret.persistence.PersistentPropertiesManager.*;
14+
import static com.github.exadmin.cyberferret.utils.MiscUtils.loadApplicationVersion;
1715

1816
public class CyberFerretApp extends Application {
1917
private static final Logger log = LoggerFactory.getLogger(CyberFerretApp.class);
2018
private static final String APPLICATION_PERSISTENT_CONTEXT_FILENAME = "app.properties";
21-
private static final String VERSION_PROPERTIES_RESOURCE = "/version.properties";
19+
2220

2321
@Override
2422
public void start(Stage stage) {
@@ -53,19 +51,5 @@ public static void main(String[] args) {
5351
launch();
5452
}
5553

56-
private String loadApplicationVersion() {
57-
Properties props = new Properties();
58-
try (InputStream input = getClass().getResourceAsStream(VERSION_PROPERTIES_RESOURCE)) {
59-
if (input == null) {
60-
log.error("Resource {} is not found on the classpath", VERSION_PROPERTIES_RESOURCE);
61-
return "UNDEFINED";
62-
}
63-
props.load(input);
64-
return props.getProperty("application.version");
65-
} catch (IOException ex) {
66-
log.error("Error while loading {}", VERSION_PROPERTIES_RESOURCE, ex);
67-
}
6854

69-
return "UNDEFINED";
70-
}
7155
}

src/main/java/com/github/exadmin/cyberferret/CyberFerretCLI.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public class CyberFerretCLI {
2626

2727
private static void printUsage() {
2828
String errMsg = """
29-
Usage: CyberFerretCLI $PATH_TO_REPOSITORY_TO_SCAN $PATH_TO_FILE_WITH_LIST_OF_FILES(optional)"
30-
Also, note that '{}' System Environment variable must be set
31-
""";
29+
Usage: CyberFerretCLI $PATH_TO_REPOSITORY_TO_SCAN $PATH_TO_FILE_WITH_LIST_OF_FILES(optional)"
30+
Also, note that '{}' System Environment variable must be set
31+
""";
3232
errMsg = ConsoleUtils.format(errMsg, SYS_ENV_VAR_PASSWORD);
3333
System.out.println(errMsg);
3434
}
@@ -46,9 +46,11 @@ public static void main(String[] args) {
4646
// Step5: Decrypt dictionary
4747
// Step6: Run check over the git-repository
4848

49+
String appVer = MiscUtils.loadApplicationVersion();
50+
ConsoleUtils.info("CyberFerretCLI version: " + appVer);
4951

5052
// Step1: Check required program arguments are set
51-
if (args.length < 1 || args.length > 2) {
53+
if (args.length != 2) {
5254
ConsoleUtils.error("Unexpected number of command line arguments");
5355
printUsage();
5456
terminateAppWithErrorCode();
@@ -70,20 +72,25 @@ public static void main(String[] args) {
7072
}
7173

7274
List<Path> stagedFiles = new ArrayList<>();
73-
if (args.length > 1) {
74-
Path stagedFilesListPath = Path.of(args[1]);
75-
if (!Files.isRegularFile(stagedFilesListPath)) {
76-
ConsoleUtils.error("Invalid path to file list {}", stagedFilesListPath);
77-
printUsage();
78-
terminateAppWithErrorCode();
79-
}
80-
try {
81-
stagedFiles = loadStagedFiles(rootPathToScan, stagedFilesListPath);
82-
} catch (IOException ex) {
83-
ConsoleUtils.error("Error while reading staged files list. " + ex.getMessage());
84-
terminateAppWithErrorCode();
85-
}
75+
76+
Path stagedFilesListPath = Path.of(args[1]);
77+
if (!Files.isRegularFile(stagedFilesListPath)) {
78+
ConsoleUtils.error("Invalid path to file list {}", stagedFilesListPath);
79+
printUsage();
80+
terminateAppWithErrorCode();
8681
}
82+
try {
83+
stagedFiles = loadStagedFiles(rootPathToScan, stagedFilesListPath);
84+
} catch (IOException ex) {
85+
ConsoleUtils.error("Error while reading staged files list. " + ex.getMessage());
86+
terminateAppWithErrorCode();
87+
}
88+
89+
if (stagedFiles.isEmpty()) {
90+
ConsoleUtils.error("No staged files found in the file {}", stagedFilesListPath);
91+
terminateAppWithErrorCode();
92+
}
93+
8794

8895
// Step3: Ensure actual dictionary is downloaded
8996
RunnableCheckOnlineDictionary dictionaryDownloader = new RunnableCheckOnlineDictionary(true);
@@ -133,7 +140,7 @@ public static void main(String[] args) {
133140
}
134141
}
135142

136-
ConsoleUtils.debug("Scan is completed. Errors are " + (runnableScanner.isAnySignatureFound() ? "found (-). Breaking commit!" : "NOT found (+)"));
143+
ConsoleUtils.info("Scan is completed. Errors are " + (runnableScanner.isAnySignatureFound() ? "found :( Breaking commit!" : "not found :)"));
137144

138145
if (runnableScanner.isAnySignatureFound()) {
139146
terminateAppWithErrorCode();

src/main/java/com/github/exadmin/cyberferret/utils/MiscUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.Path;
88
import java.security.MessageDigest;
99
import java.security.NoSuchAlgorithmException;
10+
import java.util.Properties;
1011

1112
public class MiscUtils {
1213
public static String getSHA256AsHex(String str) {
@@ -69,4 +70,23 @@ public static boolean isEmpty(String str) {
6970
public static boolean isNotEmpty(String str) {
7071
return !isEmpty(str);
7172
}
73+
74+
private static final String VERSION_PROPERTIES_RESOURCE = "/version.properties";
75+
76+
public static String loadApplicationVersion() {
77+
Properties props = new Properties();
78+
try (InputStream input = MiscUtils.class.getResourceAsStream(VERSION_PROPERTIES_RESOURCE)) {
79+
if (input == null) {
80+
// log.error("Resource {} is not found on the classpath", VERSION_PROPERTIES_RESOURCE);
81+
throw new RuntimeException("Resource '" + VERSION_PROPERTIES_RESOURCE + "' not found");
82+
}
83+
props.load(input);
84+
return props.getProperty("application.version");
85+
} catch (IOException ex) {
86+
throw new RuntimeException(ex);
87+
// log.error("Error while loading {}", VERSION_PROPERTIES_RESOURCE, ex);
88+
}
89+
90+
// return "UNDEFINED";
91+
}
7292
}

0 commit comments

Comments
 (0)