diff --git a/build.gradle b/build.gradle index 5bca0cdf..fc56db7e 100644 --- a/build.gradle +++ b/build.gradle @@ -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) + }) } } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000..8fa3ceb5 --- /dev/null +++ b/buildSrc/build.gradle @@ -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' +} + diff --git a/buildSrc/src/main/groovy/org/kordamp/ikonli/gradle/NativeImageResourceGeneratorTask.groovy b/buildSrc/src/main/groovy/org/kordamp/ikonli/gradle/NativeImageResourceGeneratorTask.groovy new file mode 100644 index 00000000..3ad7e666 --- /dev/null +++ b/buildSrc/src/main/groovy/org/kordamp/ikonli/gradle/NativeImageResourceGeneratorTask.groovy @@ -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 groupId + + @Input + final Property artifactId + + @Input + final Property version + + @Input + final Property 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" + } + ] + } +} +""" + } +}