Skip to content
This repository has been archived by the owner on Jan 18, 2021. It is now read-only.

Commit

Permalink
Make license used for pom configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
epeee committed Sep 26, 2018
1 parent 0302c6b commit d257d73
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ShipkitConfiguration {

private final GitHub gitHub = new GitHub();
private final ReleaseNotes releaseNotes = new ReleaseNotes();
private final LicenseInfo licenseInfo = new LicenseInfo();
private final Git git = new Git();
private final Team team = new Team();

Expand Down Expand Up @@ -89,6 +90,10 @@ public ReleaseNotes getReleaseNotes() {
return releaseNotes;
}

public LicenseInfo getLicenseInfo() {
return licenseInfo;
}

public Git getGit() {
return git;
}
Expand Down Expand Up @@ -222,6 +227,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 ReleaseNotes {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) == """<project>
<name>foo</name>
<packaging>jar</packaging>
<url>https://github.com/repo</url>
<description>Foo library</description>
<licenses>
<license>
<name>Eclipse Public License v2.0</name>
<url>http://www.eclipse.org/legal/epl-v20.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://github.com/repo.git</url>
</scm>
<issueManagement>
<url>https://github.com/repo/issues</url>
<system>GitHub issues</system>
</issueManagement>
<ciManagement>
<url>https://travis-ci.org/repo</url>
<system>TravisCI</system>
</ciManagement>
</project>
"""
}

private static String printXml(Node node) {
def sw = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(sw))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
"""

Expand Down

0 comments on commit d257d73

Please sign in to comment.