Added package batch file, configured application for building applications.

This commit is contained in:
Andrew Lalis 2021-06-03 13:01:23 +02:00
parent a9c335dcca
commit cca7fc544a
7 changed files with 82 additions and 35 deletions

1
.gitignore vendored
View File

@ -111,3 +111,4 @@ buildNumber.properties
.idea/ .idea/
clusters/ clusters/
output/

11
package.bat Normal file
View File

@ -0,0 +1,11 @@
call mvn clean package
call jpackage ^
--type app-image ^
--verbose ^
--dest target\image ^
--name CrystalKeep ^
--icon src/main/resources/nl/andrewlalis/crystalkeep/ui/images/cluster_node_icon.png ^
--module crystalkeep/nl.andrewlalis.crystalkeep.CrystalKeep ^
--module-path target\modules ^
--module-path target\classes ^
--win-console ^

55
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>nl.andrewlalis</groupId> <groupId>nl.andrewlalis</groupId>
<artifactId>crystalkeep</artifactId> <artifactId>crystalkeep</artifactId>
<version>1.0-SNAPSHOT</version> <version>0.0.1</version>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
@ -14,23 +14,11 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<javafx.version>16</javafx.version> <javafx.version>16</javafx.version>
<project.mainClass>nl.andrewlalis.crystalkeep.CrystalKeep</project.mainClass>
</properties> </properties>
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>nl.andrewlalis.crystalkeep.CrystalKeep</mainClass>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<compress>2</compress>
<noHeaderFiles>true</noHeaderFiles>
<launcher>crystalkeep</launcher>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
@ -42,27 +30,36 @@
<version>2.22.2</version> <version>2.22.2</version>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.openjfx</groupId>
<artifactId>maven-assembly-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>3.3.0</version> <version>0.0.4</version>
<configuration> <configuration>
<archive> <source>${java.version}</source>
<manifest> <target>${java.version}</target>
<mainClass>nl.andrewlalis.crystalkeep.CrystalKeep</mainClass> <release>${java.version}</release>
</manifest> <mainClass>${project.mainClass}</mainClass>
</archive> <jlinkVerbose>true</jlinkVerbose>
<descriptorRefs> <jmodsPath>${project.build.directory}/modules</jmodsPath>
<descriptorRef>jar-with-dependencies</descriptorRef> <mainClass>${main.class}</mainClass>
</descriptorRefs> <stripDebug>true</stripDebug>
<appendAssemblyId>true</appendAssemblyId> <jlinkZipName>test</jlinkZipName>
</configuration> </configuration>
</plugin>
<!-- Copies all dependencies into a target/modules directory so that jpackage can reference this. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<id>make-assembly</id> <id>copy-dependencies</id>
<phase>package</phase> <phase>prepare-package</phase>
<goals> <goals>
<goal>single</goal> <goal>copy-dependencies</goal>
</goals> </goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/modules</outputDirectory>
</configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>

View File

@ -6,11 +6,13 @@ import javafx.geometry.Pos;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.util.Duration;
import nl.andrewlalis.crystalkeep.io.ClusterIO; import nl.andrewlalis.crystalkeep.io.ClusterIO;
import nl.andrewlalis.crystalkeep.model.*; import nl.andrewlalis.crystalkeep.model.*;
import nl.andrewlalis.crystalkeep.view.ClusterTreeItem; import nl.andrewlalis.crystalkeep.view.ClusterTreeItem;
import nl.andrewlalis.crystalkeep.view.CrystalItemTreeCell; import nl.andrewlalis.crystalkeep.view.CrystalItemTreeCell;
import nl.andrewlalis.crystalkeep.view.ShardTreeItem; import nl.andrewlalis.crystalkeep.view.ShardTreeItem;
import org.controlsfx.control.Notifications;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
@ -82,8 +84,11 @@ public class MainViewController implements ModelListener {
this.model.setActiveClusterPassword(pw); this.model.setActiveClusterPassword(pw);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Notifications.create()
new Alert(Alert.AlertType.WARNING, "Could not load cluster.").showAndWait(); .text("Could not load cluster. Check that your password is correct.")
.hideAfter(Duration.seconds(3))
.owner(this.shardDetailContainer.getScene().getWindow())
.show();
return; return;
} }
model.setActiveCluster(cluster); model.setActiveCluster(cluster);
@ -115,6 +120,8 @@ public class MainViewController implements ModelListener {
chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Cluster Files", "cts")); chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Cluster Files", "cts"));
if (path != null) { if (path != null) {
chooser.setInitialDirectory(path.getParent().toFile()); chooser.setInitialDirectory(path.getParent().toFile());
} else {
chooser.setInitialDirectory(ClusterIO.CLUSTER_PATH.toFile());
} }
File file = chooser.showSaveDialog(this.clusterTreeView.getScene().getWindow()); File file = chooser.showSaveDialog(this.clusterTreeView.getScene().getWindow());
if (file == null) return; if (file == null) return;
@ -154,16 +161,27 @@ public class MainViewController implements ModelListener {
pw = this.promptPassword().orElse(new char[0]); pw = this.promptPassword().orElse(new char[0]);
} }
ClusterIO loader = new ClusterIO(); ClusterIO loader = new ClusterIO();
if (!path.getFileName().toString().trim().toLowerCase().endsWith(".cts")) {
path = path.resolveSibling(path.getFileName() + ".cts");
}
try { try {
if (pw.length == 0) { if (pw.length == 0) {
loader.saveUnencrypted(model.getActiveCluster(), path); loader.saveUnencrypted(model.getActiveCluster(), path);
} else { } else {
loader.save(model.getActiveCluster(), path, pw); loader.save(model.getActiveCluster(), path, pw);
} }
Notifications.create()
.text("Cluster saved to " + path)
.hideAfter(Duration.seconds(3))
.owner(this.shardDetailContainer.getScene().getWindow())
.show();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
var alert = new Alert(Alert.AlertType.ERROR, "Could not save cluster."); Notifications.create()
alert.showAndWait(); .text("Could not save cluster.")
.hideAfter(Duration.seconds(3))
.owner(this.shardDetailContainer.getScene().getWindow())
.show();
} }
} }
} }

