|
| 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