Skip to content

Commit

Permalink
Rename "provider" to "type" in an Identifier
Browse files Browse the repository at this point in the history
Also see the related purl discussion at [1]. What we were meaning by
"provider" actually more resembles purl's "type".

[1] package-url/purl-spec#33

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@here.com>
  • Loading branch information
sschuberth committed Dec 3, 2018
1 parent 65f9368 commit 05ac180
Show file tree
Hide file tree
Showing 33 changed files with 81 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.io.File
class DrupalIntegrationTest : AbstractIntegrationSpec() {
override val pkg: Package = Package(
id = Identifier(
provider = "PhpComposer",
type = "PhpComposer",
namespace = "",
name = "Drupal",
version = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.io.File
class GradleIntegrationTest : AbstractIntegrationSpec() {
override val pkg: Package = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "org.gradle",
name = "Gradle",
version = "4.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import java.io.File
class PolymerIntegrationTest : AbstractIntegrationSpec() {
override val pkg: Package = Package(
id = Identifier(
provider = "Bower",
type = "Bower",
namespace = "",
name = "polymer",
version = "2.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import java.io.File
class SimpleFormIntegrationTest : AbstractIntegrationSpec() {
override val pkg: Package = Package(
id = Identifier(
provider = "Bundler",
type = "Bundler",
namespace = "",
name = "Simple Form",
version = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import java.io.File
class VueJsIntegrationTest : AbstractIntegrationSpec() {
override val pkg: Package = Package(
id = Identifier(
provider = "NPM",
type = "NPM",
namespace = "",
name = "Vue.js",
version = ""
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/MavenSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class MavenSupport(workspaceReader: WorkspaceReader) {

return Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = mavenProject.groupId,
name = mavenProject.artifactId,
version = mavenProject.version
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/PackageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ abstract class PackageManager(

val errorProject = Project.EMPTY.copy(
id = Identifier(
provider = toString(),
type = toString(),
namespace = "",
name = relativePath,
version = ""
Expand Down
6 changes: 3 additions & 3 deletions analyzer/src/main/kotlin/managers/Bower.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ class Bower(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
private const val REQUIRED_BOWER_VERSION = "1.8.4"
private const val SCOPE_NAME_DEPENDENCIES = "dependencies"
private const val SCOPE_NAME_DEV_DEPENDENCIES = "devDependencies"
private const val PROVIDER_NAME = "Bower"
private const val PACKAGE_TYPE = "Bower"

private fun extractPackageId(node: JsonNode) = Identifier(
provider = PROVIDER_NAME,
type = PACKAGE_TYPE,
namespace = "",
name = node["pkgMeta"]["name"].textValueOrEmpty(),
version = node["pkgMeta"]["version"].textValueOrEmpty()
Expand Down Expand Up @@ -206,7 +206,7 @@ class Bower(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
Bower(analyzerConfig, repoConfig)
}

override fun toString() = PROVIDER_NAME
override fun toString() = PACKAGE_TYPE

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

Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/Gradle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Gradle(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfig

val project = Project(
id = Identifier(
provider = toString(),
type = toString(),
namespace = dependencyTreeModel.group,
name = dependencyTreeModel.name,
version = dependencyTreeModel.version
Expand Down Expand Up @@ -174,7 +174,7 @@ class Gradle(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfig
val rawPackage by lazy {
Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = dependency.groupId,
name = dependency.artifactId,
version = dependency.version
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/Maven.kt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Maven(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu

val project = Project(
id = Identifier(
provider = if (sbtMode) "SBT" else "Maven",
type = if (sbtMode) "SBT" else "Maven",
namespace = mavenProject.groupId,
name = mavenProject.artifactId,
version = mavenProject.version
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/NPM.kt
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ open class NPM(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConf

val module = Package(
id = Identifier(
provider = "NPM",
type = "NPM",
namespace = namespace,
name = name,
version = version
Expand Down Expand Up @@ -476,7 +476,7 @@ open class NPM(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConf

val project = Project(
id = Identifier(
provider = toString(),
type = toString(),
namespace = namespace,
name = name,
version = version
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/PIP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class PIP(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigura

val project = Project(
id = Identifier(
provider = toString(),
type = toString(),
namespace = "",
name = projectName,
version = projectVersion
Expand Down Expand Up @@ -439,7 +439,7 @@ class PIP(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigura

val pkg = Package(
id = Identifier(
provider = "PyPI",
type = "PyPI",
namespace = "",
name = name,
version = version
Expand Down
4 changes: 2 additions & 2 deletions analyzer/src/main/kotlin/managers/PhpComposer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class PhpComposer(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryC

return Project(
id = Identifier(
provider = toString(),
type = toString(),
namespace = rawName.substringBefore("/"),
name = rawName.substringAfter("/"),
version = json["version"].textValueOrEmpty()
Expand Down Expand Up @@ -225,7 +225,7 @@ class PhpComposer(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryC

packages[rawName] = Package(
id = Identifier(
provider = toString(),
type = toString(),
namespace = rawName.substringBefore("/"),
name = rawName.substringAfter("/"),
version = version
Expand Down
8 changes: 4 additions & 4 deletions analyzer/src/main/kotlin/managers/Stack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Stack(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
}

val projectPackage = parseCabalFile(cabalFile.readText())
val projectId = projectPackage.id.copy(provider = toString())
val projectId = projectPackage.id.copy(type = toString())

// Parse package information from the stack.yaml file.
fun runStack(vararg command: String): ProcessCapture {
Expand Down Expand Up @@ -168,7 +168,7 @@ class Stack(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
id = Identifier(
// The runtime system ships with the Glasgow Haskell Compiler (GHC) and is not hosted
// on Hackage.
provider = if (childName == "rts") "GHC" else "Hackage",
type = if (childName == "rts") "GHC" else "Hackage",
namespace = "",
name = childName,
version = versionMap[childName] ?: ""
Expand All @@ -182,7 +182,7 @@ class Stack(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
)

val pkg = allPackages.getOrPut(pkgTemplate) {
if (pkgTemplate.id.provider == "Hackage") {
if (pkgTemplate.id.type == "Hackage") {
// Enrich the package with additional meta-data from Hackage.
downloadCabalFile(pkgTemplate)?.let {
parseCabalFile(it)
Expand Down Expand Up @@ -315,7 +315,7 @@ class Stack(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryConfigu
val map = parseKeyValue(cabal.lines().listIterator())

val id = Identifier(
provider = "Hackage",
type = "Hackage",
namespace = map["category"] ?: "",
name = map["name"] ?: "",
version = map["version"] ?: ""
Expand Down
2 changes: 1 addition & 1 deletion analyzer/src/main/kotlin/managers/Unmanaged.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Unmanaged(analyzerConfig: AnalyzerConfiguration, repoConfig: RepositoryCon
override fun resolveDependencies(definitionFile: File): ProjectAnalyzerResult? {
val project = Project(
id = Identifier(
provider = toString(),
type = toString(),
namespace = "",
name = definitionFile.name,
version = ""
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/kotlin/commands/DownloaderCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object DownloaderCommand : CommandWithHelp() {

if (archive) {
val zipFile = File(outputDir,
"${pkg.id.provider.encodeOrUnknown()}-${pkg.id.namespace.encodeOrUnknown()}-" +
"${pkg.id.type.encodeOrUnknown()}-${pkg.id.namespace.encodeOrUnknown()}-" +
"${pkg.id.name.encodeOrUnknown()}-${pkg.id.version.encodeOrUnknown()}.zip")

log.info {
Expand Down
2 changes: 1 addition & 1 deletion downloader/src/funTest/kotlin/BabelTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BabelTest : StringSpec() {

val pkg = Package(
id = Identifier(
provider = "NPM",
type = "NPM",
namespace = "",
name = "babel-cli",
version = "6.26.0"
Expand Down
2 changes: 1 addition & 1 deletion downloader/src/funTest/kotlin/BeanUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class BeanUtilsTest : StringSpec() {

val pkg = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "commons-beanutils",
name = "commons-beanutils-bean-collections",
version = "1.8.3"
Expand Down
4 changes: 2 additions & 2 deletions downloader/src/funTest/kotlin/DirectoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DirectoryTest : StringSpec() {
"Creates directories for Gradle submodules" {
val pkg = Package(
id = Identifier(
provider = "provider",
type = "type",
namespace = "namespace",
name = "name",
version = "version"
Expand All @@ -68,7 +68,7 @@ class DirectoryTest : StringSpec() {
}

outputDir.list().size shouldBe 1
outputDir.list().first() shouldBe pkg.id.provider.fileSystemEncode()
outputDir.list().first() shouldBe pkg.id.type.fileSystemEncode()

val namespaceDir = File(outputDir, outputDir.list().first())
namespaceDir.list().size shouldBe 1
Expand Down
8 changes: 4 additions & 4 deletions downloader/src/funTest/kotlin/DownloaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DownloaderTest : StringSpec() {
"Downloads and unpacks JAR source package".config(tags = setOf(ExpensiveTag)) {
val pkg = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "junit",
name = "junit",
version = "4.12"
Expand Down Expand Up @@ -85,7 +85,7 @@ class DownloaderTest : StringSpec() {
"Download of JAR source package fails when hash is incorrect".config(tags = setOf(ExpensiveTag)) {
val pkg = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "junit",
name = "junit",
version = "4.12"
Expand Down Expand Up @@ -113,7 +113,7 @@ class DownloaderTest : StringSpec() {
"Falls back to downloading source package when download from VCS fails".config(tags = setOf(ExpensiveTag)) {
val pkg = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "junit",
name = "junit",
version = "4.12"
Expand Down Expand Up @@ -152,7 +152,7 @@ class DownloaderTest : StringSpec() {
val url = "https://master.dl.sourceforge.net/project/tyrex/tyrex/Tyrex%201.0.1/tyrex-1.0.1-src.tgz"
val pkg = Package(
id = Identifier(
provider = "Maven",
type = "Maven",
namespace = "tyrex",
name = "tyrex",
version = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion downloader/src/main/kotlin/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Downloader {

try {
if (target.vcsProcessed.url.isBlank()) {
val details = when (target.id.provider) {
val details = when (target.id.type) {
"Bundler" -> " Please define the \"source_code_uri\" in the \"metadata\" of the Gemspec, see: " +
"https://guides.rubygems.org/specification-reference/#metadata"
"Gradle" -> " Please make sure the release POM file includes the SCM connection, see: " +
Expand Down
27 changes: 13 additions & 14 deletions model/src/main/kotlin/Identifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import com.here.ort.utils.encodeOrUnknown
*/
data class Identifier(
/**
* The name of the provider that hosts this package, for example Maven or NPM.
* The type of package, i.e. its packaging type, for example "Maven" or "NPM".
*/
val provider: String,
val type: String,

/**
* The namespace of the package, for example the group id in Maven or the scope in NPM.
* The namespace of the package, for example the group for "Maven" or the scope for "NPM".
*/
val namespace: String,

Expand All @@ -56,33 +56,33 @@ data class Identifier(
*/
@JvmField
val EMPTY = Identifier(
provider = "",
type = "",
namespace = "",
name = "",
version = ""
)
}

private constructor(components: List<String>) : this(
provider = components.getOrElse(0) { "" },
type = components.getOrElse(0) { "" },
namespace = components.getOrElse(1) { "" },
name = components.getOrElse(2) { "" },
version = components.getOrElse(3) { "" }
)

/**
* Create an [Identifier] from a string with the format "provider:namespace:name:version". If the string has less
* than three colon separators the missing values are assigned empty strings.
* Create an [Identifier] from a string with the format "type:namespace:name:version". If the string has less than
* three colon separators the missing values are assigned empty strings.
*/
@JsonCreator
constructor(identifier: String) : this(identifier.split(':'))

private val components = listOf(provider, namespace, name, version)
private val components = listOf(type, namespace, name, version)

init {
require(components.none { ":" in it }) {
"Properties of Identifier must not contain ':' because it is used as a separator in the String " +
"representation of the Identifier: provider='$provider', namespace='$namespace', name='$name', " +
"representation of the Identifier: type='$type', namespace='$namespace', name='$name', " +
"version='$version'"
}
}
Expand All @@ -94,7 +94,7 @@ data class Identifier(
*/
fun isFromVendor(name: String): Boolean {
val lowerName = name.toLowerCase()
val vendorNamespace = when (provider) {
val vendorNamespace = when (type) {
"NPM" -> "@$lowerName"
"Gradle", "Maven", "SBT" -> "com.$lowerName"
else -> ""
Expand All @@ -104,9 +104,8 @@ data class Identifier(
}

/**
* Return true if this matches the other identifier. To match, both identifiers need to have the same
* [provider] and [namespace], and the [name] and [version] must be either equal or empty for at least one of
* them.
* Return true if this matches the other identifier. To match, both identifiers need to have the same [type] and
* [namespace], and the [name] and [version] must be either equal or empty for at least one of them.
*
* Examples for matching identifiers:
* * "maven:org.hamcrest:hamcrest-core:1.3" <-> "maven:org.hamcrest:hamcrest-core:"
Expand All @@ -118,7 +117,7 @@ data class Identifier(
* * "maven:org.hamcrest:hamcrest-core:" <-> "maven:org.hamcrest:hamcrest-library:"
*/
fun matches(other: Identifier): Boolean {
if (!provider.equals(other.provider, true)) {
if (!type.equals(other.type, true)) {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion model/src/test/assets/deprecated-errors-scan-results.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
id: "provider:namespace:name:version"
id: "type:namespace:name:version"
results:
- provenance:
download_time: "1970-01-02T00:00:00Z"
Expand Down
Loading

0 comments on commit 05ac180

Please sign in to comment.