Skip to content

Commit

Permalink
Move the isMavenCentralUrl function from core-utils to `common-ut…
Browse files Browse the repository at this point in the history
…ils`

This function can be used independently of ORT.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 5, 2021
1 parent f59c465 commit a82648b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/utils/MavenSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.yamlMapper
import org.ossreviewtoolkit.utils.common.DiskCache
import org.ossreviewtoolkit.utils.common.collectMessagesAsString
import org.ossreviewtoolkit.utils.common.isMavenCentralUrl
import org.ossreviewtoolkit.utils.common.searchUpwardsForSubdirectory
import org.ossreviewtoolkit.utils.common.withoutPrefix
import org.ossreviewtoolkit.utils.core.DeclaredLicenseProcessor
import org.ossreviewtoolkit.utils.core.OkHttpClientHelper
import org.ossreviewtoolkit.utils.core.ProcessedDeclaredLicense
import org.ossreviewtoolkit.utils.core.installAuthenticatorAndProxySelector
import org.ossreviewtoolkit.utils.core.isMavenCentralUrl
import org.ossreviewtoolkit.utils.core.log
import org.ossreviewtoolkit.utils.core.logOnce
import org.ossreviewtoolkit.utils.core.ortDataDirectory
Expand Down
2 changes: 1 addition & 1 deletion reporter/src/main/kotlin/reporters/StaticHtmlReporter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ import org.ossreviewtoolkit.reporter.ReporterInput
import org.ossreviewtoolkit.reporter.SCOPE_EXCLUDE_LIST_COMPARATOR
import org.ossreviewtoolkit.reporter.containsUnresolved
import org.ossreviewtoolkit.reporter.description
import org.ossreviewtoolkit.utils.common.isMavenCentralUrl
import org.ossreviewtoolkit.utils.common.isValidUri
import org.ossreviewtoolkit.utils.common.normalizeLineBreaks
import org.ossreviewtoolkit.utils.core.Environment
import org.ossreviewtoolkit.utils.core.ORT_FULL_NAME
import org.ossreviewtoolkit.utils.core.isMavenCentralUrl
import org.ossreviewtoolkit.utils.spdx.SpdxCompoundExpression
import org.ossreviewtoolkit.utils.spdx.SpdxConstants
import org.ossreviewtoolkit.utils.spdx.SpdxExpression
Expand Down
7 changes: 7 additions & 0 deletions utils/common/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ fun getCommonFileParent(files: Collection<File>): File? =
if (commonPrefix.isDirectory) commonPrefix else commonPrefix.parentFile
}

private val mavenCentralUrlPattern = Regex("^https?://repo1?\\.maven(\\.apache)?\\.org(/.*)?$")

/**
* Return whether the given [url] points to Maven Central or not.
*/
fun isMavenCentralUrl(url: String) = url.matches(mavenCentralUrlPattern)

/**
* Return the concatenated [strings] separated by [separator] whereas blank strings are omitted.
*/
Expand Down
25 changes: 25 additions & 0 deletions utils/common/src/test/kotlin/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.ossreviewtoolkit.utils.common

import io.kotest.core.spec.style.WordSpec
import io.kotest.inspectors.forAll
import io.kotest.matchers.collections.containExactly
import io.kotest.matchers.nulls.beNull
import io.kotest.matchers.should
Expand Down Expand Up @@ -57,4 +58,28 @@ class UtilsTest : WordSpec({
)
}
}

"isMavenCentralUrl" should {
"return true for URLs that point to Maven Central" {
listOf(
"https://repo.maven.apache.org/maven2",
"https://repo.maven.apache.org",
"http://repo.maven.apache.org",
"https://repo1.maven.org/maven2",
"https://repo1.maven.org",
"http://repo1.maven.org"
).forAll {
isMavenCentralUrl(it) shouldBe true
}
}

"return false for URLs that do not point to Maven Central" {
listOf(
"https://repo2.maven.org",
"https://github.com"
).forAll {
isMavenCentralUrl(it) shouldBe false
}
}
}
})
7 changes: 0 additions & 7 deletions utils/core/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import org.ossreviewtoolkit.utils.common.toUri
import org.ossreviewtoolkit.utils.common.withoutPrefix
import org.ossreviewtoolkit.utils.common.withoutSuffix

private val mavenCentralUrlPattern = Regex("^https?://repo1?\\.maven(\\.apache)?\\.org(/.*)?$")

/**
* The directory to store ORT (read-only) configuration in.
*/
Expand Down Expand Up @@ -142,11 +140,6 @@ fun installAuthenticatorAndProxySelector(): OrtProxySelector {
return OrtProxySelector.install()
}

/**
* Return whether the given [url] points to Maven Central or not.
*/
fun isMavenCentralUrl(url: String) = url.matches(mavenCentralUrlPattern)

/**
* Normalize a string representing a [VCS URL][vcsUrl] to a common string form.
*/
Expand Down
24 changes: 0 additions & 24 deletions utils/core/src/test/kotlin/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,6 @@ class UtilsTest : WordSpec({
}
}

"isMavenCentralUrl()" should {
"return true for URLs that point to Maven Central" {
listOf(
"https://repo.maven.apache.org/maven2",
"https://repo.maven.apache.org",
"http://repo.maven.apache.org",
"https://repo1.maven.org/maven2",
"https://repo1.maven.org",
"http://repo1.maven.org"
).forAll {
isMavenCentralUrl(it) shouldBe true
}
}

"return false for URLs that do not point to Maven Central" {
listOf(
"https://repo2.maven.org",
"https://github.com"
).forAll {
isMavenCentralUrl(it) shouldBe false
}
}
}

"normalizeVcsUrl" should {
"do nothing for empty URLs" {
normalizeVcsUrl("") shouldBe ""
Expand Down

0 comments on commit a82648b

Please sign in to comment.