|
1 | 1 | @file:Suppress("PropertyName", "HasPlatformType", "UnstableApiUsage")
|
2 | 2 |
|
3 |
| -import org.gradle.api.publish.ivy.internal.artifact.FileBasedIvyArtifact |
4 |
| -import org.gradle.api.publish.ivy.internal.publication.DefaultIvyConfiguration |
5 |
| -import org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity |
6 |
| -import org.gradle.api.publish.ivy.internal.publisher.IvyDescriptorFileGenerator |
| 3 | +import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter |
7 | 4 | import org.gradle.internal.os.OperatingSystem
|
| 5 | +import java.io.FileWriter |
8 | 6 | import java.net.URI
|
| 7 | +import javax.xml.stream.XMLOutputFactory |
| 8 | +import javax.xml.stream.XMLStreamWriter |
9 | 9 |
|
10 | 10 | plugins {
|
11 | 11 | base
|
@@ -310,40 +310,94 @@ fun writeIvyXml(
|
310 | 310 | && !jar.name.startsWith("kotlin-")
|
311 | 311 | && (allowAnnotations || jar.name != "annotations.jar") // see comments for [intellijAnnotations] above
|
312 | 312 |
|
313 |
| - with(IvyDescriptorFileGenerator(DefaultIvyPublicationIdentity(organization, moduleName, version))) { |
314 |
| - addConfiguration(DefaultIvyConfiguration("default")) |
315 |
| - addConfiguration(DefaultIvyConfiguration("sources")) |
316 |
| - artifactDir.listFiles()?.forEach { jarFile -> |
317 |
| - if (shouldIncludeIntellijJar(jarFile)) { |
318 |
| - val relativeName = jarFile.toRelativeString(baseDir).removeSuffix(".jar") |
319 |
| - addArtifact( |
320 |
| - FileBasedIvyArtifact( |
321 |
| - jarFile, |
322 |
| - DefaultIvyPublicationIdentity(organization, relativeName, version) |
323 |
| - ).also { |
324 |
| - it.conf = "default" |
| 313 | + val ivyFile = targetDir.resolve("$fileName.ivy.xml") |
| 314 | + ivyFile.parentFile.mkdirs() |
| 315 | + FileWriter(ivyFile).use { |
| 316 | + val xmlWriter = IndentingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(it)) |
| 317 | + with(xmlWriter) { |
| 318 | + document("UTF-8", "1.0") { |
| 319 | + element("ivy-module") { |
| 320 | + attribute("version", "2.0") |
| 321 | + attribute("xmlns:m", "http://ant.apache.org/ivy/maven") |
| 322 | + |
| 323 | + emptyElement("info") { |
| 324 | + attributes( |
| 325 | + "organisation" to organization, |
| 326 | + "module" to moduleName, |
| 327 | + "revision" to version, |
| 328 | + "publication" to "" |
| 329 | + ) |
| 330 | + } |
| 331 | + |
| 332 | + element("configurations") { |
| 333 | + listOf("default", "sources").forEach { configurationName -> |
| 334 | + emptyElement("conf") { |
| 335 | + attributes("name" to configurationName, "visibility" to "public") |
| 336 | + } |
| 337 | + } |
325 | 338 | }
|
326 |
| - ) |
327 |
| - } |
328 |
| - } |
329 | 339 |
|
330 |
| - sourcesJar.forEach { |
331 |
| - val sourcesArtifactName = it.name.substringBeforeLast("-").substringBeforeLast("-") |
332 |
| - addArtifact( |
333 |
| - FileBasedIvyArtifact( |
334 |
| - it, |
335 |
| - DefaultIvyPublicationIdentity(organization, sourcesArtifactName, version) |
336 |
| - ).also { artifact -> |
337 |
| - artifact.conf = "sources" |
338 |
| - artifact.classifier = "sources" |
| 340 | + element("publications") { |
| 341 | + artifactDir.listFiles()?.filter(::shouldIncludeIntellijJar)?.forEach { jarFile -> |
| 342 | + val relativeName = jarFile.toRelativeString(baseDir).removeSuffix(".jar") |
| 343 | + emptyElement("artifact") { |
| 344 | + attributes( |
| 345 | + "name" to relativeName, |
| 346 | + "type" to "jar", |
| 347 | + "ext" to "jar", |
| 348 | + "conf" to "default" |
| 349 | + ) |
| 350 | + } |
| 351 | + } |
| 352 | + |
| 353 | + sourcesJar.forEach { jarFile -> |
| 354 | + emptyElement("artifact") { |
| 355 | + val sourcesArtifactName = jarFile.name |
| 356 | + .substringBeforeLast("-") |
| 357 | + .substringBeforeLast("-") |
| 358 | + |
| 359 | + attributes( |
| 360 | + "name" to sourcesArtifactName, |
| 361 | + "type" to "jar", |
| 362 | + "ext" to "jar", |
| 363 | + "conf" to "sources", |
| 364 | + "m:classifier" to "sources" |
| 365 | + ) |
| 366 | + } |
| 367 | + } |
| 368 | + } |
339 | 369 | }
|
340 |
| - ) |
341 |
| - } |
| 370 | + } |
342 | 371 |
|
343 |
| - writeTo(File(targetDir, "$fileName.ivy.xml")) |
| 372 | + flush() |
| 373 | + close() |
| 374 | + } |
344 | 375 | }
|
345 | 376 | }
|
346 | 377 |
|
347 | 378 | fun skipToplevelDirectory(path: String) = path.substringAfter('/')
|
348 | 379 |
|
349 | 380 | fun skipContentsDirectory(path: String) = path.substringAfter("Contents/")
|
| 381 | + |
| 382 | +fun XMLStreamWriter.document(encoding: String, version: String, init: XMLStreamWriter.() -> Unit) = apply { |
| 383 | + writeStartDocument(encoding, version) |
| 384 | + init() |
| 385 | + writeEndDocument() |
| 386 | +} |
| 387 | + |
| 388 | +fun XMLStreamWriter.element(name: String, init: XMLStreamWriter.() -> Unit) = apply { |
| 389 | + writeStartElement(name) |
| 390 | + init() |
| 391 | + writeEndElement() |
| 392 | +} |
| 393 | + |
| 394 | +fun XMLStreamWriter.emptyElement(name: String, init: XMLStreamWriter.() -> Unit) = apply { |
| 395 | + writeEmptyElement(name) |
| 396 | + init() |
| 397 | +} |
| 398 | + |
| 399 | +fun XMLStreamWriter.attribute(name: String, value: String): Unit = writeAttribute(name, value) |
| 400 | + |
| 401 | +fun XMLStreamWriter.attributes(vararg attributes: Pair<String, String>) { |
| 402 | + attributes.forEach { attribute(it.first, it.second) } |
| 403 | +} |
0 commit comments