Skip to content

Commit

Permalink
chore: Align on constructing URIs without create()
Browse files Browse the repository at this point in the history
For the difference see [1].

[1]: https://www.baeldung.com/java-uri-create-and-new-uri

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Dec 13, 2024
1 parent 4872713 commit fce2829
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ private data class EclipseLicenses(

private enum class LicenseClassificationProvider(val url: String) {
DOUBLE_OPEN("https://github.com/doubleopen-project/policy-configuration/raw/main/license-classifications.yml") {
override fun getClassifications(): LicenseClassifications = yamlMapper.readValue(URI.create(url).toURL())
override fun getClassifications(): LicenseClassifications = yamlMapper.readValue(URI(url).toURL())
},
ECLIPSE("https://www.eclipse.org/legal/licenses.json") {
override fun getClassifications(): LicenseClassifications {
val json = jsonMapper.readValue<EclipseLicenses>(URI.create(url).toURL())
val json = jsonMapper.readValue<EclipseLicenses>(URI(url).toURL())

logger.info { "Importing Eclipse license classifications dated ${json.meta["updated"]}." }

Expand All @@ -110,7 +110,7 @@ private enum class LicenseClassificationProvider(val url: String) {
}
},
LDB_COLLECTOR("https://github.com/maxhbr/LDBcollector/raw/generated/ort/license-classifications.yml") {
override fun getClassifications(): LicenseClassifications = yamlMapper.readValue(URI.create(url).toURL())
override fun getClassifications(): LicenseClassifications = yamlMapper.readValue(URI(url).toURL())
};

abstract fun getClassifications(): LicenseClassifications
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,23 +284,23 @@ class VulnerableCodeTest : WordSpec({
"fixup a wrongly escaped ampersand" {
val u = """https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:retail_category_management_planning_\\&_optimization:16.0.3:*:*:*:*:*:*:*"""

URI.create(u.fixupUrlEscaping()) shouldBe URI(
URI(u.fixupUrlEscaping()) shouldBe URI(
"""https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:retail_category_management_planning_%26_optimization:16.0.3:*:*:*:*:*:*:*"""
)
}

"fixup a wrongly escaped slash" {
val u = """https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:apple:swiftnio_http\/2:*:*:*:*:*:swift:*:*"""

URI.create(u.fixupUrlEscaping()) shouldBe URI(
URI(u.fixupUrlEscaping()) shouldBe URI(
"""https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:apple:swiftnio_http/2:*:*:*:*:*:swift:*:*"""
)
}

"fixup a wrongly escaped plus" {
val u = """https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:hyperion_bi\+:*:*:*:*:*:*:*:*"""

URI.create(u.fixupUrlEscaping()) shouldBe URI(
URI(u.fixupUrlEscaping()) shouldBe URI(
"""https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:oracle:hyperion_bi%2B:*:*:*:*:*:*:*:*"""
)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/package-managers/bazel/src/main/kotlin/Bazel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class Bazel(
"Archive override URL(s) for module '$moduleName': ${urlsAsString.removeSurrounding("[", "]")}"
}

val urls = urlsAsString.removeSurrounding("[", "]").split(',').map { URI.create(it) }
val urls = urlsAsString.removeSurrounding("[", "]").split(',').map { URI(it) }

val patches = patchesAsString.takeUnless { BUILDOZER_MISSING_VALUE in it }?.let {
logger.warn {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CarthageTest : WordSpec() {

"parse a binary dependency url" {
mockkStatic("kotlin.io.TextStreamsKt")
every { URI.create("https://host.tld/path/to/binary/spec.json").toURL().readBytes() } returns
every { URI("https://host.tld/path/to/binary/spec.json").toURL().readBytes() } returns
File("src/test/assets/Carthage-binary-specification.json").readText().toByteArray()

val cartfile = File("src/test/assets/Cartfile-binary.resolved")
Expand All @@ -99,7 +99,7 @@ class CarthageTest : WordSpec() {

"parse mixed dependencies" {
mockkStatic("kotlin.io.TextStreamsKt")
every { URI.create("https://host.tld/path/to/binary/spec.json").toURL().readBytes() } returns
every { URI("https://host.tld/path/to/binary/spec.json").toURL().readBytes() } returns
File("src/test/assets/Carthage-binary-specification.json").readText().toByteArray()

val cartfile = File("src/test/assets/Cartfile-mixed.resolved")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class GitTest : WordSpec({
}
})

private val TestUri = URIish(URI.create("https://www.example.org:8080/foo").toURL())
private val TestUri = URIish(URI("https://www.example.org:8080/foo").toURL())

/**
* Mocks the utility function to query password authentication for the test URI. Return the [result] provided.
Expand Down
4 changes: 2 additions & 2 deletions utils/ort/src/main/kotlin/OkHttpClientHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fun OkHttpClient.Builder.addBasicAuthorization(username: String, password: Strin
*/
fun OkHttpClient.downloadFile(url: String, directory: File): Result<File> {
if (url.startsWith("file:/")) {
val source = File(URI.create(url))
val source = File(URI(url))
val target = directory.resolve(source.name)
return runCatching { source.copyTo(target) }
}
Expand Down Expand Up @@ -199,7 +199,7 @@ fun OkHttpClient.downloadFile(url: String, directory: File): Result<File> {
* [Result] wrapping an [IOException] (which might be a [HttpDownloadError]) on failure.
*/
fun OkHttpClient.downloadText(url: String): Result<String> {
if (url.startsWith("file:/")) return runCatching { File(URI.create(url)).readText() }
if (url.startsWith("file:/")) return runCatching { File(URI(url)).readText() }

return download(url).mapCatching { (_, body) ->
body.use { it.string() }
Expand Down
2 changes: 1 addition & 1 deletion utils/ort/src/main/kotlin/storage/S3FileStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class S3FileStorage(
S3Client.builder()
.region(Region.of(awsRegion))
.credentialsProvider(provider)
.endpointOverride(if (customEndpoint != null) URI.create(customEndpoint) else null)
.endpointOverride(if (customEndpoint != null) URI(customEndpoint) else null)
.build()
} else {
if (awsRegion != null) {
Expand Down
2 changes: 1 addition & 1 deletion utils/ort/src/test/kotlin/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class UtilsTest : WordSpec({
val host = "www.example.org"
val port = 442
val scheme = "https"
val url = URI.create("https://foo:[email protected]").toURL()
val url = URI("https://foo:[email protected]").toURL()

val auth = OrtAuthenticator().requestPasswordAuthenticationInstance(
host,
Expand Down
2 changes: 1 addition & 1 deletion utils/spdx/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ScanCodeLicenseTextProvider : SpdxLicenseTextProvider {

private val spdxIdToScanCodeKeyMap: Map<String, String> by lazy {
val jsonSlurper = JsonSlurper()
val url = URI.create("https://scancode-licensedb.aboutcode.org/index.json").toURL()
val url = URI("https://scancode-licensedb.aboutcode.org/index.json").toURL()

logger.quiet("Downloading ScanCode license index...")

Expand Down

0 comments on commit fce2829

Please sign in to comment.