Skip to content
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
4 changes: 2 additions & 2 deletions CLI_ARGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
| `--sonar-branch-name`, `-Dsonar.branch.name` | Name of the branch being analyzed |
| `--sonar-build-string`, `-Dsonar.buildString` | The string passed with this property will be stored with the analysis and available in the results of api/project_analyses/search, thus allowing you to later identify a specific analysis and obtain its key for use with api/new_code_periods/set on the SPECIFIC_ANALYSIS type |
| `--sonar-coverage-exclusions`, `--sonar.coverage.exclusions`, `-Dsonar.coverage.exclusions` | Defines the source files to be excluded from the code coverage analysis. |
| `--sonar-cpd-python-minimum-lines`, `-Dsonar.cpd.python.minimumLines` | Minimum number of tokens to be considered as a duplicated block of code |
| `--sonar-cpd-python-minimum-tokens`, `-Dsonar.cpd.python.minimumTokens` | Minimum number of tokens to be considered as a duplicated block of code |
| `--sonar-cpd-py-minimum-lines`, `-Dsonar.cpd.py.minimumLines`, `--sonar-cpd-python-minimum-lines`, `-Dsonar.cpd.python.minimumLines` | Minimum number of tokens to be considered as a duplicated block of code |
| `--sonar-cpd-py-minimum-tokens`, `-Dsonar.cpd.py.minimumTokens`, `--sonar-cpd-python-minimum-tokens`, `-Dsonar.cpd.python.minimumTokens` | Minimum number of tokens to be considered as a duplicated block of code |
| `--sonar-links-ci`, `-Dsonar.links.ci` | The URL of the continuous integration system used |
| `--sonar-links-homepage`, `-Dsonar.links.homepage` | The URL of the build project home page |
| `--sonar-links-issue`, `-Dsonar.links.issue` | The URL to the issue tracker being used |
Expand Down
4 changes: 4 additions & 0 deletions src/pysonar_scanner/configuration/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,16 @@ def __create_parser(cls):
help="Sets the limit in MB for files to be discarded from the analysis scope if the size is greater than specified",
)
scanner_behavior_group.add_argument(
"--sonar-cpd-py-minimum-tokens",
"-Dsonar.cpd.py.minimumTokens",
"--sonar-cpd-python-minimum-tokens",
"-Dsonar.cpd.python.minimumTokens",
type=int,
help="Minimum number of tokens to be considered as a duplicated block of code",
)
scanner_behavior_group.add_argument(
"--sonar-cpd-py-minimum-lines",
"-Dsonar.cpd.py.minimumLines",
"--sonar-cpd-python-minimum-lines",
"-Dsonar.cpd.python.minimumLines",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -Dsonar.cpd.python.minimumLines we shouldn't need, since any non-consumed parameter beginning with -D... will be passed along.

Same applies for minimum tokens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should keep them as we will pass the property to the correct sonar.cpd.py....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I think the PR can be merged then

type=int,
Expand Down
8 changes: 4 additions & 4 deletions src/pysonar_scanner/configuration/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
SONAR_EXCLUSIONS: Key = "sonar.exclusions"
SONAR_TESTS: Key = "sonar.tests"
SONAR_FILESIZE_LIMIT: Key = "sonar.filesize.limit"
SONAR_CPD_PYTHON_MINIMUM_TOKENS: Key = "sonar.cpd.python.minimumTokens"
SONAR_CPD_PYTHON_MINIMUM_LINES: Key = "sonar.cpd.python.minimumLines"
SONAR_CPD_PYTHON_MINIMUM_TOKENS: Key = "sonar.cpd.py.minimumTokens"
SONAR_CPD_PYTHON_MINIMUM_LINES: Key = "sonar.cpd.py.minimumLines"
SONAR_LOG_LEVEL: Key = "sonar.log.level"
SONAR_QUALITYGATE_WAIT: Key = "sonar.qualitygate.wait"
SONAR_QUALITYGATE_TIMEOUT: Key = "sonar.qualitygate.timeout"
Expand Down Expand Up @@ -361,12 +361,12 @@ def env_variable_name(self) -> str:
Property(
name=SONAR_CPD_PYTHON_MINIMUM_TOKENS,
default_value=None,
cli_getter=lambda args: args.sonar_cpd_python_minimum_tokens
cli_getter=lambda args: args.sonar_cpd_py_minimum_tokens
),
Property(
name=SONAR_CPD_PYTHON_MINIMUM_LINES,
default_value=None,
cli_getter=lambda args: args.sonar_cpd_python_minimum_lines
cli_getter=lambda args: args.sonar_cpd_py_minimum_lines
),
Property(
name=SONAR_LOG_LEVEL,
Expand Down
31 changes: 27 additions & 4 deletions tests/unit/test_configuration_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,9 @@ def test_impossible_os_choice(self):
"--sonar-filesize-limit",
"1000",
"--sonar-scm-exclusions-disabled",
"--sonar-cpd-python-minimum-tokens",
"--sonar-cpd-py-minimum-tokens",
"15",
"--sonar-cpd-python-minimum-lines",
"--sonar-cpd-py-minimum-lines",
"100",
"--sonar-log-level",
"INFO",
Expand Down Expand Up @@ -487,8 +487,8 @@ def test_all_cli_args(self):
"-Dsonar.projectBaseDir=mySonarProjectBaseDir",
"-Dsonar.filesize.limit=1000",
"-Dsonar.scm.exclusions.disabled=true",
"-Dsonar.cpd.python.minimumTokens=15",
"-Dsonar.cpd.python.minimumLines=100",
"-Dsonar.cpd.py.minimumTokens=15",
"-Dsonar.cpd.py.minimumLines=100",
"-Dsonar.qualitygate.wait=true",
"-Dsonar.qualitygate.timeout=120",
"-Dsonar.externalIssuesReportPaths=path/to/external/issues",
Expand Down Expand Up @@ -561,6 +561,29 @@ def test_both_boolean_args_given(self):
configuration = CliConfigurationLoader.load()
self.assertTrue(configuration.get(SONAR_SCM_EXCLUSIONS_DISABLED))

@patch(
"sys.argv",
[
"myscript.py",
"--token",
"myToken",
"--sonar-project-key",
"myProjectKey",
"-Dsonar.cpd.python.minimumLines=10",
"--sonar-cpd-python-minimum-tokens",
"20",
],
)
def test_cpd_config_with_py_property_name(self):
configuration = CliConfigurationLoader.load()
expected_configuration = {
SONAR_TOKEN: "myToken",
SONAR_PROJECT_KEY: "myProjectKey",
SONAR_CPD_PYTHON_MINIMUM_LINES: 10,
SONAR_CPD_PYTHON_MINIMUM_TOKENS: 20,
}
self.assertDictEqual(configuration, expected_configuration)

@patch(
"sys.argv",
[
Expand Down