-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bootstrap IT and property-dump-plugin
- Loading branch information
1 parent
271626d
commit 3b73f13
Showing
5 changed files
with
202 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
its/src/test/java/com/sonar/maven/it/suite/BootstrapTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* SonarSource :: IT :: SonarQube Maven | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package com.sonar.maven.it.suite; | ||
|
||
import com.sonar.maven.it.ItUtils; | ||
import com.sonar.orchestrator.build.BuildResult; | ||
import com.sonar.orchestrator.build.BuildRunner; | ||
import com.sonar.orchestrator.build.MavenBuild; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Properties; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class BootstrapTest extends AbstractMavenTest { | ||
|
||
@TempDir | ||
public Path temp; | ||
|
||
@Test | ||
void test_unsupported_platform() { | ||
String unsupportedOS = "unsupportedOS"; | ||
String arch = "amd64"; | ||
BuildRunner runner = new BuildRunner(ORCHESTRATOR.getConfiguration()); | ||
MavenBuild build = MavenBuild.create(ItUtils.locateProjectPom("maven/aggregator-inherit-parent")) | ||
.setProperty("sonar.scanner.os", unsupportedOS) | ||
.setProperty("sonar.scanner.arch", arch) | ||
.setProperty("sonar.login", ORCHESTRATOR.getDefaultAdminToken()) | ||
.setProperty("sonar.host.url", ORCHESTRATOR.getServer().getUrl()) | ||
// .setEnvironmentVariable("MAVEN_OPTS","-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000") | ||
.setGoals(cleanSonarGoal()); | ||
|
||
BuildResult result = runner.runQuietly(null, build); | ||
assertThat(result.isSuccess()).isFalse(); | ||
|
||
String url = ORCHESTRATOR.getServer().getUrl() + String.format("/api/v2/analysis/jres?os=%s&arch=%s", unsupportedOS, arch); | ||
String expectedLog = String.format("Error status returned by url [%s]: 400", url); | ||
assertThat(result.getLogs()).contains(expectedLog); | ||
} | ||
|
||
@Test | ||
void test_supported_arch_to_assert_jre_used() throws IOException { | ||
BuildRunner runner = new BuildRunner(ORCHESTRATOR.getConfiguration()); | ||
String projectName = "maven/aggregator-inherit-parent"; | ||
MavenBuild build = MavenBuild.create(ItUtils.locateProjectPom(projectName)) | ||
.setProperty("sonar.login", ORCHESTRATOR.getDefaultAdminToken()) | ||
.setProperty("sonar.host.url", ORCHESTRATOR.getServer().getUrl()) | ||
.setGoals(cleanSonarGoal()); | ||
|
||
|
||
BuildResult result = runner.runQuietly(null, build); | ||
assertThat(result.isSuccess()).isTrue(); | ||
//load properties file | ||
Path propertiesFile = ItUtils.locateProjectDir(projectName).toPath().resolve("target/sonar/dumpSensor.properties"); | ||
Properties props = new Properties(); | ||
props.load(Files.newInputStream(propertiesFile)); | ||
|
||
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 6)) { | ||
//we test that we are actually using the JRE downloaded from SQ | ||
assertThat(props.getProperty("java.home")) | ||
.isNotEmpty() | ||
.isNotEqualTo(System.getProperty("java.home")) | ||
.contains(".sonar" + File.separator + "cache"); | ||
} else { | ||
//we test that we are using the system JRE | ||
assertThat(props.getProperty("java.home")) | ||
.isNotEmpty() | ||
.isEqualTo(System.getProperty("java.home")) | ||
.doesNotContain(".sonar" + File.separator + "cache"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.sonarsource.parent</groupId> | ||
<artifactId>parent</artifactId> | ||
<version>74.0.0.1768</version> | ||
<relativePath /> | ||
</parent> | ||
|
||
<groupId>org.sonarsource.scanner.maven</groupId> | ||
<artifactId>property-dump-plugin</artifactId> | ||
<version>1</version> | ||
<packaging>sonar-plugin</packaging> | ||
|
||
<properties> | ||
<jdk.min.version>17</jdk.min.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.sonarsource.api.plugin</groupId> | ||
<artifactId>sonar-plugin-api</artifactId> | ||
<version>10.12.0.2522</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId> | ||
<artifactId>sonar-packaging-maven-plugin</artifactId> | ||
<version>1.23.0.740</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<pluginName>Property Dump Plugin</pluginName> | ||
<skipDependenciesPackaging>true</skipDependenciesPackaging> | ||
<pluginClass>org.sonar.dump.PropertyDumpPlugin</pluginClass> | ||
<sonarLintSupported>true</sonarLintSupported> | ||
<pluginApiMinVersion>9.14.0.375</pluginApiMinVersion> | ||
<jreMinVersion>17</jreMinVersion> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
52 changes: 52 additions & 0 deletions
52
property-dump-plugin/src/main/java/org/sonar/dump/PropertyDumpPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* property-dump-plugin | ||
* Copyright (C) 2009-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.dump; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import org.sonar.api.Plugin; | ||
import org.sonar.api.batch.sensor.Sensor; | ||
import org.sonar.api.batch.sensor.SensorContext; | ||
import org.sonar.api.batch.sensor.SensorDescriptor; | ||
|
||
public class PropertyDumpPlugin implements Plugin, Sensor { | ||
|
||
@Override | ||
public void define(Context context) { | ||
context.addExtension(this); | ||
} | ||
|
||
@Override | ||
public void describe(SensorDescriptor sensorDescriptor) { | ||
sensorDescriptor.name("Property Dump Sensor"); | ||
} | ||
|
||
@Override | ||
public void execute(SensorContext sensorContext) { | ||
var props = System.getProperties(); | ||
//please copilot, save properties to a file | ||
try { | ||
props.store(Files.newOutputStream(sensorContext.fileSystem().workDir().toPath().resolve("dumpSensor.properties")), null); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |