|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. 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, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import org.openapitools.generator.gradle.plugin.tasks.GenerateTask |
| 21 | + |
| 22 | +plugins { |
| 23 | + alias(libs.plugins.openapi.generator) |
| 24 | + id("polaris-client") |
| 25 | + alias(libs.plugins.jandex) |
| 26 | +} |
| 27 | + |
| 28 | +dependencies { |
| 29 | + implementation(project(":polaris-core")) |
| 30 | + |
| 31 | + implementation(platform(libs.iceberg.bom)) |
| 32 | + implementation("org.apache.iceberg:iceberg-api") |
| 33 | + implementation("org.apache.iceberg:iceberg-core") |
| 34 | + implementation("org.apache.iceberg:iceberg-aws") |
| 35 | + |
| 36 | + implementation(libs.jakarta.annotation.api) |
| 37 | + implementation(libs.jakarta.inject.api) |
| 38 | + implementation(libs.jakarta.validation.api) |
| 39 | + implementation(libs.swagger.annotations) |
| 40 | + |
| 41 | + implementation(libs.jakarta.servlet.api) |
| 42 | + implementation(libs.jakarta.ws.rs.api) |
| 43 | + |
| 44 | + implementation(platform(libs.micrometer.bom)) |
| 45 | + implementation("io.micrometer:micrometer-core") |
| 46 | + |
| 47 | + implementation(platform(libs.jackson.bom)) |
| 48 | + implementation("com.fasterxml.jackson.core:jackson-annotations") |
| 49 | + implementation("com.fasterxml.jackson.core:jackson-core") |
| 50 | + implementation("com.fasterxml.jackson.core:jackson-databind") |
| 51 | + |
| 52 | + compileOnly(libs.microprofile.fault.tolerance.api) |
| 53 | + |
| 54 | + compileOnly(project(":polaris-immutables")) |
| 55 | + annotationProcessor(project(":polaris-immutables", configuration = "processor")) |
| 56 | +} |
| 57 | + |
| 58 | +val rootDir = rootProject.layout.projectDirectory |
| 59 | +val specsDir = rootDir.dir("spec") |
| 60 | +val templatesDir = rootDir.dir("server-templates") |
| 61 | +// Use a different directory than 'generated/', because OpenAPI generator's `GenerateTask` adds the |
| 62 | +// whole directory to its task output, but 'generated/' is not exclusive to that task and in turn |
| 63 | +// breaks Gradle's caching. |
| 64 | +val generatedDir = project.layout.buildDirectory.dir("generated-openapi") |
| 65 | +val generatedOpenApiSrcDir = project.layout.buildDirectory.dir("generated-openapi/src/main/java") |
| 66 | + |
| 67 | +openApiGenerate { |
| 68 | + // The OpenAPI generator does NOT resolve relative paths correctly against the Gradle project |
| 69 | + // directory |
| 70 | + inputSpec = provider { specsDir.file("polaris-catalog-service.yaml").asFile.absolutePath } |
| 71 | + generatorName = "jaxrs-resteasy" |
| 72 | + outputDir = provider { generatedDir.get().asFile.absolutePath } |
| 73 | + apiPackage = "org.apache.polaris.service.aws.sign.api" |
| 74 | + ignoreFileOverride.set(provider { rootDir.file(".openapi-generator-ignore").asFile.absolutePath }) |
| 75 | + templateDir.set(provider { templatesDir.asFile.absolutePath }) |
| 76 | + removeOperationIdPrefix.set(true) |
| 77 | + globalProperties.put("apis", "S3SignerApi") |
| 78 | + globalProperties.put("models", "false") |
| 79 | + globalProperties.put("apiDocs", "false") |
| 80 | + globalProperties.put("modelTests", "false") |
| 81 | + configOptions.put("resourceName", "catalog") |
| 82 | + configOptions.put("useTags", "true") |
| 83 | + configOptions.put("useBeanValidation", "false") |
| 84 | + configOptions.put("sourceFolder", "src/main/java") |
| 85 | + configOptions.put("useJakartaEe", "true") |
| 86 | + configOptions.put("hideGenerationTimestamp", "true") |
| 87 | + additionalProperties.put("apiNamePrefix", "IcebergRest") |
| 88 | + additionalProperties.put("apiNameSuffix", "") |
| 89 | + additionalProperties.put("metricsPrefix", "polaris") |
| 90 | + serverVariables.put("basePath", "api/catalog") |
| 91 | + typeMappings = |
| 92 | + mapOf("S3SignRequest" to "org.apache.polaris.service.aws.sign.model.PolarisS3SignRequest") |
| 93 | + importMappings = |
| 94 | + mapOf( |
| 95 | + "IcebergErrorResponse" to "org.apache.iceberg.rest.responses.ErrorResponse", |
| 96 | + "S3SignRequest" to "org.apache.polaris.service.aws.sign.model.PolarisS3SignRequest", |
| 97 | + "SignS3Request200Response" to |
| 98 | + "org.apache.polaris.service.aws.sign.model.PolarisS3SignResponse", |
| 99 | + ) |
| 100 | +} |
| 101 | + |
| 102 | +listOf("sourcesJar", "compileJava", "processResources").forEach { task -> |
| 103 | + tasks.named(task) { dependsOn("openApiGenerate") } |
| 104 | +} |
| 105 | + |
| 106 | +sourceSets { main { java { srcDir(generatedOpenApiSrcDir) } } } |
| 107 | + |
| 108 | +tasks.named<GenerateTask>("openApiGenerate") { |
| 109 | + inputs.dir(templatesDir) |
| 110 | + inputs.dir(specsDir) |
| 111 | + actions.addFirst { delete { delete(generatedDir) } } |
| 112 | + doLast { |
| 113 | + // Replace S3SignRequest with PolarisS3SignRequest in generated files |
| 114 | + fileTree(generatedDir) |
| 115 | + .matching { include("**/*.java") } |
| 116 | + .forEach { file -> |
| 117 | + val content = file.readText() |
| 118 | + val updatedContent = |
| 119 | + content.replace("S3SignRequest s3SignRequest", "PolarisS3SignRequest s3SignRequest") |
| 120 | + file.writeText(updatedContent) |
| 121 | + } |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +tasks.named("javadoc") { dependsOn("jandex") } |
0 commit comments