Skip to content

Commit

Permalink
Merge branch 'main' into suneditor-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianKirmaier authored Oct 8, 2023
2 parents 9be73d9 + 218af65 commit b2de634
Show file tree
Hide file tree
Showing 21 changed files with 341 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
- name: compile
run: |
./gradlew clean multifilehandler:assemble filehandler:assemble html-jpro:assemble popups:jar native-scrolling:assemble
./gradlew clean jar
17 changes: 0 additions & 17 deletions .github/workflows/linux17.yml

This file was deleted.

30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@
This project contains multiple samples for [jpro, which enables javafx in the web.](https://www.jpro.one/)



Samples:


Sample | description | Demo
-------|---------------------------------------------------------------------------------------------------------------------------------------------|-------
popups | Shows how to use popups with JPro. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/PopupsApp)
multifilehandler | Shows how to upload and download mltiple files. | ---
filehandler | Shows how to upload and download files. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/FileHandlerApp)
html-jpro | A small sample, which shows how to use the WebAPI to communicate between JPro and a html-site. | ---
native-scrolling | A small sample on how to use native scrolling. | ---
website | A minimalistic website with multiple pages. It uses our library [jpro-web](https://github.com/Sandec/jpro-web) | ---
auth0 | Login with [Auth0](https://auth0.com/). Read the [readme](https://github.com/JPro-one/JPro-Samples/tree/master/auth0) for more details. | ---
suneditor | Example on how to integrate a html richtext editor - [suneditor]() in this case. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/JPro_Suneditor)
gps | Shows how to retrieve gps location and use it to show a map. | [link](https://www.jfx-ensemble.co/sample/jpro-samples/JPro_GeoLocation)
pwa | Install your Website as a desktop/mobile app! Read the [readme](https://github.com/JPro-one/JPro-Samples/tree/master/pwa) for more details.


| Sample | description | Demo |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------|
| popups | Shows how to use popups with JPro. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/PopupsApp) |
| multifilehandler | Shows how to upload and download mltiple files. | --- |
| filehandler | Shows how to upload and download files. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/FileHandlerApp) |
| html-jpro | A small sample, which shows how to use the WebAPI to communicate between JPro and a html-site. | --- |
| native-scrolling | A small sample on how to use native scrolling. | --- |
| website | A minimalistic website with multiple pages. It uses our library [jpro-web](https://github.com/Sandec/jpro-web) | --- |
| auth0 | Login with [Auth0](https://auth0.com/). Read the [readme](https://github.com/JPro-one/JPro-Samples/tree/master/auth0) for more details. | --- |
| logging | Shows how to configure logging via `jpro.onJVMStartup`, `jpro.onFXStartup` and `jpro.onJVMShutdown` configuration options. | --- |
| suneditor | Example on how to integrate a html richtext editor - [suneditor]() in this case. | [link](https://www.jfx-ensemble.com/sample/jpro-samples/JPro_Suneditor) |
| gps | Shows how to retrieve gps location and use it to show a map. | [link](https://www.jfx-ensemble.co/sample/jpro-samples/JPro_GeoLocation) |
| pwa | Install your Website as a desktop/mobile app! Read the [readme](https://github.com/JPro-one/JPro-Samples/tree/master/pwa) for more details. | |

# How to start #


```
./gradlew popups:jproRun
./gradlew multifilehandler:jproRun
Expand All @@ -37,6 +34,7 @@ Samples:
./gradlew auth0:jproRun # Read the Readme: https://github.com/JPro-one/JPro-Samples/tree/master/auth0
./gradlew suneditor:run
./gradlew gps:run
./gradlew logging:jproRun
```


Expand Down
1 change: 1 addition & 0 deletions auth0/src/main/java/com/jpro/samples/auth0/Auth0App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.stage.Stage;

public class Auth0App extends WebApp {

public Auth0App(Stage stage) {
super(stage);

Expand Down
4 changes: 2 additions & 2 deletions auth0/src/main/java/com/jpro/samples/auth0/Auth0Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
public class Auth0Starter extends Application {

@Override
public void start(Stage primaryStage) throws Exception {
public void start(Stage primaryStage) {
Auth0App app = new Auth0App(primaryStage);
app.start(SessionManager.getDefault(app, primaryStage));
primaryStage.setScene(new Scene(app));
primaryStage.show();
}

public static void main(String args[]) {
public static void main(String[] args) {
launch(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.jpro.samples.auth0.auth;

import com.auth0.client.auth.AuthAPI;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwk.JwkProviderBuilder;

public class AuthUtil {
static String CLIENT_ID = "???";
Expand All @@ -12,8 +10,7 @@ public class AuthUtil {
AuthAPI client;

public AuthUtil() {
JwkProvider jwkProvider = new JwkProviderBuilder(DOMAIN).build();
client = new AuthAPI(DOMAIN, CLIENT_ID, CLIENT_SECRET);
client = AuthAPI.newBuilder(DOMAIN, CLIENT_ID, CLIENT_SECRET).build();
}

public String authURL() {
Expand Down
2 changes: 1 addition & 1 deletion ensemble/site/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}

repositories {
jcenter()
mavenCentral()
}

apply plugin: 'ensemble'
Expand Down
42 changes: 42 additions & 0 deletions logging/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
45 changes: 45 additions & 0 deletions logging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
plugins {
application
id("org.openjfx.javafxplugin")
id("jpro-gradle-plugin")
}

group = "one.jpro.samples"
version = "0.0.1"

repositories {
mavenCentral()
}

val JAVAFX_VERSION = properties["JAVAFX_VERSION"] as String
val SLF4J_VERSION = properties["SLF4J_VERSION"] as String
val LOGBACK_VERSION = properties["LOGBACK_VERSION"] as String
val JUNIT_VERSION = properties["JUNIT_VERSION"] as String

javafx {
version = JAVAFX_VERSION
modules = listOf("javafx.graphics", "javafx.controls", "javafx.fxml", "javafx.media", "javafx.web")
}

dependencies {
implementation("org.slf4j:slf4j-api:$SLF4J_VERSION")
implementation("org.slf4j:jul-to-slf4j:$SLF4J_VERSION")
implementation("ch.qos.logback:logback-classic:$LOGBACK_VERSION")

testImplementation(platform("org.junit:junit-bom:$JUNIT_VERSION"))
testImplementation("org.junit.jupiter:junit-jupiter")
}

application {
mainModule.set("one.jpro.samples.logging")
// Define the main class for the application.
mainClass.set("one.jpro.samples.logging.SampleApp")
}

jpro {
port = 8080
}

tasks.test {
useJUnitPlatform()
}
15 changes: 15 additions & 0 deletions logging/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Module descriptor.
*
* @author Besmir Beqiri
*/
module one.jpro.samples.logging {
requires javafx.controls;
requires java.logging;
requires org.slf4j;
requires jul.to.slf4j;
requires ch.qos.logback.core;
requires ch.qos.logback.classic;

exports one.jpro.samples.logging;
}
18 changes: 18 additions & 0 deletions logging/src/main/java/one/jpro/samples/logging/LogOnFXStartup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package one.jpro.samples.logging;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Log config on FX startup.
*
* @author Besmir Beqiri
*/
public class LogOnFXStartup {

private static final Logger logger = Logger.getLogger(LogOnFXStartup.class.getName());

public static void main(String[] args) {
logger.log(Level.INFO, "Some logging on JavaFX Application Startup!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package one.jpro.samples.logging;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This is a simple class that will be executed on JVM startup.
*
* @author Besmir Beqiri
*/
public class LogOnJVMShutdown {

private static final Logger jullogger = Logger.getLogger(LogOnJVMShutdown.class.getName());

public static void main(String[] args) {

jullogger.log(Level.INFO, "JUL Logging on JVM Shutdown!");

for (java.util.logging.Handler handler : Logger.getLogger("").getHandlers()) {
handler.flush();
}
LogOnJVMStartup.julShutdownTrigger.complete(null);
LogOnJVMStartup.loggerContext.stop();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package one.jpro.samples.logging;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import org.slf4j.LoggerFactory;
import org.slf4j.bridge.SLF4JBridgeHandler;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.logging.*;

/**
* This is a simple class that will be executed on JVM startup.
*
* @author Besmir Beqiri
*/
public class LogOnJVMStartup {
public static LoggerContext loggerContext = null;
private static final Logger logger = Logger.getLogger(LogOnJVMStartup.class.getName());

public static void main(String[] args) {
// redirect j.u.l. logging to SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();

String logbackFile = LogOnJVMStartup.class.getResource("/logback-sample.xml").getFile();
loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);

SLF4JBridgeHandler.install();
try {
configurator.doConfigure(logbackFile);
} catch (JoranException je) {
je.printStackTrace();
throw new RuntimeException(je.getMessage());
}

synchronizeJULShutdown();

logger.log(Level.INFO, "Logging on JVM Startup!");
}

public static void synchronizeJULShutdown() {
// For reference: https://stackoverflow.com/questions/60687511/why-is-the-new-java-logger-failing-to-work-consistently-here
Logger root = Logger.getLogger("");
Handler[] handlers = root.getHandlers();

for(Handler h : handlers) {
root.removeHandler(h);
}

root.addHandler(new CleanerJoin());

for(Handler h : handlers) {
root.addHandler(h);
}
}


public static CompletableFuture<Void> julShutdownTrigger = new CompletableFuture<>();
static class CleanerJoin extends Handler {

CleanerJoin() {
}

@Override
public void close() {
boolean interrupted = false;
try {
for(;;) {
try { //Could use LogManager to lookup timeout values and use a timed join.
julShutdownTrigger.get();
break;
} catch (ExecutionException e) {
reportError("Shutdown hook failed.", e, ErrorManager.CLOSE_FAILURE);
break;
} catch (InterruptedException retry) {
interrupted = true;
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}

@Override
public void flush() {
}

@Override
public void publish(LogRecord r) {
isLoggable(r);
}
}
}
Loading

0 comments on commit b2de634

Please sign in to comment.