Skip to content

Commit

Permalink
[base] implement mmerge strategy for remaining domain sets. Fixes #400
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Oct 17, 2020
1 parent ad9153c commit 0abcae1
Show file tree
Hide file tree
Showing 26 changed files with 1,159 additions and 422 deletions.
79 changes: 75 additions & 4 deletions docs/guide/src/docs/asciidoc/plugins/base-gradle-plugin.adoc
Expand Up @@ -93,6 +93,8 @@ config {
}
<<_base_info_credentials,credentials>> {
inherits
mergeStrategy
github {
username
password
Expand All @@ -109,6 +111,8 @@ config {
}
<<_base_info_repositories,repositories>> {
inherits
mergeStrategy
<<_base_info_repository,repository>> {
name
url
Expand All @@ -120,6 +124,8 @@ config {
}
<<_base_info_people,people>> {
inherits
mergeStrategy
<<_base_info_person,person>> {
id
name
Expand All @@ -146,6 +152,8 @@ config {
}
<<_base_info_mailingLists,mailingLists>> {
inherits
mergeStrategy
<<_base_info_mailingList,mailingList>> {
name
subscribe
Expand Down Expand Up @@ -258,12 +266,24 @@ This block is optional.

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| github | Credentials | no* | | Username/Password for connecting to GitHub
| sonatype | Credentials | no* | | Username/Password for connecting to Maven Central
| named | Credentials | no* | | Defines a named credentials entry. Name may match a repository entry.
| Name | Type | Required | Default Value | Description
| github | Credentials | no* | | Username/Password for connecting to GitHub
| sonatype | Credentials | no* | | Username/Password for connecting to Maven Central
| named | Credentials | no* | | Defines a named credentials entry. Name may match a repository entry.
| inherits | boolean | no | true | Whether to inherit values from a parent `POM`.
| mergeStrategy | MergeStrategy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
|===

The value of `inherits` cannot be changed once it has been set.

The values of `mergeStrategy` control how multiple credentials will be handled

[horizontal]
PREPEND:: Child values (if any) will be placed before inherited values (if any).
APPEND:: Child values (if any) will be placed after inherited values (if any).
UNIQUE:: Child and inherited values will be merged by license id.
OVERWRITE:: Child values will be used unless empty, in which case inherited values will be used.

The `sonatype` entry may be used by the `<<_org_kordamp_gradle_bintray,org.kordamp.gradle.bintray>>` plugin to configure
auto-sync with Maven Central when pushing a publication. Named credentials my match the name of a repository, in which
case they will be used during artifact publication on the matching repository.
Expand All @@ -275,6 +295,23 @@ This block is optional.

This block defines data associated with a particular repository. Entries may be used during publication.

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| inherits | boolean | no | true | Whether to inherit values from a parent `POM`.
| mergeStrategy | MergeStrategy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
|===

The value of `inherits` cannot be changed once it has been set.

The values of `mergeStrategy` control how multiple repositories will be handled

[horizontal]
PREPEND:: Child values (if any) will be placed before inherited values (if any).
APPEND:: Child values (if any) will be placed after inherited values (if any).
UNIQUE:: Child and inherited values will be merged by license id.
OVERWRITE:: Child values will be used unless empty, in which case inherited values will be used.

[[_base_info_repository]]
*repository*

Expand All @@ -293,6 +330,23 @@ the repository name.
[[_base_info_people]]
*people*

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| inherits | boolean | no | true | Whether to inherit values from a parent `POM`.
| mergeStrategy | MergeStrategy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
|===

The value of `inherits` cannot be changed once it has been set.

The values of `mergeStrategy` control how multiple people will be handled

[horizontal]
PREPEND:: Child values (if any) will be placed before inherited values (if any).
APPEND:: Child values (if any) will be placed after inherited values (if any).
UNIQUE:: Child and inherited values will be merged by license id.
OVERWRITE:: Child values will be used unless empty, in which case inherited values will be used.

This block defines data associated with a particular person.

This block is optional if none of the following plugins are used: `<<_org_kordamp_gradle_javadoc,org.kordamp.gradle.javadoc>>`,
Expand Down Expand Up @@ -341,6 +395,23 @@ block in the POM. If a `contributor` role exists then the person instance is map
[[_base_info_mailingLists]]
*mailingLists*

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| inherits | boolean | no | true | Whether to inherit values from a parent `POM`.
| mergeStrategy | MergeStrategy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
|===

The value of `inherits` cannot be changed once it has been set.

The values of `mergeStrategy` control how multiple mailing lists will be handled

[horizontal]
PREPEND:: Child values (if any) will be placed before inherited values (if any).
APPEND:: Child values (if any) will be placed after inherited values (if any).
UNIQUE:: Child and inherited values will be merged by license id.
OVERWRITE:: Child values will be used unless empty, in which case inherited values will be used.

This block defines a list of MailingList entries.

[[_base_info_mailingList]]
Expand Down
Expand Up @@ -22,9 +22,10 @@ Configures aggregate license reports on the root project.
config {
licensing {
enabled
mergeStrategy
excludedSourceSets
licenses {
inherits
mergeStrategy
license {
id
primary
Expand All @@ -43,12 +44,15 @@ config {
|===
| Name | Type | Required | Default Value | Description
| enabled | boolean | no | true | Disables `org.kordamp.gradle.licensing` plugin if `false`
| mergeStrategy | MergeStartegy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
| excludedSourceSets | Set<String> | no | [] |
| licenses | LicenseSet | yes | | This block maps to the `<licenses>` block in POM. +
At least one nested `license` block must be defined.
At least one nested `license` block must be defined.
| inherits | boolean | no | true | Whether to inherit values from a parent `POM`.
| mergeStrategy | MergeStrategy | no | UNIQUE | One of `PREPEND`, `APPEND`, `UNIQUE`, `OVERWRITE`.
|===

The value of `inherits` cannot be changed once it has been set.

The values of `mergeStrategy` control how multiple licenses will be handled

[horizontal]
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Expand Up @@ -130,7 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
21 changes: 3 additions & 18 deletions gradlew.bat
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,29 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
@@ -0,0 +1,88 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Andres Almiray.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kordamp.gradle.plugin.base.model


import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.kordamp.gradle.plugin.base.plugins.MergeStrategy

import java.util.function.Consumer

/**
* @author Andres Almiray
* @since 0.41.0
*/
@CompileStatic
@PackageScope
abstract class AbstractDomainSet<T> implements DomainSet<T> {
MergeStrategy mergeStrategy

private boolean inherits = true
private boolean inheritsSet = false

@Override
void setMergeStrategy(String str) {
mergeStrategy = MergeStrategy.of(str)
}

@Override
void setMergeStrategy(MergeStrategy mergeStrategy) {
this.mergeStrategy = mergeStrategy ?: MergeStrategy.UNIQUE
}

@Override
void forEach(Consumer<? super T> consumer) {
for (T t : getDomainObjects()) {
consumer.accept(t)
}
}

@Override
Map<String, Object> toMap() {
Map<String, Object> map = [:]

map.inherits = isInherits()
map.mergeStrategy = mergeStrategy

if (isEmpty()) return map

populateMap(map)
map
}

void setInherits(boolean value) {
if (!inheritsSet) {
inheritsSet = true
inherits = value
if (!value) {
clearDomainSet()
}
}
}

boolean isInherits() {
this.inherits
}

protected abstract Collection<T> getDomainObjects()

protected abstract void clearDomainSet()

protected abstract void populateMap(Map<String, Object> map)
}
Expand Up @@ -19,6 +19,8 @@ package org.kordamp.gradle.plugin.base.model

import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.model.ObjectFactory
import org.kordamp.gradle.plugin.base.plugins.MergeStrategy
import org.kordamp.gradle.util.ConfigureUtil

import static org.kordamp.gradle.util.StringUtils.isBlank
Expand All @@ -31,8 +33,21 @@ import static org.kordamp.gradle.util.StringUtils.isBlank
class CiManagement {
String system
String url
MergeStrategy mergeStrategy

final NotifierSet notifiers = new NotifierSet()
final NotifierSetImpl notifiers

CiManagement(ObjectFactory objects) {
notifiers = new NotifierSetImpl(objects)
}

NotifierSet getNotifiers() {
this.notifiers
}

void setMergeStrategy(String str) {
mergeStrategy = MergeStrategy.of(str)
}

Map<String, Object> toMap() {
new LinkedHashMap<String, Object>([
Expand All @@ -45,7 +60,7 @@ class CiManagement {
static void merge(CiManagement o1, CiManagement o2) {
o1.system = o1.system ?: o2?.system
o1.url = o1.url ?: o2?.url
NotifierSet.merge(o1.notifiers, o2.notifiers)
NotifierSetImpl.merge(o1.@notifiers, o2?.@notifiers)
}

boolean isEmpty() {
Expand Down

0 comments on commit 0abcae1

Please sign in to comment.