Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Align on constructing URIs without create() #9610

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@

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())

Check warning on line 86 in helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt

View check run for this annotation

Codecov / codecov/patch

helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt#L86

Added line #L86 was not covered by tests
},
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())

Check warning on line 90 in helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt

View check run for this annotation

Codecov / codecov/patch

helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt#L90

Added line #L90 was not covered by tests

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

Expand All @@ -110,7 +110,7 @@
}
},
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())

Check warning on line 113 in helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt

View check run for this annotation

Codecov / codecov/patch

helper-cli/src/main/kotlin/commands/classifications/ImportCommand.kt#L113

Added line #L113 was not covered by tests
};

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
Loading