Add support for writing license and developer in Maven pom

See gh-1029
This commit is contained in:
Jafer Khan
2019-11-04 00:00:39 +05:00
committed by Stephane Nicoll
parent 175ed1b8e9
commit f50af605fe
7 changed files with 835 additions and 0 deletions

View File

@@ -16,6 +16,10 @@
package io.spring.initializr.generator.buildsystem.maven;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import io.spring.initializr.generator.buildsystem.BuildSettings;
import io.spring.initializr.generator.packaging.Packaging;
@@ -23,6 +27,7 @@ import io.spring.initializr.generator.packaging.Packaging;
* Maven {@link BuildSettings}.
*
* @author Stephane Nicoll
* @author Jafer Khan Shamshad
*/
public class MavenBuildSettings extends BuildSettings {
@@ -34,6 +39,10 @@ public class MavenBuildSettings extends BuildSettings {
private final String description;
private final List<MavenLicense> licenses;
private final List<MavenDeveloper> developers;
private final String sourceDirectory;
private final String testSourceDirectory;
@@ -44,6 +53,8 @@ public class MavenBuildSettings extends BuildSettings {
this.packaging = builder.packaging;
this.name = builder.name;
this.description = builder.description;
this.licenses = Collections.unmodifiableList(new ArrayList<>(builder.licenses));
this.developers = Collections.unmodifiableList(new ArrayList<>(builder.developers));
this.sourceDirectory = builder.sourceDirectory;
this.testSourceDirectory = builder.testSourceDirectory;
}
@@ -82,6 +93,22 @@ public class MavenBuildSettings extends BuildSettings {
return this.description;
}
/**
* Return the {@linkplain MavenLicense licenses} associated with the project.
* @return the licenses of the project or {@code null}
*/
public List<MavenLicense> getLicenses() {
return this.licenses;
}
/**
* Return the {@linkplain MavenDeveloper developers} associated with the project.
* @return the developers of the project or {@code null}
*/
public List<MavenDeveloper> getDevelopers() {
return this.developers;
}
/**
* Return the location of main source code. Can use Maven properties such as
* {@code ${basedir}}.
@@ -115,6 +142,10 @@ public class MavenBuildSettings extends BuildSettings {
private String description;
private List<MavenLicense> licenses = new ArrayList<>();
private List<MavenDeveloper> developers = new ArrayList<>();
private String sourceDirectory;
private String testSourceDirectory;
@@ -165,6 +196,26 @@ public class MavenBuildSettings extends BuildSettings {
return self();
}
/**
* Set the licenses of the project.
* @param licenses the licenses associated with the project
* @return this for method chaining
*/
public Builder licenses(List<MavenLicense> licenses) {
this.licenses = licenses;
return self();
}
/**
* Set the developers of the project.
* @param developers the developers associated with the project
* @return this for method chaining
*/
public Builder developers(List<MavenDeveloper> developers) {
this.developers = developers;
return self();
}
/**
* Set a human readable description of the project.
* @param description the description of the project

View File

@@ -20,6 +20,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -46,6 +47,7 @@ import io.spring.initializr.generator.version.VersionReference;
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Olga Maciaszek-Sharma
* @author Jafer Khan Shamshad
*/
public class MavenBuildWriter {
@@ -62,6 +64,8 @@ public class MavenBuildWriter {
writeProjectCoordinates(writer, settings);
writePackaging(writer, settings);
writeProjectName(writer, settings);
writeLicenses(writer, settings);
writeDevelopers(writer, settings);
writeProperties(writer, build.properties());
writeDependencies(writer, build);
writeDependencyManagement(writer, build);
@@ -129,6 +133,51 @@ public class MavenBuildWriter {
});
}
private void writeDevelopers(IndentingWriter writer, MavenBuildSettings settings) {
if (settings.getDevelopers().isEmpty()) {
return;
}
writeElement(writer, "developers",
() -> writeCollection(writer, settings.getDevelopers(), this::writeDeveloper));
}
private void writeDeveloper(IndentingWriter writer, MavenDeveloper developer) {
writeElement(writer, "developer", () -> {
writeSingleElement(writer, "id", developer.getId());
writeSingleElement(writer, "name", developer.getName());
writeSingleElement(writer, "email", developer.getEmail());
writeSingleElement(writer, "url", developer.getUrl());
writeSingleElement(writer, "organization", developer.getOrganization());
writeSingleElement(writer, "organizationUrl", developer.getOrganizationUrl());
List<String> roles = developer.getRoles();
if (!roles.isEmpty()) {
writeElement(writer, "roles", () -> roles.forEach((role) -> writeSingleElement(writer, "role", role)));
}
writeSingleElement(writer, "timezone", developer.getTimezone());
Map<String, String> properties = developer.getProperties();
if (!properties.isEmpty()) {
writeElement(writer, "properties",
() -> properties.forEach((key, value) -> writeSingleElement(writer, key, value)));
}
});
}
private void writeLicenses(IndentingWriter writer, MavenBuildSettings settings) {
if (settings.getLicenses().isEmpty()) {
return;
}
writeElement(writer, "licenses", () -> writeCollection(writer, settings.getLicenses(), this::writeLicense));
}
private void writeLicense(IndentingWriter writer, MavenLicense license) {
writeElement(writer, "license", () -> {
writeSingleElement(writer, "name", license.getName());
writeSingleElement(writer, "url", license.getUrl());
writeSingleElement(writer, "distribution", license.getDistribution());
writeSingleElement(writer, "comments", license.getComments());
});
}
private void writeDependencies(IndentingWriter writer, MavenBuild build) {
if (build.dependencies().isEmpty()) {
return;

View File

@@ -0,0 +1,254 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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 io.spring.initializr.generator.buildsystem.maven;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* A {@code <developer>} in a Maven pom.
*
* @author Jafer Khan Shamshad
*/
public class MavenDeveloper {
private final String id;
private final String name;
private final String email;
private final String url;
private final String organization;
private final String organizationUrl;
private final List<String> roles;
private final String timezone;
private final Map<String, String> properties;
public MavenDeveloper(Builder builder) {
this.id = builder.id;
this.name = builder.name;
this.email = builder.email;
this.url = builder.url;
this.organization = builder.organization;
this.organizationUrl = builder.organizationUrl;
this.roles = Collections.unmodifiableList(new ArrayList<>(builder.roles));
this.timezone = builder.timezone;
this.properties = Collections.unmodifiableMap(new LinkedHashMap<>(builder.properties));
}
/**
* Return the ID of the developer.
* @return the ID
*/
public String getId() {
return this.id;
}
/**
* Return the name of the developer.
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Return the e-mail address of the developer.
* @return the e-mail address
*/
public String getEmail() {
return this.email;
}
/**
* Return the URL of the developer.
* @return the URL
*/
public String getUrl() {
return this.url;
}
/**
* Return the organization's name of the developer.
* @return the organization
*/
public String getOrganization() {
return this.organization;
}
/**
* Return the associated organization's URL of the developer.
* @return the organization's URL
*/
public String getOrganizationUrl() {
return this.organizationUrl;
}
/**
* Return the roles of the developer.
* @return the roles
*/
public List<String> getRoles() {
return this.roles;
}
/**
* Return the timezone associated with the developer.
* @return the timezone
*/
public String getTimezone() {
return this.timezone;
}
/**
* Return other properties associated with the developer.
* @return other properties
*/
public Map<String, String> getProperties() {
return this.properties;
}
/**
* Builder for a {@link MavenDeveloper}.
*/
public static class Builder {
private String id;
private String name;
private String email;
private String url;
private String organization;
private String organizationUrl;
private final List<String> roles = new ArrayList<>();
private String timezone;
private final Map<String, String> properties = new LinkedHashMap<>();
/**
* Set the ID of the developer.
* @param id the ID of the developer or {@code null}
* @return this for method chaining
*/
public Builder id(String id) {
this.id = id;
return this;
}
/**
* Set the name of the developer.
* @param name the name of the developer or {@code null}
* @return this for method chaining
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Set the e-mail address of the developer.
* @param email the e-mail address of the developer or {@code null}
* @return this for method chaining
*/
public Builder email(String email) {
this.email = email;
return this;
}
/**
* Set the URL of the developer.
* @param url the URL of the developer or {@code null}
* @return this for method chaining
*/
public Builder url(String url) {
this.url = url;
return this;
}
/**
* Set the organization's name of the developer.
* @param organization the organization of the developer or {@code null}
* @return this for method chaining
*/
public Builder organization(String organization) {
this.organization = organization;
return this;
}
/**
* Set the associated organization's URL of the developer.
* @param organizationUrl the URL of the organization or {@code null}
* @return this for method chaining
*/
public Builder organizationUrl(String organizationUrl) {
this.organizationUrl = organizationUrl;
return this;
}
/**
* Add a role of the developer.
* @param role the role of the developer
* @return this for method chaining
*/
public Builder role(String role) {
this.roles.add(role);
return this;
}
/**
* Set the timezone associated with the developer.
* @param timezone the timezone that the developer lives in or {@code null}
* @return this for method chaining
*/
public Builder timezone(String timezone) {
this.timezone = timezone;
return this;
}
/**
* Add a property associated with the developer.
* @param key the appropriate key associated with the property
* @param value the value of the property
* @return this for method chaining
*/
public Builder property(String key, String value) {
this.properties.put(key, value);
return this;
}
public MavenDeveloper build() {
return new MavenDeveloper(this);
}
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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 io.spring.initializr.generator.buildsystem.maven;
/**
* A {@code <license>} in a Maven pom.
*
* @author Jafer Khan Shamshad
*/
public class MavenLicense {
private final String name;
private final String url;
private final String distribution;
private final String comments;
public MavenLicense(Builder builder) {
this.name = builder.name;
this.url = builder.url;
this.distribution = builder.distribution;
this.comments = builder.comments;
}
/**
* Return the name of the license.
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Return the URL of the license.
* @return the URL
*/
public String getUrl() {
return this.url;
}
/**
* Return the distribution mechanism of the project associated with the license.
* @return the distribution mechanism
*/
public String getDistribution() {
return this.distribution;
}
/**
* Return the comments associated with the license.
* @return the comments
*/
public String getComments() {
return this.comments;
}
/**
* Builder for a {@link MavenLicense}.
*/
public static class Builder {
private String name;
private String url;
private String distribution;
private String comments;
/**
* Set the name of the license.
* @param name the name of the license or {@code null}
* @return this for method chaining
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* Set the URL of the license.
* @param url the URL of the license or {@code null}
* @return this for method chaining
*/
public Builder url(String url) {
this.url = url;
return this;
}
/**
* Set the distribution mechanism of the project associated with the license.
* @param distribution the distribution mechanism of the project or {@code null}
* @return this for method chaining
*/
public Builder distribution(String distribution) {
this.distribution = distribution;
return this;
}
/**
* Set comments associated with the license.
* @param comments the comments for the license or {@code null}
* @return this for method chaining
*/
public Builder comments(String comments) {
this.comments = comments;
return this;
}
public MavenLicense build() {
return new MavenLicense(this);
}
}
}

View File

@@ -17,6 +17,7 @@
package io.spring.initializr.generator.buildsystem.maven;
import java.io.StringWriter;
import java.util.Collections;
import java.util.function.Consumer;
import io.spring.initializr.generator.buildsystem.BillOfMaterials;
@@ -36,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Stephane Nicoll
* @author Olga Maciaszek-Sharma
* @author Jafer Khan Shamshad
*/
class MavenBuildWriterTests {
@@ -107,6 +109,121 @@ class MavenBuildWriterTests {
});
}
@Test
void pomWithNoLicense() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo").build();
generatePom(build, (pom) -> assertThat(pom.nodeAtPath("/project/licenses")).isNull());
}
@Test
void pomWithLicense() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo")
.licenses(Collections.singletonList(new MavenLicense.Builder().name("Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0").distribution("repo")
.comments("A business-friendly OSS license").build()));
generatePom(build, (pom) -> {
NodeAssert licenses = pom.nodeAtPath("/project/licenses");
assertThat(licenses).isNotNull();
NodeAssert license = licenses.nodeAtPath("license");
assertThat(license).isNotNull();
assertThat(license).textAtPath("name").isEqualTo("Apache License, Version 2.0");
assertThat(license).textAtPath("url").isEqualTo("https://www.apache.org/licenses/LICENSE-2.0");
assertThat(license).textAtPath("distribution").isEqualTo("repo");
assertThat(license).textAtPath("comments").isEqualTo("A business-friendly OSS license");
});
}
@Test
void pomWithNoDeveloper() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo").build();
generatePom(build, (pom) -> assertThat(pom.nodeAtPath("/project/developers")).isNull());
}
@Test
void pomWithDeveloper() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo")
.developers(Collections.singletonList(new MavenDeveloper.Builder().id("jaferkhan")
.name("Jafer Khan Shamshad").email("jaferkhan@example.com")
.url("http://www.example.com/jaferkhan").organization("ACME")
.organizationUrl("http://www.example.com").timezone("Asia/Karachi").build()))
.build();
generatePom(build, (pom) -> {
NodeAssert developers = pom.nodeAtPath("/project/developers");
assertThat(developers).isNotNull();
NodeAssert developer = developers.nodeAtPath("developer");
assertThat(developer).isNotNull();
assertThat(developer).textAtPath("id").isEqualTo("jaferkhan");
assertThat(developer).textAtPath("name").isEqualTo("Jafer Khan Shamshad");
assertThat(developer).textAtPath("email").isEqualTo("jaferkhan@example.com");
assertThat(developer).textAtPath("url").isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer).textAtPath("organization").isEqualTo("ACME");
assertThat(developer).textAtPath("organizationUrl").isEqualTo("http://www.example.com");
assertThat(developer.nodeAtPath("roles")).isNull();
assertThat(developer).textAtPath("timezone").isEqualTo("Asia/Karachi");
assertThat(developer.nodeAtPath("properties")).isNull();
});
}
@Test
void pomWithDeveloperWithRoles() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo")
.developers(Collections.singletonList(new MavenDeveloper.Builder().id("jaferkhan")
.name("Jafer Khan Shamshad").role("developer").role("tester").build()))
.build();
generatePom(build, (pom) -> {
NodeAssert developers = pom.nodeAtPath("/project/developers");
assertThat(developers).isNotNull();
NodeAssert developer = developers.nodeAtPath("developer");
assertThat(developer).isNotNull();
assertThat(developer).textAtPath("id").isEqualTo("jaferkhan");
assertThat(developer).textAtPath("name").isEqualTo("Jafer Khan Shamshad");
assertThat(developer).textAtPath("email").isNullOrEmpty();
assertThat(developer).textAtPath("url").isNullOrEmpty();
assertThat(developer).textAtPath("organization").isNullOrEmpty();
assertThat(developer).textAtPath("organizationUrl").isNullOrEmpty();
assertThat(developer).textAtPath("timezone").isNullOrEmpty();
assertThat(developer.nodeAtPath("properties")).isNull();
NodeAssert roles = developer.nodeAtPath("roles");
assertThat(roles).isNotNull();
roles.nodesAtPath("role").hasSize(2);
assertThat(roles).textAtPath("role[1]").isEqualTo("developer");
assertThat(roles).textAtPath("role[2]").isEqualTo("tester");
});
}
@Test
void pomWithDeveloperWithProperties() {
MavenBuild build = new MavenBuild();
build.settings().coordinates("com.example.demo", "demo")
.developers(Collections.singletonList(new MavenDeveloper.Builder().id("jaferkhan")
.name("Jafer Khan Shamshad").property("hometown", "Mardan").property("ethnicity", "Pukhtun")
.property("religion", "Islam").build()))
.build();
generatePom(build, (pom) -> {
NodeAssert developers = pom.nodeAtPath("/project/developers");
assertThat(developers).isNotNull();
NodeAssert developer = developers.nodeAtPath("developer");
assertThat(developer).isNotNull();
assertThat(developer).textAtPath("id").isEqualTo("jaferkhan");
assertThat(developer).textAtPath("name").isEqualTo("Jafer Khan Shamshad");
assertThat(developer).textAtPath("email").isNullOrEmpty();
assertThat(developer).textAtPath("url").isNullOrEmpty();
assertThat(developer).textAtPath("organization").isNullOrEmpty();
assertThat(developer).textAtPath("organizationUrl").isNullOrEmpty();
assertThat(developer).textAtPath("timezone").isNullOrEmpty();
NodeAssert properties = developer.nodeAtPath("properties");
assertThat(properties).isNotNull();
assertThat(properties).textAtPath("hometown").isEqualTo("Mardan");
assertThat(properties).textAtPath("ethnicity").isEqualTo("Pukhtun");
assertThat(properties).textAtPath("religion").isEqualTo("Islam");
});
}
@Test
void pomWithAnnotationProcessorDependency() {
MavenBuild build = new MavenBuild();

View File

@@ -0,0 +1,162 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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 io.spring.initializr.generator.buildsystem.maven;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
/**
* Tests for {@link MavenDeveloper}
*
* @author Jafer Khan Shamshad
*/
class MavenDeveloperTests {
@Test
void developerWithIdOnly() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isNull();
assertThat(developer.getEmail()).isNull();
assertThat(developer.getUrl()).isNull();
assertThat(developer.getOrganization()).isNull();
assertThat(developer.getOrganizationUrl()).isNull();
assertThat(developer.getRoles()).hasSize(0);
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithName() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isNull();
assertThat(developer.getUrl()).isNull();
assertThat(developer.getOrganization()).isNull();
assertThat(developer.getOrganizationUrl()).isNull();
assertThat(developer.getRoles()).hasSize(0);
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithEmail() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isNull();
assertThat(developer.getOrganization()).isNull();
assertThat(developer.getOrganizationUrl()).isNull();
assertThat(developer.getRoles()).hasSize(0);
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithUrl() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").url("http://www.example.com/jaferkhan").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer.getOrganization()).isNull();
assertThat(developer.getOrganizationUrl()).isNull();
assertThat(developer.getRoles()).hasSize(0);
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithOrganization() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").url("http://www.example.com/jaferkhan").organization("ACME")
.organizationUrl("http://www.example.com").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer.getOrganization()).isEqualTo("ACME");
assertThat(developer.getOrganizationUrl()).isEqualTo("http://www.example.com");
assertThat(developer.getRoles()).hasSize(0);
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithRoles() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").url("http://www.example.com/jaferkhan").organization("ACME")
.organizationUrl("http://www.example.com").role("developer").role("tester").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer.getOrganization()).isEqualTo("ACME");
assertThat(developer.getOrganizationUrl()).isEqualTo("http://www.example.com");
assertThat(developer.getRoles()).hasSize(2);
assertThat(developer.getRoles().isEmpty()).isFalse();
assertThat(developer.getRoles()).containsExactly("developer", "tester");
assertThat(developer.getTimezone()).isNull();
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithTimezone() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").url("http://www.example.com/jaferkhan").organization("ACME")
.organizationUrl("http://www.example.com").role("developer").role("tester").timezone("Asia/Karachi")
.build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer.getOrganization()).isEqualTo("ACME");
assertThat(developer.getOrganizationUrl()).isEqualTo("http://www.example.com");
assertThat(developer.getRoles()).hasSize(2);
assertThat(developer.getRoles()).containsExactly("developer", "tester");
assertThat(developer.getTimezone()).isEqualTo("Asia/Karachi");
assertThat(developer.getProperties()).hasSize(0);
}
@Test
void developerWithProperties() {
MavenDeveloper developer = new MavenDeveloper.Builder().id("jaferkhan").name("Jafer Khan Shamshad")
.email("jaferkhan@example.com").url("http://www.example.com/jaferkhan").organization("ACME")
.organizationUrl("http://www.example.com").role("developer").role("tester").timezone("Asia/Karachi")
.property("hometown", "Mardan").property("ethnicity", "Pukhtun").property("religion", "Islam").build();
assertThat(developer.getId()).isEqualTo("jaferkhan");
assertThat(developer.getName()).isEqualTo("Jafer Khan Shamshad");
assertThat(developer.getEmail()).isEqualTo("jaferkhan@example.com");
assertThat(developer.getUrl()).isEqualTo("http://www.example.com/jaferkhan");
assertThat(developer.getOrganization()).isEqualTo("ACME");
assertThat(developer.getOrganizationUrl()).isEqualTo("http://www.example.com");
assertThat(developer.getRoles()).hasSize(2);
assertThat(developer.getRoles().isEmpty()).isFalse();
assertThat(developer.getRoles()).containsExactly("developer", "tester");
assertThat(developer.getTimezone()).isEqualTo("Asia/Karachi");
assertThat(developer.getProperties()).hasSize(3);
assertThat(developer.getProperties()).containsExactly(entry("hometown", "Mardan"),
entry("ethnicity", "Pukhtun"), entry("religion", "Islam"));
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* 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 io.spring.initializr.generator.buildsystem.maven;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link MavenLicense}
*
* @author Jafer Khan Shamshad
*/
class MavenLicenseTests {
@Test
void licenseWithNameOnly() {
MavenLicense license = new MavenLicense.Builder().name("Apache License, Version 2.0").build();
assertThat(license.getName()).isEqualTo("Apache License, Version 2.0");
assertThat(license.getUrl()).isNull();
assertThat(license.getDistribution()).isNull();
assertThat(license.getComments()).isNull();
}
@Test
void licenseWithUrl() {
MavenLicense license = new MavenLicense.Builder().name("Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0").build();
assertThat(license.getName()).isEqualTo("Apache License, Version 2.0");
assertThat(license.getUrl()).isEqualTo("https://www.apache.org/licenses/LICENSE-2.0");
assertThat(license.getDistribution()).isNull();
assertThat(license.getComments()).isNull();
}
@Test
void licenseWithDistribution() {
MavenLicense license = new MavenLicense.Builder().name("Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0").distribution("repo").build();
assertThat(license.getName()).isEqualTo("Apache License, Version 2.0");
assertThat(license.getUrl()).isEqualTo("https://www.apache.org/licenses/LICENSE-2.0");
assertThat(license.getDistribution()).isEqualTo("repo");
assertThat(license.getComments()).isNull();
}
@Test
void licenseWithComments() {
MavenLicense license = new MavenLicense.Builder().name("Apache License, Version 2.0")
.url("https://www.apache.org/licenses/LICENSE-2.0").distribution("repo")
.comments("A business-friendly OSS license").build();
assertThat(license.getName()).isEqualTo("Apache License, Version 2.0");
assertThat(license.getUrl()).isEqualTo("https://www.apache.org/licenses/LICENSE-2.0");
assertThat(license.getDistribution()).isEqualTo("repo");
assertThat(license.getComments()).isEqualTo("A business-friendly OSS license");
}
}