|
10 | 10 | import Libs.alchemist |
11 | 11 | import Libs.incarnation |
12 | 12 | import com.github.spotbugs.snom.SpotBugsTask |
| 13 | +import com.sun.net.httpserver.HttpExchange |
| 14 | +import com.sun.net.httpserver.HttpServer |
13 | 15 | import dev.detekt.gradle.Detekt |
14 | 16 | import it.unibo.alchemist.build.id |
15 | 17 | import it.unibo.alchemist.build.isInCI |
16 | 18 | import it.unibo.alchemist.build.isMac |
17 | 19 | import it.unibo.alchemist.build.isWindows |
| 20 | +import java.net.InetSocketAddress |
| 21 | +import kotlinx.coroutines.runBlocking |
| 22 | +import org.danilopianini.gradle.mavencentral.portal.PublishPortalDeployment |
| 23 | +import org.gradle.api.internal.ConventionTask |
18 | 24 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
19 | 25 | import org.jetbrains.dokka.gradle.AbstractDokkaTask |
20 | 26 | import org.jetbrains.dokka.gradle.tasks.DokkaBaseTask |
@@ -161,6 +167,57 @@ dependencies { |
161 | 167 | dokkaGlobalClasspath(alchemist("full")) |
162 | 168 | } |
163 | 169 |
|
| 170 | +val checkMavenCentralPortalPluginClasspath by tasks.registering { |
| 171 | + group = LifecycleBasePlugin.VERIFICATION_GROUP |
| 172 | + description = "Checks that the Maven Central Portal publishing plugin can upload to a local fake endpoint." |
| 173 | + val outputFile = layout.buildDirectory.file("reports/checkMavenCentralPortalPluginClasspath/result.txt") |
| 174 | + inputs.property("publishOnCentralPluginVersion", libs.plugins.publishOnCentral.get().version.requiredVersion) |
| 175 | + outputs.file(outputFile) |
| 176 | + doLast { |
| 177 | + val server = HttpServer.create(InetSocketAddress("127.0.0.1", 0), 0) |
| 178 | + server.createContext("/api/v1/publisher/upload") { exchange -> |
| 179 | + exchange.use { |
| 180 | + check(exchange.requestMethod == "POST") { |
| 181 | + "Expected POST to ${exchange.requestURI}, received ${exchange.requestMethod}" |
| 182 | + } |
| 183 | + exchange.requestBody.use { it.readBytes() } |
| 184 | + exchange.respond(201, "local-deployment-id") |
| 185 | + } |
| 186 | + } |
| 187 | + server.start() |
| 188 | + try { |
| 189 | + val localPortal = "http://127.0.0.1:${server.address.port}/" |
| 190 | + val bundle = temporaryDir.resolve("maven-central-portal-bundle.zip").apply { |
| 191 | + parentFile.mkdirs() |
| 192 | + writeBytes(byteArrayOf(0x50, 0x4b, 0x05, 0x06, 0, 0, 0, 0)) |
| 193 | + } |
| 194 | + val deployment = PublishPortalDeployment( |
| 195 | + project = project, |
| 196 | + baseUrl = localPortal, |
| 197 | + user = providers.provider { "local-user" }, |
| 198 | + password = providers.provider { "local-password" }, |
| 199 | + zipTask = tasks.named<ConventionTask>("zipMavenCentralPortalPublication"), |
| 200 | + ) |
| 201 | + val deploymentId = runBlocking { |
| 202 | + deployment.upload(bundle, releaseAfterUpload = false) |
| 203 | + } |
| 204 | + check(deploymentId == "local-deployment-id") { |
| 205 | + "Unexpected local Maven Central Portal deployment id: $deploymentId" |
| 206 | + } |
| 207 | + outputFile.get().asFile.apply { |
| 208 | + parentFile.mkdirs() |
| 209 | + writeText(deploymentId) |
| 210 | + } |
| 211 | + } finally { |
| 212 | + server.stop(0) |
| 213 | + } |
| 214 | + } |
| 215 | +} |
| 216 | + |
| 217 | +tasks.check { |
| 218 | + dependsOn(checkMavenCentralPortalPluginClasspath) |
| 219 | +} |
| 220 | + |
164 | 221 | tasks.matching { it.name == "kotlinStoreYarnLock" }.configureEach { |
165 | 222 | dependsOn(rootProject.tasks.named("kotlinUpgradeYarnLock")) |
166 | 223 | } |
@@ -239,3 +296,10 @@ val performWebsiteStringReplacements by tasks.registering { |
239 | 296 | tasks.hugoBuild.configure { |
240 | 297 | finalizedBy(performWebsiteStringReplacements) |
241 | 298 | } |
| 299 | + |
| 300 | +private fun HttpExchange.respond(statusCode: Int, body: String) { |
| 301 | + val response = body.toByteArray() |
| 302 | + responseHeaders.add("Content-Type", "text/plain; charset=utf-8") |
| 303 | + sendResponseHeaders(statusCode, response.size.toLong()) |
| 304 | + responseBody.use { it.write(response) } |
| 305 | +} |
0 commit comments