-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Readme, license and DependencyGetter
- Loading branch information
1 parent
c002e64
commit cc12672
Showing
6 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
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,7 @@ | ||
Copyright 2020 Xavier "jglrxavpok" Niochaut & Minestom Team | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,46 @@ | ||
# Dependency-Getter | ||
Abstraction layer over dependencies. | ||
Allows downloading artifacts from a coordinate. | ||
|
||
This library is centered around resolvers. Resolvers are the objects responsible for finding the dependency | ||
inside its locations (repositories for Maven, for instance). | ||
|
||
Throws an `UnresolvedDependencyException` if the dependency could not be resolved. | ||
|
||
# On Maven resolvers | ||
Maven resolvers will download to the given target folder. They also use this target folder as a local | ||
maven repository: any already downloaded artifact will not be redownloaded (with the exception of snapshots). | ||
|
||
They also create a temporary folder `.tmp` inside the target folder to store a Maven `settings.xml` file to specify | ||
a local repository and remote repositories. | ||
|
||
# Example | ||
|
||
## Hello Dependency | ||
```kotlin | ||
val dependencyGetter = DependencyGetter() | ||
.addResolver(MyResolver()) | ||
.addMavenResolver(repositories = listOf( | ||
MavenRepository.Jitpack, | ||
MavenRepository.Central, | ||
MavenRepository.JCenter, | ||
MavenRepository("Minecraft Libs", "https://libraries.minecraft.net"), | ||
MavenRepository("Sponge", "https://repo.spongepowered.org/maven"), | ||
)) | ||
val resolved = dependencyGetter.get("com.github.Minestom:Minestom:32d13dcbd1", targetFolder) | ||
resolved.printTree() | ||
``` | ||
|
||
## Using a Resolver directly | ||
```kotlin | ||
val repositories = listOf( | ||
MavenRepository.Jitpack, | ||
MavenRepository.Central, | ||
MavenRepository.JCenter, | ||
MavenRepository("Minecraft Libs", "https://libraries.minecraft.net"), | ||
MavenRepository("Sponge", "https://repo.spongepowered.org/maven"), | ||
) | ||
val resolver = MavenResolver(repositories) | ||
val resolved = resolver.resolve("com.github.Minestom:Minestom:32d13dcbd1", targetFolder) | ||
resolved.printTree() | ||
``` |
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/net/minestom/dependencies/DependencyGetter.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,32 @@ | ||
package net.minestom.dependencies | ||
|
||
import net.minestom.dependencies.maven.MavenRepository | ||
import net.minestom.dependencies.maven.MavenResolver | ||
import java.io.File | ||
|
||
class DependencyGetter { | ||
|
||
private val resolverList = mutableListOf<DependencyResolver>() | ||
val resolvers: List<DependencyResolver> get()= resolvers | ||
|
||
fun addResolver(resolver: DependencyResolver): DependencyGetter { | ||
resolverList += resolver | ||
return this | ||
} | ||
|
||
/** | ||
* Shorthand to add a MavenResolver with the given repositories | ||
*/ | ||
fun addMavenResolver(repositories: List<MavenRepository>) = addResolver(MavenResolver(repositories)) | ||
|
||
fun get(id: String, targetFolder: File): ResolvedDependency { | ||
for(resolver in resolverList) { | ||
try { | ||
return resolver.resolve(id, targetFolder) | ||
} catch (e: UnresolvedDependencyException) { | ||
// silence and go to next resolver | ||
} | ||
} | ||
throw UnresolvedDependencyException("Could not find $id inside resolver list: ${resolverList.joinToString { it.toString() }}") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.