Skip to content

Commit

Permalink
Improving API and Documentation (#8)
Browse files Browse the repository at this point in the history
* Improving API and Documentation

The documentation was not updated with the last
pull request. I added it now.
Furthermore we improved the API for easier usage.

* changing directories and further improvements
  • Loading branch information
aepfli authored Mar 25, 2021
1 parent f9d1d8f commit 2569bc8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
52 changes: 30 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ gitLab {
* */
applyToProject = true
/**
* After the repository with this name, the repositories will be added
* */
afterRepository = 'MavenLocal'
/**
* Token configuration also the order in which we try to apply them.
* The key is the name of the token, and the value will be used for application.
Expand Down Expand Up @@ -108,7 +103,7 @@ apply plugin: 'at.schrottner.gitlab-repositories'

```kotlin
plugins {
id("at.schrottner.gitlab-repositories") version "0.1.4"
id("at.schrottner.gitlab-repositories") version "<version>"
}
```

Expand All @@ -118,7 +113,7 @@ plugins {
buildscript {
// ..
dependencies {
classpath("at.schrottner.gradle.gitlab-plugin:gitlab-repositories:0.1.4")
classpath("at.schrottner.gradle.gitlab-plugin:gitlab-repositories:<version>")
}
}

Expand All @@ -130,17 +125,19 @@ apply(plugin = "at.schrottner.gitlab-repositories")
The plugin offers you a nice helper method inspired by `gradle-jruby-plugin` to easily add repositories.

```groovy
gitLab.project(projectId)
gitLab.project(projectId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
gitLab.group(groupId)
gitLab.group(groupId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
repositories {
maven gitLab.project(projectId)
maven gitLab.project(projectId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
maven gitLab.group(groupId)
maven gitLab.group(groupId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
}
```

Expand All @@ -156,6 +153,13 @@ publishing {
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
maven gitLab.upload(projectId)
maven gitLab.upload(projectId) {
name = "custom name"
tokenSelektor = "" // a name of a configured token
tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set
}
}
}
```
Expand All @@ -165,8 +169,12 @@ publishing {
This will add a repository and will apply conditions for the first token matching, and not being empty.

```groovy
gitLab.project(1)
gitLab.group(1)
// pluginManagment.repositories { // when in settings.gradle
repositories {
maven gitLab.project(1)
maven gitLab.group(1)
}
```

### Adding a repository with specific tokens
Expand Down Expand Up @@ -213,12 +221,12 @@ gitLab {
}
repositories {
gitLab.group("ID")
maven gitLab.group("ID")
}
publishing {
repositories {
gitLab.upload(owner, "ID")
maven gitLab.upload(owner, "ID")
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
import org.gradle.api.initialization.Settings
import org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler
import org.gradle.api.model.ObjectFactory
import org.slf4j.Logger
import org.slf4j.LoggerFactory
Expand All @@ -19,12 +20,10 @@ import org.slf4j.LoggerFactory
* It provides additional methods to automatically add repositories based on GitLab Groups
* or Projects.
*/
@CompileStatic
class GitlabRepositoriesExtension {

private static final Logger logger = LoggerFactory.getLogger(RepositoryHandler)
public static final String NAME = "gitLab"
private final RepositoryHandler repositories
private final ObjectFactory objects
private final RepositoryActionHandler handler

Expand All @@ -36,14 +35,12 @@ class GitlabRepositoriesExtension {

GitlabRepositoriesExtension(Settings settings, ObjectFactory objects) {
this.objects = objects
this.repositories = settings.pluginManagement.repositories
handler = new RepositoryActionHandler(this)
setup()
}

GitlabRepositoriesExtension(Project project, ObjectFactory objects, GitlabRepositoriesExtension parent = null) {
this.objects = objects
this.repositories = project.repositories
handler = new RepositoryActionHandler(this)
if (parent) {
this.baseUrl = parent.baseUrl
Expand Down Expand Up @@ -84,13 +81,33 @@ class GitlabRepositoriesExtension {
tokens.put(token.key, token)
}

def upload(String id, Action<? super RepositoryConfiguration> configAction = null) {
RepositoryConfiguration repositoryConfiguration = generateRepositoryConfiguration(id, GitLabEntityType.PROJECT)
/**
* Special endpoint for uploading as GitLab only supports uploads for project, this is using the project endpoint.
* it allows to be directly added to a DefaultRepositoryHandler, as the ID might be some env variable only
* available during CI builds etc. and this might cause on wanted side-effects if it is not resolving to a
* usable endpoint
*
*
* @param delegate
* @param id
* @param configAction
* @return
*/
def upload(def delegate, String projectId, Action<? super RepositoryConfiguration> configAction = null) {
def internal = upload(projectId, configAction)
if (projectId)
delegate?.maven(internal)
internal
}

def upload(String projectId, Action<? super RepositoryConfiguration> configAction = null) {
RepositoryConfiguration repositoryConfiguration = generateRepositoryConfiguration(projectId, GitLabEntityType.PROJECT)
mavenInternal(repositoryConfiguration, configAction)
}


private RepositoryConfiguration generateRepositoryConfiguration(String id, GitLabEntityType entityType) {
RepositoryConfiguration repositoryConfiguration = objects.newInstance(RepositoryConfiguration.class, id, entityType)
RepositoryConfiguration repositoryConfiguration = objects.newInstance(RepositoryConfiguration.class, id ?: "NOT_PROPERLY_SET", entityType)
repositoryConfiguration
}

Expand Down

0 comments on commit 2569bc8

Please sign in to comment.