Skip to content

Commit

Permalink
feat: Register font resources with GraalVM native-image resources
Browse files Browse the repository at this point in the history
Relates to #170
  • Loading branch information
aalmiray committed Jan 27, 2025
1 parent 0112bf0 commit 2f70561
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ subprojects { subproj ->
compileOnly "org.kordamp.jipsy:jipsy-annotations:${jipsyVersion}"
annotationProcessor "org.kordamp.jipsy:jipsy-processor:${jipsyVersion}"
}

tasks.processResources.dependsOn(tasks.register('generateNativeImageResource', org.kordamp.ikonli.gradle.NativeImageResourceGeneratorTask) { t ->
String ipn = project.name - 'ikonli-' - '-pack'

t.outputDirectory.set(file('build/resources/main/META-INF/native-image'))
t.groupId.set(project.group)
t.artifactId.set(project.name)
t.version.set(project."${ipn}Version")
t.iconPackName.set(ipn)
})
}
}

Expand Down
22 changes: 22 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2015-2025 Andres Almiray
*
* 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.
*/
plugins {
id 'java-library'
id 'groovy'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2015-2025 Andres Almiray
*
* 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.
*/
package org.kordamp.ikonli.gradle

import groovy.transform.CompileStatic
import org.gradle.api.DefaultTask
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

import javax.inject.Inject
import java.nio.file.Files

@CompileStatic
class NativeImageResourceGeneratorTask extends DefaultTask {
@OutputDirectory
final DirectoryProperty outputDirectory

@Input
final Property<String> groupId

@Input
final Property<String> artifactId

@Input
final Property<String> version

@Input
final Property<String> iconPackName

@Inject
NativeImageResourceGeneratorTask(ObjectFactory objects) {
outputDirectory = objects.directoryProperty()
groupId = objects.property(String)
artifactId = objects.property(String)
version = objects.property(String)
iconPackName = objects.property(String)
}

@TaskAction
void generateResourceConfigFile() {
File resourceConfig = outputDirectory.get().file("${groupId.get()}/${artifactId.get()}/resources-config.json").asFile
Files.createDirectories(resourceConfig.parentFile.toPath())

resourceConfig.text = """
{
"resources": {
"includes": [
{
"pattern": "META-INF/resources/${iconPackName.get()}/${version.get()}/fonts/*.ttf"
}
]
}
}
"""
}
}

0 comments on commit 2f70561

Please sign in to comment.