diff options
author | Wojtek Wajerowicz <115081248+wojciech-wajerowicz-sonarsource@users.noreply.github.com> | 2024-01-22 10:41:11 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-01-22 20:02:34 +0000 |
commit | 4ee88736f5cd0eb649a8a289ddb5a6fd36c78024 (patch) | |
tree | 20878e31bea7419d578c6c04a9e412a7f52b6dab /server | |
parent | 27d03effdb54942a24c19bfeb49f084bffbcd4d3 (diff) | |
download | sonarqube-4ee88736f5cd0eb649a8a289ddb5a6fd36c78024.tar.gz sonarqube-4ee88736f5cd0eb649a8a289ddb5a6fd36c78024.zip |
SONAR-19603 Throw exception when lib/scanner doesn't exist.
Diffstat (limited to 'server')
-rw-r--r-- | server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/BatchIndex.java | 4 | ||||
-rw-r--r-- | server/sonar-webserver-webapi/src/test/java/org/sonar/server/batch/BatchIndexTest.java | 13 |
2 files changed, 16 insertions, 1 deletions
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())); + } } |