Skip to content

Commit 6346354

Browse files
committed
feat: Register font resources with GraalVM native-image resources
Relates to #170
1 parent 0112bf0 commit 6346354

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed

build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,16 @@ subprojects { subproj ->
133133
compileOnly "org.kordamp.jipsy:jipsy-annotations:${jipsyVersion}"
134134
annotationProcessor "org.kordamp.jipsy:jipsy-processor:${jipsyVersion}"
135135
}
136+
137+
tasks.processResources.dependsOn(tasks.register('generateNativeImageResource', org.kordamp.ikonli.gradle.NativeImageResourceGeneratorTask) { t ->
138+
String ipn = project.name - 'ikonli-' - '-pack'
139+
140+
t.outputDirectory.set(file('build/resources/main/META-INF/native-image'))
141+
t.groupId.set(project.group)
142+
t.artifactId.set(project.name)
143+
t.version.set(project."${ipn}Version")
144+
t.iconPackName.set(ipn)
145+
})
136146
}
137147
}
138148

buildSrc/build.gradle

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2015-2025 Andres Almiray
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
plugins {
19+
id 'java-library'
20+
id 'groovy'
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright 2015-2025 Andres Almiray
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.kordamp.ikonli.gradle
19+
20+
import groovy.transform.CompileStatic
21+
import org.gradle.api.DefaultTask
22+
import org.gradle.api.file.DirectoryProperty
23+
import org.gradle.api.model.ObjectFactory
24+
import org.gradle.api.provider.Property
25+
import org.gradle.api.tasks.Input
26+
import org.gradle.api.tasks.OutputDirectory
27+
import org.gradle.api.tasks.TaskAction
28+
29+
import javax.inject.Inject
30+
import java.nio.file.Files
31+
32+
@CompileStatic
33+
class NativeImageResourceGeneratorTask extends DefaultTask {
34+
@OutputDirectory
35+
final DirectoryProperty outputDirectory
36+
37+
@Input
38+
final Property<String> groupId
39+
40+
@Input
41+
final Property<String> artifactId
42+
43+
@Input
44+
final Property<String> version
45+
46+
@Input
47+
final Property<String> iconPackName
48+
49+
@Inject
50+
NativeImageResourceGeneratorTask(ObjectFactory objects) {
51+
outputDirectory = objects.directoryProperty()
52+
groupId = objects.property(String)
53+
artifactId = objects.property(String)
54+
version = objects.property(String)
55+
iconPackName = objects.property(String)
56+
}
57+
58+
@TaskAction
59+
void generateResourceConfigFile() {
60+
File resourceConfig = outputDirectory.get().file("${groupId.get()}/${artifactId.get()}/resources-config.json").asFile
61+
Files.createDirectories(resourceConfig.parentFile.toPath())
62+
63+
resourceConfig.text = """
64+
{
65+
"resources": {
66+
"includes": [
67+
{
68+
"pattern": "META-INF/resources/${iconPackName.get()}/${version.get()}/fonts/*.tff"
69+
}
70+
]
71+
}
72+
}
73+
"""
74+
}
75+
}

0 commit comments

Comments
 (0)