WIP
This commit is contained in:
@@ -137,4 +137,9 @@ public class Releaser {
|
||||
File output = this.templateGenerator.releaseNotes(projects);
|
||||
log.info("\nSuccessfully created release notes at location [{}]", output);
|
||||
}
|
||||
|
||||
public void updateSagan(ProjectVersion releaseVersion) {
|
||||
//File output = this.templateGenerator.releaseNotes(projects);
|
||||
//log.info("\nSuccessfully created release notes at location [{}]", output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.springframework.cloud.release.internal.pom;
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Object representing a root project's version.
|
||||
@@ -15,16 +16,19 @@ public class ProjectVersion {
|
||||
public final String projectName;
|
||||
public final String version;
|
||||
private final PomReader pomReader = new PomReader();
|
||||
private final Model model;
|
||||
|
||||
public ProjectVersion(String projectName, String version) {
|
||||
this.projectName = nameWithoutParent(projectName);
|
||||
this.version = version;
|
||||
this.model = null;
|
||||
}
|
||||
|
||||
public ProjectVersion(File project) {
|
||||
Model model = this.pomReader.readPom(project);
|
||||
this.projectName = nameWithoutParent(model.getArtifactId());
|
||||
this.version = model.getVersion();
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
private String nameWithoutParent(String projectName) {
|
||||
@@ -45,6 +49,18 @@ public class ProjectVersion {
|
||||
return String.format("%s.%s.%s.%s", splitVersion[0], splitVersion[1], incrementedPatch, splitVersion[3]);
|
||||
}
|
||||
|
||||
public String groupId() {
|
||||
if (this.model != null) {
|
||||
if (StringUtils.hasText(this.model.getGroupId())) {
|
||||
return this.model.getGroupId();
|
||||
}
|
||||
if (this.model.getParent() != null && StringUtils.hasText(this.model.getParent().getGroupId())) {
|
||||
return this.model.getParent().getGroupId();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return this.version.contains("SNAPSHOT");
|
||||
}
|
||||
|
||||
@@ -10,4 +10,11 @@ public class ReleaseUpdate {
|
||||
public String releaseStatus = "";
|
||||
public String refDocUrl = "";
|
||||
public String apiDocUrl = "";
|
||||
|
||||
@Override public String toString() {
|
||||
return "ReleaseUpdate{" + "groupId='" + groupId + '\'' + ", artifactId='"
|
||||
+ artifactId + '\'' + ", version='" + version + '\'' + ", releaseStatus='"
|
||||
+ releaseStatus + '\'' + ", refDocUrl='" + refDocUrl + '\''
|
||||
+ ", apiDocUrl='" + apiDocUrl + '\'' + '}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.springframework.cloud.release.internal.sagan;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.release.internal.ReleaserProperties;
|
||||
import org.springframework.cloud.release.internal.pom.ProjectVersion;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class SaganUpdater {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SaganUpdater.class);
|
||||
|
||||
private final ReleaserProperties properties;
|
||||
private final SaganClient saganClient;
|
||||
|
||||
public SaganUpdater(ReleaserProperties properties, SaganClient saganClient) {
|
||||
this.properties = properties;
|
||||
this.saganClient = saganClient;
|
||||
}
|
||||
|
||||
public void updateSagan(ProjectVersion version) {
|
||||
ReleaseUpdate update = new ReleaseUpdate();
|
||||
update.groupId = version.groupId();
|
||||
update.artifactId = version.projectName;
|
||||
update.version = version.version;
|
||||
update.apiDocUrl = "http://github.com/spring-cloud/" + version.projectName;
|
||||
update.refDocUrl = referenceUrl(version);
|
||||
log.info("Updating Sagan with \n\n{}", update);
|
||||
this.saganClient.createOrUpdateRelease(version.projectName, update);
|
||||
}
|
||||
|
||||
private String referenceUrl(ProjectVersion version) {
|
||||
if (version.isRelease()) {
|
||||
return "http://cloud.spring.io/spring-cloud-static/" + version.projectName + "/{version}/";
|
||||
}
|
||||
// is from master ?
|
||||
// if not pick from /1.1.x/ url
|
||||
return "http://cloud.spring.io/spring-cloud-sleuth/" + version.projectName + ".html";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.springframework.cloud.release.internal.pom;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -8,9 +11,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.release.internal.git.GitRepoTests;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@@ -59,6 +59,13 @@ public class ProjectVersionTests {
|
||||
then(projectVersion.projectName).isEqualTo("spring-cloud-contract");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_group_id_when_it_is_present() {
|
||||
ProjectVersion projectVersion = new ProjectVersion(this.springCloudContract);
|
||||
|
||||
then(projectVersion.groupId()).isEqualTo("org.springframework.cloud");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_throw_exception_if_version_is_not_long_enough() {
|
||||
String version = "1.0";
|
||||
@@ -145,6 +152,13 @@ public class ProjectVersionTests {
|
||||
then(projectVersion(version).isRc()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_return_empty_group_id_when_it_is_missing() {
|
||||
ProjectVersion projectVersion = projectVersion("1.0.0.RC1");
|
||||
|
||||
then(projectVersion.groupId()).isEmpty();
|
||||
}
|
||||
|
||||
private ProjectVersion projectVersion(String version) {
|
||||
return new ProjectVersion("foo", version);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user