-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organize the gradle plugin code and document it
- Loading branch information
Showing
6 changed files
with
144 additions
and
36 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
6 changes: 6 additions & 0 deletions
6
gradle-plugin/src/main/java/revxrsal/zapper/gradle/Relocation.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,6 @@ | ||
package revxrsal.zapper.gradle | ||
|
||
/** | ||
* Represents a basic relocation rule | ||
*/ | ||
data class Relocation(val pattern: String, val newPattern: String) |
72 changes: 61 additions & 11 deletions
72
gradle-plugin/src/main/java/revxrsal/zapper/gradle/ZapperExtension.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 |
---|---|---|
@@ -1,38 +1,88 @@ | ||
package revxrsal.zapper.gradle | ||
|
||
import org.gradle.api.Action | ||
|
||
/** | ||
* The maven central repository, which is added by default. | ||
*/ | ||
private const val MAVEN_CENTRAL = "https://repo.maven.apache.org/maven2/" | ||
|
||
/** | ||
* Configure Zapper properties | ||
*/ | ||
open class ZapperExtension { | ||
|
||
/** | ||
* The subfolder in the plugin directory where libraries | ||
* should be installed | ||
*/ | ||
var libsFolder: String = "libs" | ||
|
||
/** | ||
* The relocation prefix of all libraries | ||
*/ | ||
var relocationPrefix: String = "zapperlib" | ||
private var _repositories = mutableListOf<String>() | ||
|
||
/** | ||
* The repositories URLs | ||
*/ | ||
private var _repositories = mutableListOf<String>(MAVEN_CENTRAL) | ||
|
||
/** | ||
* The relocation rules | ||
*/ | ||
private var _relocations = mutableListOf<Relocation>() | ||
|
||
/** | ||
* The currently added repositories | ||
*/ | ||
val repositries: List<String> get() = _repositories | ||
|
||
/** | ||
* The current relocation rules | ||
*/ | ||
val relocations: List<Relocation> get() = _relocations | ||
|
||
internal var useProjectRepositories = false | ||
/** | ||
* Should project repositories be remembered for downloading | ||
* repositories at runtime? | ||
*/ | ||
internal var includeProjectRepositories = false | ||
|
||
fun repositories(configure: RepositoryDsl.() -> Unit) { | ||
/** | ||
* Configures the repositories that are used for downloading dependencies. | ||
* | ||
* See [RepositoryDsl] | ||
*/ | ||
fun repositories(configure: Action<RepositoryDsl>) { | ||
val dsl = BasicRepositoryDsl() | ||
dsl.mavenCentral() | ||
dsl.configure() | ||
configure.execute(dsl) | ||
_repositories = dsl.repositories | ||
useProjectRepositories = dsl.projectRepositories | ||
includeProjectRepositories = dsl.includeProjectRepositories | ||
} | ||
|
||
/** | ||
* Adds a relocation rule | ||
*/ | ||
fun relocate(pattern: String, newPattern: String) { | ||
_relocations.add(Relocation(pattern, newPattern)) | ||
} | ||
|
||
/** | ||
* A fancy toString implementation | ||
*/ | ||
override fun toString(): String { | ||
return "RuntimeLibsExtension(libsFolder='$libsFolder', useProjectRepositories=$useProjectRepositories, repositries=$repositries)" | ||
return "RuntimeLibsExtension(libsFolder='$libsFolder', includeProjectRepositories=$includeProjectRepositories, repositries=$repositries)" | ||
} | ||
|
||
/** | ||
* Generates the content of the properties file of this extension | ||
*/ | ||
internal fun toPropertiesFile(): String { | ||
//language=Properties | ||
return """ | ||
libs-folder=${libsFolder} | ||
relocation-prefix=${relocationPrefix} | ||
""".trimIndent() | ||
} | ||
|
||
fun relocate(pattern: String, newPattern: String) { | ||
_relocations.add(Relocation(pattern, newPattern)) | ||
} | ||
} |
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
45 changes: 35 additions & 10 deletions
45
gradle-plugin/src/main/java/revxrsal/zapper/gradle/repository.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 |
---|---|---|
@@ -1,26 +1,51 @@ | ||
package revxrsal.zapper.gradle | ||
|
||
/** | ||
* A basic interface DSL for specifying repositories to be used | ||
* for dependencies | ||
*/ | ||
interface RepositoryDsl { | ||
fun mavenCentral() = maven("https://repo.maven.apache.org/maven2/") | ||
fun jitpack() = maven("https://jitpack.io/") | ||
|
||
/** | ||
* Adds the given repository to the repositories list | ||
*/ | ||
fun maven(url: String) | ||
fun useProjectRepositories() | ||
|
||
/** | ||
* Tells Zapper to include the project repositories for | ||
* resolving dependencies | ||
*/ | ||
fun includeProjectRepositories() | ||
} | ||
|
||
/** | ||
* A basic implementation of [RepositoryDsl] | ||
*/ | ||
internal class BasicRepositoryDsl : RepositoryDsl { | ||
|
||
/** | ||
* The repositories list | ||
*/ | ||
val repositories = mutableListOf<String>() | ||
var projectRepositories = false | ||
|
||
/** | ||
* Should project repositories be included? | ||
*/ | ||
var includeProjectRepositories = false | ||
|
||
/** | ||
* Adds the given repository to the repositories list | ||
*/ | ||
override fun maven(url: String) { | ||
repositories.add(url) | ||
} | ||
|
||
override fun useProjectRepositories() { | ||
projectRepositories = true | ||
/** | ||
* Tells Zapper to include the project repositories for | ||
* resolving dependencies | ||
*/ | ||
override fun includeProjectRepositories() { | ||
includeProjectRepositories = true | ||
} | ||
} | ||
|
||
data class Relocation( | ||
val pattern: String, | ||
val newPattern: String | ||
) |