Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose jpackage's --resource-dir in Gradle DSL #1843

Closed
wants to merge 1 commit into from
Closed

Expose jpackage's --resource-dir in Gradle DSL #1843

wants to merge 1 commit into from

Conversation

AltNico
Copy link

@AltNico AltNico commented Feb 14, 2022

jpackage provides the option --resource-dir that allows to override

resources used by jpackage, such as background images and template files for properties and scripts.

https://docs.oracle.com/en/java/javase/17/jpackage/override-jpackage-resources.html

This includes files like preinst and postinst that are used by .deb files to allow modifications of the installation process.

When looking at the .deb file generated by jpackage, the default preinst and postinst scripts land in the control.tar.xz archive of the .deb file.

However, with the .deb files produced by the packageDeb task, one can see that the files from the source's appResourcesRootDir (specified in build.gradle.kts) land in /opt/briar-desktop/lib/app/resources/ inside the data.tar.xz
archive.

Looking at the jpackage parameters used during packageDeb, one can see that it uses compose/tmp/resources:

--resource-dir
"/home/dev/Documents/briar-desktop/build/compose/tmp/resources"

[project root]/build/compose/tmp/packageDeb.args.txt

Looking at that directory, it is empty. However, inside compose/tmp/main/resources the files provided in source's appResourcesRootDir are found:

$ ls -l compose/tmp/main/resources/
total 8
-rwxr-xr-x 1 dev dev   9 Feb 14 13:02 postinst
-rwxr-xr-x 1 dev dev 618 Feb 14 13:02 preinst
$ ls -l compose/tmp/resources/
total 0

This MR therefore exposes jpackageResources to be specified in Gradle build files by
Compose projects.

https://github.com/JetBrains/compose-jb/blob/v1.0.1/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt#L248

Fixes #1766.

@AltNico
Copy link
Author

AltNico commented Feb 14, 2022

Hints on how to test this (and directly use it in our next Briar Desktop release) are highly appreciated!

@AlexeyTsvetkov
Copy link
Collaborator

@AltNico I'm not sure I like the idea of mixing packaging resources and app resources. Just to be clear, I'm not strongly against it either. That's why there are two AbstractJPackageTask properties: jpackageResources and appResourcesDir.
However, jpackageResources is not exposed in the DSL. The reason for that was that at the time I was not sure, if users actually need it, and I try to avoid adding public APIs unless I understand use cases.
Now it seems that definitely there are users, who need it, so instead of merging jpackageResources and appResourcesDir, we could just expose jpackageResources in the DSL similarly to appResourcesDir (e.g. via packagingResourcesRootDir or jpackageResourcesRootDir property). @AltNico what do you think about this alternative option?

jpackage provides the option `--resource-dir` that allows to override
> resources used by jpackage, such as background images and template
> files for properties and scripts.

https://docs.oracle.com/en/java/javase/17/jpackage/override-jpackage-resources.html

This includes files like `preinst` and `postinst` that are used by .deb
files to allow modifications of the installation process.

When looking at the .deb file generated by jpackage, the default
`preinst` and `postinst` scripts land in the _control.tar.xz_ archive of
the .deb file.

However, with the .deb files produced by the `packageDeb` task, one can
see that the files from the source's `appResourcesRootDir` (specified in
`build.gradle.kts`) land in
_/opt/briar-desktop/lib/app/resources/_ inside the _data.tar.xz_
archive.

Looking at the jpackage parameters used during `packageDeb`, one can see
that it uses _compose/tmp/resources_:
```
--resource-dir
"/home/dev/Documents/briar-desktop/build/compose/tmp/resources"
```
[project root]/build/compose/tmp/packageDeb.args.txt

Looking at that directory, it is empty. However, inside
_compose/tmp/main/resources_ the files provided in source's `appResourcesRootDir`
are found:
```
$ ls -l compose/tmp/main/resources/
total 8
-rwxr-xr-x 1 dev dev   9 Feb 14 13:02 postinst
-rwxr-xr-x 1 dev dev 618 Feb 14 13:02 preinst
$ ls -l compose/tmp/resources/
total 0
```

This MR therefore exposes `jpackageResources` to be specified in Gradle build files  by
Compose projects.

https://github.com/JetBrains/compose-jb/blob/v1.0.1/gradle-plugins/compose/src/main/kotlin/org/jetbrains/compose/desktop/application/tasks/AbstractJPackageTask.kt#L248

Fixes #1766.
Copy link
Author

@AltNico AltNico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlexeyTsvetkov Exposing jpackageResources via the DSL sounds good to me! I gave it a try and implemented packagingResourcesRootDir analogously to how appResourcesDir is implemented. I'm adding some comments in the code, but just want to mention that I did not add the preparePackagingResources functions to the configurePackagingTask() calls of run composeTask and JavaExec.configureRunTask because there we don't need those packaging resources, I guess.

Still unsure on how to test it (with Briar Desktop), though.

@@ -27,6 +27,7 @@ open class NativeDistributions @Inject constructor(
var vendor: String? = null
var packageVersion: String? = null
val appResourcesRootDir: DirectoryProperty = objects.directoryProperty()
val packagingResourcesRootDir: DirectoryProperty = objects.directoryProperty()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now adding packagingResourcesRootDir to the DSL similar to how appResourcesRootDir is implemented.

val resourcesDir = project.layout.dir(prepareResources.map { it.destinationDir })
jpackageResources.set(resourcesDir)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm not sure whether resourcesDir contains the right path.

val destDir = project.layout.buildDirectory.dir("compose/tmp/resources")
into(destDir)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows to specify different files per OS/arch combination, just like with appResourcesRootDir.

@AltNico AltNico changed the title Use correct path for jpackage --resource-dir Expose jpackage's --resource-dir in Gradle DSL Feb 14, 2022
@krizzu
Copy link

krizzu commented Dec 15, 2022

Hey @AlexeyTsvetkov I know it's been a while, but what you think about the PR? I think it'd be super useful to get in

@AltNico AltNico closed this by deleting the head repository Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[linux] Scripts (preinst, postinst) inserted on installation resources don't execute
4 participants