Skip to content

Commit

Permalink
Merge pull request #10 from IntershopCommunicationsAG/updategradle4
Browse files Browse the repository at this point in the history
Updategradle4
  • Loading branch information
m-raab authored Dec 16, 2017
2 parents 9f82768 + b60750a commit 61c66d9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 223 deletions.
48 changes: 6 additions & 42 deletions README.asciidoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
= Repository Configuration Init Script Plugin
:latestRevision: 3.3.0
:latestRevision: 4.1.0
:toc:
:icons: font

NOTE: Version 3 of this plugin will only work with Gradle 4 and JDK 8.

== Summary
This is an init script plugin to provide special repository settings for project teams or companies.
See https://docs.gradle.org/current/userguide/init_scripts.html and http://gradle.org/standardizing-enterprise-builds-with-gradle/.
With this plugin it is also possible to inject repository configurations easily in a settings.gradle file.
See https://docs.gradle.org/current/userguide/init_scripts.html[Initialization Scripts].

== Usage
Expand Down Expand Up @@ -46,11 +48,10 @@ repositoryConfiguration {
----

This plugin applies the following configurations and properties to all projects with the same init.gradle script.
Furthermore it adds one method to the Gradle object.

.Ivy configuration
These Ivy patterns will be applied to all configured Ivy repositories - read, build script and publishing configurations.
These patterns will be also stored in Gradle and project properties.
These Ivy patterns will be applied to all configured Ivy repositories - read, build script and publishing
configurations if the name starts with 'intershop'.

* Ivy pattern +
pattern: `'[organisation]/[module]/[revision]/[type]s/ivy-[revision].xml'` +
Expand All @@ -62,29 +63,6 @@ property: `corporateArtifactPattern`
pattern: `'[organisation]/[module]/[revision]/[type]s/ivy-[revision].xml'` +
property: `corporateIvyAsArtifactPattern`

.Extension for Gradle object with method `injectRepositories`
This method can be used to add repositories to existing repository containers.

.settings.gradle (example)
[source,groovy,subs="attributes"]
----
buildscript {
gradle.injectRepositories(repositories, configurations)
dependencies {
classpath 'com.intershop:deployment-bootstrap:2.7.0'
}
}
apply plugin: com.intershop.deploy.bootstrap.DeploymentBootstrapPlugin
deploymentBootstrap {
gradle.injectRepositories(repositoryHandler, configurationContainer)
assembly (installAssembly) {
...
----

== Init Script Extension 'repositoryConfiguration'
=== Properties

Expand All @@ -107,15 +85,6 @@ deploymentBootstrap {

|===

== Gradle Extension
=== Methods
[cols="20%,15%,65%", width="95%", options="header"]
|===
|Method | Parameters | Description
|*injectRepositories* | RepositoryHandler, ConfigurationContainer | See https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/RepositoryHandler.html[RepositoryHandler] and
https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/ConfigurationContainer.html[ConfigurationContainer] in Gradle standard documentation.
|===

=== Additional Environment or System Variables
For local publishing it is necessary to configure a local repository. Therefore it is necessary to specify a path.

Expand Down Expand Up @@ -144,12 +113,7 @@ For special use cases it is necessary to enable or disable special sets of repos
|`DISABLE_INITDEFAULTS`|`disableInitDefaults`|`false`|If true, all default settings are disabled.
|`ENABLE_SNAPSHOTS` |`enableSnapshots` |`false`|If true, snapshot repositories (`ivy.snapshots.pathList`, `maven.snapshots.pathList`) will be enabled for build dependencies.
|`DISABLE_REPOS` |`disableRepos` |`false`|If true, repositories from `ivy.repository.pathList` and `maven.repository.pathList` will be disabled for build dependencies.
|`ENABLE_BUILDSCRIPT_SNAPSHOTS` |`enableBuildscriptSnapshots` |`false`|If true, snapshot repositories (`ivy.snapshots.pathList`, `maven.snapshots.pathList`) will be enabled for buildscript dependencies.
|`DISABLE_BUILDSCRIPT_REPOS` |`disableBuildscriptRepos` |`false`|If true, repositories from `ivy.repository.pathList` and `maven.repository.pathList` will be disabled for buildscript dependencies.
|`DISABLE_LOCAL_REPO` |`disableLocalRepo` |`false`|If true, default configuration for local repository is disabled.
|`DISABLE_IVYPATTERN_PUBLISH` |`disableIvyPatternPublish` |`false`|If true, the default ivy pattern will be disabled for all publish configurations.
|`DISABLE_IVYPATTERN_BUILDSCRIPT` |`disableIvyPatternBuildscript` |`false`|If true, the default ivy pattern will be disabled for all buildscript configurations.
|`DISABLE_IVYPATTERN` |`disableIvyPattern` |`false`|If true, the default ivy pattern will be disabled for all build configurations.
|===

== License
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,6 @@ class RepoConfigPlugin implements Plugin<Gradle> {
// default local repo path
String repoPath = config.localRepositoryPath ?: (new File(gradle.gradleUserHomeDir, '.localRepo')).canonicalPath

if (!config.disableInitDefaults) {
// add repositories to settings gradle repositories configuration
int outputGradleCount = 0
gradle.ext.injectRepositories = { RepositoryHandler repositories, ConfigurationContainer configurations ->
if(outputGradleCount == 0) {
println "Defaults for ${extension.getCorporateName() ?: 'project'} are used for inject repositories!"
outputGradleCount = 1
}
// local repository
if(! config.disableLocalRepository) {
addLocalRepository(repositories, repoPath)
}
// repositories
if (!config.disableRepos) {
addRepositories(repositories, configurations)
}
// snapshot repositories
if (config.enableSnapshots) {
addSnapshotsRepositories(repositories, configurations)
}

addPulicMavenRepository(repositories)
addJCenter(repositories)

// add pattern
if(! config.disableIvyPattern) {
repositories.withType(IvyArtifactRepository) { IvyArtifactRepository repo ->
repo.layout('pattern') {
ivy config.ivyPattern
artifact config.artifactPattern
artifact config.ivyAsAnArtifactPattern
}
}
}
}
}

// add gradle properties
gradle.ext {
corporateIvyPattern = config.ivyPattern
corporateArtifactPattern = config.artifactPattern
corporateIvyAsArtifactPattern = config.ivyAsAnArtifactPattern
}


int outputProjectCount = 0
gradle.allprojects(new Action<Project>() {
@Override
Expand Down Expand Up @@ -132,32 +87,16 @@ class RepoConfigPlugin implements Plugin<Gradle> {
}
}

if(!config.disableBuildscriptLocalRepo) {
log.debug('Add local repositories for build script for project {}', project.path)
//add local repo to build script configuration
addLocalRepository(project.buildscript.repositories, repoPath)
}

//add repositories
if (!config.disableRepos) {
log.debug('Add repositories for project build {}', project.path)
addRepositories(project.repositories, project.configurations)
}
//add build script repositories
if (!config.disableBuildscriptRepos) {
log.debug('Add repositories for build script for project {}', project.path)
addRepositories(project.buildscript.repositories, project.buildscript.configurations)
}
//add snapshot repositories
if (config.enableSnapshots) {
log.debug('Add snapshot repositories for project {}', project.path)
addSnapshotsRepositories(project.repositories, project.configurations)
}
//add snapshot repositories to build script configuration
if (config.enableBuildscriptSnapshots) {
log.debug('Add snapshot repositories for build script for project {}', project.path)
addSnapshotsRepositories(project.buildscript.repositories, project.buildscript.configurations)
}

addPulicMavenRepository(project.repositories)
addPulicMavenRepository(project.buildscript.repositories)
Expand All @@ -166,7 +105,6 @@ class RepoConfigPlugin implements Plugin<Gradle> {
addJCenter(project.buildscript.repositories)
}
// set pattern for publishing
if (!config.disableIvyPatternPublish) {
project.plugins.withType(IvyPublishPlugin) {
project.publishing {
repositories.withType(IvyArtifactRepository) { IvyArtifactRepository repo ->
Expand All @@ -182,10 +120,10 @@ class RepoConfigPlugin implements Plugin<Gradle> {
}
}
}
}


//set pattern for buildscript repositories
if(! config.disableIvyPatternBuildscript) {

project.repositories.withType(IvyArtifactRepository) { IvyArtifactRepository repo ->
if(repo.name.startsWith('intershop')) {
log.debug("Add pattern to {}", repo.name)
Expand All @@ -198,9 +136,9 @@ class RepoConfigPlugin implements Plugin<Gradle> {
log.debug("Pattern will be not added to {}.", repo.name)
}
}
}

//set pattern for repositories
if(! config.disableIvyPattern) {

project.buildscript.repositories.withType(IvyArtifactRepository) { IvyArtifactRepository repo ->
if(repo.name.startsWith('intershop')) {
log.debug("Add pattern to {}", repo.name)
Expand All @@ -213,7 +151,7 @@ class RepoConfigPlugin implements Plugin<Gradle> {
log.debug("Pattern will be not added to {}.", repo.name)
}
}
}


// Remove repositories that are non-local and pointing to our repository server or not maven or ivy repositories
project.repositories.all { ArtifactRepository repo ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,12 @@ class RepoConfigRegistry {
final static String DISABLE_REPOS_ENV = 'disableRepos'
final static String DISABLE_REPOS_SYS = 'DISABLE_REPOS'

/*
* Settings for enable all build script snapshot repositories
*/
final static String ENABLE_BUILDSCIPT_SNAPSHOTS_ENV = 'enableBuildscriptSnapshots'
final static String ENABLE_BUILDSCIPT_SNAPSHOTS_SYS = 'ENABLE_BUILDSCRIPT_SNAPSHOTS'

/*
* Settings for disable all other build script repositories
*/
final static String DISABLE_BUILDSCIPT_REPOS_ENV = 'disableBuildscriptRepos'
final static String DISABLE_BUILDSCIPT_REPOS_SYS = 'DISABLE_BUILDSCRIPT_REPOS'

/*
* Settings for disable local build script repositories
*/
final static String DISABLE_BUILDSCIPT_LOCAL_REPO_ENV = 'disableBuildscriptLocalRepo'
final static String DISABLE_BUILDSCIPT_LOCAL_REPO_SYS = 'DISABLE_BUILDSCRIPT_LOCAL_REPO'

/*
* Setting for disable local repository publishing and usage
*/
final static String DISABLE_LOCAL_REPO_ENV = 'disableLocalRepo'
final static String DISABLE_LOCAL_REPO_SYS = 'DISABLE_LOCAL_REPO'

/*
* Setting for disable publish ivy pattern
*/
final static String DISABLE_IVYPATTERN_PUBLISH_ENV = 'disableIvyPatternPublish'
final static String DISABLE_IVYPATTERN_PUBLISH_SYS = 'DISABLE_IVYPATTERN_PUBLISH'

/*
* Setting for disable buildscript ivy pattern
*/
final static String DISABLE_IVYPATTERN_BUILDSCRIPT_ENV = 'disableIvyPatternBuildscript'
final static String DISABLE_IVYPATTERN_BUILDSCRIPT_SYS = 'DISABLE_IVYPATTERN_BUILDSCRIPT'

/*
* Setting for disable buildscript ivy pattern
*/
final static String DISABLE_IVYPATTERN_ENV = 'disableIvyPattern'
final static String DISABLE_IVYPATTERN_SYS = 'DISABLE_IVYPATTERN'

/*
* Setting for local repository path
*/
Expand Down Expand Up @@ -135,46 +99,16 @@ class RepoConfigRegistry {
*/
final boolean disableRepos

/**
* Disable usage of repositories for the buildscript configuration
*/
final boolean disableBuildscriptRepos

/**
* Enable usage of snapshot repositories
*/
final boolean enableSnapshots

/**
* Enable usage of snapshot repositories for the buildscript configuration
*/
final boolean enableBuildscriptSnapshots

/**
* Disable usage of local repository
*/
final boolean disableLocalRepository

/**
* Disable usage of local repository for build scripts
*/
final boolean disableBuildscriptLocalRepo

/**
* Disable corporate ivy pattern for publishing
*/
final boolean disableIvyPatternPublish

/**
* Disable corporate ivy pattern for Buildscript repositories
*/
final boolean disableIvyPatternBuildscript

/**
* Disable corporate ivy pattern for build repositories
*/
final boolean disableIvyPattern

/**
* Path for local repository
*/
Expand All @@ -187,18 +121,11 @@ class RepoConfigRegistry {
disableInitDefaults = getConfigurationValue(DISABLE_DEFAULTS_ENV, DISABLE_DEFAULTS_SYS, 'false').toBoolean()

disableRepos = getConfigurationValue(DISABLE_REPOS_ENV, DISABLE_REPOS_SYS, 'false').toBoolean()
disableBuildscriptRepos = getConfigurationValue(DISABLE_BUILDSCIPT_REPOS_ENV, DISABLE_BUILDSCIPT_REPOS_SYS, 'false').toBoolean()

enableSnapshots = getConfigurationValue(ENABLE_SNAPSHOTS_ENV, ENABLE_SNAPSHOTS_SYS, 'false').toBoolean()
enableBuildscriptSnapshots = getConfigurationValue(ENABLE_BUILDSCIPT_SNAPSHOTS_ENV, ENABLE_BUILDSCIPT_SNAPSHOTS_SYS, 'false').toBoolean()

disableLocalRepository = getConfigurationValue(DISABLE_LOCAL_REPO_ENV, DISABLE_LOCAL_REPO_SYS, 'false').toBoolean()
disableBuildscriptLocalRepo = getConfigurationValue(DISABLE_BUILDSCIPT_LOCAL_REPO_ENV, DISABLE_BUILDSCIPT_LOCAL_REPO_SYS, 'false').toBoolean()
localRepositoryPath = getConfigurationValue(LOCAL_REPO_PATH_ENV, LOCAL_REPO_PATH_SYS, '')

disableIvyPatternPublish = getConfigurationValue(DISABLE_IVYPATTERN_PUBLISH_ENV, DISABLE_IVYPATTERN_PUBLISH_SYS, 'false').toBoolean()
disableIvyPatternBuildscript = getConfigurationValue(DISABLE_IVYPATTERN_BUILDSCRIPT_ENV, DISABLE_IVYPATTERN_BUILDSCRIPT_SYS, 'false').toBoolean()
disableIvyPattern = getConfigurationValue(DISABLE_IVYPATTERN_ENV, DISABLE_IVYPATTERN_SYS, 'false').toBoolean()
}

/**
Expand Down
Loading

0 comments on commit 61c66d9

Please sign in to comment.