Skip to content

Commit

Permalink
feat(core): Promote inceptionYear to property. Resolves #881
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Aug 10, 2022
1 parent 1c05d4d commit 32a660e
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,9 @@ public Map<String, Object> props(JReleaserModel model) {
if (isNotBlank(project.getLicense())) {
props.put(Constants.KEY_PROJECT_LICENSE, project.getLicense());
}
if (null != project.getInceptionYear()) {
props.put(Constants.KEY_PROJECT_INCEPTION_YEAR, project.getInceptionYear());
}
if (isNotBlank(project.getCopyright())) {
props.put(Constants.KEY_PROJECT_COPYRIGHT, project.getCopyright());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ private void fillProjectProperties(Map<String, Object> props, Project project) {
if (isNotBlank(project.getLicense())) {
props.put(Constants.KEY_PROJECT_LICENSE, project.getLicense());
}
if (null != project.getInceptionYear()) {
props.put(Constants.KEY_PROJECT_INCEPTION_YEAR, project.getInceptionYear());
}
if (isNotBlank(project.getCopyright())) {
props.put(Constants.KEY_PROJECT_COPYRIGHT, project.getCopyright());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class Project extends AbstractModelObject<Project> implements Domain, Ext
private String description;
private String longDescription;
private String license;
private String inceptionYear;
private String copyright;
private String vendor;
private Stereotype stereotype = Stereotype.NONE;
Expand All @@ -91,6 +92,7 @@ public void merge(Project project) {
this.description = merge(this.description, project.description);
this.longDescription = merge(this.longDescription, project.longDescription);
this.license = merge(this.license, project.license);
this.inceptionYear = merge(this.inceptionYear, project.inceptionYear);
this.copyright = merge(this.copyright, project.copyright);
this.vendor = merge(this.vendor, project.vendor);
this.stereotype = merge(this.stereotype, project.stereotype);
Expand Down Expand Up @@ -224,6 +226,15 @@ public void setLicenseUrl(String licenseUrl) {
links.setLicense(licenseUrl);
}

public String getInceptionYear() {
return inceptionYear;
}

public void setInceptionYear(String inceptionYear) {
freezeCheck();
this.inceptionYear = inceptionYear;
}

public String getCopyright() {
return copyright;
}
Expand Down Expand Up @@ -330,6 +341,7 @@ public Map<String, Object> asMap(boolean full) {
map.put("description", description);
map.put("longDescription", longDescription);
map.put("license", license);
map.put("inceptionYear", inceptionYear);
map.put("copyright", copyright);
map.put("vendor", vendor);
map.put("authors", authors);
Expand Down Expand Up @@ -618,6 +630,9 @@ public Map<String, Object> props(JReleaserModel model) {
if (isNotBlank(project.getLicense())) {
props.put(Constants.KEY_PROJECT_LICENSE, project.getLicense());
}
if (null != project.getInceptionYear()) {
props.put(Constants.KEY_PROJECT_INCEPTION_YEAR, project.getInceptionYear());
}
if (isNotBlank(project.getCopyright())) {
props.put(Constants.KEY_PROJECT_COPYRIGHT, project.getCopyright());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,21 @@ public static void postValidateProject(JReleaserContext context, JReleaserContex
context.getLogger().debug("project");
Project project = context.getModel().getProject();

// TODO: remove in 2.0.0
if (null == project.getInceptionYear() &&
project.getExtraProperties().containsKey("inceptionYear")) {
project.setInceptionYear(project.getExtraProperty("inceptionYear"));
}

if (isBlank(project.getCopyright())) {
if (project.getExtraProperties().containsKey("inceptionYear") &&
if (project.getInceptionYear() != null &&
!project.getAuthors().isEmpty()) {
project.setCopyright(
project.getExtraProperties().get("inceptionYear") + " " +
project.getInceptionYear() + " " +
String.join(",", project.getAuthors()));
} else {
context.nag("0.4.0", "project.copyright must not be blank");
project.setCopyright("");
// errors.configuration("project.copyright must not be blank");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"groupId": "com.acme",
"version": "8"
},
"extraProperties": {
"inceptionYear": "@year@"
}
"inceptionYear": "@year@"
},

"release": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
links.homepage = "https://acme.com/app"
java.groupId = "com.acme"
java.version = "8"
extraProperties.inceptionYear = "@year@"
inceptionYear = "@year@"

[release.github]
owner = "duke"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ project:
java:
groupId: com.acme
version: 8
extraProperties:
inceptionYear: @year@
inceptionYear: @year@

release:
github:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public interface Constants {
String KEY_PROJECT_COPYRIGHT = "projectCopyright";
String KEY_PROJECT_VENDOR = "projectVendor";
String KEY_PROJECT_LICENSE = "projectLicense";
String KEY_PROJECT_INCEPTION_YEAR = "projectInceptionYear";
String KEY_PROJECT_LICENSE_URL = "projectLicenseUrl";
String KEY_PROJECT_AUTHORS_BY_SPACE = "projectAuthorsBySpace";
String KEY_PROJECT_AUTHORS_BY_COMMA = "projectAuthorsByComma";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ interface Project extends ExtraProperties {

Property<String> getLicense()

Property<String> getInceptionYear()

@Deprecated
Property<String> getLicenseUrl()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class KordampJReleaserAdapter {
if (!jreleaser.project.description.present) {
jreleaser.project.description.set(config.info.description)
}
if (!jreleaser.project.website.present) {
jreleaser.project.website.set(config.info.links.website)
if (!jreleaser.project.links.homepage.present) {
jreleaser.project.links.homepage.set(config.info.links.website)
}
if (!jreleaser.project.authors.present) {
jreleaser.project.authors.set(config.info.authors)
Expand All @@ -55,12 +55,8 @@ class KordampJReleaserAdapter {
jreleaser.project.license.set(license.name)
}
}
if (jreleaser.project.extraProperties.present) {
if (!jreleaser.project.extraProperties.get().containsKey('inceptionYear')) {
jreleaser.project.extraProperties.put('inceptionYear', config.info.inceptionYear)
}
} else {
jreleaser.project.extraProperties.put('inceptionYear', config.info.inceptionYear)
if (!jreleaser.project.inceptionYear.present) {
jreleaser.project.inceptionYear.set(config.info.inceptionYear)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ProjectImpl implements Project {
final Property<String> description
final Property<String> longDescription
final Property<String> website
final Property<String> inceptionYear
final Property<String> license
final Property<String> licenseUrl
final Property<String> copyright
Expand All @@ -73,6 +74,7 @@ class ProjectImpl implements Project {
longDescription = objects.property(String).convention(descriptionProvider)
website = objects.property(String).convention(Providers.notDefined())
license = objects.property(String).convention(Providers.notDefined())
inceptionYear = objects.property(String).convention(Providers.notDefined())
licenseUrl = objects.property(String).convention(Providers.notDefined())
copyright = objects.property(String).convention(Providers.notDefined())
vendor = objects.property(String).convention(Providers.notDefined())
Expand Down Expand Up @@ -147,6 +149,7 @@ class ProjectImpl implements Project {
if (longDescription.present) project.longDescription = longDescription.get()
if (website.present) project.links.homepage = website.get()
if (license.present) project.license = license.get()
if (inceptionYear.present) project.inceptionYear = inceptionYear.get()
if (licenseUrl.present) project.links.license = licenseUrl.get()
if (copyright.present) project.copyright = copyright.get()
if (vendor.present) project.vendor = vendor.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ private static void configureProject(Project project, MavenProject mavenProject,
project.getLinks().setLicense(license.getUrl());
}
}
if (!project.getExtraProperties().containsKey("inceptionYear") &&
isNotBlank(mavenProject.getInceptionYear())) {
project.getExtraProperties().put("inceptionYear", mavenProject.getInceptionYear());
if (isBlank(project.getInceptionYear()) && isNotBlank(mavenProject.getInceptionYear())) {
project.setInceptionYear(mavenProject.getInceptionYear());
}

project.getJava().setGroupId(mavenProject.getGroupId());
Expand Down

0 comments on commit 32a660e

Please sign in to comment.