-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
213 additions
and
127 deletions.
There are no files selected for viewing
Empty file.
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 |
---|---|---|
@@ -1,26 +1,35 @@ | ||
<p align="center"><img src="https://i.imgur.com/xcIhGwP.png" alt="Run SonarQube Scanner with composer" /></p> | ||
<p align="center"><img width="250" src="https://i.imgur.com/xcIhGwP.png" alt="Run SonarQube Scanner with composer" /></p> | ||
|
||
[![Build Status](https://travis-ci.org/rogervila/php-sonarqube-scanner.svg?branch=master)](https://travis-ci.org/rogervila/php-sonarqube-scanner) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/weidwo98jcdrtkxm?svg=true)](https://ci.appveyor.com/project/roger-vila/php-sonarqube-scanner) | ||
|
||
|
||
# Run SonarQube Scanner with composer | ||
|
||
## Usage | ||
|
||
**Install the package as a dev requirement** | ||
|
||
``` | ||
composer install rogervila/php-sonarqube-scanner --dev | ||
``` | ||
|
||
> Make sure you have a `sonar-project.properties` on your project root! | ||
|
||
**Run with composer** | ||
|
||
``` | ||
vendor/bin/sonar-scanner | ||
``` | ||
|
||
## Defaults | ||
|
||
In some cases, if the package finds missing properties, it will provide them automatically. | ||
|
||
| Property | Source | Example | ||
|----|---|---| | ||
| sonar.projectKey | adapted `composer.json` name property | `-Dsonar.projectKey=rogervila_php-sonarqube-scanner` | ||
| sonar.projectName | adapted `composer.json` name property | `-Dsonar.projectName=php-sonarqube-scanner` | ||
|
||
## License | ||
|
||
This project is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). |
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
Empty file.
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 was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
src/Exceptions/InvalidOperatingSystemException.php
100644 → 100755
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
This file was deleted.
Oops, something went wrong.
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
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,121 @@ | ||
<?php | ||
|
||
namespace Sonar; | ||
|
||
class Options | ||
{ | ||
const PROPERTIES_FILE_NAME = 'sonar-project.properties'; | ||
const INLINE_PREFIX = '-D'; | ||
const LAUNCHER = 'sonar-scanner'; | ||
const PROJECT_KEY = 'sonar.projectKey'; | ||
const PROJECT_NAME = 'sonar.projectName'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $basePath; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $propertiesFile; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $arguments; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $composer = []; | ||
|
||
/** | ||
* @param string $basePath | ||
*/ | ||
public function __construct(string $basePath) | ||
{ | ||
$this->basePath = trim($basePath); | ||
|
||
$this->propertiesFile = $this->basePath . DIRECTORY_SEPARATOR . self::PROPERTIES_FILE_NAME; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setComposerConfiguration(array $composer) | ||
{ | ||
$this->composer = $composer; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function parse(array $arguments) | ||
{ | ||
if (self::LAUNCHER == substr(self::LAUNCHER, -strlen(self::LAUNCHER))) { | ||
array_shift($arguments); | ||
} | ||
|
||
$this->arguments = $arguments; | ||
|
||
if (!$this->hasArgument(self::INLINE_PREFIX . self::PROJECT_KEY) | ||
&& !$this->propertiesFileHasOption(self::PROJECT_KEY) | ||
&& isset($this->composer['name'])) { | ||
$this->setProjectKeyFromComposer(); | ||
} | ||
|
||
if (!$this->hasArgument(self::INLINE_PREFIX . self::PROJECT_NAME) | ||
&& !$this->propertiesFileHasOption(self::PROJECT_NAME) | ||
&& isset($this->composer['name'])) { | ||
$this->setProjectNameFromComposer(); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function cli() | ||
{ | ||
return implode(' ', $this->arguments); | ||
} | ||
|
||
private function hasArgument(string $argument) | ||
{ | ||
return count(preg_grep('/^' . str_replace('.', '\.', $argument) . '/m', $this->arguments)) > 0; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private function propertiesFileHasOption($option) | ||
{ | ||
if (!file_exists($this->propertiesFile)) { | ||
return false; | ||
} | ||
|
||
preg_match('/^' . str_replace('.', '\.', $option) . '/m', file_get_contents($this->propertiesFile), $matches); | ||
|
||
return count($matches) > 0; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function setProjectKeyFromComposer() | ||
{ | ||
array_push($this->arguments, self::INLINE_PREFIX . self::PROJECT_KEY . '=' . str_replace('/', '_', $this->composer['name'])); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function setProjectNameFromComposer() | ||
{ | ||
$result = explode('/', $this->composer['name']); | ||
|
||
if (isset($result[1])) { | ||
array_push($this->arguments, self::INLINE_PREFIX . self::PROJECT_NAME . '=' . $result[1]); | ||
} | ||
} | ||
} |
Oops, something went wrong.