Skip to content

Commit 6ddcbca

Browse files
SCAN4NET-294 Deduplicate help message IT (#2369)
1 parent 4cf357c commit 6ddcbca

File tree

5 files changed

+16
-63
lines changed

5 files changed

+16
-63
lines changed

azure-pipelines.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,6 @@ stages:
474474
inputs:
475475
versionSpec: $(NUGET_VERSION)
476476

477-
- powershell: |
478-
$projectVersion = Get-Content "$(Build.SourcesDirectory)\build\version.txt"
479-
Write-Host "##vso[task.setvariable variable=SONAR_PROJECT_VERSION]$projectVersion"
480-
displayName: "Get version from artifact file"
481-
482477
- task: Maven@4
483478
displayName: 'Run Maven ITs for $(PRODUCT) $(SQ_VERSION)'
484479
env:
@@ -512,7 +507,6 @@ stages:
512507
-Dsonar.textplugin.version=$(TEXT_VERSION)
513508
-Dsonar.goplugin.version=$(GO_VERSION)
514509
-Dsonar.runtimeVersion=$(SQ_VERSION)
515-
-DscannerForMSBuild.version=$(SONAR_PROJECT_VERSION).$(Build.BuildId)
516510
-Dmsbuild.path="$(MSBUILD_PATH)"
517511
-Dmsbuild.platformtoolset=$(PLATFORMTOOLSET)
518512
-Dmsbuild.windowssdk=$(WINDOWSSDKTARGET)

its/pom.xml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,4 @@
124124
</plugins>
125125
</build>
126126

127-
<profiles>
128-
<profile>
129-
<id>download-scanner-artifacts</id>
130-
<activation>
131-
<property>
132-
<name>scannerForMSBuild.version</name>
133-
</property>
134-
</activation>
135-
<build>
136-
<plugins>
137-
<plugin>
138-
<groupId>org.apache.maven.plugins</groupId>
139-
<artifactId>maven-dependency-plugin</artifactId>
140-
<version>3.6.1</version>
141-
<executions>
142-
<execution>
143-
<id>download-scanner</id>
144-
<phase>initialize</phase>
145-
<goals>
146-
<goal>get</goal>
147-
</goals>
148-
<configuration>
149-
<artifact>org.sonarsource.scanner.msbuild:sonar-scanner:${scannerForMSBuild.version}:zip:net-framework</artifact>
150-
</configuration>
151-
</execution>
152-
</executions>
153-
</plugin>
154-
</plugins>
155-
</build>
156-
</profile>
157-
</profiles>
158-
159127
</project>

its/src/test/java/com/sonar/it/scanner/msbuild/sonarqube/ScannerMSBuildTest.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.sonar.it.scanner.msbuild.utils.ScannerCommand;
2828
import com.sonar.it.scanner.msbuild.utils.TestUtils;
2929
import com.sonar.orchestrator.build.BuildResult;
30-
import com.sonar.orchestrator.build.ScannerForMSBuild;
3130
import com.sonar.orchestrator.http.HttpException;
3231
import com.sonar.orchestrator.locator.FileLocation;
3332
import com.sonar.orchestrator.util.Command;
@@ -205,17 +204,6 @@ void testSampleWithProxyAuth() throws Exception {
205204
assertThat(seenByProxy).isNotEmpty();
206205
}
207206

208-
@Test
209-
void testHelpMessage() throws IOException {
210-
assumeTrue(TestUtils.getScannerVersion(ORCHESTRATOR) == null);
211-
212-
Path projectDir = TestUtils.projectDir(basePath, "ProjectUnderTest");
213-
BuildResult result = ORCHESTRATOR.executeBuild(ScannerForMSBuild.create(projectDir.toFile()).addArgument("/?"));
214-
215-
assertThat(result.getLogs()).contains("Usage");
216-
assertTrue(result.isSuccess());
217-
}
218-
219207
@Test
220208
void testNoProjectNameAndVersion() throws Exception {
221209
String localProjectKey = PROJECT_KEY + ".4";
@@ -486,8 +474,9 @@ void testVerbose() throws IOException {
486474
@Test
487475
void testHelp() throws IOException {
488476
Path projectDir = TestUtils.projectDir(basePath, "ProjectUnderTest");
489-
BuildResult result = ORCHESTRATOR.executeBuild(ScannerForMSBuild.create(projectDir.toFile()).addArgument("/?"));
477+
BuildResult result = ScannerCommand.createHelpStep(ScannerClassifier.NET_FRAMEWORK, projectDir).execute(ORCHESTRATOR);
490478

479+
assertTrue(result.isSuccess());
491480
assertThat(result.getLogs()).contains("Usage");
492481
assertThat(result.getLogs()).contains("SonarScanner.MSBuild.exe");
493482
}

its/src/test/java/com/sonar/it/scanner/msbuild/utils/ScannerCommand.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class ScannerCommand {
3838

3939
private enum Step {
40+
help,
4041
begin,
4142
end
4243
}
@@ -71,6 +72,10 @@ public static ScannerCommand createEndStep(ScannerClassifier classifier, String
7172
return new ScannerCommand(Step.end, classifier, token, projectDir, null);
7273
}
7374

75+
public static ScannerCommand createHelpStep(ScannerClassifier classifier, Path projectDir) {
76+
return new ScannerCommand(Step.help, classifier, null, projectDir, null);
77+
}
78+
7479
public ScannerCommand setProperty(String key, @Nullable String value) {
7580
if (value == null) {
7681
this.properties.remove(key);
@@ -164,10 +169,14 @@ private Command createCommand(Orchestrator orchestrator) {
164169
var tokenProperty = orchestrator.getServer().version().isGreaterThanOrEquals(10, 0)
165170
? "/d:sonar.token=" + token // The `sonar.token` property was introduced in SonarQube 10.0
166171
: "/d:sonar.login=" + token; // sonar.login is obsolete
167-
var command = classifier.createBaseCommand()
168-
.setDirectory(projectDir.toFile())
169-
.addArgument(step.toString())
170-
.addArgument(tokenProperty);
172+
var command = classifier.createBaseCommand().setDirectory(projectDir.toFile());
173+
if (step == Step.help) {
174+
command.addArgument("/?");
175+
} else {
176+
command
177+
.addArgument(step.toString())
178+
.addArgument(tokenProperty);
179+
}
171180
if (step == Step.begin) {
172181
command.addArgument("/k:" + projectKey);
173182
if (!properties.containsKey("sonar.host.url")) {

its/src/test/java/com/sonar/it/scanner/msbuild/utils/TestUtils.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import com.sonar.orchestrator.Orchestrator;
2323
import com.sonar.orchestrator.build.BuildResult;
24-
import com.sonar.orchestrator.http.HttpMethod;
2524
import com.sonar.orchestrator.locator.Location;
2625
import com.sonar.orchestrator.locator.MavenLocation;
2726
import com.sonar.orchestrator.util.Command;
@@ -70,11 +69,6 @@ public class TestUtils {
7069
public static final Long TIMEOUT_LIMIT = 60 * 1000L;
7170
public static final String MSBUILD_DEFAULT_PATH = "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\MSBuild\\Current\\Bin\\MSBuild.exe";
7271

73-
@CheckForNull
74-
public static String getScannerVersion(Orchestrator orchestrator) {
75-
return orchestrator.getConfiguration().getString("scannerForMSBuild.version");
76-
}
77-
7872
@CheckForNull
7973
public static String getAnalyzerVersion(Orchestrator orchestrator) {
8074
return orchestrator.getConfiguration().getString("DOTNET_VERSION");
@@ -345,8 +339,7 @@ public static BuildResult executeEndStepAndDumpResults(Orchestrator orchestrator
345339
endCommand.setEnvironmentVariable(pair.getName(), pair.getValue());
346340
}
347341

348-
for (var property : additionalProperties)
349-
{
342+
for (var property : additionalProperties) {
350343
var keyValue = property.split("=");
351344
var value = keyValue.length > 1 ? keyValue[1] : null;
352345
LOG.info("Setting property: {}={}", keyValue[0], value);

0 commit comments

Comments
 (0)