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
3 changes: 1 addition & 2 deletions src/pysonar_scanner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def scan():
config = ConfigurationLoader.load()
set_logging_options(config)

cache_manager = cache.get_default()

api = build_api(config)
check_version(api)
update_config_with_api_urls(config, api.base_urls)

cache_manager = cache.get_cache(config)
scanner = create_scanner_engine(api, cache_manager, config)

return scanner.run(config)
Expand Down
9 changes: 7 additions & 2 deletions src/pysonar_scanner/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from dataclasses import dataclass

from pysonar_scanner import utils
from pysonar_scanner.configuration.properties import SONAR_USER_HOME

OpenBinaryMode = typing.Literal["wb", "xb"]

Expand Down Expand Up @@ -68,5 +69,9 @@ def create_cache(cache_folder: pathlib.Path):
return Cache(cache_folder)


def get_default() -> Cache:
return Cache.create_cache(pathlib.Path.home() / ".sonar-scanner/cache")
def get_cache(config) -> Cache:
if SONAR_USER_HOME in config:
cache_folder = pathlib.Path(config[SONAR_USER_HOME]) / "cache"
else:
cache_folder = pathlib.Path.home() / ".sonar/cache"
return Cache.create_cache(cache_folder)
1 change: 1 addition & 0 deletions tests/unit/sq_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#
import contextlib
from typing import Optional

from pysonar_scanner import utils
from pysonar_scanner.api import JRE, BaseUrls, SonarQubeApi
import responses
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from pysonar_scanner.cache import Cache, CacheFile
import pysonar_scanner.cache as cache
from pysonar_scanner.configuration.properties import SONAR_USER_HOME


class TestCacheFile(unittest.TestCase):
Expand Down Expand Up @@ -52,7 +53,10 @@ def test_get_file(self):
self.assertEqual(cache_file.checksum, "123")

def test_get_default(self):
self.assertEqual(cache.get_default().cache_folder, pathlib.Path.home() / ".sonar-scanner/cache")
self.assertEqual(cache.get_cache({}).cache_folder, pathlib.Path.home() / ".sonar/cache")

def test_uses_user_home(self):
self.assertEqual(cache.get_cache({SONAR_USER_HOME: "my/home"}).cache_folder, pathlib.Path("my/home") / "cache")

def test_exists(self):
cache = Cache.create_cache(pathlib.Path("/folder1/folder2/"))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_jre.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TestJREProvisioner(pyfakefs.TestCase):
def setUp(self):
self.setUpPyfakefs(allow_root_user=False)

self.cache = cache.get_default()
self.cache = cache.get_cache({})
self.api = sq_api_utils.get_sq_server()

self.__setup_zip_file()
Expand Down
5 changes: 1 addition & 4 deletions tests/unit/test_scannerengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@

from pysonar_scanner import cache
from pysonar_scanner import scannerengine
from pysonar_scanner.api import SQVersion
from pysonar_scanner.exceptions import ChecksumException, SQTooOldException
from pysonar_scanner.jre import JREResolvedPath, JREResolver
from pysonar_scanner.exceptions import ChecksumException
from pysonar_scanner.scannerengine import (
LogLine,
ScannerEngine,
ScannerEngineProvisioner,
default_log_line_listener,
)
Expand Down