Skip to content

Commit

Permalink
Support custom command line options for Mac apps.
Browse files Browse the repository at this point in the history
  • Loading branch information
colorizenl committed Apr 12, 2023
1 parent b5e7f0c commit 1551710
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 132 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ build/
.idea/
*.iml
example/build

example/.gradle/
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}

plugins {
id "io.freefair.lombok" version "6.6.3"
id "io.freefair.lombok" version "8.0.1"
id "com.github.ben-manes.versions" version "0.46.0"
}

Expand All @@ -20,7 +20,7 @@ apply plugin: "com.gradle.plugin-publish"
apply plugin: "jacoco"

group = "nl.colorize"
version = "2023.4"
version = "2023.6"
sourceCompatibility = "17"
targetCompatibility = "17"
compileJava.options.encoding = "UTF-8"
Expand Down
Binary file removed example/.gradle/7.6/checksums/checksums.lock
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file removed example/.gradle/7.6/fileChanges/last-build.bin
Binary file not shown.
Binary file removed example/.gradle/7.6/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed example/.gradle/7.6/fileHashes/fileHashes.lock
Binary file not shown.
Binary file not shown.
Empty file removed example/.gradle/7.6/gc.properties
Empty file.
Binary file not shown.
2 changes: 0 additions & 2 deletions example/.gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed example/.gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file removed example/.gradle/file-system.probe
Binary file not shown.
Empty file.
29 changes: 26 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: "java"
apply plugin: "nl.colorize.gradle.application"

