#157 - Enable calver to TrainIteration resolution.
This commit is contained in:
@@ -16,7 +16,9 @@
|
||||
package org.springframework.data.release.cli;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.data.release.model.ArtifactVersion;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
import org.springframework.data.release.model.Train;
|
||||
import org.springframework.shell.core.Completion;
|
||||
@@ -27,11 +29,14 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Component
|
||||
public class TrainConverter implements Converter<Train> {
|
||||
|
||||
/*
|
||||
private static final Pattern CALVER = Pattern.compile("(\\d{4})(\\.(\\d))+");
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.shell.core.Converter#supports(java.lang.Class, java.lang.String)
|
||||
*/
|
||||
@@ -40,16 +45,27 @@ public class TrainConverter implements Converter<Train> {
|
||||
return Train.class.isAssignableFrom(type);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.shell.core.Converter#convertFromText(java.lang.String, java.lang.Class, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Train convertFromText(String value, Class<?> targetType, String optionContext) {
|
||||
return StringUtils.hasText(value) ? ReleaseTrains.getTrainByName(value) : null;
|
||||
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (CALVER.matcher(value).matches()) {
|
||||
|
||||
ArtifactVersion version = ArtifactVersion.of(value);
|
||||
return ReleaseTrains.getTrainByCalver(version.getVersion());
|
||||
}
|
||||
|
||||
return ReleaseTrains.getTrainByName(value);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.shell.core.Converter#getAllPossibleValues(java.util.List, java.lang.Class, java.lang.String, java.lang.String, org.springframework.shell.core.MethodTarget)
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package org.springframework.data.release.cli;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.data.release.model.ArtifactVersion;
|
||||
import org.springframework.data.release.model.Iteration;
|
||||
import org.springframework.data.release.model.ReleaseTrains;
|
||||
import org.springframework.data.release.model.Train;
|
||||
@@ -28,10 +30,13 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Component
|
||||
public class TrainIterationConverter implements Converter<TrainIteration> {
|
||||
|
||||
private static final Pattern CALVER = Pattern.compile("(\\d{4})(\\.(\\d))+(-M(\\d)|-RC(\\d))?");
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.shell.core.Converter#supports(java.lang.Class, java.lang.String)
|
||||
@@ -48,6 +53,21 @@ public class TrainIterationConverter implements Converter<TrainIteration> {
|
||||
@Override
|
||||
public TrainIteration convertFromText(String value, Class<?> targetType, String optionContext) {
|
||||
|
||||
if (CALVER.matcher(value).matches()) {
|
||||
|
||||
ArtifactVersion version = ArtifactVersion.of(value);
|
||||
Train train = ReleaseTrains.getTrainByCalver(version.getVersion());
|
||||
|
||||
if (version.isReleaseVersion()) {
|
||||
if (version.isBugFixVersion()) {
|
||||
return train.getIteration("SR" + version.getVersion().getBugfix());
|
||||
}
|
||||
return train.getIteration(Iteration.GA);
|
||||
}
|
||||
|
||||
return train.getIteration(version.getSuffix());
|
||||
}
|
||||
|
||||
String[] parts = value.split(" ");
|
||||
|
||||
if (parts.length != 2) {
|
||||
@@ -74,6 +94,10 @@ public class TrainIterationConverter implements Converter<TrainIteration> {
|
||||
TrainIteration trainIteration = train.getIteration(iteration.getName());
|
||||
|
||||
completions.add(new Completion(trainIteration.toString()));
|
||||
|
||||
if (trainIteration.getTrain().usesCalver()) {
|
||||
completions.add(new Completion(trainIteration.getCalver().toMajorMinorBugfix()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ArtifactVersion implements Comparable<ArtifactVersion> {
|
||||
private static final String VALID_SUFFIX = String.format("%s|%s|%s|-%s|-%s|-%s", RELEASE_SUFFIX, MILESTONE_SUFFIX,
|
||||
SNAPSHOT_SUFFIX, RELEASE_SUFFIX, MILESTONE_SUFFIX, SNAPSHOT_MODIFIER);
|
||||
|
||||
private final Version version;
|
||||
private final @Getter Version version;
|
||||
private final @With boolean modifierFormat;
|
||||
private final @Getter String suffix;
|
||||
|
||||
@@ -163,7 +163,7 @@ public class ArtifactVersion implements Comparable<ArtifactVersion> {
|
||||
* @return
|
||||
*/
|
||||
public boolean isReleaseVersion() {
|
||||
return suffix.equals(RELEASE_SUFFIX);
|
||||
return suffix.equals("") || suffix.equals(RELEASE_SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,6 +122,15 @@ public class ReleaseTrains {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static Train getTrainByCalver(Version calver) {
|
||||
|
||||
return TRAINS.stream() //
|
||||
.filter(Train::usesCalver)
|
||||
.filter(it -> it.getCalver().getMajor() == calver.getMajor() && it.getCalver().getMinor() == calver.getMinor()) //
|
||||
.findFirst() //
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static Project getProjectByName(String name) {
|
||||
|
||||
return PROJECTS.stream() //
|
||||
|
||||
@@ -157,6 +157,7 @@ public class Train implements Streamable<Module> {
|
||||
return new TrainIteration(this, iterations.getIterationByName(name));
|
||||
}
|
||||
|
||||
|
||||
public ArtifactVersion getModuleVersion(Project project, Iteration iteration) {
|
||||
|
||||
Module module = getModule(project);
|
||||
@@ -169,7 +170,18 @@ public class Train implements Streamable<Module> {
|
||||
}
|
||||
|
||||
public Train withCalver(String calverVersion) {
|
||||
return new Train(name, modules, Version.parse(calverVersion), iterations, alwaysUseBranch);
|
||||
|
||||
Version calver = Version.parse(calverVersion);
|
||||
Set<Module> modules = this.modules.stream().map(it -> {
|
||||
|
||||
if (it.getProject() == Projects.BOM) {
|
||||
return new Module(it.getProject(), calver.toMajorMinorBugfix());
|
||||
}
|
||||
return it;
|
||||
|
||||
}).collect(Collectors.toSet());
|
||||
|
||||
return new Train(name, Modules.of(modules), calver, iterations, alwaysUseBranch);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -199,7 +211,7 @@ public class Train implements Streamable<Module> {
|
||||
* @return
|
||||
* @throws IllegalArgumentException in case the given {@link Iteration} is not available in this {@link Train}.
|
||||
*/
|
||||
private TrainIteration getIteration(Iteration iteration) {
|
||||
public TrainIteration getIteration(Iteration iteration) {
|
||||
|
||||
Assert.isTrue(iterations.contains(iteration),
|
||||
String.format("Iteration %s is not a valid one for the configured iterations %s!", iteration, iterations));
|
||||
|
||||
@@ -21,8 +21,9 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for release {@link Train}s.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class TrainsUnitTest {
|
||||
|
||||
@@ -38,4 +39,12 @@ class TrainsUnitTest {
|
||||
void addsNewlyAddedModule() {
|
||||
assertThat(ReleaseTrains.HOPPER.getModule(Projects.ENVERS)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void considersCalverInBom() {
|
||||
|
||||
assertThat(ReleaseTrains.OCKHAM.getModule(Projects.BOM).getVersion().toMajorMinorBugfix()).isEqualTo("2020.0.0");
|
||||
|
||||
assertThat(ReleaseTrains.PASCAL.getModule(Projects.BOM).getVersion().toMajorMinorBugfix()).isEqualTo("2021.0.0");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user