Skip to content
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

Feature/GH-115 add skip parameter #116

Merged
merged 2 commits into from
Jul 15, 2021
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
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

--
### Added

- support for skipping execution via
parameter ([#115](https://github.com/r0bb3n/sonar-quality-gate-maven-plugin/issues/115))

[unreleased]: https://github.com/r0bb3n/sonar-quality-gate-maven-plugin/compare/v1.1.0...HEAD

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mvn sonar-quality-gate:check -Dsonar-quality-gate.branch=develop
| `sonar.login` | sonar login (username or token) for basic auth (aligned to [sonar-maven-plugin analysis parameters][sonar-analysis-param])<br>see also [SonarQube - Web API Authentication][sonar-web-api-auth] | _all_ |
| `sonar.password` | sonar password for basic auth (aligned to [sonar-maven-plugin analysis parameters][sonar-analysis-param])<br>see also [SonarQube - Web API Authentication][sonar-web-api-auth] | _all_ |
| `sonar.projectKey` | project key used in sonar for this project (aligned to [sonar-maven-plugin analysis parameters][sonar-analysis-param])<br>(default: `${project.groupId}:${project.artifactId}`) | simple, advanced |
| `sonar-quality-gate.skip` | skip plugin execution | _all_ |
| `sonar-quality-gate.branch` | name of the branch to check the quality gate in sonar | advanced |
| `sonar-quality-gate.pullRequest` | name of the pull request to check the quality gate in sonar | advanced |
| `sonar-quality-gate.checkTask.attempts` | How often try to retrieve the analysis id from the task details in sonar until stopping the job<br>(default: `10`) | integrated |
Expand Down
1 change: 1 addition & 0 deletions src/lombok.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# project wide lombok config
lombok.addLombokGeneratedAnnotation = true
config.stopBubbling = true
11 changes: 11 additions & 0 deletions src/main/java/org/r0bb3n/maven/SonarQualityGateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class SonarQualityGateMojo extends AbstractMojo {
@Parameter(property = PROP_SONAR_PASSWORD)
private String sonarPassword;

/**
* skip the execution of this plugin
*/
@Parameter(property = "sonar-quality-gate.skip", defaultValue = "false")
private boolean skip;

/**
* name of the branch to check the quality gate in sonar
*/
Expand Down Expand Up @@ -123,6 +129,11 @@ public class SonarQualityGateMojo extends AbstractMojo {
* @throws MojoFailureException quality gate evaluates as not passed
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("skipped");
return;
}

if (Util.isBlank(sonarLogin) && !Util.isBlank(sonarPassword)) {
throw new MojoExecutionException(String
.format("you cannot specify '%s' without '%s'", PROP_SONAR_PASSWORD, PROP_SONAR_LOGIN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,13 @@ public void mojoExecuteWithProjectKeyAndPullRequestWarn() throws Exception {
Mockito.verify(underTestSpy, Mockito.never()).retrieveAnalysisId(Mockito.any(), Mockito.any());
}

@Test
public void mojoExecuteWithSkipEnabled() throws Exception {
MojoConfigurator.configure(underTestSpy).setSkip(true);

underTestSpy.execute();
// assert is difficult - let's check, if a log gets written for skipping
Mockito.verify(logSpy).info("skipped");
}

}
5 changes: 5 additions & 0 deletions src/test/java/org/r0bb3n/maven/util/MojoConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public MojoConfigurator setSonarPassword(String sonarPassword) throws Exception
return this;
}

public MojoConfigurator setSkip(boolean skip) throws Exception {
setField("skip", skip);
return this;
}

public MojoConfigurator setBranch(String branch) throws Exception {
setField("branch", branch);
return this;
Expand Down