mirror of
https://github.com/ethauvin/rife2.git
synced 2025-05-01 19:08:12 -07:00
WIP publish operation
This commit is contained in:
parent
1676a8aff2
commit
d780cf3187
9 changed files with 238 additions and 94 deletions
53
lib/src/main/java/rife/bld/publish/MetadataBuilder.java
Normal file
53
lib/src/main/java/rife/bld/publish/MetadataBuilder.java
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||||
|
*/
|
||||||
|
package rife.bld.publish;
|
||||||
|
|
||||||
|
import rife.template.TemplateFactory;
|
||||||
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
|
import java.time.*;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class MetadataBuilder {
|
||||||
|
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||||
|
|
||||||
|
private PublishInfo info_ = null;
|
||||||
|
private ZonedDateTime timestamp_ = null;
|
||||||
|
|
||||||
|
public MetadataBuilder info(PublishInfo info) {
|
||||||
|
info_ = info;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PublishInfo info() {
|
||||||
|
return info_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetadataBuilder updated(ZonedDateTime timestamp) {
|
||||||
|
timestamp_ = timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime updated() {
|
||||||
|
return timestamp_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String build() {
|
||||||
|
var t = TemplateFactory.XML.get("bld.maven_metadata_blueprint");
|
||||||
|
|
||||||
|
var info = info();
|
||||||
|
if (info != null) {
|
||||||
|
t.setValueEncoded("groupId", Objects.requireNonNullElse(info.groupId(), ""));
|
||||||
|
t.setValueEncoded("artifactId", Objects.requireNonNullElse(info.artifactId(), ""));
|
||||||
|
t.setValueEncoded("version", Objects.requireNonNullElse(info.version(), ""));
|
||||||
|
}
|
||||||
|
if (timestamp_ != null) {
|
||||||
|
t.setValueEncoded("timestamp", Objects.requireNonNullElse(TIMESTAMP_FORMATTER.format(updated().withZoneSameInstant(ZoneId.of("UTC"))), ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringUtils.stripBlankLines(t.getContent());
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,8 @@ import rife.template.Template;
|
||||||
import rife.template.TemplateFactory;
|
import rife.template.TemplateFactory;
|
||||||
import rife.tools.StringUtils;
|
import rife.tools.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class PomBuilder {
|
public class PomBuilder {
|
||||||
private PublishInfo info_ = null;
|
private PublishInfo info_ = null;
|
||||||
private DependencyScopes dependencies_ = new DependencyScopes();
|
private DependencyScopes dependencies_ = new DependencyScopes();
|
||||||
|
@ -36,11 +38,17 @@ public class PomBuilder {
|
||||||
|
|
||||||
var info = info();
|
var info = info();
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
t.setBean(info);
|
t.setValueEncoded("groupId", Objects.requireNonNullElse(info.groupId(), ""));
|
||||||
|
t.setValueEncoded("artifactId", Objects.requireNonNullElse(info.artifactId(), ""));
|
||||||
|
t.setValueEncoded("version", Objects.requireNonNullElse(info.version(), ""));
|
||||||
|
t.setValueEncoded("name", Objects.requireNonNullElse(info.name(), ""));
|
||||||
|
t.setValueEncoded("description", Objects.requireNonNullElse(info.description(), ""));
|
||||||
|
t.setValueEncoded("url", Objects.requireNonNullElse(info.url(), ""));
|
||||||
|
|
||||||
if (!info.licenses().isEmpty()) {
|
if (!info.licenses().isEmpty()) {
|
||||||
for (var license : info.licenses()) {
|
for (var license : info.licenses()) {
|
||||||
t.setBean(license, "license-");
|
t.setValueEncoded("license-name", Objects.requireNonNullElse(license.name(), ""));
|
||||||
|
t.setValueEncoded("license-url", Objects.requireNonNullElse(license.url(), ""));
|
||||||
t.appendBlock("licenses", "license");
|
t.appendBlock("licenses", "license");
|
||||||
}
|
}
|
||||||
t.setBlock("licenses-tag");
|
t.setBlock("licenses-tag");
|
||||||
|
@ -48,14 +56,20 @@ public class PomBuilder {
|
||||||
|
|
||||||
if (!info.developers().isEmpty()) {
|
if (!info.developers().isEmpty()) {
|
||||||
for (var developer : info.developers()) {
|
for (var developer : info.developers()) {
|
||||||
t.setBean(developer, "developer-");
|
t.setValueEncoded("developer-id", Objects.requireNonNullElse(developer.id(), ""));
|
||||||
|
t.setValueEncoded("developer-name", Objects.requireNonNullElse(developer.name(), ""));
|
||||||
|
t.setValueEncoded("developer-email", Objects.requireNonNullElse(developer.email(), ""));
|
||||||
|
t.setValueEncoded("developer-url", Objects.requireNonNullElse(developer.url(), ""));
|
||||||
t.appendBlock("developers", "developer");
|
t.appendBlock("developers", "developer");
|
||||||
}
|
}
|
||||||
t.setBlock("developers-tag");
|
t.setBlock("developers-tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.scm() != null) {
|
if (info.scm() != null) {
|
||||||
t.setBean(info.scm(), "scm-");
|
var scm = info.scm();
|
||||||
|
t.setValueEncoded("scm-connection", Objects.requireNonNullElse(scm.connection(), ""));
|
||||||
|
t.setValueEncoded("scm-developerConnection", Objects.requireNonNullElse(scm.developerConnection(), ""));
|
||||||
|
t.setValueEncoded("scm-url", Objects.requireNonNullElse(scm.url(), ""));
|
||||||
t.setBlock("scm-tag");
|
t.setBlock("scm-tag");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,55 +10,39 @@ public class PublishDeveloper {
|
||||||
private String email_;
|
private String email_;
|
||||||
private String url_;
|
private String url_;
|
||||||
|
|
||||||
public String getId() {
|
public String id() {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishDeveloper id(String id) {
|
public PublishDeveloper id(String id) {
|
||||||
setId(id);
|
id_ = id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public String name() {
|
||||||
this.id_ = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishDeveloper name(String name) {
|
public PublishDeveloper name(String name) {
|
||||||
setName(name);
|
name_ = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public String email() {
|
||||||
this.name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEmail() {
|
|
||||||
return email_;
|
return email_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishDeveloper email(String email) {
|
public PublishDeveloper email(String email) {
|
||||||
setEmail(email);
|
email_ = email;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmail(String email) {
|
public String url() {
|
||||||
this.email_ = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url_;
|
return url_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishDeveloper url(String url) {
|
public PublishDeveloper url(String url) {
|
||||||
setUrl(url);
|
url_ = url;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url_ = url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,82 +21,58 @@ public class PublishInfo {
|
||||||
private final List<PublishDeveloper> developers_ = new ArrayList<>();
|
private final List<PublishDeveloper> developers_ = new ArrayList<>();
|
||||||
private PublishScm scm_ = null;
|
private PublishScm scm_ = null;
|
||||||
|
|
||||||
public String getGroupId() {
|
public String groupId() {
|
||||||
return groupId_;
|
return groupId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo groupId(String groupId) {
|
public PublishInfo groupId(String groupId) {
|
||||||
setGroupId(groupId);
|
groupId_ = groupId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGroupId(String groupId) {
|
public String artifactId() {
|
||||||
groupId_ = groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getArtifactId() {
|
|
||||||
return artifactId_;
|
return artifactId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo artifactId(String artifactId) {
|
public PublishInfo artifactId(String artifactId) {
|
||||||
setArtifactId(artifactId);
|
artifactId_ = artifactId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setArtifactId(String artifactId) {
|
public VersionNumber version() {
|
||||||
artifactId_ = artifactId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VersionNumber getVersion() {
|
|
||||||
return version_;
|
return version_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo version(VersionNumber version) {
|
public PublishInfo version(VersionNumber version) {
|
||||||
setVersion(version);
|
version_ = version;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(VersionNumber version) {
|
public String name() {
|
||||||
version_ = version;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo name(String name) {
|
public PublishInfo name(String name) {
|
||||||
setName(name);
|
name_ = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public String description() {
|
||||||
name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description_;
|
return description_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo description(String description) {
|
public PublishInfo description(String description) {
|
||||||
setDescription(description);
|
description_ = description;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public String url() {
|
||||||
description_ = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url_;
|
return url_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo url(String url) {
|
public PublishInfo url(String url) {
|
||||||
setUrl(url);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
url_ = url;
|
url_ = url;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishInfo developer(PublishDeveloper developer) {
|
public PublishInfo developer(PublishDeveloper developer) {
|
||||||
|
|
|
@ -8,29 +8,21 @@ public class PublishLicense {
|
||||||
private String name_;
|
private String name_;
|
||||||
private String url_;
|
private String url_;
|
||||||
|
|
||||||
public String getName() {
|
public String name() {
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishLicense name(String name) {
|
public PublishLicense name(String name) {
|
||||||
setName(name);
|
name_ = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public String url() {
|
||||||
this.name_ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url_;
|
return url_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishLicense url(String url) {
|
public PublishLicense url(String url) {
|
||||||
setUrl(url);
|
url_ = url;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url_ = url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,42 +9,30 @@ public class PublishScm {
|
||||||
private String developerConnection_;
|
private String developerConnection_;
|
||||||
private String url_;
|
private String url_;
|
||||||
|
|
||||||
public String getConnection() {
|
public String connection() {
|
||||||
return connection_;
|
return connection_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishScm connection(String connection) {
|
public PublishScm connection(String connection) {
|
||||||
setConnection(connection);
|
connection_ = connection;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnection(String connection) {
|
public String developerConnection() {
|
||||||
this.connection_ = connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeveloperConnection() {
|
|
||||||
return developerConnection_;
|
return developerConnection_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishScm developerConnection(String developerConnection) {
|
public PublishScm developerConnection(String developerConnection) {
|
||||||
setDeveloperConnection(developerConnection);
|
developerConnection_ = developerConnection;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDeveloperConnection(String developerConnection) {
|
public String url() {
|
||||||
this.developerConnection_ = developerConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url_;
|
return url_;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PublishScm url(String url) {
|
public PublishScm url(String url) {
|
||||||
setUrl(url);
|
url_ = url;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUrl(String url) {
|
|
||||||
this.url_ = url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId><!--v groupId--><!--/v--></groupId>
|
||||||
|
<artifactId><!--v artifactId--><!--/v--></artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest><!--v version--><!--/v--></latest>
|
||||||
|
<release><!--v version/--></release>
|
||||||
|
<versions>
|
||||||
|
<version><!--v version/--></version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated><!--v timestamp--><!--/v--></lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
|
@ -20,6 +20,18 @@ public class TestPublishOperation {
|
||||||
void testInstantiation() {
|
void testInstantiation() {
|
||||||
var operation = new PublishOperation();
|
var operation = new PublishOperation();
|
||||||
assertNull(operation.repository());
|
assertNull(operation.repository());
|
||||||
|
assertTrue(operation.dependencies().isEmpty());
|
||||||
|
assertNotNull(operation.info());
|
||||||
|
assertNull(operation.info().groupId());
|
||||||
|
assertNull(operation.info().artifactId());
|
||||||
|
assertNull(operation.info().version());
|
||||||
|
assertNull(operation.info().name());
|
||||||
|
assertNull(operation.info().description());
|
||||||
|
assertNull(operation.info().url());
|
||||||
|
assertTrue(operation.info().licenses().isEmpty());
|
||||||
|
assertTrue(operation.info().developers().isEmpty());
|
||||||
|
assertNull(operation.info().scm());
|
||||||
|
assertTrue(operation.artifacts().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
112
lib/src/test/java/rife/bld/publish/TestMetadataBuilder.java
Normal file
112
lib/src/test/java/rife/bld/publish/TestMetadataBuilder.java
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2001-2023 Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License")
|
||||||
|
*/
|
||||||
|
package rife.bld.publish;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import rife.bld.dependencies.*;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class TestMetadataBuilder {
|
||||||
|
@Test
|
||||||
|
void testInstantiation() {
|
||||||
|
var builder = new MetadataBuilder();
|
||||||
|
assertNull(builder.info());
|
||||||
|
assertNull(builder.updated());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testEmptyBuild() {
|
||||||
|
var builder = new MetadataBuilder();
|
||||||
|
assertEquals("""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId></groupId>
|
||||||
|
<artifactId></artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest></latest>
|
||||||
|
<release></release>
|
||||||
|
<versions>
|
||||||
|
<version></version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated></lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
||||||
|
""", builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMainInfoBuild() {
|
||||||
|
var builder = new MetadataBuilder()
|
||||||
|
.info(new PublishInfo()
|
||||||
|
.groupId("com.example")
|
||||||
|
.artifactId("myapp")
|
||||||
|
.version(VersionNumber.parse("1.2.3-SNAPSHOT")));
|
||||||
|
assertEquals("""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>myapp</artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest>1.2.3-SNAPSHOT</latest>
|
||||||
|
<release>1.2.3-SNAPSHOT</release>
|
||||||
|
<versions>
|
||||||
|
<version>1.2.3-SNAPSHOT</version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated></lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
||||||
|
""", builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdatedBuild() {
|
||||||
|
var builder = new MetadataBuilder()
|
||||||
|
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
|
||||||
|
assertEquals("""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId></groupId>
|
||||||
|
<artifactId></artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest></latest>
|
||||||
|
<release></release>
|
||||||
|
<versions>
|
||||||
|
<version></version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated>20230327125617</lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
||||||
|
""", builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testCompleteBuild() {
|
||||||
|
var builder = new MetadataBuilder()
|
||||||
|
.info(new PublishInfo()
|
||||||
|
.groupId("com.example")
|
||||||
|
.artifactId("myapp")
|
||||||
|
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
|
||||||
|
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
|
||||||
|
assertEquals("""
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<metadata>
|
||||||
|
<groupId>com.example</groupId>
|
||||||
|
<artifactId>myapp</artifactId>
|
||||||
|
<versioning>
|
||||||
|
<latest>1.2.3-SNAPSHOT</latest>
|
||||||
|
<release>1.2.3-SNAPSHOT</release>
|
||||||
|
<versions>
|
||||||
|
<version>1.2.3-SNAPSHOT</version>
|
||||||
|
</versions>
|
||||||
|
<lastUpdated>20230327125617</lastUpdated>
|
||||||
|
</versioning>
|
||||||
|
</metadata>
|
||||||
|
""", builder.build());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue