Skip to content

Commit

Permalink
Build jar with plugins (#283)
Browse files Browse the repository at this point in the history
* Upgrade gradle

* Remove pmsmart documentation

* Move product to separate submodule

* Add MacOS build

* Fix paths

* Deactivate macos build

* Fix sonar findings

---------

Co-authored-by: kaklakariada <[email protected]>
  • Loading branch information
kaklakariada and kaklakariada authored Oct 12, 2024
1 parent b2b0f8e commit a5ff27c
Show file tree
Hide file tree
Showing 31 changed files with 237 additions and 225 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
java: [21]
os: ['ubuntu-latest', 'windows-latest']
os: ['ubuntu-latest', 'windows-latest'] # 'macos-latest' not supported at the moment
env:
DEFAULT_JAVA: 21
DEFAULT_OS: 'ubuntu-latest'
Expand Down Expand Up @@ -59,8 +59,8 @@ jobs:
name: executable-jar
retention-days: 5
path: |
jfxui/build/libs/white-rabbit-fx-*.jar
jfxui/build/libs-checksums/*
product/build/libs/white-rabbit-fx-*.jar
product/build/libs-checksums/*
if-no-files-found: error

- name: Archive test reports for ${{ matrix.os }} using Java ${{ matrix.java }}
Expand Down Expand Up @@ -92,8 +92,8 @@ jobs:
name: packages-${{ runner.os }}
retention-days: 5
path: |
jfxui/build/jpackage-dist/*
jfxui/build/jpackage-checksums/*
product/build/jpackage-dist/*
product/build/jpackage-checksums/*
if-no-files-found: error

build:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
retention-days: 5
if-no-files-found: error
path: |
jfxui/build/libs/white-rabbit-fx-*.jar
jfxui/build/libs-checksums/*
product/build/libs/white-rabbit-fx-*.jar
product/build/libs-checksums/*
- name: Archive native package for ${{ runner.os }}
uses: actions/upload-artifact@v4
Expand All @@ -62,8 +62,8 @@ jobs:
retention-days: 5
if-no-files-found: error
path: |
jfxui/build/jpackage-dist/*
jfxui/build/jpackage-checksums/*
product/build/jpackage-dist/*
product/build/jpackage-checksums/*
release:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public interface MonthDataStorage extends PluginFeature
/**
* A {@link ModelFactory} allows creating new instances of the data model.
*/
public interface ModelFactory
interface ModelFactory
{
/**
* Create a new {@link MonthData} instance.
Expand All @@ -82,4 +82,4 @@ public interface ModelFactory
*/
ActivityData createActivityData();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ public interface ActivityData
* the new comment.
*/
void setComment(String comment);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,4 @@ public interface DayData
* new new activities.
*/
void setActivities(List<ActivityData> activities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum DayType

private final boolean workDay;

private DayType(final boolean workDay)
DayType(final boolean workDay)
{
this.workDay = workDay;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ public interface MonthData
* the new {@link DayData}s.
*/
void setDays(List<DayData> days);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public interface Project
* @return the cost carrier of this project.
*/
String getCostCarrier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ public interface ProjectReport
* @return the activities in this project report.
*/
List<ProjectReportActivity> getProjects();
}
}
6 changes: 5 additions & 1 deletion docs/developer_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ echo "data = $HOME/time-recording-data/" > $HOME/.whiterabbit.properties
# To skip unit and ui-tests, run
./gradlew build installPlugins -x test -x uiTest
# Run
java -jar jfxui/build/libs/white-rabbit-fx-<version>[-SNAPSHOT].jar
java -jar product/build/libs/white-rabbit-fx-<version>[-SNAPSHOT].jar

# Build and run, loading plugins from $HOME/.whiterabbit/plugins/
./gradlew run

# Build and run including plugins. Useful when developing plugins.
# Make sure to remove unwanted plugins from $HOME/.whiterabbit/plugins/
./gradlew runWithPlugins

# Build and run the shadowJar of the final product.
./gradlew runProduct
```

### Running Tests
Expand Down Expand Up @@ -66,6 +69,7 @@ Precondition for Windows: Install the [WiX Toolset](https://wixtoolset.org) and
```sh
./gradlew jpackage --info
```

### Creating a Release

#### Preparations
Expand Down
42 changes: 1 addition & 41 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,47 +137,7 @@ WhiteRabbit logs to stdout and to `$data/logs/white-rabbit.log` where `$data` is

## <a name="plugins"></a>Using Plugins

The default plugins pmsmart, holidays-calculator and csv are already included in the download packages. To install third-party plugins, copy them to `$HOME/.whiterabbit/plugins/`.

### <a name="pmsmart"></a>Using the PM-Smart Exporter Plugin

#### Requirements for Using the PM-Smart Exporter Plugin

* Microsoft Edge browser with password-less access to pm-smart

#### Setup and usage

1. Create a project configuration as described [above](#project_config). Make sure to use the same IDs for `costCarrier` as in pm-smart.
1. Add the base URL of your pm-smart server to the configuration file:

```properties
pmsmart.baseurl = http://my-pmsmart.example.com
```

1. In pm-smart open the week view ("Wochenansicht") and add favorites for all projects you use. The export will only work for projects added as favorite.
1. Start the export in WhiteRabbit:

1. Select the month that you want to export
1. Select menu Reports > Project report
1. Click button "Export to pmsmart"

#### Optional configuration settings

Optionally you can configure pmsmart plugin to skip transfer of a comment for each activity.

For each activity in WhiteRabbit you can enter a comment. By default pmsmart plugin transfers these comment to pm-smart. As the web ui is quite slow, transfer of comments can take a while. If you want to speed-up pm-smart export by skipping transfer of comments you can add an optional property to WhiteRabbit configuration file:

```properties
pmsmart.transfer.comments = false
```

Optionally you can configure pmsmart plugin to clear durations for all other projects, not matching any activity recorded in WhiteRabbit.

For each day pm-smart plugin by default transfers the durations of all activities entered into WhiteRabbit. If pm-smart contains durations for other projects then pm-smart plugin does not overwrite these. This will especially happen if users export their time recordings for a particular month multiple times and change the selection of activities in between. In order to ensure consistent data in pm-smart you can add an optional property to WhiteRabbit configuration file:

```properties
pmsmart.clear_other_projects = true
```
The default plugins `holidays-calculator` and `csv` are already included in the download packages. To install third-party plugins, copy them to `$HOME/.whiterabbit/plugins/`.

### <a name="holidays_calculator"></a>Using the Holidays Calculator Plugin

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
138 changes: 6 additions & 132 deletions jfxui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
plugins {
id 'com.github.johnrengelman.shadow'
id 'org.panteleyev.jpackageplugin'
id 'org.gradle.crypto.checksum'
}

dependencies {
implementation project(':logic')
def javaFxVersion = libs.versions.javafx.get()
Expand All @@ -28,87 +22,6 @@ dependencies {
testRuntimeOnly libs.monocle
}

shadowJar {
archiveBaseName.set('white-rabbit-fx')
archiveClassifier.set(null)
archiveVersion.set(project.version.toString())
}

task createSha512ChecksumExecutableJar(type: org.gradle.crypto.checksum.Checksum, dependsOn: [tasks.shadowJar]) {
files = files(tasks.shadowJar.outputs.files)
outputDir = new File(project.buildDir, "libs-checksums")
algorithm = org.gradle.crypto.checksum.Checksum.Algorithm.SHA512
appendFileNameToChecksum = true
}

tasks.shadowJar.configure {
finalizedBy createSha512ChecksumExecutableJar
}

ext {
mainClass = 'org.itsallcode.whiterabbit.jfxui.App'
}

jar {
manifest {
attributes 'Main-Class': project.mainClass
}
}

build.dependsOn shadowJar

def jPackageDir = "$buildDir/jpackage-jars"

project(':plugins').afterEvaluate {
List<Task> pluginJarTasks = project(':plugins').ext.pluginBuildTasks

def userHome = System.properties['user.home']
if(project.hasProperty('user.home')) {
userHome = project.property('user.home')
}

task runWithPlugins(type: JavaExec, dependsOn: [shadowJar] + pluginJarTasks, group: 'run') {
group = "run"
def pluginJars = files(pluginJarTasks.collect {it.outputs.files })
classpath = shadowJar.outputs.files + pluginJars
mainClass = project.mainClass
workingDir = rootProject.projectDir
systemProperties = ['user.home': userHome]
}

task runJfxuiWithPlugins(dependsOn: runWithPlugins, group: 'run') {
// deprecated
}

def getUnwantedPlatforms = {
OperatingSystem os = org.gradle.nativeplatform.platform.internal.DefaultNativePlatform.currentOperatingSystem
if(os.isLinux()) {
return ["mac", "win"]
}
if(os.isWindows()) {
return ["mac", "linux"]
}
if(os.isMacOsX()) {
return ["linux", "win"]
}
}

task copyJPackageDependencies(type: Copy, dependsOn: ["jar"]) {
def unwantedPlatforms = getUnwantedPlatforms()
from(configurations.runtimeClasspath.filter { file ->
unwantedPlatforms.every { platform -> !file.name.endsWith("-${platform}.jar") }
}).into jPackageDir
from(tasks.jar.outputs.files).into jPackageDir
from(pluginJarTasks).into jPackageDir
}
}

task run(type: JavaExec, dependsOn: shadowJar, group: 'run') {
classpath = shadowJar.outputs.files
mainClass = project.mainClass
workingDir = rootProject.projectDir
}

sourceSets {
uiTest {
compileClasspath += sourceSets.main.output
Expand Down Expand Up @@ -153,51 +66,12 @@ check.dependsOn uiTest

tasks["jacocoTestReport"].executionData fileTree(project.buildDir).include("jacoco/*.exec")

tasks.jpackage {
dependsOn("copyJPackageDependencies")

input = jPackageDir
destination = "$buildDir/jpackage-dist"

appName = "WhiteRabbit"
vendor = '"It\'s all code"'
copyright = '"Copyright (C) 2024 Christoph Pirkl <christoph at users.sourceforge.net>"'
licenseFile = "${rootProject.rootDir}/LICENSE"
appDescription = '"A time recording tool"'
icon = "${projectDir}/src/main/resources/icon.png"

mainJar = tasks.jar.archiveFileName.get()
mainClass = project.mainClass

verbose = false
arguments = []
javaOptions = ["-Dfile.encoding=UTF-8"]
additionalParameters = ["--about-url", "https://github.com/itsallcode/white-rabbit/blob/main/README.md"]
windows {
winConsole = false
winPerUserInstall = true
winMenu = true
winMenuGroup = "Time Recording"
winShortcut = true
icon = "${projectDir}/src/main/resources/icon.ico"
}

mac {
macPackageIdentifier = "org.itsallcode.white-rabbit"
macPackageName = "WhiteRabbit"
icon = "${projectDir}/src/main/resources/icon.icns"
}
}

task createSha512ChecksumsNativePackage(type: org.gradle.crypto.checksum.Checksum, dependsOn: [tasks.shadowJar]) {
files = files(fileTree(tasks.jpackage.destination) {
include '*'
})
outputDir = new File(project.buildDir, "jpackage-checksums")
algorithm = org.gradle.crypto.checksum.Checksum.Algorithm.SHA512
appendFileNameToChecksum = true
ext {
mainClass = 'org.itsallcode.whiterabbit.jfxui.App'
}

tasks.jpackage.configure {
finalizedBy createSha512ChecksumsNativePackage
task run(type: JavaExec, group: 'run') {
mainClass = project.mainClass
workingDir = rootProject.projectDir
classpath = sourceSets.main.runtimeClasspath
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import javafx.application.Platform;

public class JavaFxUtil
public final class JavaFxUtil
{
private JavaFxUtil()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ else if (os.indexOf("linux") >= 0)
{
return OSType.LINUX;
}
return OSType.OTHER;
else
{
return OSType.OTHER;
}
}

public boolean isDesktopSupported()
Expand Down
Loading

0 comments on commit a5ff27c

Please sign in to comment.