Skip to content

Commit

Permalink
Switch from the unmaintained vdurmont/semver4j to semver4j/semver4j
Browse files Browse the repository at this point in the history
The new semver4j GitHub organization contains a maintained fork / copy
of the original semver4j library by @vdurmont. However, the API changed
quite significantly. Catch up with those changes in order to (partly) fix
issue #6153.

[1]: https://github.com/semver4j/semver4j

Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
  • Loading branch information
sschuberth committed Jan 4, 2023
1 parent db46c9c commit 0f61618
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 86 deletions.
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package org.ossreviewtoolkit.analyzer.managers

import com.fasterxml.jackson.databind.JsonNode

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.util.SortedSet
import java.util.Stack
Expand Down Expand Up @@ -50,6 +48,9 @@ import org.ossreviewtoolkit.utils.common.fieldsOrEmpty
import org.ossreviewtoolkit.utils.common.stashDirectories
import org.ossreviewtoolkit.utils.common.textValueOrEmpty

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [Bower](https://bower.io/) package manager for JavaScript.
*/
Expand Down Expand Up @@ -225,7 +226,7 @@ class Bower(

override fun command(workingDir: File?) = if (Os.isWindows) "bower.cmd" else "bower"

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[1.8.8,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[1.8.8,)")

override fun beforeResolution(definitionFiles: List<File>) = checkVersion()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/CocoaPods.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.node.ObjectNode

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.util.SortedSet

Expand Down Expand Up @@ -60,6 +58,9 @@ import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.common.stashDirectories
import org.ossreviewtoolkit.utils.common.textValueOrEmpty

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [CocoaPods](https://cocoapods.org/) package manager for Objective-C.
*
Expand Down Expand Up @@ -93,7 +94,7 @@ class CocoaPods(

override fun command(workingDir: File?) = "pod"

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[1.11.0,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[1.11.0,)")

override fun getVersionArguments() = "--version --allow-root"

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Composer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package org.ossreviewtoolkit.analyzer.managers
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ObjectNode

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.io.IOException
import java.util.SortedSet
Expand Down Expand Up @@ -58,6 +56,9 @@ import org.ossreviewtoolkit.utils.common.stashDirectories
import org.ossreviewtoolkit.utils.common.textValueOrEmpty
import org.ossreviewtoolkit.utils.ort.showStackTrace

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

const val COMPOSER_PHAR_BINARY = "composer.phar"
const val COMPOSER_LOCK_FILE = "composer.lock"

Expand Down Expand Up @@ -108,7 +109,7 @@ class Composer(
// Composer version @package_branch_alias_version@ (1.0.0-beta2) 2016-03-27 16:00:34
output.splitOnWhitespace().dropLast(2).last().removeSurrounding("(", ")")

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[1.5,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[1.5,)")

override fun beforeResolution(definitionFiles: List<File>) {
// If all directories we are analyzing contain a composer.phar, no global installation of Composer is required
Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Conan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package org.ossreviewtoolkit.analyzer.managers
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.readValue

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.util.SortedSet

Expand Down Expand Up @@ -57,6 +55,9 @@ import org.ossreviewtoolkit.utils.common.toUri
import org.ossreviewtoolkit.utils.ort.createOrtTempDir
import org.ossreviewtoolkit.utils.ort.requestPasswordAuthentication

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [Conan](https://conan.io/) package manager for C / C++.
*
Expand Down Expand Up @@ -114,7 +115,7 @@ class Conan(
// Conan version 1.18.0
output.removePrefix("Conan version ")

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[1.18.0,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[1.18.0,)")

override fun beforeResolution(definitionFiles: List<File>) = checkVersion()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Npm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ package org.ossreviewtoolkit.analyzer.managers
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.ObjectNode

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.util.concurrent.ConcurrentHashMap

Expand Down Expand Up @@ -81,6 +79,9 @@ import org.ossreviewtoolkit.utils.common.realFile
import org.ossreviewtoolkit.utils.common.stashDirectories
import org.ossreviewtoolkit.utils.common.textValueOrEmpty

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [Node package manager](https://www.npmjs.com/) for JavaScript.
*
Expand Down Expand Up @@ -145,7 +146,7 @@ open class Npm(

override fun command(workingDir: File?) = if (Os.isWindows) "npm.cmd" else "npm"

override fun getVersionRequirement(): Requirement = Requirement.buildNPM("6.* - 8.*")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("6.* - 8.*")

override fun mapDefinitionFiles(definitionFiles: List<File>) = mapDefinitionFilesForNpm(definitionFiles).toList()

Expand Down
9 changes: 5 additions & 4 deletions analyzer/src/main/kotlin/managers/Pipenv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.ossreviewtoolkit.analyzer.managers

import com.vdurmont.semver4j.Requirement
import com.vdurmont.semver4j.Semver

import java.io.File

import org.apache.logging.log4j.kotlin.Logging
Expand All @@ -34,6 +31,10 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.ProcessCapture

import org.semver4j.RangesList
import org.semver4j.RangesListFactory
import org.semver4j.Semver

/**
* The version that introduced the requirements command.
*/
Expand Down Expand Up @@ -64,7 +65,7 @@ class Pipenv(
// pipenv, version 2018.11.26
output.removePrefix("pipenv, version ")

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[2018.10.9,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[2018.10.9,)")

override fun beforeResolution(definitionFiles: List<File>) = checkVersion()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Pnpm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.ossreviewtoolkit.analyzer.managers

import com.vdurmont.semver4j.Requirement

import java.io.File

import org.ossreviewtoolkit.analyzer.AbstractPackageManagerFactory
Expand All @@ -31,6 +29,9 @@ import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.realFile

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [fast, disk space efficient package manager](https://pnpm.io/).
*/
Expand Down Expand Up @@ -69,7 +70,7 @@ class Pnpm(

override fun command(workingDir: File?) = if (Os.isWindows) "pnpm.cmd" else "pnpm"

override fun getVersionRequirement(): Requirement = Requirement.buildNPM("5.* - 7.*")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("5.* - 7.*")

override fun mapDefinitionFiles(definitionFiles: List<File>) = mapDefinitionFilesForPnpm(definitionFiles).toList()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package org.ossreviewtoolkit.analyzer.managers
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.dataformat.yaml.JacksonYAMLParseException

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.io.IOException
import java.util.SortedSet
Expand Down Expand Up @@ -68,6 +66,9 @@ import org.ossreviewtoolkit.utils.ort.OkHttpClientHelper
import org.ossreviewtoolkit.utils.ort.ortToolsDirectory
import org.ossreviewtoolkit.utils.ort.showStackTrace

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

private const val GRADLE_VERSION = "7.3"
private const val PUBSPEC_YAML = "pubspec.yaml"
private const val PUB_LOCK_FILE = "pubspec.lock"
Expand Down Expand Up @@ -121,7 +122,7 @@ class Pub(

override fun transformVersion(output: String) = output.removePrefix("Dart SDK version: ").substringBefore(' ')

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[2.10,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[2.10,)")

override fun beforeResolution(definitionFiles: List<File>) {
gradleDefinitionFilesForPubDefinitionFiles.clear()
Expand Down
13 changes: 7 additions & 6 deletions analyzer/src/main/kotlin/managers/Sbt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.ossreviewtoolkit.analyzer.managers

import com.vdurmont.semver4j.Requirement
import com.vdurmont.semver4j.Semver

import java.io.File
import java.io.IOException
import java.nio.file.StandardCopyOption
Expand All @@ -43,6 +40,10 @@ import org.ossreviewtoolkit.utils.common.searchUpwardsForSubdirectory
import org.ossreviewtoolkit.utils.common.suppressInput
import org.ossreviewtoolkit.utils.ort.createOrtTempDir

import org.semver4j.RangesList
import org.semver4j.RangesListFactory
import org.semver4j.Semver

/**
* The [SBT](https://www.scala-sbt.org/) package manager for Scala.
*/
Expand Down Expand Up @@ -121,11 +122,11 @@ class Sbt(
return checkForSameSbtVersion(versions)
}

override fun getVersionRequirement(): Requirement =
override fun getVersionRequirement(): RangesList =
// We need at least sbt version 0.13.0 to be able to use "makePom" instead of the deprecated hyphenated
// form "make-pom" and to support declaring Maven-style repositories, see
// http://www.scala-sbt.org/0.13/docs/Publishing.html#Modifying+the+generated+POM.
Requirement.buildIvy("[0.13.0,)")
RangesListFactory.create("[0.13.0,)")

private fun checkForSameSbtVersion(versions: List<Semver>): String {
val uniqueVersions = versions.toSortedSet()
Expand Down Expand Up @@ -202,7 +203,7 @@ class Sbt(
val sbtVersionRequirement = getVersionRequirement()
val lowestSbtVersion = checkForSameSbtVersion(versions)

if (!sbtVersionRequirement.isSatisfiedBy(lowestSbtVersion)) {
if (!Semver(lowestSbtVersion).satisfies(sbtVersionRequirement)) {
throw IOException(
"Unsupported $managerName version $lowestSbtVersion does not fulfill " +
"$sbtVersionRequirement."
Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ package org.ossreviewtoolkit.analyzer.managers
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.module.kotlin.readValue

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.io.IOException
import java.util.SortedSet
Expand Down Expand Up @@ -52,6 +50,9 @@ import org.ossreviewtoolkit.utils.common.ProcessCapture
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
import org.ossreviewtoolkit.utils.ort.OkHttpClientHelper

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

/**
* The [Stack](https://haskellstack.org/) package manager for Haskell.
*/
Expand Down Expand Up @@ -103,7 +104,7 @@ class Stack(
// Version 2.1.1, Git revision f612ea85316bbc327a64e4ad8d9f0b150dc12d4b (7648 commits) x86_64 hpack-0.31.2
output.removePrefix("Version ").substringBefore(',').substringBefore(' ')

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[2.1.1,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[2.1.1,)")

override fun beforeResolution(definitionFiles: List<File>) = checkVersion()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Yarn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ package org.ossreviewtoolkit.analyzer.managers

import com.fasterxml.jackson.databind.JsonNode

import com.vdurmont.semver4j.Requirement

import java.io.File

import kotlin.time.Duration.Companion.days
Expand All @@ -40,6 +38,9 @@ import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.mebibytes
import org.ossreviewtoolkit.utils.ort.ortDataDirectory

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

private val yarnInfoCache = DiskCache(
directory = ortDataDirectory.resolve("cache/analyzer/yarn/info"),
maxCacheSizeInBytes = 100.mebibytes,
Expand Down Expand Up @@ -71,7 +72,7 @@ class Yarn(

override fun command(workingDir: File?) = if (Os.isWindows) "yarn.cmd" else "yarn"

override fun getVersionRequirement(): Requirement = Requirement.buildNPM("1.3.* - 1.22.*")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("1.3.* - 1.22.*")

override fun mapDefinitionFiles(definitionFiles: List<File>) = mapDefinitionFilesForYarn(definitionFiles).toList()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/Yarn2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import com.fasterxml.jackson.module.kotlin.readValues

import com.vdurmont.semver4j.Requirement

import java.io.File

import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -72,6 +70,9 @@ import org.ossreviewtoolkit.utils.common.ProcessCapture
import org.ossreviewtoolkit.utils.common.textValueOrEmpty
import org.ossreviewtoolkit.utils.ort.showStackTrace

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

internal const val OPTION_DISABLE_REGISTRY_CERTIFICATE_VERIFICATION = "disableRegistryCertificateVerification"

// The various Yarn dependency types supported by this package manager.
Expand Down Expand Up @@ -189,7 +190,7 @@ class Yarn2(
// TODO: An alternative would be to collate the versions of all tools in `yarn2CommandsByPath`.
if (workingDir == null) "" else super.getVersion(workingDir)

override fun getVersionRequirement(): Requirement = Requirement.buildNPM(">=2.0.0")
override fun getVersionRequirement(): RangesList = RangesListFactory.create(">=2.0.0")

override fun mapDefinitionFiles(definitionFiles: List<File>) = mapDefinitionFilesForYarn2(definitionFiles).toList()

Expand Down
7 changes: 4 additions & 3 deletions analyzer/src/main/kotlin/managers/utils/PythonInspector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.ossreviewtoolkit.analyzer.managers.utils

import com.vdurmont.semver4j.Requirement

import java.io.File
import java.util.SortedSet

Expand Down Expand Up @@ -48,6 +46,9 @@ import org.ossreviewtoolkit.utils.ort.ProcessedDeclaredLicense
import org.ossreviewtoolkit.utils.ort.createOrtTempFile
import org.ossreviewtoolkit.utils.spdx.SpdxLicenseIdExpression

import org.semver4j.RangesList
import org.semver4j.RangesListFactory

private const val GENERIC_BSD_LICENSE = "BSD License"
private const val SHORT_STRING_MAX_CHARS = 200

Expand All @@ -58,7 +59,7 @@ internal object PythonInspector : CommandLineTool, Logging {

override fun transformVersion(output: String) = output.removePrefix("Python-inspector version: ")

override fun getVersionRequirement(): Requirement = Requirement.buildIvy("[0.9.2,)")
override fun getVersionRequirement(): RangesList = RangesListFactory.create("[0.9.2,)")

fun run(
workingDir: File,
Expand Down
Loading

0 comments on commit 0f61618

Please sign in to comment.