mirror of
https://github.com/ethauvin/rife2.git
synced 2025-04-30 10:38: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.tools.StringUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class PomBuilder {
|
||||
private PublishInfo info_ = null;
|
||||
private DependencyScopes dependencies_ = new DependencyScopes();
|
||||
|
@ -36,11 +38,17 @@ public class PomBuilder {
|
|||
|
||||
var info = info();
|
||||
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()) {
|
||||
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.setBlock("licenses-tag");
|
||||
|
@ -48,14 +56,20 @@ public class PomBuilder {
|
|||
|
||||
if (!info.developers().isEmpty()) {
|
||||
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.setBlock("developers-tag");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,55 +10,39 @@ public class PublishDeveloper {
|
|||
private String email_;
|
||||
private String url_;
|
||||
|
||||
public String getId() {
|
||||
public String id() {
|
||||
return id_;
|
||||
}
|
||||
|
||||
public PublishDeveloper id(String id) {
|
||||
setId(id);
|
||||
id_ = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id_ = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name_;
|
||||
}
|
||||
|
||||
public PublishDeveloper name(String name) {
|
||||
setName(name);
|
||||
name_ = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name_ = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
public String email() {
|
||||
return email_;
|
||||
}
|
||||
|
||||
public PublishDeveloper email(String email) {
|
||||
setEmail(email);
|
||||
email_ = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email_ = email;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
public String url() {
|
||||
return url_;
|
||||
}
|
||||
|
||||
public PublishDeveloper url(String url) {
|
||||
setUrl(url);
|
||||
url_ = url;
|
||||
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 PublishScm scm_ = null;
|
||||
|
||||
public String getGroupId() {
|
||||
public String groupId() {
|
||||
return groupId_;
|
||||
}
|
||||
|
||||
public PublishInfo groupId(String groupId) {
|
||||
setGroupId(groupId);
|
||||
groupId_ = groupId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
groupId_ = groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
public String artifactId() {
|
||||
return artifactId_;
|
||||
}
|
||||
|
||||
public PublishInfo artifactId(String artifactId) {
|
||||
setArtifactId(artifactId);
|
||||
artifactId_ = artifactId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setArtifactId(String artifactId) {
|
||||
artifactId_ = artifactId;
|
||||
}
|
||||
|
||||
public VersionNumber getVersion() {
|
||||
public VersionNumber version() {
|
||||
return version_;
|
||||
}
|
||||
|
||||
public PublishInfo version(VersionNumber version) {
|
||||
setVersion(version);
|
||||
version_ = version;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setVersion(VersionNumber version) {
|
||||
version_ = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name_;
|
||||
}
|
||||
|
||||
public PublishInfo name(String name) {
|
||||
setName(name);
|
||||
name_ = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
public String description() {
|
||||
return description_;
|
||||
}
|
||||
|
||||
public PublishInfo description(String description) {
|
||||
setDescription(description);
|
||||
description_ = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
description_ = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
public String url() {
|
||||
return url_;
|
||||
}
|
||||
|
||||
public PublishInfo url(String url) {
|
||||
setUrl(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
url_ = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PublishInfo developer(PublishDeveloper developer) {
|
||||
|
|
|
@ -8,29 +8,21 @@ public class PublishLicense {
|
|||
private String name_;
|
||||
private String url_;
|
||||
|
||||
public String getName() {
|
||||
public String name() {
|
||||
return name_;
|
||||
}
|
||||
|
||||
public PublishLicense name(String name) {
|
||||
setName(name);
|
||||
name_ = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name_ = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
public String url() {
|
||||
return url_;
|
||||
}
|
||||
|
||||
public PublishLicense url(String url) {
|
||||
setUrl(url);
|
||||
url_ = url;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url_ = url;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,42 +9,30 @@ public class PublishScm {
|
|||
private String developerConnection_;
|
||||
private String url_;
|
||||
|
||||
public String getConnection() {
|
||||
public String connection() {
|
||||
return connection_;
|
||||
}
|
||||
|
||||
public PublishScm connection(String connection) {
|
||||
setConnection(connection);
|
||||
connection_ = connection;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setConnection(String connection) {
|
||||
this.connection_ = connection;
|
||||
}
|
||||
|
||||
public String getDeveloperConnection() {
|
||||
public String developerConnection() {
|
||||
return developerConnection_;
|
||||
}
|
||||
|
||||
public PublishScm developerConnection(String developerConnection) {
|
||||
setDeveloperConnection(developerConnection);
|
||||
developerConnection_ = developerConnection;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setDeveloperConnection(String developerConnection) {
|
||||
this.developerConnection_ = developerConnection;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
public String url() {
|
||||
return url_;
|
||||
}
|
||||
|
||||
public PublishScm url(String url) {
|
||||
setUrl(url);
|
||||
url_ = url;
|
||||
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() {
|
||||
var operation = new PublishOperation();
|
||||
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
|
||||
|
|
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