Skip to content

Commit 77709f6

Browse files
authored
Make sure to send XML 1.0 (#231)
* Make sure to send XML 1.0 * fix tests
1 parent 0e19581 commit 77709f6

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

nmcp-tasks/src/main/kotlin/nmcp/internal/task/metadata.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package nmcp.internal.task
22

33
import kotlinx.serialization.Serializable
44
import kotlinx.serialization.StringFormat
5-
import nl.adaptivity.xmlutil.serialization.XML
5+
import nl.adaptivity.xmlutil.XmlDeclMode
6+
import nl.adaptivity.xmlutil.core.XmlVersion
67
import nl.adaptivity.xmlutil.serialization.XML1_0
78
import nl.adaptivity.xmlutil.serialization.XmlChildrenName
8-
import nl.adaptivity.xmlutil.serialization.XmlConfig
99
import nl.adaptivity.xmlutil.serialization.XmlElement
1010
import nl.adaptivity.xmlutil.serialization.XmlSerialName
1111

@@ -84,4 +84,9 @@ internal data class ArtifactMetadata(
8484

8585
internal val xml: StringFormat = XML1_0.recommended {
8686
indentString = " "
87+
// Maven Central doesn't understand XML 1.1
88+
// See also https://github.com/pdvrieze/xmlutil/issues/324
89+
xmlVersion = XmlVersion.XML10
90+
// Also set the charset explicitly
91+
xmlDeclMode = XmlDeclMode.Charset
8792
}

nmcp-tasks/src/main/kotlin/nmcp/transport/transport.kt

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal class HttpTransport(
101101
response.close()
102102
return null
103103
}
104-
if(!response.isSuccessful) {
104+
if (!response.isSuccessful) {
105105
response.close()
106106
error("Nmcp: cannot GET '$url' (statusCode=${response.code}):\n${response.body.string()}")
107107
}
@@ -127,31 +127,24 @@ internal class HttpTransport(
127127
check(response.isSuccessful) {
128128
buildString {
129129
appendLine("Nmcp: cannot PUT '$url' (statusCode=${response.code}).")
130-
appendLine("Response body: ${response.body.string()}")
130+
appendLine("Response body: '${response.body.string()}'")
131131
when (response.code) {
132+
400 -> {
133+
appendLine("Things to double check:")
134+
appendLine("Your artifacts have proper extensions (.jar, .pom, ...).")
135+
appendLine("If publishing a XML file, the XML version is 1.0.")
136+
appendLine("If publishing a snapshot, the artifacts version is ending with `-SNAPSHOT`.")
137+
}
138+
401 -> {
139+
appendLine("Check your credentials")
140+
appendLine("If publishing a snapshot, make sure you enabled snapshots on your namespace at https://central.sonatype.com/publishing/namespaces.")
141+
}
142+
403 -> {
143+
appendLine("Check that you are publishing to the correct groupId.")
144+
}
132145
429 -> {
133146
appendLine("Too many requests, try again later")
134147
}
135-
else -> {
136-
appendLine("Things to double check:")
137-
/**
138-
* I have seen 401 for this
139-
*/
140-
appendLine(" - Are your credentials correct?")
141-
appendLine(" - Did you enable the snapshots on your namespace at https://central.sonatype.com/publishing/namespaces?")
142-
/**
143-
* I have seen 400 for this
144-
*/
145-
appendLine(" - Is your version ending with `-SNAPSHOT`?")
146-
/**
147-
* I have seen 400 for this.
148-
*/
149-
appendLine(" - Do your artifacts have proper extensions (.jar, .pom, ...)?")
150-
/**
151-
* I have seen 403 for this.
152-
*/
153-
appendLine(" - Is your groupId correct?")
154-
}
155148
}
156149
}
157150
}

nmcp-tasks/src/test/kotlin/MetadataTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MetadataTest {
4545
*/
4646
// language=xml
4747
val xmlData = """
48-
<?xml version='1.1' ?>
48+
<?xml version='1.0' encoding='UTF-8' ?>
4949
<metadata modelVersion="1.1.0">
5050
<groupId>com.apollographql.apollo</groupId>
5151
<artifactId>apollo-api-jvm</artifactId>
@@ -111,7 +111,7 @@ class MetadataTest {
111111
fun versionMetadataIsEncodedSuccessfully() {
112112
// language=xml
113113
val xmlData = """
114-
<?xml version='1.1' ?>
114+
<?xml version='1.0' encoding='UTF-8' ?>
115115
<metadata modelVersion="1.1.0">
116116
<groupId>com.apollographql.apollo</groupId>
117117
<artifactId>apollo-api-jvm</artifactId>
@@ -178,7 +178,7 @@ class MetadataTest {
178178

179179
val result = encodeToXml(metadata)
180180

181-
assertEquals(xmlData, result,)
181+
assertEquals(xmlData, result)
182182
}
183183

184184
@Test

0 commit comments

Comments
 (0)