Not throwing exception when pom is missing'

This commit is contained in:
Marcin Grzejszczak
2018-10-31 11:31:15 +01:00
parent 412b78311d
commit 56536bbfd2
5 changed files with 17 additions and 4 deletions

View File

@@ -38,6 +38,9 @@ class PomReader {
if (file.isDirectory()) {
pom = new File(file,"pom.xml");
}
if (!pom.exists()) {
return null;
}
String fileText = "";
try(Reader reader = new FileReader(pom)) {
if (file.isFile()) {

View File

@@ -68,6 +68,10 @@ class PomUpdater {
return false;
}
Model model = this.pomReader.readPom(rootPom);
if (model == null) {
log.info("Failed to read the model");
return false;
}
String artifactId = artifactId(model);
if (!versions.shouldBeUpdated(artifactId)) {
log.info("Skipping project [{}] since it's not on the list of projects to update", model.getArtifactId());

View File

@@ -68,10 +68,8 @@ public class PomReaderTests {
}
@Test
public void should_throw_exception_when_file_is_missing() {
thenThrownBy(() -> this.pomReader.readPom(new File("foo/bar")))
.hasMessageStartingWith("Failed to read file: ")
.hasCauseInstanceOf(IOException.class);
public void should_return_null_when_file_is_missing() {
then(this.pomReader.readPom(new File("foo/bar"))).isNull();
}
@Test

View File

@@ -81,6 +81,14 @@ public class PomUpdaterTests {
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue();
}
@Test
public void should_not_update_pom_when_project_is_on_the_versions_list_but_there_is_no_pom() throws Exception {
File springCloudSleuthPom = file("/projects/spring-cloud-sleuth/empty-folder");
BDDAssertions
.then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isFalse();
}
@Test
public void should_not_update_the_pom_if_no_changes_were_made() throws Exception {
File originalPom = pom("/projects/project");