Skip to content

Commit

Permalink
Improved PWA support.
Browse files Browse the repository at this point in the history
  • Loading branch information
colorizenl committed Jan 2, 2024
1 parent b994f7e commit 57f6867
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 79 deletions.
13 changes: 7 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ buildscript {

plugins {
id "io.freefair.lombok" version "8.4"
id "com.github.ben-manes.versions" version "0.49.0"
id "com.github.ben-manes.versions" version "0.50.0"
}

apply plugin: "java-gradle-plugin"
apply plugin: "com.gradle.plugin-publish"
apply plugin: "jacoco"

group = "nl.colorize"
version = "2023.10.1"
version = "2024.1"
compileJava.options.encoding = "UTF-8"

java {
sourceCompatibility = "17"
targetCompatibility = "17"
sourceCompatibility = "21"
targetCompatibility = "21"
sourceSets.main.java.srcDirs = ["source"]
sourceSets.main.resources.srcDirs = ["resources"]
sourceSets.test.java.srcDirs = ["test"]
Expand All @@ -39,10 +39,11 @@ dependencies {
implementation gradleApi()
implementation localGroovy()
implementation files("lib/appbundler-1.0ea.jar")
implementation "org.jsoup:jsoup:1.16.2"
implementation "org.jsoup:jsoup:1.17.1"
implementation "org.commonmark:commonmark:0.21.0"
implementation "org.nanohttpd:nanohttpd-webserver:2.3.1"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.0"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.1"
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
}

jar {
Expand Down
15 changes: 9 additions & 6 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ apply plugin: "nl.colorize.gradle.application"

group = "nl.colorize"
version = "0.1"
sourceCompatibility = "17"
targetCompatibility = "17"
compileJava.options.encoding = "UTF-8"
sourceSets.main.java.srcDirs = ["source"]
sourceSets.main.resources.srcDirs = ["../resources"]
sourceSets.test.java.srcDirs = ["source"]

java {
sourceCompatibility = "21"
targetCompatibility = "21"
sourceSets.main.java.srcDirs = ["source"]
sourceSets.main.resources.srcDirs = ["../resources"]
sourceSets.test.java.srcDirs = ["source"]
}

jar {
archiveFileName = "example.jar"
Expand All @@ -37,7 +40,7 @@ macApplicationBundle {
identifier = "com.example"
bundleVersion = "0.1"
description = "A simple example application"
copyright = "Copyright 2010-2023 Colorize"
copyright = "Copyright 2010-2024 Colorize"
icon = "../resources/icon.icns"
applicationCategory = "public.app-category.developer-tools"
mainClassName = "com.example.ExampleApp"
Expand Down
2 changes: 1 addition & 1 deletion example/source/ExampleApp.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
10 changes: 4 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ multiple application types for different source technologies and target platform
This allows you to distribute the same application to multiple platforms, without having to
maintain platform-specific code.

![Example of building native apps for multiple platforms](example/resources/example-gallery.png)

System requirements
-------------------

Expand All @@ -44,7 +42,7 @@ The plugin is available from the [Gradle plugin registry](https://plugins.gradle
use the plugin in your Gradle project by adding the following to `build.gradle`:

plugins {
id "nl.colorize.gradle.application" version "2023.10.1"
id "nl.colorize.gradle.application" version "2024.1"
}

Building native Mac application bundles
Expand All @@ -69,7 +67,7 @@ The following shows an example on how to define this configuration in Gradle:
name = "Example"
identifier = "com.example"
description = "A description for your application"
copyright = "Copyright 2023"
copyright = "Copyright 2024"
bundleVersion = "1.0"
icon = "resources/icon.icns"
applicationCategory = "public.app-category.developer-tools"
Expand Down Expand Up @@ -308,7 +306,7 @@ Instructions for building the plugin itself

Building the plugin itself can only be done on Mac OS. It also requires the following:

- [Java JDK](http://java.oracle.com) 17+
- [Java JDK](http://java.oracle.com) 21+
- [Gradle](http://gradle.org)
- [Ant](https://ant.apache.org)

Expand Down Expand Up @@ -350,7 +348,7 @@ the plugin itself. Refer to the documentation for each application type for deta
License
-------

Copyright 2010-2023 Colorize
Copyright 2010-2024 Colorize

> Licensed under the Apache License, Version 2.0 (the "License");
> you may not use this file except in compliance with the License.
Expand Down
24 changes: 10 additions & 14 deletions resources/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ const RESOURCE_FILES = [
];

self.addEventListener("install", event => {
event.waitUntil(async () => {
const cache = await caches.open(CACHE_NAME);
return cache.addAll(RESOURCE_FILES);
});
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
return cache.addAll(RESOURCE_FILES);
})
);
});

self.addEventListener("fetch", event => {
event.respondWith(async () => {
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);

if (cachedResponse === undefined) {
return fetch(event.request);
} else {
return cachedResponse;
}
});
event.respondWith(
fetch(event.request).catch(() => {
return caches.match(event.request);
})
);
});
2 changes: 1 addition & 1 deletion source/nl/colorize/gradle/application/AppHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/gradle/application/Validatable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -43,6 +43,8 @@ public class MacApplicationBundleExt implements Validatable {
private String outputDir;

public static final List<String> SUPPORTED_EMBEDDED_JDKS = List.of(
"temurin-21.jdk",
"temurin-m1-21.jdk",
"temurin-17.jdk",
"temurin-m1-17.jdk",
"adoptopenjdk-11.jdk"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -81,7 +81,7 @@ private String prepareServiceWorker(PwaExt config) throws IOException {
.map(file -> base.relativize(file).toString())
.filter(file -> !file.startsWith("userHome"))
.sorted()
.map(file -> "\"" + file + "\",\n")
.map(file -> "\"/" + file + "\",\n")
.collect(Collectors.joining(""));

return AppHelper.loadResourceFile("service-worker.js", Map.of(
Expand Down
2 changes: 1 addition & 1 deletion source/nl/colorize/gradle/application/pwa/PwaExt.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion test/nl/colorize/gradle/application/AppHelperTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -31,7 +31,7 @@ void createApplicationBundleJLink(@TempDir File tempDir) {
config.setName("Example");
config.setIdentifier("com.example");
config.setDescription("A description for your application");
config.setCopyright("Copyright 2023");
config.setCopyright("Copyright 2024");
config.setMainClassName("HelloWorld.Main");
config.setContentDir("resources");
config.setBundleVersion("1.0");
Expand All @@ -47,7 +47,7 @@ void createApplicationBundleJLink(@TempDir File tempDir) {
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/MacOS").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/MacOS/JavaAppLauncher").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Plugins").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Plugins/temurin-17.jdk").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Plugins/temurin-21.jdk").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Resources").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Resources/icon.icns").exists());
assertTrue(new File(tempDir + "/build/mac/Example.app/Contents/Info.plist").exists());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down
30 changes: 13 additions & 17 deletions test/nl/colorize/gradle/application/pwa/GeneratePwaTaskTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-----------------------------------------------------------------------------
// Gradle Application Plugin
// Copyright 2010-2023 Colorize
// Copyright 2010-2024 Colorize
// Apache license (http://www.apache.org/licenses/LICENSE-2.0)
//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -95,29 +95,25 @@ void generateServiceWorker(@TempDir File tempDir) throws IOException {
const RESOURCE_FILES = [
"/",
"index.html",
"manifest.json",
"/index.html",
"/manifest.json",
];
self.addEventListener("install", event => {
event.waitUntil(async () => {
const cache = await caches.open(CACHE_NAME);
return cache.addAll(RESOURCE_FILES);
});
event.waitUntil(
caches.open(CACHE_NAME).then(cache => {
return cache.addAll(RESOURCE_FILES);
})
);
});
self.addEventListener("fetch", event => {
event.respondWith(async () => {
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);
if (cachedResponse === undefined) {
return fetch(event.request);
} else {
return cachedResponse;
}
});
event.respondWith(
fetch(event.request).catch(() => {
return caches.match(event.request);
})
);
});
""";

Expand Down

0 comments on commit 57f6867

Please sign in to comment.