Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release with new features and bugfixes:

* https://github.com/devonfw/IDEasy/issues/1351[#1729]: Jline update fix. Installed version of Jline: 3.30.6 ProgressBar version changed to 0.10.2 Dependencies jline-terminal and jline-native were added explicitly.
* https://github.com/devonfw/IDEasy/issues/1713[#1713]: Advanced logging and writing logfiles
* https://github.com/devonfw/IDEasy/issues/1731[#1731]: Fixed SonarQube installation path resolution

The full list of changes for this release can be found in https://github.com/devonfw/IDEasy/milestone/41?closed=1[milestone 2026.03.001].

Expand Down
27 changes: 22 additions & 5 deletions cli/src/main/java/com/devonfw/tools/ide/tool/sonar/Sonar.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.process.ProcessContext;
import com.devonfw.tools.ide.process.ProcessMode;
import com.devonfw.tools.ide.property.EnumProperty;
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
import com.devonfw.tools.ide.tool.ToolInstallation;
Expand Down Expand Up @@ -81,20 +83,35 @@ protected void doRun() {

@Override
protected String getBinaryName() {

SonarCommand command = this.command.getValue();
if (this.context.getSystemInfo().isWindows()) {
SonarCommand command = this.command.getValue();
if (command.equals(SonarCommand.START)) {
return "windows-x86-64/StartSonar.bat";
} else if (command.equals(SonarCommand.STOP)) {
if (command != null && command.equals(SonarCommand.STOP)) {
return "windows-x86-64/SonarService.bat";

} else {
return "windows-x86-64/StartSonar.bat";
}
Comment thread
tmukh marked this conversation as resolved.
} else if (this.context.getSystemInfo().isMac()) {
return "macosx-universal-64/sonar.sh";
}
return "linux-x86-64/sonar.sh";
}

// Instead of relying on relative Path (which breaks), we directly construct the absolute path
// so getToolBinPath would return /software/sonar/bin and .resolve adds x86-x64
// ProcessContext can now execute the abs path without any issues.
// Worst case, we fall back to the default configureToolBinary, which uses relative path.
@Override
protected void configureToolBinary(ProcessContext pc, ProcessMode processMode) {
Path toolBinPath = getToolBinPath();
if (toolBinPath != null) {
Path binaryPath = toolBinPath.resolve(getBinaryName());
pc.executable(binaryPath);
} else {
super.configureToolBinary(pc, processMode);
}
}

private void printSonarWebPort() {

LOG.info("SonarQube is running at localhost on the following port (default 9000):");
Expand Down
119 changes: 119 additions & 0 deletions cli/src/test/java/com/devonfw/tools/ide/tool/sonar/SonarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.devonfw.tools.ide.tool.sonar;

import java.nio.file.Path;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.os.SystemInfoMock;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;

/**
* Test of {@link Sonar}.
*/
@WireMockTest
class SonarTest extends AbstractIdeContextTest {

private static final String PROJECT_SONAR = "sonar";
private static final String SONAR_VERSION = "26.3.0.120487";

/**
* Tests the installation of {@link Sonar}.
*
* @param os String of the OS to use.
* @param wmRuntimeInfo wireMock server on a random port
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
void testSonarInstall(String os, WireMockRuntimeInfo wmRuntimeInfo) {

// arrange
IdeTestContext context = newContext(PROJECT_SONAR, wmRuntimeInfo);
context.setSystemInfo(SystemInfoMock.of(os));
Sonar sonar = context.getCommandletManager().getCommandlet(Sonar.class);
sonar.command.setValueAsString("start", context);

// act
sonar.install(true);

// assert
checkInstallation(context);
}

/**
* Tests parsing of command values for {@link Sonar#command}.
*/
@ParameterizedTest
@CsvSource({ "start, START", "stop, STOP", "analyze, ANALYZE" })
void testSonarCommandParsing(String command, SonarCommand expectedCommand) {

// arrange
IdeTestContext context = new IdeTestContext();
Sonar sonar = new Sonar(context);

// act
sonar.command.setValueAsString(command, context);

// assert
assertThat(sonar.command.getValue()).isEqualTo(expectedCommand);
}

/**
* Tests that {@link Sonar#getBinaryName} returns correct values for different commands.
*
* @param os String of the OS to use.
*/
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
void testSonarGetBinaryName(String os) {

// arrange
IdeTestContext context = new IdeTestContext();
context.setSystemInfo(SystemInfoMock.of(os));
Sonar sonar = new Sonar(context);

// act & assert - START command
sonar.command.setValueAsString("start", context);
String startBinary = sonar.getBinaryName();
if (context.getSystemInfo().isWindows()) {
assertThat(startBinary).isEqualTo("windows-x86-64/StartSonar.bat");
} else if (context.getSystemInfo().isMac()) {
assertThat(startBinary).isEqualTo("macosx-universal-64/sonar.sh");
} else {
assertThat(startBinary).isEqualTo("linux-x86-64/sonar.sh");
}

// act & assert - STOP command
sonar.command.setValueAsString("stop", context);
String stopBinary = sonar.getBinaryName();
if (context.getSystemInfo().isWindows()) {
assertThat(stopBinary).isEqualTo("windows-x86-64/SonarService.bat");
} else if (context.getSystemInfo().isMac()) {
assertThat(stopBinary).isEqualTo("macosx-universal-64/sonar.sh");
} else {
assertThat(stopBinary).isEqualTo("linux-x86-64/sonar.sh");
}
}

private void checkInstallation(IdeTestContext context) {

assertThat(context.getSoftwarePath().resolve("sonar/.ide.software.version")).exists().hasContent(SONAR_VERSION);
assertThat(context).logAtSuccess().hasMessageContaining("Successfully installed sonar in version " + SONAR_VERSION);

// Verify the binary exists based on OS
Path softwarePath = context.getSoftwarePath();
if (context.getSystemInfo().isWindows()) {
assertThat(softwarePath.resolve("sonar/bin/windows-x86-64/StartSonar.bat")).exists();
assertThat(softwarePath.resolve("sonar/bin/windows-x86-64/SonarService.bat")).exists();
} else if (context.getSystemInfo().isMac()) {
assertThat(softwarePath.resolve("sonar/bin/macosx-universal-64/sonar.sh")).exists();
} else {
assertThat(softwarePath.resolve("sonar/bin/linux-x86-64/sonar.sh")).exists();
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${testbaseurl}/download/java/java/17.0.10_7/java-17.0.10_7.tgz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${testbaseurl}/download/sonar/sonar/26.3.0.120487/sonar-26.3.0.120487.tgz
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SONAR_VERSION=26.3.0.120487
JAVA_VERSION=17.0.10_7

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
17.0.10_7

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

exit 0
echo "java version 17.0.10"
# Mock java binary for testing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
26.3.0.120487
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# Mock sonar.sh for testing
echo "Starting SonarQube..."
exit 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
# Mock sonar.sh for testing
echo "Starting SonarQube..."
exit 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

exit /b 0
echo Sonar Service...
REM Mock SonarService.bat for testing
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off
REM Mock StartSonar.bat for testing
echo Starting SonarQube...
exit /b 0

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SonarQube test properties
sonar.web.port=9000

Loading