From dce776db2b747b69eb38b500fa1fb1cd239fb2c0 Mon Sep 17 00:00:00 2001 From: epeee Date: Wed, 26 Sep 2018 17:54:40 +0200 Subject: [PATCH] Make license used for pom configurable --- .../configuration/ShipkitConfiguration.java | 23 +++++++++ .../internal/gradle/util/PomCustomizer.java | 4 +- .../gradle/util/PomCustomizerTest.groovy | 48 +++++++++++++++++++ .../testutil/GradleSpecification.groovy | 3 ++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/subprojects/shipkit/src/main/groovy/org/shipkit/gradle/configuration/ShipkitConfiguration.java b/subprojects/shipkit/src/main/groovy/org/shipkit/gradle/configuration/ShipkitConfiguration.java index 941e845b..a52d65eb 100644 --- a/subprojects/shipkit/src/main/groovy/org/shipkit/gradle/configuration/ShipkitConfiguration.java +++ b/subprojects/shipkit/src/main/groovy/org/shipkit/gradle/configuration/ShipkitConfiguration.java @@ -27,6 +27,7 @@ public class ShipkitConfiguration { private final GitHub gitHub = new GitHub(); private final Javadoc javadoc = new Javadoc(); private final ReleaseNotes releaseNotes = new ReleaseNotes(); + private final LicenseInfo licenseInfo = new LicenseInfo(); private final Git git = new Git(); private final Team team = new Team(); @@ -95,6 +96,10 @@ public ReleaseNotes getReleaseNotes() { return releaseNotes; } + public LicenseInfo getLicenseInfo() { + return licenseInfo; + } + public Git getGit() { return git; } @@ -231,6 +236,24 @@ public void setWriteAuthToken(String writeAuthToken) { } } + public class LicenseInfo { + public String getLicense() { + return store.getString("licenseInfo.license"); + } + + public void setLicense(String license) { + store.put("licenseInfo.license", license); + } + + public String getUrl() { + return store.getString("licenseInfo.url"); + } + + public void setUrl(String url) { + store.put("licenseInfo.url", url); + } + } + public class Javadoc { /** * GitHub Javadoc repository name, for example: "mockito/shipkit-javadoc". diff --git a/subprojects/shipkit/src/main/groovy/org/shipkit/internal/gradle/util/PomCustomizer.java b/subprojects/shipkit/src/main/groovy/org/shipkit/internal/gradle/util/PomCustomizer.java index db3300d3..1a282000 100644 --- a/subprojects/shipkit/src/main/groovy/org/shipkit/internal/gradle/util/PomCustomizer.java +++ b/subprojects/shipkit/src/main/groovy/org/shipkit/internal/gradle/util/PomCustomizer.java @@ -76,8 +76,8 @@ static void customizePom(Node root, ShipkitConfiguration conf, } Node license = root.appendNode("licenses").appendNode("license"); - license.appendNode("name", "The MIT License"); - license.appendNode("url", repoLink + "/blob/master/LICENSE"); + license.appendNode("name", conf.getLicenseInfo().getLicense()); + license.appendNode("url", conf.getLicenseInfo().getUrl()); license.appendNode("distribution", "repo"); root.appendNode("scm").appendNode("url", repoLink + ".git"); diff --git a/subprojects/shipkit/src/test/groovy/org/shipkit/internal/gradle/util/PomCustomizerTest.groovy b/subprojects/shipkit/src/test/groovy/org/shipkit/internal/gradle/util/PomCustomizerTest.groovy index c1cc5e0e..23d743c2 100644 --- a/subprojects/shipkit/src/test/groovy/org/shipkit/internal/gradle/util/PomCustomizerTest.groovy +++ b/subprojects/shipkit/src/test/groovy/org/shipkit/internal/gradle/util/PomCustomizerTest.groovy @@ -34,6 +34,9 @@ class PomCustomizerTest extends Specification { //wwilk will not be duplicated in developers/contributors conf.team.contributors = ["mstachniuk:Marcin Stachniuk", "wwilk:Wojtek Wilk"] + conf.licenseInfo.license = "The MIT License" + conf.licenseInfo.url = "https://github.com/repo/blob/master/LICENSE" + PomCustomizer.customizePom(node, conf, "foo", "Foo library", new DefaultProjectContributorsSet()) expect: @@ -92,6 +95,10 @@ class PomCustomizerTest extends Specification { conf.gitHub.repository = "repo" conf.team.developers = ["mockitoguy:Szczepan Faber", "wwilk:Wojtek Wilk"] conf.team.contributors = [] + + conf.licenseInfo.license = "The MIT License" + conf.licenseInfo.url = "https://github.com/repo/blob/master/LICENSE" + //wwilk will not be duplicated in developers/contributors def contributorsSet = new DefaultProjectContributorsSet() contributorsSet.addContributor(new DefaultProjectContributor("Wojtek Wilk", "wwilk", "https://github.com/wwilk", 5)) @@ -156,6 +163,9 @@ class PomCustomizerTest extends Specification { conf.team.developers = [] conf.team.contributors = [] + conf.licenseInfo.license = "The MIT License" + conf.licenseInfo.url = "https://github.com/repo/blob/master/LICENSE" + PomCustomizer.customizePom(node, conf, "foo", "Foo library", new DefaultProjectContributorsSet()) expect: @@ -186,6 +196,44 @@ class PomCustomizerTest extends Specification { """ } + def "use epl v2.0 license"() { + conf.gitHub.repository = "repo" + conf.team.developers = [] + conf.team.contributors = [] + + conf.licenseInfo.license = "Eclipse Public License v2.0" + conf.licenseInfo.url = "http://www.eclipse.org/legal/epl-v20.html" + + PomCustomizer.customizePom(node, conf, "foo", "Foo library", new DefaultProjectContributorsSet()) + + expect: + printXml(node) == """ + foo + jar + https://github.com/repo + Foo library + + + Eclipse Public License v2.0 + http://www.eclipse.org/legal/epl-v20.html + repo + + + + https://github.com/repo.git + + + https://github.com/repo/issues + GitHub issues + + + https://travis-ci.org/repo + TravisCI + + +""" + } + private static String printXml(Node node) { def sw = new StringWriter() def printer = new XmlNodePrinter(new PrintWriter(sw)) diff --git a/subprojects/shipkit/src/test/groovy/testutil/GradleSpecification.groovy b/subprojects/shipkit/src/test/groovy/testutil/GradleSpecification.groovy index 03c722f4..5dc73b7b 100644 --- a/subprojects/shipkit/src/test/groovy/testutil/GradleSpecification.groovy +++ b/subprojects/shipkit/src/test/groovy/testutil/GradleSpecification.groovy @@ -52,6 +52,9 @@ abstract class GradleSpecification extends Specification implements GradleVersio gitHub.readOnlyAuthToken = "foo" gitHub.repository = "repo" releaseNotes.publicationRepository = "repo" + + licenseInfo.license = "The MIT License" + licenseInfo.url = "https://github.com/repo/blob/master/LICENSE" } """