Skip to content

Commit c17451e

Browse files
whyolegIgnatBeresnev
authored andcommitted
Replace usages of deprecated in JDK 20 java.net.URL constructor in Gradle runner (#3435)
(cherry picked from commit 54111b9)
1 parent 46762da commit c17451e

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

dokka-runners/runner-gradle-plugin-classic/src/main/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilder.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.gradle.kotlin.dsl.property
1616
import org.gradle.kotlin.dsl.setProperty
1717
import org.jetbrains.dokka.*
1818
import java.io.File
19+
import java.net.URI
1920
import java.net.URL
2021

2122
/**
@@ -462,7 +463,7 @@ open class GradleDokkaSourceSetBuilder(
462463
* Convenient override to **append** external documentation links to [externalDocumentationLinks].
463464
*/
464465
fun externalDocumentationLink(url: String, packageListUrl: String? = null) {
465-
externalDocumentationLink(URL(url), packageListUrl = packageListUrl?.let(::URL))
466+
externalDocumentationLink(URI(url).toURL(), packageListUrl = packageListUrl?.let(::URI)?.toURL())
466467
}
467468

468469
/**

dokka-runners/runner-gradle-plugin-classic/src/main/kotlin/org/jetbrains/dokka/gradle/GradleExternalDocumentationLinkBuilder.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import java.net.URL
3030
*
3131
* ```kotlin
3232
* externalDocumentationLink {
33-
* url.set(URL("https://kotlinlang.org/api/kotlinx.serialization/"))
33+
* url.set(URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL())
3434
* packageListUrl.set(
35-
* rootProject.projectDir.resolve("serialization.package.list").toURL()
35+
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
3636
* )
3737
* }
3838
* ```
@@ -53,13 +53,13 @@ class GradleExternalDocumentationLinkBuilder(
5353
* Example:
5454
*
5555
* ```kotlin
56-
* java.net.URL("https://kotlinlang.org/api/kotlinx.serialization/")
56+
* java.net.URI("https://kotlinlang.org/api/kotlinx.serialization/").toURL()
5757
* ```
5858
*/
5959
@Internal
6060
val url: Property<URL> = project.objects.property()
6161

62-
@Input // URL is deprecated in gradle inputs
62+
@Input // URL is deprecated in Gradle inputs
6363
internal fun getUrlString() = url.map(URL::toString)
6464

6565
/**
@@ -69,13 +69,13 @@ class GradleExternalDocumentationLinkBuilder(
6969
* Example:
7070
*
7171
* ```kotlin
72-
* rootProject.projectDir.resolve("serialization.package.list").toURL()
72+
* rootProject.projectDir.resolve("serialization.package.list").toURI().toURL()
7373
* ```
7474
*/
7575
@Internal
7676
val packageListUrl: Property<URL> = project.objects.property()
7777

78-
@Input // URL is deprecated in gradle inputs
78+
@Input // URL is deprecated in Gradle inputs
7979
@Optional
8080
internal fun getPackageListUrlString() = packageListUrl.map(URL::toString)
8181

dokka-runners/runner-gradle-plugin-classic/src/main/kotlin/org/jetbrains/dokka/gradle/GradleSourceLinkBuilder.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.net.URL
2626
* ```kotlin
2727
* sourceLink {
2828
* localDirectory.set(projectDir.resolve("src"))
29-
* remoteUrl.set(URL("https://github.com/kotlin/dokka/tree/master/src"))
29+
* remoteUrl.set(URI("https://github.com/kotlin/dokka/tree/master/src").toURL())
3030
* remoteLineSuffix.set("#L")
3131
* }
3232
* ```
@@ -68,13 +68,13 @@ class GradleSourceLinkBuilder(
6868
* Example:
6969
*
7070
* ```kotlin
71-
* java.net.URL("https://github.com/username/projectname/tree/master/src"))
71+
* java.net.URI("https://github.com/username/projectname/tree/master/src").toURL()
7272
* ```
7373
*/
7474
@Internal
7575
val remoteUrl: Property<URL> = project.objects.property()
7676

77-
@Input // TODO: URL is deprecated in grapdle inputs
77+
@Input // URL is deprecated in Gradle inputs
7878
internal fun getRemoteUrlString() = remoteUrl.map(URL::toString)
7979

8080

dokka-runners/runner-gradle-plugin-classic/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationJsonTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.jetbrains.dokka.gradle.utils.externalDocumentationLink_
1414
import org.jetbrains.dokka.gradle.utils.withDependencies_
1515
import org.jetbrains.dokka.toCompactJsonString
1616
import java.io.File
17-
import java.net.URL
17+
import java.net.URI
1818
import kotlin.test.Test
1919
import kotlin.test.assertEquals
2020

@@ -50,8 +50,8 @@ class DokkaConfigurationJsonTest {
5050
reportUndocumented.set(true)
5151

5252
externalDocumentationLink_ {
53-
packageListUrl.set(URL("http://some.url"))
54-
url.set(URL("http://some.other.url"))
53+
packageListUrl.set(URI("http://some.url").toURL())
54+
url.set(URI("http://some.other.url").toURL())
5555
}
5656
perPackageOption {
5757
includeNonPublic.set(true)

dokka-runners/runner-gradle-plugin-classic/src/test/kotlin/org/jetbrains/dokka/gradle/DokkaConfigurationSerializableTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.junit.jupiter.api.io.TempDir
1515
import java.io.File
1616
import java.io.ObjectInputStream
1717
import java.io.ObjectOutputStream
18-
import java.net.URL
18+
import java.net.URI
1919
import kotlin.test.Test
2020
import kotlin.test.assertEquals
2121

@@ -51,8 +51,8 @@ class DokkaConfigurationSerializableTest {
5151
reportUndocumented.set(true)
5252

5353
externalDocumentationLink_ {
54-
packageListUrl.set(URL("http://some.url"))
55-
url.set(URL("http://some.other.url"))
54+
packageListUrl.set(URI("http://some.url").toURL())
55+
url.set(URI("http://some.other.url").toURL())
5656
}
5757

5858
perPackageOption {

dokka-runners/runner-gradle-plugin-classic/src/test/kotlin/org/jetbrains/dokka/gradle/GradleDokkaSourceSetBuilderTest.kt

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import org.gradle.kotlin.dsl.closureOf
1010
import org.gradle.testfixtures.ProjectBuilder
1111
import org.jetbrains.dokka.*
1212
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
13-
import java.net.URL
13+
import java.net.URI
1414
import kotlin.test.*
1515

1616
class GradleDokkaSourceSetBuilderTest {
@@ -222,37 +222,37 @@ class GradleDokkaSourceSetBuilderTest {
222222
GradleSourceLinkBuilder(project).apply {
223223
this.remoteLineSuffix.set("ls1")
224224
this.localDirectory.set(project.file("p1"))
225-
this.remoteUrl.set(URL("https://u1"))
225+
this.remoteUrl.set(URI("https://u1").toURL())
226226
})
227227

228228
sourceSet.sourceLink {
229229
remoteLineSuffix.set("ls2")
230230
localDirectory.set(project.file("p2"))
231-
remoteUrl.set(URL("https://u2"))
231+
remoteUrl.set(URI("https://u2").toURL())
232232
}
233233

234234
sourceSet.sourceLink(project.closureOf<GradleSourceLinkBuilder> {
235235
this.remoteLineSuffix.set("ls3")
236236
this.localDirectory.set(project.file("p3"))
237-
this.remoteUrl.set(URL("https://u3"))
237+
this.remoteUrl.set(URI("https://u3").toURL())
238238
})
239239

240240
assertEquals(
241241
setOf(
242242
SourceLinkDefinitionImpl(
243243
remoteLineSuffix = "ls1",
244244
localDirectory = project.file("p1").absolutePath,
245-
remoteUrl = URL("https://u1")
245+
remoteUrl = URI("https://u1").toURL()
246246
),
247247
SourceLinkDefinitionImpl(
248248
remoteLineSuffix = "ls2",
249249
localDirectory = project.file("p2").absolutePath,
250-
remoteUrl = URL("https://u2")
250+
remoteUrl = URI("https://u2").toURL()
251251
),
252252
SourceLinkDefinitionImpl(
253253
remoteLineSuffix = "ls3",
254254
localDirectory = project.file("p3").absolutePath,
255-
remoteUrl = URL("https://u3")
255+
remoteUrl = URI("https://u3").toURL()
256256
)
257257
),
258258
sourceSet.build().sourceLinks,
@@ -306,29 +306,29 @@ class GradleDokkaSourceSetBuilderTest {
306306

307307
sourceSet.externalDocumentationLinks.add(
308308
GradleExternalDocumentationLinkBuilder(project).apply {
309-
this.url.set(URL("https://u1"))
310-
this.packageListUrl.set(URL("https://pl1"))
309+
this.url.set(URI("https://u1").toURL())
310+
this.packageListUrl.set(URI("https://pl1").toURL())
311311
}
312312
)
313313

314314
sourceSet.externalDocumentationLink {
315-
url.set(URL("https://u2"))
315+
url.set(URI("https://u2").toURL())
316316
}
317317

318318
sourceSet.externalDocumentationLink(project.closureOf<GradleExternalDocumentationLinkBuilder> {
319-
url.set(URL("https://u3"))
319+
url.set(URI("https://u3").toURL())
320320
})
321321

322322
sourceSet.externalDocumentationLink(url = "https://u4", packageListUrl = "https://pl4")
323-
sourceSet.externalDocumentationLink(url = URL("https://u5"))
323+
sourceSet.externalDocumentationLink(url = URI("https://u5").toURL())
324324

325325
assertEquals(
326326
setOf(
327-
ExternalDocumentationLinkImpl(URL("https://u1"), URL("https://pl1")),
328-
ExternalDocumentationLinkImpl(URL("https://u2"), URL("https://u2/package-list")),
329-
ExternalDocumentationLinkImpl(URL("https://u3"), URL("https://u3/package-list")),
330-
ExternalDocumentationLinkImpl(URL("https://u4"), URL("https://pl4")),
331-
ExternalDocumentationLinkImpl(URL("https://u5"), URL("https://u5/package-list"))
327+
ExternalDocumentationLinkImpl(URI("https://u1").toURL(), URI("https://pl1").toURL()),
328+
ExternalDocumentationLinkImpl(URI("https://u2").toURL(), URI("https://u2/package-list").toURL()),
329+
ExternalDocumentationLinkImpl(URI("https://u3").toURL(), URI("https://u3/package-list").toURL()),
330+
ExternalDocumentationLinkImpl(URI("https://u4").toURL(), URI("https://pl4").toURL()),
331+
ExternalDocumentationLinkImpl(URI("https://u5").toURL(), URI("https://u5/package-list").toURL())
332332
),
333333
sourceSet.build().externalDocumentationLinks,
334334
"Expected all external documentation links being present after build"

0 commit comments

Comments
 (0)