Skip to content
Permalink
Browse files

Add a new library module for interacting with the ClearDefined REST API

Signed-off-by: Sebastian Schuberth <sebastian.schuberth@bosch-si.com>
  • Loading branch information...
sschuberth committed Aug 19, 2019
1 parent a3ee50e commit 847eafbd8e39338b902e5f2e94bc1ad3c916884c
@@ -0,0 +1,12 @@
val retrofitVersion: String by project

plugins {
// Apply core plugins.
`java-library`
}

dependencies {
api("com.squareup.retrofit2:retrofit:$retrofitVersion")

implementation("com.squareup.retrofit2:converter-jackson:$retrofitVersion")
}
@@ -0,0 +1,160 @@
/*
* Copyright (C) 2019 Bosch Software Innovations GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

package com.here.ort.clearlydefined

import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonValue

import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.Retrofit
import retrofit2.converter.jackson.JacksonConverterFactory

import java.io.File
import java.net.URL

/**
* Interface for the ClearlyDefined REST API, based on code generated by https://app.quicktype.io/ from
* https://github.com/clearlydefined/service/tree/master/schemas.
*/
interface ClearlyDefinedService {
companion object {
fun create(server: Server): ClearlyDefinedService {
val retrofit = Retrofit.Builder()
.baseUrl(server.url)
.addConverterFactory(JacksonConverterFactory.create())
.build()

return retrofit.create(ClearlyDefinedService::class.java)
}
}

enum class Server(val url: String) {
PRODUCTION("https://api.clearlydefined.io"),
DEVELOPMENT("https://dev-api.clearlydefined.io"),
LOCALHOST("http://localhost:4000")
}

/**
* See https://github.com/clearlydefined/service/blob/master/schemas/curation-1.0.json.
*/
data class Curation(
val described: Described? = null,
val files: List<FileEntry>? = null,
val licensed: Licensed? = null
)

data class Described(
val facets: Facets? = null,
val issueTracker: URL? = null,
val projectWebsite: URL? = null,
val releaseDate: String? = null,
val sourceLocation: SourceLocation? = null
)

data class Facets(
val data: List<String>? = null,
val dev: List<String>? = null,
val doc: List<String>? = null,
val examples: List<String>? = null,
val tests: List<String>? = null
)

data class SourceLocation(
val name: String,
val namespace: String? = null,
val path: String? = null,
val provider: Provider,
val revision: String,
val type: Type,
val url: String? = null
)

// See https://github.com/clearlydefined/service/blob/master/schemas/curation-1.0.json#L44
enum class Provider(val value: String) {
COCOAPODS("cocoapods"),
CRATES_IO("cratesio"),
DEBIAN("debian"),
GITHUB("github"),
MAVEN_CENTRAL("mavencentral"),
NPM_JS("npmjs"),
NUGET("nuget"),
PACKAGIST("packagist"),
PYPI("pypi"),
RUBYGEMS("rubygems");

companion object {
@JsonCreator
@JvmStatic
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, true) }
}

@JsonValue
override fun toString() = value
}

// See https://github.com/clearlydefined/service/blob/master/schemas/curation-1.0.json#L23.
enum class Type(val value: String) {
COMPOSER("composer"),
CRATE("crate"),
DEBIAN("deb"),
DEBIAN_SOURCES("debsrc"),
GEM("gem"),
GIT("git"),
MAVEN("maven"),
NPM("npm"),
NUGET("nuget"),
POD("pod"),
PYPI("pypi"),
SOURCE_ARCHIVE("sourcearchive");

companion object {
@JsonCreator
@JvmStatic
fun fromString(value: String) = enumValues<Provider>().single { value.equals(it.value, true) }
}

@JsonValue
override fun toString() = value
}

data class FileEntry(
val attributions: List<String>? = null,
val license: String? = null,
val path: File
)

data class Licensed(
val declared: String? = null
)

/**
* Get a curation for a component revision.
*/
@GET("curations/{type}/{provider}/{namespace}/{name}/{revision}")
fun getCuration(
@Path("type") type: Type,
@Path("provider") provider: Provider,
@Path("namespace") namespace: String,
@Path("name") name: String,
@Path("revision") revision: String
): Call<Curation>
}
@@ -29,6 +29,7 @@ okhttpVersion = 4.1.1
postgresVersion = 42.2.6
postgresEmbeddedVersion = 0.13.1
reflectionsVersion = 0.9.11
retrofitVersion = 2.6.1
semverVersion = 3.0.0
simpleExcelVersion = 1.1
toml4jVersion = 0.7.2
@@ -25,6 +25,7 @@ pluginManagement {
rootProject.name = "oss-review-toolkit"

include("analyzer")
include("clearly-defined")
include("cli")
include("downloader")
include("evaluator")

0 comments on commit 847eafb

Please sign in to comment.
You can’t perform that action at this time.