Build: Remove dependency on internal indenting stream writer
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
@file:Suppress("PropertyName", "HasPlatformType", "UnstableApiUsage")
|
@file:Suppress("PropertyName", "HasPlatformType", "UnstableApiUsage")
|
||||||
|
|
||||||
import com.sun.xml.internal.txw2.output.IndentingXMLStreamWriter
|
|
||||||
import org.gradle.internal.os.OperatingSystem
|
import org.gradle.internal.os.OperatingSystem
|
||||||
|
import java.io.Closeable
|
||||||
import java.io.FileWriter
|
import java.io.FileWriter
|
||||||
|
import java.io.OutputStreamWriter
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.*
|
||||||
import javax.xml.stream.XMLOutputFactory
|
import javax.xml.stream.XMLOutputFactory
|
||||||
import javax.xml.stream.XMLStreamWriter
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
base
|
base
|
||||||
@@ -312,66 +314,62 @@ fun writeIvyXml(
|
|||||||
|
|
||||||
val ivyFile = targetDir.resolve("$fileName.ivy.xml")
|
val ivyFile = targetDir.resolve("$fileName.ivy.xml")
|
||||||
ivyFile.parentFile.mkdirs()
|
ivyFile.parentFile.mkdirs()
|
||||||
FileWriter(ivyFile).use {
|
with(XMLWriter(FileWriter(ivyFile))) {
|
||||||
val xmlWriter = IndentingXMLStreamWriter(XMLOutputFactory.newInstance().createXMLStreamWriter(it))
|
document("UTF-8", "1.0") {
|
||||||
with(xmlWriter) {
|
element("ivy-module") {
|
||||||
document("UTF-8", "1.0") {
|
attribute("version", "2.0")
|
||||||
element("ivy-module") {
|
attribute("xmlns:m", "http://ant.apache.org/ivy/maven")
|
||||||
attribute("version", "2.0")
|
|
||||||
attribute("xmlns:m", "http://ant.apache.org/ivy/maven")
|
|
||||||
|
|
||||||
emptyElement("info") {
|
emptyElement("info") {
|
||||||
attributes(
|
attributes(
|
||||||
"organisation" to organization,
|
"organisation" to organization,
|
||||||
"module" to moduleName,
|
"module" to moduleName,
|
||||||
"revision" to version,
|
"revision" to version,
|
||||||
"publication" to ""
|
"publication" to SimpleDateFormat("yyyyMMddHHmmss").format(Date())
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
element("configurations") {
|
||||||
|
listOf("default", "sources").forEach { configurationName ->
|
||||||
|
emptyElement("conf") {
|
||||||
|
attributes("name" to configurationName, "visibility" to "public")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
element("configurations") {
|
element("publications") {
|
||||||
listOf("default", "sources").forEach { configurationName ->
|
artifactDir.listFiles()?.filter(::shouldIncludeIntellijJar)?.forEach { jarFile ->
|
||||||
emptyElement("conf") {
|
val relativeName = jarFile.toRelativeString(baseDir).removeSuffix(".jar")
|
||||||
attributes("name" to configurationName, "visibility" to "public")
|
emptyElement("artifact") {
|
||||||
}
|
attributes(
|
||||||
|
"name" to relativeName,
|
||||||
|
"type" to "jar",
|
||||||
|
"ext" to "jar",
|
||||||
|
"conf" to "default"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
element("publications") {
|
sourcesJar.forEach { jarFile ->
|
||||||
artifactDir.listFiles()?.filter(::shouldIncludeIntellijJar)?.forEach { jarFile ->
|
emptyElement("artifact") {
|
||||||
val relativeName = jarFile.toRelativeString(baseDir).removeSuffix(".jar")
|
val sourcesArtifactName = jarFile.name
|
||||||
emptyElement("artifact") {
|
.substringBeforeLast("-")
|
||||||
attributes(
|
.substringBeforeLast("-")
|
||||||
"name" to relativeName,
|
|
||||||
"type" to "jar",
|
|
||||||
"ext" to "jar",
|
|
||||||
"conf" to "default"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sourcesJar.forEach { jarFile ->
|
attributes(
|
||||||
emptyElement("artifact") {
|
"name" to sourcesArtifactName,
|
||||||
val sourcesArtifactName = jarFile.name
|
"type" to "jar",
|
||||||
.substringBeforeLast("-")
|
"ext" to "jar",
|
||||||
.substringBeforeLast("-")
|
"conf" to "sources",
|
||||||
|
"m:classifier" to "sources"
|
||||||
attributes(
|
)
|
||||||
"name" to sourcesArtifactName,
|
|
||||||
"type" to "jar",
|
|
||||||
"ext" to "jar",
|
|
||||||
"conf" to "sources",
|
|
||||||
"m:classifier" to "sources"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flush()
|
|
||||||
close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,25 +377,55 @@ fun skipToplevelDirectory(path: String) = path.substringAfter('/')
|
|||||||
|
|
||||||
fun skipContentsDirectory(path: String) = path.substringAfter("Contents/")
|
fun skipContentsDirectory(path: String) = path.substringAfter("Contents/")
|
||||||
|
|
||||||
fun XMLStreamWriter.document(encoding: String, version: String, init: XMLStreamWriter.() -> Unit) = apply {
|
class XMLWriter(private val outputStreamWriter: OutputStreamWriter) : Closeable {
|
||||||
writeStartDocument(encoding, version)
|
|
||||||
init()
|
|
||||||
writeEndDocument()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun XMLStreamWriter.element(name: String, init: XMLStreamWriter.() -> Unit) = apply {
|
private val xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStreamWriter)
|
||||||
writeStartElement(name)
|
|
||||||
init()
|
|
||||||
writeEndElement()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun XMLStreamWriter.emptyElement(name: String, init: XMLStreamWriter.() -> Unit) = apply {
|
private var depth = 0
|
||||||
writeEmptyElement(name)
|
private val indent = " "
|
||||||
init()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun XMLStreamWriter.attribute(name: String, value: String): Unit = writeAttribute(name, value)
|
fun document(encoding: String, version: String, init: XMLWriter.() -> Unit) = apply {
|
||||||
|
xmlStreamWriter.writeStartDocument(encoding, version)
|
||||||
|
|
||||||
fun XMLStreamWriter.attributes(vararg attributes: Pair<String, String>) {
|
init()
|
||||||
attributes.forEach { attribute(it.first, it.second) }
|
|
||||||
}
|
xmlStreamWriter.writeEndDocument()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun element(name: String, init: XMLWriter.() -> Unit) = apply {
|
||||||
|
writeIndent()
|
||||||
|
xmlStreamWriter.writeStartElement(name)
|
||||||
|
depth += 1
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
|
depth -= 1
|
||||||
|
writeIndent()
|
||||||
|
xmlStreamWriter.writeEndElement()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun emptyElement(name: String, init: XMLWriter.() -> Unit) = apply {
|
||||||
|
writeIndent()
|
||||||
|
xmlStreamWriter.writeEmptyElement(name)
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun attribute(name: String, value: String): Unit = xmlStreamWriter.writeAttribute(name, value)
|
||||||
|
|
||||||
|
fun attributes(vararg attributes: Pair<String, String>) {
|
||||||
|
attributes.forEach { attribute(it.first, it.second) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun writeIndent() {
|
||||||
|
xmlStreamWriter.writeCharacters("\n")
|
||||||
|
repeat(depth) {
|
||||||
|
xmlStreamWriter.writeCharacters(indent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun close() {
|
||||||
|
xmlStreamWriter.flush()
|
||||||
|
xmlStreamWriter.close()
|
||||||
|
outputStreamWriter.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user