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

Make license used for pom configurable #760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();

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

public LicenseInfo getLicenseInfo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to now configure a few licenses? E.g. one open source and one commercial?

return licenseInfo;
}

public Git getGit() {
return git;
}
Expand Down Expand Up @@ -231,6 +236,24 @@ public void setWriteAuthToken(String writeAuthToken) {
}
}

public class LicenseInfo {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about distribution property in pom?

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".
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add defaults, Apache 2.0 and blob/master/LICENSE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, good feedback, thx!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Let me know when you're ready.

MIT is 30y old and lawyers no longer like it. Let's default to Apache 2.0.

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