From 4ee88736f5cd0eb649a8a289ddb5a6fd36c78024 Mon Sep 17 00:00:00 2001 From: Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:41:11 +0100 Subject: [PATCH] SONAR-19603 Throw exception when lib/scanner doesn't exist. --- .../java/org/sonar/server/batch/BatchIndex.java | 4 ++++ .../java/org/sonar/server/batch/BatchIndexTest.java | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java index fb210a45791..2fa9934bee9 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java @@ -35,6 +35,8 @@ import org.sonar.api.server.ServerSide; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.platform.ServerFileSystem; +import static java.lang.String.format; + /** * Scanner Engine JAR file(s) to be downloaded by sonar-scanner-api. There is currently only one JAR (see assembly.xml) * but let's keep possibility to pass several files for possible future evolutions. @@ -66,6 +68,8 @@ public class BatchIndex implements Startable { } } } + } else { + throw new IllegalStateException(format("%s folder not found", batchDir.getAbsolutePath())); } this.index = sb.toString(); } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/BatchIndexTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/BatchIndexTest.java index 989386e590f..5a744a8615e 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/BatchIndexTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/BatchIndexTest.java @@ -30,6 +30,7 @@ import org.junit.rules.TemporaryFolder; import org.sonar.server.exceptions.NotFoundException; import org.sonar.server.platform.ServerFileSystem; +import static java.lang.String.format; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; @@ -40,7 +41,6 @@ public class BatchIndexTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - private File jar; private ServerFileSystem fs = mock(ServerFileSystem.class); @@ -103,4 +103,15 @@ public class BatchIndexTest { .isInstanceOf(NotFoundException.class) .hasMessage("Bad filename: other.jar"); } + + @Test + public void start_whenBatchDirDoesntExist_shouldThrow() throws IOException { + File homeDir = temp.newFolder(); + when(fs.getHomeDir()).thenReturn(homeDir); + + BatchIndex batchIndex = new BatchIndex(fs); + assertThatThrownBy(batchIndex::start) + .isInstanceOf(IllegalStateException.class) + .hasMessage(format("%s/lib/scanner folder not found", homeDir.getAbsolutePath())); + } } -- 2.39.5