2
0
Fork 0
mirror of https://github.com/ethauvin/rife2.git synced 2025-04-30 18:48:13 -07:00

Improvements to release publishing.

Added support for snapshot publishing.
This commit is contained in:
Geert Bevin 2023-03-29 19:40:59 -04:00
parent 56faf51a48
commit ec3797e29c
13 changed files with 795 additions and 96 deletions

View file

@ -6,6 +6,7 @@ package rife.bld;
import rife.bld.help.*;
import rife.bld.operations.*;
import rife.bld.publish.PublishArtifact;
import java.io.File;
import java.util.List;
@ -78,8 +79,8 @@ public class WebProject extends Project {
new WarOperation().fromProject(this).execute();
var operation = new PublishOperation().fromProject(this);
operation.artifacts().add(new File(buildDistDirectory(), uberJarFileName()));
operation.artifacts().add(new File(buildDistDirectory(), warFileName()));
operation.artifacts().add(new PublishArtifact(new File(buildDistDirectory(), uberJarFileName()), "uber", "jar"));
operation.artifacts().add(new PublishArtifact(new File(buildDistDirectory(), warFileName()), "", "war"));
operation.execute();
}

View file

@ -23,12 +23,16 @@ import static rife.bld.dependencies.Scope.test;
*/
public class BlankProjectBlueprint extends Project {
public BlankProjectBlueprint(File work, String packageName, String projectName) {
this(work, packageName, projectName, new VersionNumber(0,0,1));
}
public BlankProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
workDirectory = work;
pkg = packageName;
name = projectName;
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Main";
version = new VersionNumber(0,0,1);
version = versionNumber;
downloadSources = true;
repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);

View file

