Skip to content

Commit

Permalink
Merge pull request #1 from das-Abroxas/hotfix/container_timestamp
Browse files Browse the repository at this point in the history
hotfix/container_timestamp
  • Loading branch information
das-Abroxas authored Dec 3, 2020
2 parents b317973 + 41683ee commit 06fb656
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>life.jlu</groupId>
<artifactId>osgi-package-tool</artifactId>
<name>OSGi Package Tool</name>
<version>1.1.0</version>
<version>1.1.1</version>
<url>https://github.com/das-Abroxas/osgi-package-tool</url>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
import life.jlu.osgi.packagetool.util.ExecutorUtil;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -789,24 +793,36 @@ protected void succeeded() {
private class CreateDistroTask extends Task<File> {

private final bnd bndtools = new bnd();
private final String stamp = new SimpleDateFormat("yyyyMMdd_HH-mm-ss").format(new Date());
private final String jar = String.format("liferay-osgi-distro_%s.jar", stamp);

private final Path outputDir = Paths.get(AppPreferences.getStringPreference("container_path"));
private final String jarPath = Paths.get(outputDir.toString(), jar).toString();

private final String[] args = new String[] {
"remote",
"-h", AppPreferences.getStringPreference("container_host"),
"-p", AppPreferences.getIntegerPreference("container_port").toString(),
"distro",
"-o", AppPreferences.getStringPreference("container_path"),
"liferay-osgi-container", "20201125"};
"-o", jarPath, // Output file
"liferay-osgi-container", // Bundle-SymbolicName
stamp.substring(0,8) // Bundle-Version: yyyyMMdd
};

@Override
protected File call() throws Exception {

updateMessage("Validating output directory ...");
if (!Files.exists(outputDir))
throw new IllegalArgumentException("Output directory does not exist.");

updateMessage("Creating Container Distro ...");

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

return new File(AppPreferences.getStringPreference("container_path"));
return new File(jarPath);
}

@Override
Expand All @@ -817,9 +833,14 @@ protected void succeeded() {

@Override
protected void failed() {
Platform.runLater(() ->
Platform.runLater(() -> {
if (getException().getMessage() != null)
DialogUtil.showErrorDialog("Creating Distro failed",
getException().getMessage());
else
DialogUtil.showErrorDialog("Creating Distro failed",
bndtools.getErrors().get( bndtools.getErrors().size()-1 )));
bndtools.getErrors().get( bndtools.getErrors().size()-1 ));
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package life.jlu.osgi.packagetool.controller;


import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import life.jlu.osgi.packagetool.application.AppPreferences;
import life.jlu.osgi.packagetool.util.StringToIntegerConverter;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
* Adds the functionality to the preferences.fxml scene.
Expand All @@ -36,14 +41,28 @@ public class PreferencesController {
@FXML
private CheckBox dynamic_include;

@FXML
private Button save_btn;


/* ----------------------------------------------------------------------------------------- */
/* ----- Validation Properties ------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------- */
private final BooleanProperty valid_path = new SimpleBooleanProperty(false);


/* ----------------------------------------------------------------------------------------- */
/* ----- Initialization -------------------------------------------------------------------- */
/* ----------------------------------------------------------------------------------------- */
@FXML
public void initialize() {
container_path.setText( AppPreferences.getStringPreference(container_path.getId()) );
container_path.setTooltip( new Tooltip("Path to the OSGi Container Distro JAR.") );
addValidationListener();
addValidationBinding();

container_path.setText(
AppPreferences.getStringPreference(container_path.getId()) );
container_path.setTooltip(
new Tooltip("Full path to the directory in which the OSGi container distro JAR will be created.") );

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

private void addValidationListener() {
container_path.textProperty().addListener(event -> {
valid_path.setValue( Files.exists(Paths.get(container_path.getText())) );

if (!valid_path.getValue()) {
if (!container_path.getStyleClass().contains("invalid-pref"))
container_path.getStyleClass().add("invalid-pref");
} else {
container_path.getStyleClass().remove("invalid-pref");
}
});
}

private void addValidationBinding() {
save_btn.disableProperty().bind( valid_path.not() );
}


/* ----------------------------------------------------------------------------------------- */
/* ----- FXML defined actions -------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bundle/about_en.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name=OSGi Package Tool
version=1.1.0
version=1.1.1
url=https://github.com/das-Abroxas/osgi-package-tool
4 changes: 4 additions & 0 deletions src/main/resources/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
-fx-text-fill: #555;
}

.invalid-pref {
-fx-background-color: #ff8989;
}


/* --------------------------------------------------------------------------------------------- */
/* ----- Custom Package Metadata Dialog Classes ------------------------------------------------ */
Expand Down

0 comments on commit 06fb656

Please sign in to comment.