Fixed boot support
This commit is contained in:
@@ -127,18 +127,20 @@ class PomUpdater {
|
||||
}
|
||||
String parentGroupId = model.getParent().getGroupId();
|
||||
String parentArtifactId = model.getParent().getArtifactId();
|
||||
log.debug("Searching for a version of parent [{}:{}]", parentGroupId, parentArtifactId);
|
||||
String oldVersion = model.getParent().getVersion();
|
||||
String version = versions.versionForProject(parentArtifactId);
|
||||
log.debug("Found version is [{}]", version);
|
||||
if (StringUtils.isEmpty(version)) {
|
||||
if (StringUtils.hasText(model.getParent().getRelativePath())) {
|
||||
version = versions.versionForProject(rootProjectName);
|
||||
} else {
|
||||
log.warn("There is no info on the [{}] version", model.getArtifactId());
|
||||
log.warn("There is no info on the [{}:{}] version", parentGroupId, parentArtifactId);
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
if (oldVersion.equals(version)) {
|
||||
log.info("Won't update the version of [{}]:[{}] since you're already using the proper one", parentGroupId, parentArtifactId);
|
||||
log.debug("Won't update the version of [{}:{}] since you're already using the proper one", parentGroupId, parentArtifactId);
|
||||
return changes;
|
||||
}
|
||||
log.info("Setting version of parent [{}] to [{}] for module [{}]", parentArtifactId,
|
||||
@@ -153,14 +155,16 @@ class PomUpdater {
|
||||
List<VersionChange> changes = new ArrayList<>(sourceChanges);
|
||||
String groupId = groupId(model);
|
||||
String artifactId = model.getArtifactId();
|
||||
log.debug("Searching for a version [{}:{}]", groupId, artifactId);
|
||||
String oldVersion = model.getVersion();
|
||||
String version = versions.versionForProject(rootProjectName);
|
||||
log.debug("Found version is [{}]", version);
|
||||
if (StringUtils.isEmpty(version) || StringUtils.isEmpty(model.getVersion())) {
|
||||
log.warn("There was no version set for project [{}], skipping version setting for module [{}]", rootProjectName, model.getArtifactId());
|
||||
log.debug("There was no version set for project [{}], skipping version setting for module [{}]", rootProjectName, model.getArtifactId());
|
||||
return changes;
|
||||
}
|
||||
if (oldVersion.equals(version)) {
|
||||
log.info("Won't update the version of [{}]:[{}] since you're already using the proper one", groupId, artifactId);
|
||||
log.debug("Won't update the version of [{}]:[{}] since you're already using the proper one", groupId, artifactId);
|
||||
return changes;
|
||||
}
|
||||
log.info("Setting [{}] version to [{}]", artifactId, version);
|
||||
@@ -223,13 +227,13 @@ class PomWriter {
|
||||
for (VersionChange versionChange : wrapper.sourceChanges) {
|
||||
changer.apply(versionChange);
|
||||
}
|
||||
log.info("Applying properties changes to the pom [{}]", pom);
|
||||
log.debug("Applying properties changes to the pom [{}]", pom);
|
||||
new PropertyVersionChanger(wrapper, versions, parsedPom, loggerToMavenLog)
|
||||
.apply(null);
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(pom))) {
|
||||
bw.write(input.toString());
|
||||
}
|
||||
log.info("Flushed changes to the pom file [{}]", pom);
|
||||
log.debug("Flushed changes to the pom file [{}]", pom);
|
||||
} catch (Exception e) {
|
||||
log.error("Exception occurred while trying to apply changes to the POM", e);
|
||||
}
|
||||
@@ -272,7 +276,11 @@ class PropertyVersionChanger extends AbstractVersionChanger {
|
||||
.filter(project -> {
|
||||
Properties properties = getModel().getProperties();
|
||||
String projectVersionKey = propertyName(project);
|
||||
return properties.containsKey(projectVersionKey);
|
||||
if (!properties.containsKey(projectVersionKey)) {
|
||||
return false;
|
||||
}
|
||||
String version = properties.getProperty(projectVersionKey);
|
||||
return !version.equals(project.version);
|
||||
})
|
||||
.forEach(project -> {
|
||||
String propertyName = propertyName(project);
|
||||
|
||||
@@ -44,13 +44,15 @@ public class ProjectUpdater {
|
||||
this.gitProjectRepo.checkout(clonedScRelease, this.properties.getBranch());
|
||||
SCReleasePomParser sCReleasePomParser = new SCReleasePomParser(clonedScRelease);
|
||||
Versions versions = sCReleasePomParser.allVersions();
|
||||
log.info("Retrieved the following versions\n{}", versions);
|
||||
if (!this.pomUpdater.shouldProjectBeUpdated(projectRoot, versions)) {
|
||||
log.info("Skipping project updating");
|
||||
return;
|
||||
}
|
||||
File rootPom = new File(projectRoot, "pom.xml");
|
||||
ModelWrapper rootPomModel = this.pomUpdater.readModel(rootPom);
|
||||
processAllPoms(projectRoot, new PomWalker(rootPomModel, versions, this.pomUpdater));
|
||||
processAllPoms(projectRoot, new PomWalker(rootPomModel, versions, this.pomUpdater,
|
||||
properties));
|
||||
}
|
||||
|
||||
private void processAllPoms(File projectRoot, PomWalker pomWalker) {
|
||||
@@ -64,27 +66,39 @@ public class ProjectUpdater {
|
||||
|
||||
private class PomWalker extends SimpleFileVisitor<Path> {
|
||||
|
||||
private static final String POM_XML = "pom.xml";
|
||||
private static final String POM_XML = "pom.xml";
|
||||
|
||||
private final ModelWrapper rootPom;
|
||||
private final Versions versions;
|
||||
private final PomUpdater pomUpdater;
|
||||
private final ReleaserProperties properties;
|
||||
|
||||
private PomWalker(ModelWrapper rootPom, Versions versions, PomUpdater pomUpdater) {
|
||||
private PomWalker(ModelWrapper rootPom, Versions versions, PomUpdater pomUpdater,
|
||||
ReleaserProperties properties) {
|
||||
this.rootPom = rootPom;
|
||||
this.versions = versions;
|
||||
this.pomUpdater = pomUpdater;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path path, BasicFileAttributes attr) {
|
||||
File file = path.toFile();
|
||||
if (POM_XML.equals(file.getName())) {
|
||||
if (pathIgnored(file)) {
|
||||
log.debug("Ignoring file [{}] since it's on a list of patterns to ignore", file);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
ModelWrapper model = this.pomUpdater.updateModel(this.rootPom, file, this.versions);
|
||||
this.pomUpdater.overwritePomIfDirty(model, this.versions, file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
|
||||
private boolean pathIgnored(File file) {
|
||||
String path = file.getPath();
|
||||
return this.properties.getIgnoredPomRegex().stream().anyMatch(path::matches);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.springframework.cloud.release.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
@@ -18,6 +22,15 @@ public class ReleaserProperties {
|
||||
*/
|
||||
private String cloneDestinationDir;
|
||||
|
||||
/**
|
||||
* List of regular expressions of ignored poms. Defaults to test projects and samples.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<String> ignoredPomRegex = Arrays.asList(new String[] {
|
||||
"^.*spring-cloud-contract-maven-plugin/src/test/projects/.*$",
|
||||
"^.*samples/standalone.*$"
|
||||
});
|
||||
|
||||
/**
|
||||
* Which branch of Spring Cloud Release should be checked out. Defaults to {@code master}
|
||||
*/
|
||||
@@ -46,4 +59,12 @@ public class ReleaserProperties {
|
||||
public void setBranch(String branch) {
|
||||
this.branch = branch;
|
||||
}
|
||||
|
||||
public List<String> getIgnoredPomRegex() {
|
||||
return this.ignoredPomRegex;
|
||||
}
|
||||
|
||||
public void setIgnoredPomRegex(List<String> ignoredPomRegex) {
|
||||
this.ignoredPomRegex = ignoredPomRegex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cloud.release.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
@@ -60,7 +61,14 @@ class SCReleasePomParser {
|
||||
Versions allVersions() {
|
||||
Versions boot = bootVersion();
|
||||
Versions cloud = springCloudVersions();
|
||||
return new Versions(boot.bootVersion, cloud.scBuildVersion, cloud.projects);
|
||||
return new Versions(boot.bootVersion, cloud.scBuildVersion, allProjects(boot, cloud));
|
||||
}
|
||||
|
||||
private Set<Project> allProjects(Versions boot, Versions cloud) {
|
||||
Set<Project> allProjects = new HashSet<>();
|
||||
allProjects.addAll(boot.projects);
|
||||
allProjects.addAll(cloud.projects);
|
||||
return allProjects;
|
||||
}
|
||||
|
||||
Versions bootVersion() {
|
||||
|
||||
@@ -3,7 +3,9 @@ package org.springframework.cloud.release.internal;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.cloud.release.internal.SpringCloudConstants.BOOT_STARTER_ARTIFACT_ID;
|
||||
import static org.springframework.cloud.release.internal.SpringCloudConstants.BUILD_ARTIFACT_ID;
|
||||
import static org.springframework.cloud.release.internal.SpringCloudConstants.CLOUD_DEPENDENCIES_ARTIFACT_ID;
|
||||
|
||||
@@ -24,6 +26,7 @@ class Versions {
|
||||
Versions(String bootVersion) {
|
||||
this.bootVersion = bootVersion;
|
||||
this.projects.add(new Project(SPRING_BOOT_PROJECT_NAME, bootVersion));
|
||||
this.projects.add(new Project(BOOT_STARTER_ARTIFACT_ID, bootVersion));
|
||||
}
|
||||
|
||||
Versions(String scBuildVersion, Set<Project> projects) {
|
||||
@@ -70,6 +73,12 @@ class Versions {
|
||||
String withoutParent = projectName.substring(0, projectName.indexOf("-parent"));
|
||||
return project.name.equals(withoutParent);
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "Spring Boot Version=[" + this.bootVersion + ']' + "\nSpring Cloud Build Version=["
|
||||
+ this.scBuildVersion + ']' + "\nProjects=\n\t" + this.projects.stream().map(Object::toString).collect(
|
||||
Collectors.joining("\n\t"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,6 +116,6 @@ class Project {
|
||||
}
|
||||
|
||||
@Override public String toString() {
|
||||
return "Project{" + "name='" + this.name + '\'' + ", version='" + this.version + '\'' + '}';
|
||||
return "name=[" + this.name + "], version=[" + this.version + ']';
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,10 @@ public class VersionsTests {
|
||||
@Test
|
||||
public void should_add_boot_to_versions_when_version_is_created() {
|
||||
then(new Versions("1.2.3.RELEASE").projects)
|
||||
.containsExactly(new Project("spring-boot", "1.2.3.RELEASE"));
|
||||
.contains(
|
||||
new Project("spring-boot", "1.2.3.RELEASE"),
|
||||
new Project("spring-boot-starter-parent", "1.2.3.RELEASE")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user