@ -25,12 +25,16 @@ import static rife.bld.dependencies.Scope.*;
*/
public class Rife2ProjectBlueprint extends WebProject {
public Rife2ProjectBlueprint(File work, String packageName, String projectName) {
this(work, packageName, projectName, new VersionNumber(0,0,1));
}
public Rife2ProjectBlueprint(File work, String packageName, String projectName, VersionNumber versionNumber) {
workDirectory = work;
pkg = packageName;
name = projectName;
mainClass = packageName + "." + StringUtils.capitalize(projectName) + "Site";
version = new VersionNumber(0,0,1);
version = versionNumber;
precompiledTemplateTypes = List.of(TemplateType.HTML);

View file

@ -23,7 +23,7 @@ import java.util.regex.Pattern;
* @since 1.5
*/
public record VersionNumber(Integer major, Integer minor, Integer revision, String qualifier, String separator) implements Comparable<VersionNumber> {
private static final String SNAPSHOT_VERSION = "SNAPSHOT";
public static final String SNAPSHOT_QUALIFIER = "SNAPSHOT";
/**
* Singleton to use when the version is not specified.
@ -142,6 +142,16 @@ public record VersionNumber(Integer major, Integer minor, Integer revision, Stri
return new VersionNumber(major, minor, revision, null);
}
/**
* Retrieves the version number with a different qualifier.
*
* @return this version number with a different qualifier
* @since 1.5.8
*/
public VersionNumber withQualifier(String qualifier) {
return new VersionNumber(major, minor, revision, qualifier);
}
/**
* Returns a primitive integer for the major version component.
*
@ -180,7 +190,7 @@ public record VersionNumber(Integer major, Integer minor, Integer revision, Stri
* @since 1.5.8
*/
public boolean isSnapshot() {
return qualifier().toUpperCase().contains(SNAPSHOT_VERSION);
return qualifier().toUpperCase().contains(SNAPSHOT_QUALIFIER);
}
public int compareTo(VersionNumber other) {

View file

@ -11,7 +11,13 @@ import rife.xml.Xml2Data;
import java.util.*;
import java.util.regex.Pattern;
class Xml2MavenMetadata extends Xml2Data implements MavenMetadata {
/**
* Parses an XML document to generate {@link MavenMetadata}.
*
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @since 1.5.8
*/
public class Xml2MavenMetadata extends Xml2Data implements MavenMetadata {
private VersionNumber latest_ = VersionNumber.UNKNOWN;
private VersionNumber release_ = VersionNumber.UNKNOWN;
private final List<VersionNumber> versions_;
@ -62,10 +68,12 @@ class Xml2MavenMetadata extends Xml2Data implements MavenMetadata {
case "timestamp" -> snapshotTimestamp_ = characterData_.toString();
case "buildNumber" -> snapshotBuildNumber_ = Integer.parseInt(characterData_.toString());
case "snapshot" -> {
if (!versions_.isEmpty()) {
var version = versions_.get(0);
snapshot_ = new VersionNumber(version.major(), version.minor(), version.revision(), snapshotTimestamp_ + "-" + snapshotBuildNumber_);
}
}
}
characterData_ = null;
}

View file

@ -6,6 +6,7 @@ package rife.bld.operations;
import rife.bld.Project;
import rife.bld.dependencies.*;
import rife.bld.dependencies.exceptions.ArtifactNotFoundException;
import rife.bld.operations.exceptions.OperationOptionException;
import rife.bld.operations.exceptions.UploadException;
import rife.bld.publish.*;
@ -19,10 +20,10 @@ import java.nio.file.Files;
import java.security.*;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import static rife.bld.publish.MetadataBuilder.SNAPSHOT_TIMESTAMP_FORMATTER;
import static rife.tools.HttpUtils.HEADER_AUTHORIZATION;
import static rife.tools.HttpUtils.basicAuthorizationHeader;
import static rife.tools.StringUtils.encodeHexLower;
@ -34,12 +35,11 @@ import static rife.tools.StringUtils.encodeHexLower;
* @since 1.5.7
*/
public class PublishOperation extends AbstractOperation<PublishOperation> {
private static final DateTimeFormatter SNAPSHOT_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd.HHmmss");
private ZonedDateTime moment_ = null;
private Repository repository_;
private final DependencyScopes dependencies_ = new DependencyScopes();
private PublishInfo info_ = new PublishInfo();
private final List<File> artifacts_ = new ArrayList<>();
private final List<PublishArtifact> artifacts_ = new ArrayList<>();
/**
* Performs the publish operation.
@ -51,33 +51,90 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
throw new OperationOptionException("ERROR: the publication repository should be specified");
}
var moment = moment_;
if (moment == null) {
moment = ZonedDateTime.now();
}
var current_versions = new ArrayList<VersionNumber>();
var resolver = new DependencyResolver(List.of(repository()), new Dependency(info().groupId(), info().artifactId(), info().version()));
try {
current_versions.addAll(resolver.getMavenMetadata().getVersions());
} catch (ArtifactNotFoundException e) {
// no existing versions could be found
}
var client = HttpClient.newHttpClient();
var info_version = info().version();
var actual_version = info_version;
String snapshot_qualifier = null;
// treat a snapshot version differently
if (info_version.isSnapshot()) {
var snapshot_timestamp = SNAPSHOT_TIMESTAMP_FORMATTER.format(moment.withZoneSameInstant(ZoneId.of("UTC")));
;
// determine with build number to use
var snapshot_build_number = 1;
try {
var snapshot_meta = resolver.getSnapshotMavenMetadata();
snapshot_build_number = snapshot_meta.getSnapshotBuildNumber() + 1;
} catch (ArtifactNotFoundException e) {
// start the build number from the beginning
}
// adapt the actual version that's use by the artifacts
snapshot_qualifier = snapshot_timestamp + "-" + snapshot_build_number;
actual_version = info_version.withQualifier(snapshot_qualifier);
// include version information about each artifact in this snapshot
var metadata = new MetadataBuilder();
for (var artifact : artifacts()) {
metadata.snapshotVersions().add(new SnapshotVersion(artifact.classifier(), artifact.type(), actual_version.toString(), moment));
}
metadata.snapshotVersions().add(new SnapshotVersion(null, "pom", actual_version.toString(), moment));
// upload snapshot metadata
uploadStringArtifact(client, metadata
.info(info())
.updated(moment)
.snapshot(moment, snapshot_build_number)
.build(),
info_version + "/maven-metadata.xml");
}
// upload artifacts
for (var artifact : artifacts()) {
var artifact_name = new StringBuilder(info().artifactId()).append("-").append(actual_version);
if (!artifact.classifier().isEmpty()) {
artifact_name.append("-").append(artifact.classifier());
}
var type = artifact.type();
if (type == null) {
type = "jar";
}
artifact_name.append(".").append(type);
uploadFileArtifact(client,
artifact,
info_version + "/" + artifact.getName());
artifact.file(),
info_version + "/" + artifact_name);
}
// generate and upload pom
uploadStringArtifact(client,
new PomBuilder().info(info()).dependencies(dependencies()).build(),
info_version + "/" + info().artifactId() + "-" + info_version + ".pom");
info_version + "/" + info().artifactId() + "-" + actual_version + ".pom");
// upload metadata
uploadStringArtifact(client,
new MetadataBuilder().info(info()).build(),
new MetadataBuilder()
.info(info())
.updated(moment)
.otherVersions(current_versions)
.build(),
"maven-metadata.xml");
}
private String createSnapshotTimestamp() {
var moment = ZonedDateTime.now();
return SNAPSHOT_TIMESTAMP_FORMATTER.format(moment.withZoneSameInstant(ZoneId.of("UTC")));
}
private void uploadStringArtifact(HttpClient client, String content, String path)
throws UploadException {
try {
@ -173,7 +230,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
public PublishOperation fromProject(Project project) {
repository(project.publishRepository());
dependencies().include(project.dependencies());
artifacts(List.of(new File(project.buildDistDirectory(), project.jarFileName())));
artifacts(List.of(new PublishArtifact(new File(project.buildDistDirectory(), project.jarFileName()), "", "jar")));
var info = project.publishInfo();
if (info != null) {
info_ = info;
@ -193,6 +250,31 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
return this;
}
/**
* Provides the moment of publication.
* <p>
* If this is not provided, the publication will use the current data and time.
*
* @param moment the publication moment
* @return this operation instance
* @since 1.5.8
*/
public PublishOperation moment(ZonedDateTime moment) {
moment_ = moment;
return this;
}
/**
* Retrieves the moment of publication.
*
* @return the moment of publication; or
* {@code null} if it wasn't provided
* @since 1.5.8
*/
public ZonedDateTime moment() {
return moment_;
}
/**
* Provides the repository to publish to
*
@ -224,7 +306,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
* @return this operation instance
* @since 1.5.7
*/
public PublishOperation artifacts(List<File> artifacts) {
public PublishOperation artifacts(List<PublishArtifact> artifacts) {
artifacts_.addAll(artifacts);
return this;
}
@ -271,7 +353,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
* @return the list of artifacts to publish
* @since 1.5.7
*/
public List<File> artifacts() {
public List<PublishArtifact> artifacts() {
return artifacts_;
}
}

View file

@ -4,12 +4,13 @@
*/
package rife.bld.publish;
import rife.bld.dependencies.VersionNumber;
import rife.template.TemplateFactory;
import rife.tools.StringUtils;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Objects;
import java.util.*;
/**
* Provides the functionalities to build a Maven metadata xml file.
@ -18,10 +19,15 @@ import java.util.Objects;
* @since 1.5.7
*/
public class MetadataBuilder {
private static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
public static final DateTimeFormatter TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
public static final DateTimeFormatter SNAPSHOT_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd.HHmmss");
private PublishInfo info_ = null;
private ZonedDateTime timestamp_ = null;
private final SortedSet<VersionNumber> otherVersions_ = new TreeSet<>(Collections.reverseOrder());
private ZonedDateTime snapshotTimestamp_ = null;
private Integer snapshotBuildNumber_ = null;
private final List<SnapshotVersion> snapshotVersions_ = new ArrayList<>();
/**
* Provides the publishing info to build the metadata for.
@ -67,6 +73,91 @@ public class MetadataBuilder {
return timestamp_;
}
/**
* Provides the other versions for the metadata.
*
* @param otherVersions the other versions to include
* @return this {@code MetadataBuilder} instance
* @since 1.5.8
*/
public MetadataBuilder otherVersions(Collection<VersionNumber> otherVersions) {
otherVersions_.addAll(otherVersions);
return this;
}
/**
* Retrieves the other versions for the metadata.
* <p>
* This is a modifiable set that can be retrieved and changed.
*
* @return the other versions
* @since 1.5.8
*/
public Set<VersionNumber> otherVersions() {
return otherVersions_;
}
/**
* Provides the snapshot details for this metadata, this will switch it to
* snapshot formatting, which is different from main artifact metadata.
*
* @param timestamp the snapshot timestamp
* @param buildNumber the snapshot build number
* @return this {@code MetadataBuilder} instance
* @since 1.5.8
*/
public MetadataBuilder snapshot(ZonedDateTime timestamp, Integer buildNumber) {
snapshotTimestamp_ = timestamp;
snapshotBuildNumber_ = buildNumber;
return this;
}
/**
* Retrieves the snapshot timestamp.
*
* @return the snapshot timestamp; or
* {@code null} if this is not snapshot metadata
* @since 1.5.8
*/
public ZonedDateTime snapshotTimestamp() {
return snapshotTimestamp_;
}
/**
* Retrieves the snapshot build number.
*
* @return the snapshot build number; or
* {@code null} if this is not snapshot metadata
* @since 1.5.8
*/
public Integer snapshotBuildNumber() {
return snapshotBuildNumber_;
}
/**
* Provides the snapshot versions for the metadata.
*
* @param snapshotVersions the snapshot versions to include
* @return this {@code MetadataBuilder} instance
* @since 1.5.8
*/
public MetadataBuilder snapshotVersions(Collection<SnapshotVersion> snapshotVersions) {
snapshotVersions_.addAll(snapshotVersions);
return this;
}
/**
* Retrieves the snapshot versions for the metadata.
* <p>
* This is a modifiable set that can be retrieved and changed.
*
* @return the snapshot versions
* @since 1.5.8
*/
public Collection<SnapshotVersion> snapshotVersions() {
return snapshotVersions_;
}
/**
* Builds the Maven metadata xml file.
*
@ -80,10 +171,53 @@ public class MetadataBuilder {
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"))), ""));
if (snapshotTimestamp() != null && snapshotBuildNumber() != null) {
t.setValueEncoded("mainVersion", Objects.requireNonNullElse(info.version(), ""));
t.setBlock("mainVersion-tag");
t.setValueEncoded("snapshot-timestamp", SNAPSHOT_TIMESTAMP_FORMATTER.format(snapshotTimestamp().withZoneSameInstant(ZoneId.of("UTC"))));
t.setValueEncoded("snapshot-buildNumber", snapshotBuildNumber());
t.setBlock("snapshot-tag");
if (!snapshotVersions().isEmpty()) {
for (var snapshot_version : snapshotVersions()) {
if (snapshot_version.classifier().isEmpty()) {
t.blankValue("snapshotVersionClassifier-tag");
} else {
t.setValueEncoded("snapshotVersion-classifier", snapshot_version.classifier());
t.setBlock("snapshotVersionClassifier-tag");
}
t.setValueEncoded("snapshotVersion-extension", Objects.requireNonNullElse(snapshot_version.extension(), ""));
t.setValueEncoded("snapshotVersion-value", Objects.requireNonNullElse(snapshot_version.value(), ""));
t.setValueEncoded("snapshotVersion-updated", Objects.requireNonNullElse(TIMESTAMP_FORMATTER.format(snapshot_version.updated().withZoneSameInstant(ZoneId.of("UTC"))), ""));
t.appendBlock("snapshotVersions", "snapshotVersion");
}
t.setBlock("snapshotVersions-tag");
}
} else {
if (info != null && info.version() != null) {
t.setValueEncoded("latestVersion", Objects.requireNonNullElse(info.version(), ""));
t.setValueEncoded("releaseVersion", Objects.requireNonNullElse(info.version(), ""));
t.setBlock("versionLatest-tag");
t.setValueEncoded("version", info.version());
t.appendBlock("versions", "version");
}
for (var version : otherVersions()) {
if (info == null || info.version() == null || !version.equals(info.version())) {
t.setValueEncoded("version", version);
t.appendBlock("versions", "version");
}
}
if (t.isValueSet("versions")) {
t.setBlock("versions-tag");
}
}
if (updated() != null) {
t.setValueEncoded("lastUpdated", Objects.requireNonNullElse(TIMESTAMP_FORMATTER.format(updated().withZoneSameInstant(ZoneId.of("UTC"))), ""));
t.setBlock("lastUpdated-tag");
}
return StringUtils.stripBlankLines(t.getContent());

View file

@ -0,0 +1,24 @@
/*
* 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 java.io.File;
/**
* Contains the information about an artifact that will be published.
*
* @param file the file that will be published
* @param classifier the classifier of the artifact
* @param type the type of the artifact
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @since 1.5.8
*/
public record PublishArtifact(File file, String classifier, String type) {
public PublishArtifact(File file, String classifier, String type) {
this.file = file;
this.classifier = (classifier == null ? "" : classifier);
this.type = (type == null ? "jar" : type);
}
}

View file

@ -0,0 +1,26 @@
/*
* 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 java.time.ZonedDateTime;
/**
* Contains the information to describe a particular artifact in a snapshot version.
*
* @param classifier the classifier of the artifact
* @param extension the file extension of the artifact
* @param value the version value
* @param updated the timestamp of publication
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
* @since 1.5.8
*/
public record SnapshotVersion(String classifier, String extension, String value, ZonedDateTime updated) {
public SnapshotVersion(String classifier, String extension, String value, ZonedDateTime updated) {
this.classifier = (classifier == null ? "" : classifier);
this.extension = (extension == null ? "jar" : extension);
this.value = value;
this.updated = updated;
}
}

View file

@ -1,13 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<metadata modelVersion="1.1.0">
<groupId><!--v groupId--><!--/v--></groupId>
<artifactId><!--v artifactId--><!--/v--></artifactId>
<!--v mainVersion-tag--><!--/v-->
<!--b mainVersion-tag-->
<version><!--v mainVersion--><!--/v--></version>
<!--/b-->
<versioning>
<latest><!--v version--><!--/v--></latest>
<release><!--v version/--></release>
<!--v versionLatest-tag--><!--/v-->
<!--b versionLatest-tag-->
<latest><!--v latestVersion--><!--/v--></latest>
<release><!--v releaseVersion--><!--/v--></release>
<!--/b-->
<!--v versions-tag--><!--/v-->
<!--b versions-tag-->
<versions>
<version><!--v version/--></version>
<!--v versions--><!--/v-->
<!--b version-->
<version><!--v version--><!--/v--></version>
<!--/b-->
</versions>
<lastUpdated><!--v timestamp--><!--/v--></lastUpdated>
<!--/b-->
<!--v snapshot-tag--><!--/v-->
<!--b snapshot-tag-->
<snapshot>
<timestamp><!--v snapshot-timestamp--><!--/v--></timestamp>
<buildNumber><!--v snapshot-buildNumber--><!--/v--></buildNumber>
</snapshot>
<!--/b-->
<!--v lastUpdated-tag--><!--/v-->
<!--b lastUpdated-tag-->
<lastUpdated><!--v lastUpdated--><!--/v--></lastUpdated>
<!--/b-->
<!--v snapshotVersions-tag--><!--/v-->
<!--b snapshotVersions-tag-->
<snapshotVersions>
<!--v snapshotVersions--><!--/v-->
<!--b snapshotVersion-->
<snapshotVersion>
<!--v snapshotVersionClassifier-tag--><!--/v-->
<!--b snapshotVersionClassifier-tag-->
<classifier><!--v snapshotVersion-classifier--><!--/v--></classifier>
<!--/b-->
<extension><!--v snapshotVersion-extension--><!--/v--></extension>
<value><!--v snapshotVersion-value--><!--/v--></value>
<updated><!--v snapshotVersion-updated--><!--/v--></updated>
</snapshotVersion>
<!--/b-->
</snapshotVersions>
<!--/b-->
</versioning>
</metadata>

View file

@ -136,4 +136,11 @@ public class TestVersionNumber {
assertEquals(new VersionNumber(1, 2, 3, null).getBaseVersion(), new VersionNumber(1, 2, 3, null));
assertEquals(new VersionNumber(1, 2, 3, "beta").getBaseVersion(), new VersionNumber(1, 2, 3, null));
}
@Test
void testWithQualifier() {
assertEquals(new VersionNumber(1, 2, 3, null).withQualifier("SNAPSHOT"), new VersionNumber(1, 2, 3, "SNAPSHOT"));
assertEquals(new VersionNumber(1, 2, 3, "beta").withQualifier("SNAPSHOT"), new VersionNumber(1, 2, 3, "SNAPSHOT"));
assertEquals(new VersionNumber(1, 2, 4, "beta").withQualifier(null), new VersionNumber(1, 2, 4, null));
}
}

View file

@ -7,16 +7,17 @@ package rife.bld.operations;
import com.reposilite.ReposiliteLauncherKt;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import rife.bld.WebProject;
import rife.bld.Project;
import rife.bld.blueprints.BlankProjectBlueprint;
import rife.bld.dependencies.*;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;
import java.util.List;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import static org.junit.jupiter.api.Assertions.*;
@ -49,13 +50,14 @@ public class TestPublishOperation {
}
@Test
void testExecution()
void testPublishRelease()
throws Exception {
var tmp = Files.createTempDirectory("test").toFile();
var tmp2 = Files.createTempDirectory("test").toFile();
var tmp1 = Files.createTempDirectory("test1").toFile();
var tmp2 = Files.createTempDirectory("test2").toFile();
var tmp_reposilite = Files.createTempDirectory("test").toFile();
try {
var repository = ReposiliteLauncherKt.createWithParameters(
"-wd", tmp2.getAbsolutePath(),
"-wd", tmp_reposilite.getAbsolutePath(),
"-p", "8081",
"--token", "manager:passwd");
repository.launch();
@ -63,69 +65,333 @@ public class TestPublishOperation {
// wait for full startup
Thread.sleep(2000);
// verify the version doesn't exist
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
var create_operation = new CreateBlankOperation()
.workDirectory(tmp)
// create a first publication
var create_operation1 = new CreateBlankOperation()
.workDirectory(tmp1)
.packageName("test.pkg")
.projectName("myapp")
.downloadDependencies(true);
create_operation.execute();
create_operation1.execute();
new CompileOperation()
.fromProject(create_operation.project())
.fromProject(create_operation1.project())
.execute();
var jar_operation = new JarOperation()
.fromProject(create_operation.project());
jar_operation.execute();
var jar_operation1 = new JarOperation()
.fromProject(create_operation1.project());
jar_operation1.execute();
var operation = new PublishOperation()
.fromProject(create_operation.project())
var publish_operation1 = new PublishOperation()
.fromProject(create_operation1.project())
.repository(new Repository("http://localhost:8081/releases", "manager", "passwd"));
operation.execute();
publish_operation1.execute();
var dir_json = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertEquals("myapp", dir_json.get("name"));
var dir_files_json = dir_json.getJSONArray("files");
assertEquals(6, dir_files_json.length());
assertEquals("0.0.1", dir_files_json.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.md5", dir_files_json.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha1", dir_files_json.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha256", dir_files_json.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml.sha512", dir_files_json.getJSONObject(4).get("name"));
assertEquals("maven-metadata.xml", dir_files_json.getJSONObject(5).get("name"));
var dir_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertEquals("myapp", dir_json1.get("name"));
var dir_files_json1 = dir_json1.getJSONArray("files");
assertEquals(6, dir_files_json1.length());
assertEquals("0.0.1", dir_files_json1.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.md5", dir_files_json1.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha1", dir_files_json1.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha256", dir_files_json1.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml.sha512", dir_files_json1.getJSONObject(4).get("name"));
assertEquals("maven-metadata.xml", dir_files_json1.getJSONObject(5).get("name"));
var version_json = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
assertEquals("0.0.1", version_json.get("name"));
var version_files_json = version_json.getJSONArray("files");
assertEquals(10, version_files_json.length());
assertEquals("myapp-0.0.1.jar.md5", version_files_json.getJSONObject(0).get("name"));
assertEquals("myapp-0.0.1.jar.sha1", version_files_json.getJSONObject(1).get("name"));
assertEquals("myapp-0.0.1.jar.sha256", version_files_json.getJSONObject(2).get("name"));
assertEquals("myapp-0.0.1.jar.sha512", version_files_json.getJSONObject(3).get("name"));
assertEquals("myapp-0.0.1.jar", version_files_json.getJSONObject(4).get("name"));
assertEquals("myapp-0.0.1.pom.md5", version_files_json.getJSONObject(5).get("name"));
assertEquals("myapp-0.0.1.pom.sha1", version_files_json.getJSONObject(6).get("name"));
assertEquals("myapp-0.0.1.pom.sha256", version_files_json.getJSONObject(7).get("name"));
assertEquals("myapp-0.0.1.pom.sha512", version_files_json.getJSONObject(8).get("name"));
assertEquals("myapp-0.0.1.pom", version_files_json.getJSONObject(9).get("name"));
var maven_metadata1 = new Xml2MavenMetadata();
maven_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
assertNull(maven_metadata1.getSnapshotTimestamp());
assertNull(maven_metadata1.getSnapshotBuildNumber());
assertEquals(1, maven_metadata1.getVersions().size());
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
var version_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
assertEquals("0.0.1", version_json1.get("name"));
var version_files_json1 = version_json1.getJSONArray("files");
assertEquals(10, version_files_json1.length());
assertEquals("myapp-0.0.1.jar.md5", version_files_json1.getJSONObject(0).get("name"));
assertEquals("myapp-0.0.1.jar.sha1", version_files_json1.getJSONObject(1).get("name"));
assertEquals("myapp-0.0.1.jar.sha256", version_files_json1.getJSONObject(2).get("name"));
assertEquals("myapp-0.0.1.jar.sha512", version_files_json1.getJSONObject(3).get("name"));
assertEquals("myapp-0.0.1.jar", version_files_json1.getJSONObject(4).get("name"));
assertEquals("myapp-0.0.1.pom.md5", version_files_json1.getJSONObject(5).get("name"));
assertEquals("myapp-0.0.1.pom.sha1", version_files_json1.getJSONObject(6).get("name"));
assertEquals("myapp-0.0.1.pom.sha256", version_files_json1.getJSONObject(7).get("name"));
assertEquals("myapp-0.0.1.pom.sha512", version_files_json1.getJSONObject(8).get("name"));
assertEquals("myapp-0.0.1.pom", version_files_json1.getJSONObject(9).get("name"));
// created an updated publication
var create_operation2 = new CreateBlankOperation() {
protected Project createProjectBlueprint() {
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1,0,0));
}
}
.workDirectory(tmp2)
.packageName("test.pkg")
.projectName("myapp")
.downloadDependencies(true);
create_operation2.execute();
new CompileOperation()
.fromProject(create_operation2.project())
.execute();
var jar_operation2 = new JarOperation()
.fromProject(create_operation2.project());
jar_operation2.execute();
var publish_operation2 = new PublishOperation()
.fromProject(create_operation2.project())
.repository(new Repository("http://localhost:8081/releases", "manager", "passwd"));
publish_operation2.execute();
var dir_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertEquals("myapp", dir_json2.get("name"));
var dir_files_json2 = dir_json2.getJSONArray("files");
assertEquals(7, dir_files_json2.length());
assertEquals("0.0.1", dir_files_json2.getJSONObject(0).get("name"));
assertEquals("1.0.0", dir_files_json2.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.md5", dir_files_json2.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha1", dir_files_json2.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml.sha256", dir_files_json2.getJSONObject(4).get("name"));
assertEquals("maven-metadata.xml.sha512", dir_files_json2.getJSONObject(5).get("name"));
assertEquals("maven-metadata.xml", dir_files_json2.getJSONObject(6).get("name"));
var maven_metadata2 = new Xml2MavenMetadata();
maven_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
assertNull(maven_metadata2.getSnapshotTimestamp());
assertNull(maven_metadata2.getSnapshotBuildNumber());
assertEquals(2, maven_metadata2.getVersions().size());
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
var version_json1b = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/0.0.1")));
assertEquals("0.0.1", version_json1b.get("name"));
var version_files_json1b = version_json1b.getJSONArray("files");
assertEquals(10, version_files_json1b.length());
assertEquals("myapp-0.0.1.jar.md5", version_files_json1b.getJSONObject(0).get("name"));
assertEquals("myapp-0.0.1.jar.sha1", version_files_json1b.getJSONObject(1).get("name"));
assertEquals("myapp-0.0.1.jar.sha256", version_files_json1b.getJSONObject(2).get("name"));
assertEquals("myapp-0.0.1.jar.sha512", version_files_json1b.getJSONObject(3).get("name"));
assertEquals("myapp-0.0.1.jar", version_files_json1b.getJSONObject(4).get("name"));
assertEquals("myapp-0.0.1.pom.md5", version_files_json1b.getJSONObject(5).get("name"));
assertEquals("myapp-0.0.1.pom.sha1", version_files_json1b.getJSONObject(6).get("name"));
assertEquals("myapp-0.0.1.pom.sha256", version_files_json1b.getJSONObject(7).get("name"));
assertEquals("myapp-0.0.1.pom.sha512", version_files_json1b.getJSONObject(8).get("name"));
assertEquals("myapp-0.0.1.pom", version_files_json1b.getJSONObject(9).get("name"));
var version_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.0.0")));
assertEquals("1.0.0", version_json2.get("name"));
var version_files_json2 = version_json2.getJSONArray("files");
assertEquals(10, version_files_json2.length());
assertEquals("myapp-1.0.0.jar.md5", version_files_json2.getJSONObject(0).get("name"));
assertEquals("myapp-1.0.0.jar.sha1", version_files_json2.getJSONObject(1).get("name"));
assertEquals("myapp-1.0.0.jar.sha256", version_files_json2.getJSONObject(2).get("name"));
assertEquals("myapp-1.0.0.jar.sha512", version_files_json2.getJSONObject(3).get("name"));
assertEquals("myapp-1.0.0.jar", version_files_json2.getJSONObject(4).get("name"));
assertEquals("myapp-1.0.0.pom.md5", version_files_json2.getJSONObject(5).get("name"));
assertEquals("myapp-1.0.0.pom.sha1", version_files_json2.getJSONObject(6).get("name"));
assertEquals("myapp-1.0.0.pom.sha256", version_files_json2.getJSONObject(7).get("name"));
assertEquals("myapp-1.0.0.pom.sha512", version_files_json2.getJSONObject(8).get("name"));
assertEquals("myapp-1.0.0.pom", version_files_json2.getJSONObject(9).get("name"));
repository.shutdown();
} finally {
FileUtils.deleteDirectory(tmp_reposilite);
FileUtils.deleteDirectory(tmp2);
FileUtils.deleteDirectory(tmp);
FileUtils.deleteDirectory(tmp1);
}
}
@Test
void testFromProject()
void testPublishSnapshot()
throws Exception {
var tmp = Files.createTempDirectory("test").toFile();
var tmp1 = Files.createTempDirectory("test1").toFile();
var tmp2 = Files.createTempDirectory("test2").toFile();
var tmp_reposilite = Files.createTempDirectory("test").toFile();
try {
var repository = ReposiliteLauncherKt.createWithParameters(
"-wd", tmp_reposilite.getAbsolutePath(),
"-p", "8081",
"--token", "manager:passwd");
repository.launch();
// wait for full startup
Thread.sleep(2000);
// verify the version doesn't exist
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertThrows(FileUtilsErrorException.class, () -> FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
// create a first publication
var create_operation1 = new CreateBlankOperation() {
protected Project createProjectBlueprint() {
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1,2,3,"SNAPSHOT"));
}
}
.workDirectory(tmp1)
.packageName("test.pkg")
.projectName("myapp")
.downloadDependencies(true);
create_operation1.execute();
new CompileOperation()
.fromProject(create_operation1.project())
.execute();
var jar_operation1 = new JarOperation()
.fromProject(create_operation1.project());
jar_operation1.execute();
var publish_operation1 = new PublishOperation()
.fromProject(create_operation1.project())
.moment(ZonedDateTime.of(2023, 3, 29, 18, 54, 32, 909, ZoneId.of("America/New_York")))
.repository(new Repository("http://localhost:8081/releases", "manager", "passwd"));
publish_operation1.execute();
var dir_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertEquals("myapp", dir_json1.get("name"));
var dir_files_json1 = dir_json1.getJSONArray("files");
assertEquals(6, dir_files_json1.length());
assertEquals("1.2.3-SNAPSHOT", dir_files_json1.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.md5", dir_files_json1.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha1", dir_files_json1.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha256", dir_files_json1.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml.sha512", dir_files_json1.getJSONObject(4).get("name"));
assertEquals("maven-metadata.xml", dir_files_json1.getJSONObject(5).get("name"));
var maven_metadata1 = new Xml2MavenMetadata();
maven_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
assertEquals(create_operation1.project().version(), maven_metadata1.getLatest());
assertEquals(create_operation1.project().version(), maven_metadata1.getRelease());
assertEquals(VersionNumber.UNKNOWN, maven_metadata1.getSnapshot());
assertNull(maven_metadata1.getSnapshotTimestamp());
assertNull(maven_metadata1.getSnapshotBuildNumber());
assertEquals(1, maven_metadata1.getVersions().size());
assertTrue(maven_metadata1.getVersions().contains(create_operation1.project().version()));
var version_json1 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
assertEquals("1.2.3-SNAPSHOT", version_json1.get("name"));
var version_files_json1 = version_json1.getJSONArray("files");
assertEquals(15, version_files_json1.length());
assertEquals("maven-metadata.xml.md5", version_files_json1.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.sha1", version_files_json1.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha256", version_files_json1.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha512", version_files_json1.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml", version_files_json1.getJSONObject(4).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.jar.md5", version_files_json1.getJSONObject(5).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha1", version_files_json1.getJSONObject(6).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha256", version_files_json1.getJSONObject(7).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.jar.sha512", version_files_json1.getJSONObject(8).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.jar", version_files_json1.getJSONObject(9).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.pom.md5", version_files_json1.getJSONObject(10).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha1", version_files_json1.getJSONObject(11).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha256", version_files_json1.getJSONObject(12).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.pom.sha512", version_files_json1.getJSONObject(13).get("name"));
assertEquals("myapp-1.2.3-20230329.225432-1.pom", version_files_json1.getJSONObject(14).get("name"));
var maven_snapshot_metadata1 = new Xml2MavenMetadata();
maven_snapshot_metadata1.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata.xml")));
assertEquals(create_operation1.project().version(), maven_snapshot_metadata1.getLatest());
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata1.getRelease());
assertEquals(new VersionNumber(1,2,3,"20230329.225432-1"), maven_snapshot_metadata1.getSnapshot());
assertEquals("20230329.225432", maven_snapshot_metadata1.getSnapshotTimestamp());
assertEquals(1, maven_snapshot_metadata1.getSnapshotBuildNumber());
assertEquals(1, maven_snapshot_metadata1.getVersions().size());
assertTrue(maven_snapshot_metadata1.getVersions().contains(create_operation1.project().version()));
// created an updated publication
var create_operation2 = new CreateBlankOperation() {
protected Project createProjectBlueprint() {
return new BlankProjectBlueprint(new File(workDirectory(), projectName()), packageName(), projectName(), new VersionNumber(1,2,3,"SNAPSHOT"));
}
}
.workDirectory(tmp2)
.packageName("test.pkg")
.projectName("myapp")
.downloadDependencies(true);
create_operation2.execute();
new CompileOperation()
.fromProject(create_operation2.project())
.execute();
var jar_operation2 = new JarOperation()
.fromProject(create_operation2.project());
jar_operation2.execute();
var publish_operation2 = new PublishOperation()
.fromProject(create_operation2.project())
.moment(ZonedDateTime.of(2023, 3, 30, 13, 17, 29, 89, ZoneId.of("America/New_York")))
.repository(new Repository("http://localhost:8081/releases", "manager", "passwd"));
publish_operation2.execute();
var dir_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp")));
assertEquals("myapp", dir_json2.get("name"));
var dir_files_json2 = dir_json2.getJSONArray("files");
assertEquals(6, dir_files_json2.length());
assertEquals("1.2.3-SNAPSHOT", dir_files_json2.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.md5", dir_files_json2.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha1", dir_files_json2.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha256", dir_files_json2.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml.sha512", dir_files_json2.getJSONObject(4).get("name"));
assertEquals("maven-metadata.xml", dir_files_json2.getJSONObject(5).get("name"));
var maven_metadata2 = new Xml2MavenMetadata();
maven_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/maven-metadata.xml")));
assertEquals(create_operation2.project().version(), maven_metadata2.getLatest());
assertEquals(create_operation2.project().version(), maven_metadata2.getRelease());
assertEquals(VersionNumber.UNKNOWN, maven_metadata2.getSnapshot());
assertNull(maven_metadata2.getSnapshotTimestamp());
assertNull(maven_metadata2.getSnapshotBuildNumber());
assertEquals(1, maven_metadata2.getVersions().size());
assertTrue(maven_metadata2.getVersions().contains(create_operation1.project().version()));
assertTrue(maven_metadata2.getVersions().contains(create_operation2.project().version()));
var version_json2 = new JSONObject(FileUtils.readString(new URL("http://localhost:8081/api/maven/details/releases/test/pkg/myapp/1.2.3-SNAPSHOT")));
assertEquals("1.2.3-SNAPSHOT", version_json2.get("name"));
var version_files_json2 = version_json2.getJSONArray("files");
assertEquals(15, version_files_json2.length());
assertEquals("maven-metadata.xml.md5", version_files_json2.getJSONObject(0).get("name"));
assertEquals("maven-metadata.xml.sha1", version_files_json2.getJSONObject(1).get("name"));
assertEquals("maven-metadata.xml.sha256", version_files_json2.getJSONObject(2).get("name"));
assertEquals("maven-metadata.xml.sha512", version_files_json2.getJSONObject(3).get("name"));
assertEquals("maven-metadata.xml", version_files_json2.getJSONObject(4).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.jar.md5", version_files_json2.getJSONObject(5).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha1", version_files_json2.getJSONObject(6).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha256", version_files_json2.getJSONObject(7).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.jar.sha512", version_files_json2.getJSONObject(8).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.jar", version_files_json2.getJSONObject(9).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.pom.md5", version_files_json2.getJSONObject(10).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha1", version_files_json2.getJSONObject(11).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha256", version_files_json2.getJSONObject(12).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.pom.sha512", version_files_json2.getJSONObject(13).get("name"));
assertEquals("myapp-1.2.3-20230330.171729-2.pom", version_files_json2.getJSONObject(14).get("name"));
var maven_snapshot_metadata2 = new Xml2MavenMetadata();
maven_snapshot_metadata2.processXml(FileUtils.readString(new URL("http://localhost:8081/releases/test/pkg/myapp/1.2.3-SNAPSHOT/maven-metadata.xml")));
assertEquals(create_operation2.project().version(), maven_snapshot_metadata2.getLatest());
assertEquals(VersionNumber.UNKNOWN, maven_snapshot_metadata2.getRelease());
assertEquals(new VersionNumber(1,2,3,"20230330.171729-2"), maven_snapshot_metadata2.getSnapshot());
assertEquals("20230330.171729", maven_snapshot_metadata2.getSnapshotTimestamp());
assertEquals(2, maven_snapshot_metadata2.getSnapshotBuildNumber());
assertEquals(1, maven_snapshot_metadata2.getVersions().size());
assertTrue(maven_snapshot_metadata2.getVersions().contains(create_operation2.project().version()));
repository.shutdown();
} finally {
FileUtils.deleteDirectory(tmp);
FileUtils.deleteDirectory(tmp_reposilite);
FileUtils.deleteDirectory(tmp2);
FileUtils.deleteDirectory(tmp1);
}
}
}

View file

@ -9,6 +9,7 @@ import rife.bld.dependencies.*;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@ -25,16 +26,10 @@ public class TestMetadataBuilder {
var builder = new MetadataBuilder();
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<metadata modelVersion="1.1.0">
<groupId></groupId>
<artifactId></artifactId>
<versioning>
<latest></latest>
<release></release>
<versions>
<version></version>
</versions>
<lastUpdated></lastUpdated>
</versioning>
</metadata>
""", builder.build());
@ -49,7 +44,7 @@ public class TestMetadataBuilder {
.version(VersionNumber.parse("1.2.3-SNAPSHOT")));
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<metadata modelVersion="1.1.0">
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<versioning>
@ -58,7 +53,6 @@ public class TestMetadataBuilder {
<versions>
<version>1.2.3-SNAPSHOT</version>
</versions>
<lastUpdated></lastUpdated>
</versioning>
</metadata>
""", builder.build());
@ -70,21 +64,36 @@ public class TestMetadataBuilder {
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<metadata modelVersion="1.1.0">
<groupId></groupId>
<artifactId></artifactId>
<versioning>
<latest></latest>
<release></release>
<versions>
<version></version>
</versions>
<lastUpdated>20230327125617</lastUpdated>
</versioning>
</metadata>
""", builder.build());
}
@Test
void testOtherVersionsBuild() {
var builder = new MetadataBuilder()
.otherVersions(List.of(new VersionNumber(6,0,1), new VersionNumber(3,0,2), new VersionNumber(1,0,3), new VersionNumber(3,0,2)));
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId></groupId>
<artifactId></artifactId>
<versioning>
<versions>
<version>6.0.1</version>
<version>3.0.2</version>
<version>1.0.3</version>
</versions>
</versioning>
</metadata>
""", builder.build());
}
@Test
void testCompleteBuild() {
var builder = new MetadataBuilder()
@ -92,10 +101,11 @@ public class TestMetadataBuilder {
.groupId("com.example")
.artifactId("myapp")
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
.otherVersions(List.of(new VersionNumber(6,0,1), new VersionNumber(3,0,2), new VersionNumber(1,0,3), new VersionNumber(3,0,2)))
.updated(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")));
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<metadata modelVersion="1.1.0">
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<versioning>
@ -103,10 +113,88 @@ public class TestMetadataBuilder {
<release>1.2.3-SNAPSHOT</release>
<versions>
<version>1.2.3-SNAPSHOT</version>
<version>6.0.1</version>
<version>3.0.2</version>
<version>1.0.3</version>
</versions>
<lastUpdated>20230327125617</lastUpdated>
</versioning>
</metadata>
""", builder.build());
}
@Test
void testSnapshot() {
var builder = new MetadataBuilder()
.info(new PublishInfo()
.groupId("com.example")
.artifactId("myapp")
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
.snapshot(ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York")), 5);
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<version>1.2.3-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20230327.125617</timestamp>
<buildNumber>5</buildNumber>
</snapshot>
</versioning>
</metadata>
""", builder.build());
}
@Test
void testSnapshotVersions() {
var moment = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
var moment2 = ZonedDateTime.of(2023, 3, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
var moment3 = ZonedDateTime.of(2023, 5, 27, 8, 56, 17, 123, ZoneId.of("America/New_York"));
var builder = new MetadataBuilder()
.info(new PublishInfo()
.groupId("com.example")
.artifactId("myapp")
.version(VersionNumber.parse("1.2.3-SNAPSHOT")))
.snapshot(moment, 5)
.snapshotVersions(List.of(
new SnapshotVersion("classifier1", "ext1", "123", moment2),
new SnapshotVersion("classifier2", "ext2", "456", moment3),
new SnapshotVersion("classifier3", "ext3", "789", moment2)));
assertEquals("""
<?xml version="1.0" encoding="UTF-8"?>
<metadata modelVersion="1.1.0">
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<version>1.2.3-SNAPSHOT</version>
<versioning>
<snapshot>
<timestamp>20230327.125617</timestamp>
<buildNumber>5</buildNumber>
</snapshot>
<snapshotVersions>
<snapshotVersion>
<classifier>classifier1</classifier>
<extension>ext1</extension>
<value>123</value>
<updated>20230327125617</updated>
</snapshotVersion>
<snapshotVersion>
<classifier>classifier2</classifier>
<extension>ext2</extension>
<value>456</value>
<updated>20230527125617</updated>
</snapshotVersion>
<snapshotVersion>
<classifier>classifier3</classifier>
<extension>ext3</extension>
<value>789</value>
<updated>20230327125617</updated>
</snapshotVersion>
</snapshotVersions>
</versioning>
</metadata>
""", builder.build());
}
}