Skip to content

Commit 06fb656

Browse files
authored
Merge pull request #1 from das-Abroxas/hotfix/container_timestamp
hotfix/container_timestamp
2 parents b317973 + 41683ee commit 06fb656

5 files changed

Lines changed: 70 additions & 9 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>life.jlu</groupId>
88
<artifactId>osgi-package-tool</artifactId>
99
<name>OSGi Package Tool</name>
10-
<version>1.1.0</version>
10+
<version>1.1.1</version>
1111
<url>https://github.com/das-Abroxas/osgi-package-tool</url>
1212

1313
<properties>

src/main/java/life/jlu/osgi/packagetool/controller/MainController.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
import life.jlu.osgi.packagetool.util.ExecutorUtil;
4848

4949
import java.io.File;
50+
import java.nio.file.Files;
51+
import java.nio.file.Path;
52+
import java.nio.file.Paths;
53+
import java.text.SimpleDateFormat;
5054
import java.util.*;
5155
import java.util.concurrent.*;
5256
import java.util.stream.Collectors;
@@ -789,24 +793,36 @@ protected void succeeded() {
789793
private class CreateDistroTask extends Task<File> {
790794

791795
private final bnd bndtools = new bnd();
796+
private final String stamp = new SimpleDateFormat("yyyyMMdd_HH-mm-ss").format(new Date());
797+
private final String jar = String.format("liferay-osgi-distro_%s.jar", stamp);
798+
799+
private final Path outputDir = Paths.get(AppPreferences.getStringPreference("container_path"));
800+
private final String jarPath = Paths.get(outputDir.toString(), jar).toString();
801+
792802
private final String[] args = new String[] {
793803
"remote",
794804
"-h", AppPreferences.getStringPreference("container_host"),
795805
"-p", AppPreferences.getIntegerPreference("container_port").toString(),
796806
"distro",
797-
"-o", AppPreferences.getStringPreference("container_path"),
798-
"liferay-osgi-container", "20201125"};
807+
"-o", jarPath, // Output file
808+
"liferay-osgi-container", // Bundle-SymbolicName
809+
stamp.substring(0,8) // Bundle-Version: yyyyMMdd
810+
};
799811

800812
@Override
801813
protected File call() throws Exception {
802814

815+
updateMessage("Validating output directory ...");
816+
if (!Files.exists(outputDir))
817+
throw new IllegalArgumentException("Output directory does not exist.");
818+
803819
updateMessage("Creating Container Distro ...");
804820

805821
System.setSecurityManager(secManager); // Enable catch System.exit()
806822
bndtools.start(args);
807823
System.setSecurityManager(null); // Disable catch System.exit()
808824

809-
return new File(AppPreferences.getStringPreference("container_path"));
825+
return new File(jarPath);
810826
}
811827

812828
@Override
@@ -817,9 +833,14 @@ protected void succeeded() {
817833

818834
@Override
819835
protected void failed() {
820-
Platform.runLater(() ->
836+
Platform.runLater(() -> {
837+
if (getException().getMessage() != null)
838+
DialogUtil.showErrorDialog("Creating Distro failed",
839+
getException().getMessage());
840+
else
821841
DialogUtil.showErrorDialog("Creating Distro failed",
822-
bndtools.getErrors().get( bndtools.getErrors().size()-1 )));
842+
bndtools.getErrors().get( bndtools.getErrors().size()-1 ));
843+
});
823844
}
824845
}
825846
}

src/main/java/life/jlu/osgi/packagetool/controller/PreferencesController.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package life.jlu.osgi.packagetool.controller;
22

33

4+
import javafx.beans.property.BooleanProperty;
5+
import javafx.beans.property.SimpleBooleanProperty;
46
import javafx.event.ActionEvent;
57
import javafx.fxml.FXML;
68
import javafx.scene.control.*;
79
import javafx.scene.layout.GridPane;
810
import javafx.stage.FileChooser;
911
import javafx.stage.Stage;
12+
1013
import life.jlu.osgi.packagetool.application.AppPreferences;
1114
import life.jlu.osgi.packagetool.util.StringToIntegerConverter;
1215

1316
import java.io.File;
17+
import java.nio.file.Files;
18+
import java.nio.file.Paths;
1419

1520
/**
1621
* Adds the functionality to the preferences.fxml scene.
@@ -36,14 +41,28 @@ public class PreferencesController {
3641
@FXML
3742
private CheckBox dynamic_include;
3843

44+
@FXML
45+
private Button save_btn;
46+
47+
48+
/* ----------------------------------------------------------------------------------------- */
49+
/* ----- Validation Properties ------------------------------------------------------------- */
50+
/* ----------------------------------------------------------------------------------------- */
51+
private final BooleanProperty valid_path = new SimpleBooleanProperty(false);
52+
3953

4054
/* ----------------------------------------------------------------------------------------- */
4155
/* ----- Initialization -------------------------------------------------------------------- */
4256
/* ----------------------------------------------------------------------------------------- */
4357
@FXML
4458
public void initialize() {
45-
container_path.setText( AppPreferences.getStringPreference(container_path.getId()) );
46-
container_path.setTooltip( new Tooltip("Path to the OSGi Container Distro JAR.") );
59+
addValidationListener();
60+
addValidationBinding();
61+
62+
container_path.setText(
63+
AppPreferences.getStringPreference(container_path.getId()) );
64+
container_path.setTooltip(
65+
new Tooltip("Full path to the directory in which the OSGi container distro JAR will be created.") );
4766

4867
container_host.setText( AppPreferences.getStringPreference(container_host.getId()) );
4968
container_host.setTooltip( new Tooltip("Either machine name or IP v4/v6 address of the host."));
@@ -75,6 +94,23 @@ public void initialize() {
7594
task_timeout.getValueFactory().setValue(AppPreferences.getIntegerPreference(task_timeout.getId()));
7695
}
7796

97+
private void addValidationListener() {
98+
container_path.textProperty().addListener(event -> {
99+
valid_path.setValue( Files.exists(Paths.get(container_path.getText())) );
100+
101+
if (!valid_path.getValue()) {
102+
if (!container_path.getStyleClass().contains("invalid-pref"))
103+
container_path.getStyleClass().add("invalid-pref");
104+
} else {
105+
container_path.getStyleClass().remove("invalid-pref");
106+
}
107+
});
108+
}
109+
110+
private void addValidationBinding() {
111+
save_btn.disableProperty().bind( valid_path.not() );
112+
}
113+
78114

79115
/* ----------------------------------------------------------------------------------------- */
80116
/* ----- FXML defined actions -------------------------------------------------------------- */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name=OSGi Package Tool
2-
version=1.1.0
2+
version=1.1.1
33
url=https://github.com/das-Abroxas/osgi-package-tool

src/main/resources/css/main.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@
158158
-fx-text-fill: #555;
159159
}
160160

161+
.invalid-pref {
162+
-fx-background-color: #ff8989;
163+
}
164+
161165

162166
/* --------------------------------------------------------------------------------------------- */
163167
/* ----- Custom Package Metadata Dialog Classes ------------------------------------------------ */

0 commit comments

Comments
 (0)