/depchecker-core

A library to check artifact versions programmatically

Primary LanguageKotlinMIT LicenseMIT

depchecker-core

GitHub version Jitpack Version Build Status Codecov GitHub license

GitHub top language GitHub last commit GitHub commit activity GitHub issues

GitHub forks GitHub stars GitHub watchers

Description

A library to check artifact versions programmatically (currently with MavenCentral repository)

Adding to project

dependencies {
    implementation "com.github.icarohs7:depchecker-core:$depchecker_version"
}
repositories {
    maven { url "https://jitpack.io" }
}

Usage

Version Checking

The core functionality of this library is checking versions of artifacts, as below:

val artifact = Artifact("com.github.icarohs7.unoxlib:UNoxLib")
// OR
val artifact = Artifact(group = "com.github.icarohs7.unoxlib", artifactId = "UNoxLib")

// Returns a string with the last version of the artifact
assertThat(MavenCentralRepositoryImpl.getLastVersion(artifact), `is`("0.3.1"))

// Returns a list of versions of an artifact
val expectedVersionList = listOf(
    "0.3.1",
    "0.3.0",
    "0.2.4",
    "0.2.3",
    "0.2.0",
    "0.1.1"
)
assertThat(MavenCentralRepositoryImpl.getAllVersions(artifact), `is`(expectedVersionList))

Both functions can also be called as instance members of the class Artifact with the names
getLastVersionAt(DcRepository): String? and getAllVersionsAt(DcRepository): List<String>

Persisting artifacts

It also exposes a interface to be implemented to save collections of artifacts to the storage of your preference, coming with a buit-in in-memory implementation.

//Get an instance of the DAO used to store your saved artifacts
//getInMemoryDatabaseInstance() - Built-in implementation using RAM as storage
val artifactDao = ArtifactDao.getInMemoryDatabaseInstance()
val artifact = Artifact("com.github.icarohs7:depchecker-core")
  • Persisting an artifact
artifactDao.insert(artifact)
  • Reading the list of persisted artifacts
val allArtifacts = artifactDao.queryAll() 
assertThat(allArtifacts, `is`(listOf(artifact)))
  • Removing an artifact from the storage
artifactDao.remove(artifact)
  • Clearing the storage
artifactDao.removeAll()

Extending

It is possible to easily add more repositories by simply creating a class implementing the interface DcRepository and its methods,
as shown in the class MavenCentralRepositoryImpl, under the package repositories, you can also implement your storage method
through the interface ArtifactDao

More Examples

More usages can be found under the test package