View File

@ -33,8 +33,15 @@ import java.security.spec.KeySpec;
* @see nl.andrewlalis.crystalkeep.io.serialization.ClusterSerializer * @see nl.andrewlalis.crystalkeep.io.serialization.ClusterSerializer
*/ */
public class ClusterIO { public class ClusterIO {
public static final Path CLUSTER_PATH = Path.of("clusters"); public static final Path CLUSTER_PATH = Path.of(System.getProperty("user.home"), ".crystalkeep", "clusters");
public static final int FILE_VERSION = 1; public static final int FILE_VERSION = 1;
static {
try {
Files.createDirectories(CLUSTER_PATH);
} catch (IOException e) {
e.printStackTrace();
}
}
private final SecureRandom random; private final SecureRandom random;

View File

@ -1,6 +1,13 @@
package nl.andrewlalis.crystalkeep.util; package nl.andrewlalis.crystalkeep.util;
public class StringUtils { public class StringUtils {
public static final String[] IMAGE_TYPES = {
"png", "jpg", "jpeg", "gif"
};
public static final String[] PLAIN_TEXT_TYPES = {
"txt"
};
public static boolean endsWithAny(String s, String... suffixes) { public static boolean endsWithAny(String s, String... suffixes) {
for (String suffix : suffixes) { for (String suffix : suffixes) {
if (s.endsWith(suffix)) return true; if (s.endsWith(suffix)) return true;

View File

@ -74,12 +74,18 @@ public class FileShardViewModel extends ShardViewModel<FileShard> {
gp.add(extractFileButton, 1, 2); gp.add(extractFileButton, 1, 2);
container.getChildren().add(gp); container.getChildren().add(gp);
if (StringUtils.endsWithAny(shard.getFileName().toLowerCase(), ".png", ".jpg", ".jpeg", ".gif")) { if (StringUtils.endsWithAny(shard.getFileName().toLowerCase(), StringUtils.IMAGE_TYPES)) {
container.getChildren().add(new Separator(Orientation.HORIZONTAL)); container.getChildren().add(new Separator(Orientation.HORIZONTAL));
ImageView imageView = new ImageView(new Image(new ByteArrayInputStream(shard.getContents()))); ImageView imageView = new ImageView(new Image(new ByteArrayInputStream(shard.getContents())));
imageView.setPreserveRatio(true); imageView.setPreserveRatio(true);
ScrollPane scrollPane = new ScrollPane(imageView); ScrollPane scrollPane = new ScrollPane(imageView);
container.getChildren().add(scrollPane); container.getChildren().add(scrollPane);
} else if (StringUtils.endsWithAny(shard.getFileName().toLowerCase(), StringUtils.PLAIN_TEXT_TYPES)) {
container.getChildren().add(new Separator(Orientation.HORIZONTAL));
TextArea textArea = new TextArea(new String(shard.getContents()));
textArea.setEditable(false);
textArea.setWrapText(true);
container.getChildren().add(textArea);
} }
return container; return container;