-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add librarianGenerateBintrayGroups task
- Loading branch information
Showing
20 changed files
with
502 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
plugin-core/src/main/kotlin/net/meilcli/librarian/plugin/entities/BintrayLicense.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package net.meilcli.librarian.plugin.entities | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BintrayLicense( | ||
@SerialName("name") | ||
val name: String, | ||
|
||
@SerialName("longname") | ||
val fullName: String, | ||
|
||
@SerialName("url") | ||
val url: String | ||
) |
28 changes: 28 additions & 0 deletions
28
plugin-core/src/main/kotlin/net/meilcli/librarian/plugin/entities/BintrayPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net.meilcli.librarian.plugin.entities | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BintrayPackage( | ||
@SerialName("repo") | ||
val repository: String, | ||
|
||
@SerialName("owner") | ||
val owner: String, | ||
|
||
@SerialName("desc") | ||
val description: String? = null, | ||
|
||
@SerialName("licenses") | ||
val licenses: List<String> = emptyList(), | ||
|
||
@SerialName("github_repo") | ||
val githubRepository: String? = null, | ||
|
||
@SerialName("vcs_url") | ||
val vcsUrl: String? = null, | ||
|
||
@SerialName("website_url") | ||
val websiteUrl: String? = null | ||
) |
3 changes: 3 additions & 0 deletions
3
plugin-core/src/main/kotlin/net/meilcli/librarian/plugin/entities/BintrayRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package net.meilcli.librarian.plugin.entities | ||
|
||
data class BintrayRepository(val url: String, val repository: String, val owner: String) |
19 changes: 19 additions & 0 deletions
19
plugin-core/src/main/kotlin/net/meilcli/librarian/plugin/entities/BintraySearchResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package net.meilcli.librarian.plugin.entities | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BintraySearchResult( | ||
@SerialName("name") | ||
val packageName: String, | ||
|
||
@SerialName("owner") | ||
val owner: String, | ||
|
||
@SerialName("repo") | ||
val repository: String | ||
) { | ||
|
||
fun urlEscapedPackageName() = packageName.replace(":", "&3A") | ||
} |
14 changes: 14 additions & 0 deletions
14
.../kotlin/net/meilcli/librarian/plugin/internal/artifacts/ArtifactsByLibraryGroupsFilter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.meilcli.librarian.plugin.internal.artifacts | ||
|
||
import net.meilcli.librarian.plugin.entities.Artifact | ||
import net.meilcli.librarian.plugin.entities.LibraryGroup | ||
import net.meilcli.librarian.plugin.internal.IFilter | ||
|
||
class ArtifactsByLibraryGroupsFilter( | ||
private val libraryGroups: List<LibraryGroup> | ||
) : IFilter<Collection<Artifact>> { | ||
|
||
override fun filter(source: Collection<Artifact>): Collection<Artifact> { | ||
return source.filter { x -> libraryGroups.all { y -> y.artifacts.contains(x.artifact).not() } } | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...i/librarian/plugin/internal/bintray/ArtifactAndBintrayRepositoryToBintrayPackageLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package net.meilcli.librarian.plugin.internal.bintray | ||
|
||
import net.meilcli.librarian.plugin.entities.Artifact | ||
import net.meilcli.librarian.plugin.entities.BintrayPackage | ||
import net.meilcli.librarian.plugin.entities.BintrayRepository | ||
import net.meilcli.librarian.plugin.internal.IParameterizedLoader | ||
import org.gradle.api.Project | ||
import org.slf4j.LoggerFactory | ||
|
||
class ArtifactAndBintrayRepositoryToBintrayPackageLoader( | ||
private val project: Project | ||
) : IParameterizedLoader<Pair<Artifact, BintrayRepository>, BintrayPackage?> { | ||
|
||
private val api = IBintrayApi.default | ||
private val logger = LoggerFactory.getLogger(ArtifactAndBintrayRepositoryToBintrayPackageLoader::class.java) | ||
private val resultCache = mutableMapOf<Pair<Artifact, BintrayRepository>, BintrayPackage?>() | ||
private var notService = false | ||
|
||
override fun load(parameter: Pair<Artifact, BintrayRepository>): BintrayPackage? { | ||
if (notService) { | ||
project.logger.quiet("not service hit") | ||
return null | ||
} | ||
if (resultCache.containsKey(parameter)) { | ||
project.logger.quiet("cache hit") | ||
return resultCache[parameter] | ||
} | ||
|
||
try { | ||
// search package name, because name convention is difference each repository | ||
val searchResponse = api | ||
.searchPackage( | ||
group = parameter.first.group, | ||
artifact = parameter.first.name, | ||
owner = parameter.second.owner, | ||
repository = parameter.second.repository | ||
) | ||
.execute() | ||
|
||
if (500 <= searchResponse.code()) { | ||
notService = true | ||
return null | ||
} | ||
if (searchResponse.isSuccessful.not()) { | ||
resultCache[parameter] = null | ||
return null | ||
} | ||
|
||
val searchResults = searchResponse.body() | ||
if (searchResults == null) { | ||
resultCache[parameter] = null | ||
return null | ||
} | ||
val searchResult = searchResults.find { | ||
it.owner == parameter.second.owner && it.repository == parameter.second.repository | ||
} | ||
if (searchResult == null) { | ||
resultCache[parameter] = null | ||
return null | ||
} | ||
|
||
val packageResponse = api | ||
.getPackage( | ||
owner = parameter.second.owner, | ||
repository = parameter.second.repository, | ||
packageName = searchResult.packageName | ||
) | ||
.execute() | ||
|
||
if (500 <= packageResponse.code()) { | ||
notService = true | ||
return null | ||
} | ||
if (packageResponse.isSuccessful.not()) { | ||
resultCache[parameter] = null | ||
return null | ||
} | ||
|
||
resultCache[parameter] = packageResponse.body() | ||
return resultCache[parameter] | ||
} catch (exception: Exception) { | ||
logger.warn("Librarian unknown exception", exception) | ||
project.logger.quiet("exception") | ||
return null | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...kotlin/net/meilcli/librarian/plugin/internal/bintray/ArtifactToBintrayRepositoryLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.meilcli.librarian.plugin.internal.bintray | ||
|
||
import net.meilcli.librarian.plugin.entities.Artifact | ||
import net.meilcli.librarian.plugin.entities.BintrayRepository | ||
import net.meilcli.librarian.plugin.internal.ILoader | ||
import net.meilcli.librarian.plugin.internal.IParameterizedLoader | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import org.slf4j.LoggerFactory | ||
|
||
class ArtifactToBintrayRepositoryLoader( | ||
bintrayRepositoriesLoader: ILoader<List<BintrayRepository>> | ||
) : IParameterizedLoader<Artifact, BintrayRepository?> { | ||
|
||
private val client = OkHttpClient() | ||
private val logger = LoggerFactory.getLogger(ArtifactToBintrayRepositoryLoader::class.java) | ||
private val bintrayRepositories = bintrayRepositoriesLoader.load() | ||
private val notServiceRepositories = mutableListOf<BintrayRepository>() | ||
private val resultCache = mutableMapOf<Artifact, BintrayRepository?>() | ||
|
||
override fun load(parameter: Artifact): BintrayRepository? { | ||
if (resultCache.containsKey(parameter)) { | ||
return resultCache[parameter] | ||
} | ||
for (bintrayRepository in bintrayRepositories) { | ||
if (notServiceRepositories.contains(bintrayRepository)) { | ||
continue | ||
} | ||
|
||
val httpStatusCode = try { | ||
head(bintrayRepository, parameter) | ||
} catch (exception: Exception) { | ||
logger.warn("Librarian: unknown exception when head bintray", exception) | ||
400 | ||
} | ||
if (500 <= httpStatusCode) { | ||
notServiceRepositories += bintrayRepository | ||
continue | ||
} | ||
if (300 <= httpStatusCode) { | ||
continue | ||
} | ||
resultCache[parameter] = bintrayRepository | ||
return bintrayRepository | ||
} | ||
|
||
return null | ||
} | ||
|
||
private fun head(bintrayRepository: BintrayRepository, artifact: Artifact): Int { | ||
fun String.replaceDot(): String { | ||
return replace('.', '/') | ||
} | ||
|
||
val request = Request.Builder() | ||
.head() | ||
.url("${bintrayRepository.url}/${artifact.group.replaceDot()}/${artifact.name}/${artifact.version}/${artifact.name}-${artifact.version}.pom") | ||
.build() | ||
|
||
client.newCall(request).execute().use { | ||
return it.code | ||
} | ||
} | ||
} |
Oops, something went wrong.