group = "nl.colorize"
version = "1.0"
version = "0.1"
sourceCompatibility = "17"
targetCompatibility = "17"
compileJava.options.encoding = "UTF-8"
Expand All @@ -28,7 +28,7 @@ jar.duplicatesStrategy = DuplicatesStrategy.WARN
macApplicationBundle {
name = "Example"
identifier = "com.example"
bundleVersion = "1.0"
bundleVersion = "0.1"
description = "A simple example application"
copyright = "Copyright 2010-2023 Colorize"
icon = "../resources/icon.icns"
Expand All @@ -38,12 +38,21 @@ macApplicationBundle {

windows {
inherit = true
mainJar = "example.jar"
mainJarName = "example.jar"
vendor = "Colorize"
icon = "../resources/icon.ico"
uuid = "b9112b5f-2340-4541-8883-6abd3c9c8780"
}

xcode {
appId = "Example"
bundleId = "com.example"
appName = "Example App"
appVersion = "0.1"
icon = "../resources/icon.png"
resourcesDir = "${buildDir}/staticsite"
}

pwa {
webAppDir = "${buildDir}/staticsite"
manifest = "web/manifest.json"
Expand All @@ -54,4 +63,18 @@ staticSite {
contentDir = "web"
}

generateStaticSite.doLast {
copy {
from "../resources/icon.png"
into "${buildDir}/staticsite/images"
}
}

generatePWA.dependsOn generateStaticSite
xcodeGen.dependsOn generateStaticSite

task allMac(dependsOn: ["signApplicationBundle", "generateStaticSite", "generatePWA", "xcodeGen"]) {
}

task allWindows(dependsOn: ["packageMSI", "generateStaticSite", "generatePWA"]) {
}
14 changes: 14 additions & 0 deletions example/web/example.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
html {
background-color: #FFFFFF;
}

body {
background-color: #EBEBEB;
color: #323232;
padding: 30px;
margin: 30px 20px 30px 20px;
}

img {
max-width: 200px;
}
2 changes: 1 addition & 1 deletion example/web/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Example

![Colorize logo](../../../resources/icon.png)
![Colorize logo](images/icon.png)
16 changes: 16 additions & 0 deletions example/web/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,25 @@
<meta charset="UTF-8" />
<title>Example</title>
<meta name="viewport" content="initial-scale=1.0, width=device-width, user-scalable=no" />
<link rel="stylesheet" href="example.css" />
</head>

<body>
<clrz-content />

<div id="ajaxImage">
Loading image using JavaScript...
</div>

<script>
document.addEventListener("DOMContentLoaded", event => {
const image = document.createElement("img");
image.addEventListener("load", () => {
const description = "Loaded image size: " + image.width + "x" + image.height;
document.getElementById("ajaxImage").innerText = description;
});
image.src = "images/icon.png";
});
</script>
</body>
</html>
96 changes: 52 additions & 44 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ to be available in the development environment and/or build server:
Usage
-----

The plugin is available from the [Gradle plugin registry](https://plugins.gradle.org). Adding the
plugin to the build is done by adding the following to `build.gradle`:
The plugin is available from the [Gradle plugin registry](https://plugins.gradle.org). You can
use the plugin in your Gradle project by adding the following to `build.gradle`:

plugins {
id "nl.colorize.gradle.application" version "2023.4"
id "nl.colorize.gradle.application" version "2023.6"
}

Building native Mac application bundles
Expand Down Expand Up @@ -65,24 +65,25 @@ The following shows an example on how to define this configuration in Gradle:

The following configuration options are available:

| Name | Required | Description |
|-------------------------|----------|-----------------------------------------------------------------------|
| `name` | yes | Mac application name. |
| `displayName` | no | Optional display name, defaults to the value of `name`. |
| `identifier` | yes | Apple application identfiier, in the format "com.example.name". |
| `bundleVersion` | yes | Application bundle version number. |
| `description` | yes | Short description text. |
| `copyright` | yes | Copyright statement text. |
| `applicationCategory` | yes | Apple application category ID. |
| `minimumSystemVersion` | no | Minimum required Mac OS version number. Defaults to 10.13. |
| `architectures` | no | List of supported CPU architectures. Default is `arm64` and `x86_64`. |
| `mainClassName` | yes | Fully qualified main class name. |
| `jdkPath` | no | Location of JDK. Defaults to `JAVA_HOME`. |
| `modules` | no | List of JDK modules. An empty list will embed the entire JDK. |
| `options` | no | List of command line options. |
| `startOnFirstThread` | no | When true, starts the application with `-XstartOnFirstThread`. |
| `icon` | yes | Location of the `.icns` file. |
| `outputDir` | no | Output directory path, defaults to `build/mac`. |
| Name | Required | Description |
|------------------------|----------|-----------------------------------------------------------------------|
| `name` | yes | Mac application name. |
| `displayName` | no | Optional display name, defaults to the value of `name`. |
| `identifier` | yes | Apple application identfiier, in the format "com.example.name". |
| `bundleVersion` | yes | Application bundle version number. |
| `description` | yes | Short description text. |
| `copyright` | yes | Copyright statement text. |
| `applicationCategory` | yes | Apple application category ID. |
| `minimumSystemVersion` | no | Minimum required Mac OS version number. Defaults to 10.13. |
| `architectures` | no | List of supported CPU architectures. Default is `arm64` and `x86_64`. |
| `mainClassName` | yes | Fully qualified main class name. |
| `jdkPath` | no | Location of JDK. Defaults to `JAVA_HOME`. |
| `modules` | no | List of JDK modules. An empty list will embed the entire JDK. |
| `options` | no | List of JVM command line options. |
| `args` | no | List of command line arguments provided to the main class. |
| `startOnFirstThread` | no | When true, starts the application with `-XstartOnFirstThread`. |
| `icon` | yes | Location of the `.icns` file. |
| `outputDir` | no | Output directory path, defaults to `build/mac`. |

- Note that, in addition to the `bundleVersion` property, there is also the concept of build
version. This is normally the same as the bundle version, but can be manually specified for each
Expand Down Expand Up @@ -151,6 +152,8 @@ are available:
| `inherit` | no | Inherits some configuration options from Mac app configuration. |
| `mainJarName` | yes | File name of the main JAR file. Defaults to application JAR. |
| `mainClassName` | depends | Fully qualified main class name. |
| `options` | no | List of JVM command line options. |
| `args` | no | List of command line arguments provided to the main class. |
| `name` | depends | Windows application name. |
| `version` | depends | Windows application version number. |
| `vendor` | yes | Vendor display name. |
Expand Down Expand Up @@ -178,16 +181,17 @@ when using this task.

The following configuration options are available via the `xcode` section:

| Name | Required | Description |
|----------------|----------|-------------------------------------------------------------------|
| `appId` | yes | App ID in the form MyApp. |
| `bundleId` | yes | Apple bundleID in the form com.example. |
| `appName` | yes | App display name in the form My App. |
| `appVersion` | yes | App version number in the form 1.2.3. |
| `icon` | yes | PNG file that will be used to generate the app icons. |
| `resourcesDir` | yes | Directory to copy into the app's resources. |
| `outputDir` | no | Directory for the Xcode project, defaults to `build/xcode`. |
| `xcodeGenPath` | no | XcodeGen install location, defaults to `/usr/local/bin/xcodegen`. |
| Name | Required | Description |
|---------------------|----------|-------------------------------------------------------------------|
| `appId` | yes | App ID in the form MyApp. |
| `bundleId` | yes | Apple bundleID in the form com.example. |
| `appName` | yes | App display name in the form My App. |
| `appVersion` | yes | App version number in the form 1.2.3. |
| `icon` | yes | PNG file that will be used to generate the app icons. |
| `resourcesDir` | yes | Directory to copy into the app's resources. |
| `launchScreenColor` | no | Background color for the app's launch screen. |
| `outputDir` | no | Directory for the Xcode project, defaults to `build/xcode`. |
| `xcodeGenPath` | no | XcodeGen install location, defaults to `/usr/local/bin/xcodegen`. |

Like the Mac application bundle, the `buildversion` system property can be used to set the build
version during the build. If this system property is not present, the build version is the same
Expand Down Expand Up @@ -271,8 +275,8 @@ due to a [Gradle issue](https://github.com/gradle/gradle/issues/18647). These pr
automatically used when running from Gradle, but need to be added manually when running tests
from an IDE.

Testing the plugin using an example application
-----------------------------------------------
Testing the plugin with an example application
----------------------------------------------

The plugin comes with an example application, that can be used to test the plugin on itself:

Expand All @@ -284,6 +288,10 @@ The plugin comes with an example application, that can be used to test the plugi
- Run `gradle xcodeGen` to generate a Xcode project for a hybrid iOS app.
- Run `gradle generateStaticSite` to generate a website from Markdown templates.
- Run `gradle generatePWA` to create a PWA version of the aforementioned website.
- Running `gradle allMac` will build all example applications that are supported on Mac, which
is everything except the Windows MSI.
- Similarly, running `gradle allWindows` will build all example applications supported on
Windows, which is everything except the Mac application bundle and iOS app.

Note signing the Mac application requires environment variables for the signing identity. See
the documentation section on the Mac-specific configurtion for details.
Expand All @@ -293,14 +301,14 @@ License

Copyright 2010-2023 Colorize

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
> Licensed under the Apache License, Version 2.0 (the "License");
> you may not use this file except in compliance with the License.
> You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS,
> WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> See the License for the specific language governing permissions and
> limitations under the License.
5 changes: 3 additions & 2 deletions resources/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct Test_AppApp: App {
var body: some Scene {
WindowGroup {
HybridWebView()
.ignoresSafeArea()
}
}
}
Expand All @@ -30,9 +31,9 @@ struct HybridWebView: UIViewRepresentable {

func updateUIView(_ webView: WKWebView, context: Context) {
DispatchQueue.main.async {
let url = Bundle.main.url(forResource: "index", withExtension: "html")!
let path = Bundle.main.path(forResource: "HybridResources/index", ofType: "html")!
let url = URL(fileURLWithPath: path)
webView.loadFileURL(url, allowingReadAccessTo: url)
webView.load(URLRequest(url: url))
}
}
}
54 changes: 0 additions & 54 deletions resources/Info.plist

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ private void bundle(MacApplicationBundleExt config, File jdk, File outputDir) {
task.setShortVersion(getShortVersion(config));
task.setCopyright(config.getCopyright());
task.setIcon(new File(config.getIcon()));
task.setApplicationCategory(config.getApplicationCategory());
if (config.getApplicationCategory() != null) {
task.setApplicationCategory(config.getApplicationCategory());
}
task.setMinimumSystemVersion(config.getMinimumSystemVersion());
task.setMainClassName(config.getMainClassName());
config.getArchitectures().forEach(arch -> task.addConfiguredArch(toArch(arch)));
task.addConfiguredClassPath(createClassPath(config));
getCombinedOptions(config).forEach(option -> task.addConfiguredOption(createOption(option)));
config.getArgs().forEach(arg -> task.addConfiguredArgument(createArg(arg)));
if (config.getModules().isEmpty()) {
task.addConfiguredRuntime(createRuntime(jdk));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand All @@ -34,6 +35,7 @@ public class MacApplicationBundleExt {
private String mainClassName;
private List<String> modules;
private List<String> options;
private List<String> args;
private boolean startOnFirstThread;
private String jdkPath;
private String outputDir;
Expand Down Expand Up @@ -62,12 +64,12 @@ public MacApplicationBundleExt() {
copyright = "Copyright " + new SimpleDateFormat("yyyy").format(new Date());
bundleVersion = "1.0";

applicationCategory = "public.app-category.developer-tools";
minimumSystemVersion = "10.13";
architectures = List.of("arm64", "x86_64");

modules = DEFAULT_MODULES;
options = List.of("-Xmx2g");
args = Collections.emptyList();
startOnFirstThread = false;

jdkPath = AppHelper.getEnvironmentVariable("JAVA_HOME");
Expand Down

0 comments on commit 1551710

Please sign in to comment.