Skip to content

Commit b97fea5

Browse files
committed
feat: Split project into common, fx and cli modules
1 parent fa7d062 commit b97fea5

Some content is hidden

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

47 files changed

+478
-200
lines changed

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,43 @@ Scans any files for different pre-defined signatures (supporting RegExp and othe
1212
* Install JavaFX (24 or newer) from https://gluonhq.com/products/javafx/
1313
* Install Apache Maven (ver 3.9.x) from https://maven.apache.org/download.cgi
1414
* Setup M2_HOME, JAVA_HOME and PATH (add maven and java) System Variables as recommended for Java and Maven usage
15-
* Optional = setup JAVAFX_PATH System Variable for handy run of the application using predefined shell-scripts in ./src/shell/*.*
15+
* Optional = setup JAVAFX_PATH System Variable for handy run of the application using predefined shell-scripts in ./fx/src/shell/*.*
1616

1717
## Compilation & build
1818
Navigate to the CyberFerret folder where ./pom.xml presents and run:
1919
```shell
2020
mvn clean package assembly:single
2121
```
2222

23-
Find built ".\target\cyberferret.jar" file which is 17+MiB of size. Use it as a single pack of whole application.
23+
After build you will get module-specific JARs under `fx/target` and `cli/target`.
24+
25+
Build only CLI:
26+
```shell
27+
mvn -pl cli -am clean package assembly:single
28+
```
29+
30+
Build only JavaFX:
31+
```shell
32+
mvn -pl fx -am clean package assembly:single
33+
```
34+
35+
After modularization, build artifacts are:
36+
* JavaFX app: `.\fx\target\cyberferret-fx.jar`
37+
* CLI app: `.\cli\target\cyberferret-cli.jar`
2438

2539
# How to run - Windows version
2640
Replace "${PATH_TO_JAVA_FX_SDK}" with correct path to JavaFx SDK
2741
```shell
28-
java --module-path "${PATH_TO_JAVA_FX_SDK}\lib" --add-modules javafx.controls,javafx.web,javafx.graphics --enable-native-access=javafx.graphics -jar cyberferret.jar
42+
java --module-path "${PATH_TO_JAVA_FX_SDK}\lib" --add-modules javafx.controls,javafx.web,javafx.graphics --enable-native-access=javafx.graphics -jar .\fx\target\cyberferret-fx.jar
2943
```
30-
or use ./src/shell/run-app.cmd file
44+
or use ./fx/src/shell/run-app.cmd file
3145

3246
# How to run - Linux/macOS version
3347
Replace "$path_to_javafx_sdk" with correct path to JavaFx SDK
3448
```shell
35-
java --module-path $path_to_javafx_sdk/lib --add-modules javafx.controls,javafx.web,javafx.graphics --enable-native-access=javafx.graphics -jar ./target/cyber-ferret.jar
49+
java --module-path $path_to_javafx_sdk/lib --add-modules javafx.controls,javafx.web,javafx.graphics --enable-native-access=javafx.graphics -jar ./fx/target/cyberferret-fx.jar
3650
```
37-
or use ./src/shell/run-app.sh file
51+
or use ./fx/src/shell/run-app.sh file
3852

3953
# How to run - in IntelliJ IDEA
4054
## prerequisites

cli/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.github.exadmin</groupId>
9+
<artifactId>cyberferret</artifactId>
10+
<version>1.2.2</version>
11+
</parent>
12+
13+
<artifactId>cyberferret-cli</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.github.exadmin</groupId>
18+
<artifactId>cyberferret-common</artifactId>
19+
<version>${project.version}</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.junit.jupiter</groupId>
24+
<artifactId>junit-jupiter-api</artifactId>
25+
<scope>test</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.junit.jupiter</groupId>
29+
<artifactId>junit-jupiter-engine</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
</dependencies>
33+
34+
<build>
35+
<plugins>
36+
<plugin>
37+
<groupId>org.apache.maven.plugins</groupId>
38+
<artifactId>maven-assembly-plugin</artifactId>
39+
<configuration>
40+
<descriptorRefs>
41+
<descriptorRef>jar-with-dependencies</descriptorRef>
42+
</descriptorRefs>
43+
<archive>
44+
<manifest>
45+
<mainClass>com.github.exadmin.cyberferret.CyberFerretCLI</mainClass>
46+
</manifest>
47+
</archive>
48+
<finalName>${project.artifactId}</finalName>
49+
<appendAssemblyId>false</appendAssemblyId>
50+
</configuration>
51+
<executions>
52+
<execution>
53+
<phase>package</phase>
54+
<goals>
55+
<goal>single</goal>
56+
</goals>
57+
</execution>
58+
</executions>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
</project>

src/main/java/com/github/exadmin/cyberferret/CyberFerretCLI.java renamed to cli/src/main/java/com/github/exadmin/cyberferret/CyberFerretCLI.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.github.exadmin.cyberferret.async.RunnableCheckOnlineDictionary;
44
import com.github.exadmin.cyberferret.async.RunnableScanner;
55
import com.github.exadmin.cyberferret.async.RunnableSigsLoader;
6-
import com.github.exadmin.cyberferret.fxui.FxConstants;
76
import com.github.exadmin.cyberferret.model.FoundItemsContainer;
87
import com.github.exadmin.cyberferret.model.FoundPathItem;
98
import com.github.exadmin.cyberferret.utils.*;
@@ -22,7 +21,7 @@
2221
* This is CLI version of CyberFerret app with focus on quick initialization and run triggered by pre-commit framework.
2322
*/
2423
public class CyberFerretCLI {
25-
public static final String SYS_ENV_VAR_PASSWORD = "CYBER_FERRET_PASSWORD";
24+
public static final String SYS_ENV_VAR_PASSWORD = AppConstants.SYS_ENV_VAR_PASSWORD;
2625

2726
private static void printUsage() {
2827
String errMsg = """
@@ -106,7 +105,7 @@ public static void main(String[] args) {
106105
ConsoleUtils.error("Global hooksPath is not empty");
107106
terminateAppWithErrorCode();
108107
}
109-
Path path = Paths.get(prefix, FxConstants.DICTIONARY_FILE_PATH_ENCRYPTED);
108+
Path path = Paths.get(prefix, AppConstants.DICTIONARY_FILE_PATH_ENCRYPTED);
110109
String encryptedBody = FileUtils.readFile(path);
111110
String decryptedBody = PasswordBasedEncryption.decrypt(encryptedBody, pass);
112111

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.github.exadmin.cyberferret;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.io.TempDir;
5+
6+
import java.io.IOException;
7+
import java.nio.charset.StandardCharsets;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.List;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
import static org.junit.jupiter.api.Assertions.assertTrue;
14+
15+
public class CyberFerretCLITests {
16+
@TempDir
17+
Path tempDir;
18+
19+
@Test
20+
public void loadStagedFiles_readsRelativeAndQuotedPaths() throws IOException {
21+
Path root = tempDir.resolve("repo");
22+
Files.createDirectories(root.resolve("sub/dir"));
23+
24+
Path listFile = tempDir.resolve("staged.txt");
25+
String content = String.join("\n",
26+
"file1.txt",
27+
" sub/dir/file2.txt ",
28+
"\"file 3.txt\"",
29+
"",
30+
" "
31+
);
32+
Files.writeString(listFile, content, StandardCharsets.UTF_8);
33+
34+
List<Path> staged = CyberFerretCLI.loadStagedFiles(root, listFile);
35+
36+
assertEquals(3, staged.size());
37+
assertEquals(root.resolve("file1.txt").normalize(), staged.get(0));
38+
assertEquals(root.resolve("sub/dir/file2.txt").normalize(), staged.get(1));
39+
assertEquals(root.resolve("file 3.txt").normalize(), staged.get(2));
40+
}
41+
42+
@Test
43+
public void loadStagedFiles_keepsAbsolutePaths() throws IOException {
44+
Path root = tempDir.resolve("repo");
45+
Files.createDirectories(root);
46+
47+
Path absoluteFile = tempDir.resolve("absolute.txt");
48+
Files.writeString(absoluteFile, "data", StandardCharsets.UTF_8);
49+
50+
Path listFile = tempDir.resolve("staged.txt");
51+
Files.writeString(listFile, absoluteFile.toString(), StandardCharsets.UTF_8);
52+
53+
List<Path> staged = CyberFerretCLI.loadStagedFiles(root, listFile);
54+
55+
assertEquals(1, staged.size());
56+
assertTrue(staged.get(0).isAbsolute());
57+
assertEquals(absoluteFile.normalize(), staged.get(0));
58+
}
59+
}

common/pom.xml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.github.exadmin</groupId>
9+
<artifactId>cyberferret</artifactId>
10+
<version>1.2.2</version>
11+
</parent>
12+
13+
<artifactId>cyberferret-common</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.openjfx</groupId>
18+
<artifactId>javafx-base</artifactId>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.slf4j</groupId>
22+
<artifactId>slf4j-api</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.apache.logging.log4j</groupId>
26+
<artifactId>log4j-slf4j2-impl</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.apache.logging.log4j</groupId>
30+
<artifactId>log4j-core</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.fasterxml.jackson.core</groupId>
34+
<artifactId>jackson-databind</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.httpcomponents</groupId>
38+
<artifactId>httpclient</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.drewnoakes</groupId>
42+
<artifactId>metadata-extractor</artifactId>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-api</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter-engine</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
</dependencies>
56+
57+
<build>
58+
<resources>
59+
<resource>
60+
<directory>src/main/resources</directory>
61+
<filtering>true</filtering>
62+
<includes>
63+
<include>version.properties</include>
64+
</includes>
65+
</resource>
66+
<resource>
67+
<directory>src/main/resources</directory>
68+
<filtering>false</filtering>
69+
<excludes>
70+
<exclude>version.properties</exclude>
71+
</excludes>
72+
</resource>
73+
</resources>
74+
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-assembly-plugin</artifactId>
79+
<configuration>
80+
<descriptorRefs>
81+
<descriptorRef>jar-with-dependencies</descriptorRef>
82+
</descriptorRefs>
83+
<finalName>${project.artifactId}</finalName>
84+
<appendAssemblyId>false</appendAssemblyId>
85+
</configuration>
86+
<executions>
87+
<execution>
88+
<phase>package</phase>
89+
<goals>
90+
<goal>single</goal>
91+
</goals>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
</plugins>
96+
</build>
97+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.exadmin.cyberferret;
2+
3+
public final class AppConstants {
4+
public static final String SYS_ENV_VAR_PASSWORD = "CYBER_FERRET_PASSWORD";
5+
public static final String CYBER_FERRET_ONLINE_DICTIONARY_URL =
6+
"https://raw.githubusercontent.com/exadmin/CyberFerretDictionary/main/dictionary-latest.encrypted";
7+
public static final String DICTIONARY_FILE_PATH_ENCRYPTED = "./dictionary-latest-cache.encrypted";
8+
public static final String DICTIONARY_FILE_PATH_DECRYPTED = "./dictionary-latest-cache.decrypted";
9+
10+
private AppConstants() {
11+
}
12+
}

src/main/java/com/github/exadmin/cyberferret/async/ARunnable.java renamed to common/src/main/java/com/github/exadmin/cyberferret/async/ARunnable.java

File renamed without changes.

src/main/java/com/github/exadmin/cyberferret/async/FxCallback.java renamed to common/src/main/java/com/github/exadmin/cyberferret/async/FxCallback.java

File renamed without changes.

src/main/java/com/github/exadmin/cyberferret/async/RunnableCheckOnlineDictionary.java renamed to common/src/main/java/com/github/exadmin/cyberferret/async/RunnableCheckOnlineDictionary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.exadmin.cyberferret.async;
22

3-
import com.github.exadmin.cyberferret.fxui.FxConstants;
3+
import com.github.exadmin.cyberferret.AppConstants;
44
import com.github.exadmin.cyberferret.utils.GitUtils;
55
import org.apache.http.client.methods.CloseableHttpResponse;
66
import org.apache.http.client.methods.HttpGet;
@@ -30,7 +30,7 @@ protected void _run() {
3030
String prefix = "";
3131
if (isCLIMode()) prefix = GitUtils.getGlobalConfigValue("core.hooksPath");
3232
if (prefix == null) prefix = "";
33-
Path path = Paths.get(prefix, FxConstants.DICTIONARY_FILE_PATH_ENCRYPTED);
33+
Path path = Paths.get(prefix, AppConstants.DICTIONARY_FILE_PATH_ENCRYPTED);
3434
File savePath = path.toFile();
3535

3636
if (savePath.exists()) {
@@ -57,7 +57,7 @@ protected void _run() {
5757
protected void downloadOnlineDictionary(File savePath) {
5858
logInfo("Downloading latest online dictionary");
5959
try (CloseableHttpClient client = HttpClients.createDefault()) {
60-
HttpGet request = new HttpGet(FxConstants.CYBER_FERRET_ONLINE_DICTIONARY_URL);
60+
HttpGet request = new HttpGet(AppConstants.CYBER_FERRET_ONLINE_DICTIONARY_URL);
6161
try (CloseableHttpResponse response = client.execute(request);
6262
InputStream inputStream = response.getEntity().getContent();
6363
FileWriter writer = new FileWriter(savePath)) {

0 commit comments

Comments
 (0)