-
Notifications
You must be signed in to change notification settings - Fork 724
SONARJAVA-6854 Externalize ruling test project definitions to JSON #6041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
romainbrenguier
wants to merge
3
commits into
master
Choose a base branch
from
romain/project-mapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
52d513b
Externalize ruling test project definitions to JSON
romainbrenguier 8620b5b
Fix executeMavenBuild to use project path and improve exception handling
romainbrenguier 1d2626f
Fix pom path duplication in ruling tests and address S5853 quality ga…
romainbrenguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
92 changes: 92 additions & 0 deletions
92
its/ruling/src/test/java/org/sonar/java/it/ProjectConfigLoader.java
This file contains hidden or 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,92 @@ | ||
| /* | ||
| * SonarQube Java | ||
| * Copyright (C) SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * You can redistribute and/or modify this program under the terms of | ||
| * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. | ||
| * | ||
| * 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 Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonar.java.it; | ||
|
|
||
| import com.google.gson.Gson; | ||
| import com.google.gson.JsonParseException; | ||
| import com.google.gson.reflect.TypeToken; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
|
|
||
| /** | ||
| * Loads ruling project configurations from the ruling-projects.json resource file. | ||
| * This allows external tools to discover available projects for ruling tests. | ||
| */ | ||
| public final class ProjectConfigLoader { | ||
|
|
||
| private static final String CONFIG_RESOURCE = "ruling-projects.json"; | ||
| private static final Gson GSON = new Gson(); | ||
|
|
||
| private ProjectConfigLoader() { | ||
| // Utility class | ||
| } | ||
|
|
||
| /** | ||
| * Loads all ruling project configurations from the classpath resource. | ||
| * | ||
| * @return unmodifiable list of project configurations, never null | ||
| * @throws IllegalStateException if the resource cannot be found or parsed | ||
| */ | ||
| public static List<RulingProject> loadProjects() { | ||
| try (InputStream is = ProjectConfigLoader.class.getClassLoader().getResourceAsStream(CONFIG_RESOURCE)) { | ||
| if (is == null) { | ||
| throw new IllegalStateException("Resource '" + CONFIG_RESOURCE + "' not found on classpath"); | ||
| } | ||
| List<RulingProject> projects = GSON.fromJson( | ||
| new InputStreamReader(is, StandardCharsets.UTF_8), | ||
| new TypeToken<List<RulingProject>>() {}.getType() | ||
| ); | ||
| return projects != null ? Collections.unmodifiableList(projects) : Collections.emptyList(); | ||
| } catch (IOException | JsonParseException e) { | ||
| throw new IllegalStateException("Failed to load ruling project configurations", e); | ||
| } | ||
|
gitar-bot[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Finds a project configuration by its project name. | ||
| * | ||
| * @param projectName the project name to find | ||
| * @return the project configuration, or null if not found | ||
| */ | ||
| public static RulingProject findByProjectName(String projectName) { | ||
| return loadProjects().stream() | ||
| .filter(p -> projectName.equals(p.projectName())) | ||
| .findFirst() | ||
| .orElse(null); | ||
| } | ||
|
|
||
| /** | ||
| * Finds a project configuration by name and asserts it exists. | ||
| * | ||
| * @param projectName the project name to find | ||
| * @return the project configuration, never null | ||
| * @throws AssertionError if the project is not found | ||
| */ | ||
| public static RulingProject requireProject(String projectName) { | ||
| RulingProject project = findByProjectName(projectName); | ||
| Assertions.assertThat(project) | ||
| .as("Project '%s' should be defined in ruling-projects.json", projectName) | ||
| .isNotNull(); | ||
| return project; | ||
| } | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
its/ruling/src/test/java/org/sonar/java/it/ProjectConfigLoaderTest.java
This file contains hidden or 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,62 @@ | ||
| /* | ||
| * SonarQube Java | ||
| * Copyright (C) SonarSource Sàrl | ||
| * mailto:info AT sonarsource DOT com | ||
| * | ||
| * You can redistribute and/or modify this program under the terms of | ||
| * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. | ||
| * | ||
| * 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 Sonar Source-Available License for more details. | ||
| * | ||
| * You should have received a copy of the Sonar Source-Available License | ||
| * along with this program; if not, see https://sonarsource.com/license/ssal/ | ||
| */ | ||
| package org.sonar.java.it; | ||
|
|
||
| import java.util.List; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ProjectConfigLoaderTest { | ||
|
|
||
| @Test | ||
| public void loadProjectsReturnsAllProjects() { | ||
| List<RulingProject> projects = ProjectConfigLoader.loadProjects(); | ||
| assertThat(projects).hasSize(12); | ||
| } | ||
|
|
||
| @Test | ||
| public void findByProjectNameReturnsCorrectProject() { | ||
| RulingProject project = ProjectConfigLoader.findByProjectName("guava"); | ||
| assertThat(project).isNotNull(); | ||
| assertThat(project.projectKey()).isEqualTo("com.google.guava:guava"); | ||
| assertThat(project.path()).isEqualTo("guava"); | ||
| assertThat(project.buildType()).isEqualTo(RulingProject.BuildType.MAVEN); | ||
| } | ||
|
|
||
| @Test | ||
| public void findByProjectNameReturnsNullForUnknownProject() { | ||
| RulingProject project = ProjectConfigLoader.findByProjectName("non-existent"); | ||
| assertThat(project).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| public void mavenExistingProjectsAreMarkedCorrectly() { | ||
| RulingProject project = ProjectConfigLoader.findByProjectName("eclipse-jetty-similar-to-main"); | ||
| assertThat(project).isNotNull(); | ||
| assertThat(project.isExistingProject()).isTrue(); | ||
| assertThat(project.isMavenBuild()).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| public void sonarScannerProjectIsMarkedCorrectly() { | ||
| RulingProject project = ProjectConfigLoader.findByProjectName("jboss-ejb3-tutorial"); | ||
| assertThat(project).isNotNull(); | ||
| assertThat(project.buildType()).isEqualTo(RulingProject.BuildType.SONAR_SCANNER); | ||
| assertThat(project.isMavenBuild()).isFalse(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.