File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,12 +42,11 @@ def scan():
4242 config = ConfigurationLoader .load ()
4343 set_logging_options (config )
4444
45- cache_manager = cache .get_default ()
46-
4745 api = build_api (config )
4846 check_version (api )
4947 update_config_with_api_urls (config , api .base_urls )
5048
49+ cache_manager = cache .get_cache (config )
5150 scanner = create_scanner_engine (api , cache_manager , config )
5251
5352 return scanner .run (config )
Original file line number Diff line number Diff line change 2323from dataclasses import dataclass
2424
2525from pysonar_scanner import utils
26+ from pysonar_scanner .configuration .properties import SONAR_USER_HOME
2627
2728OpenBinaryMode = typing .Literal ["wb" , "xb" ]
2829
@@ -68,5 +69,9 @@ def create_cache(cache_folder: pathlib.Path):
6869 return Cache (cache_folder )
6970
7071
71- def get_default () -> Cache :
72- return Cache .create_cache (pathlib .Path .home () / ".sonar-scanner/cache" )
72+ def get_cache (config ) -> Cache :
73+ if SONAR_USER_HOME in config :
74+ cache_folder = pathlib .Path (config [SONAR_USER_HOME ]) / "cache"
75+ else :
76+ cache_folder = pathlib .Path .home () / ".sonar/cache"
77+ return Cache .create_cache (cache_folder )
Original file line number Diff line number Diff line change 1919#
2020import contextlib
2121from typing import Optional
22+
2223from pysonar_scanner import utils
2324from pysonar_scanner .api import JRE , BaseUrls , SonarQubeApi
2425import responses
Original file line number Diff line number Diff line change 2323
2424from pysonar_scanner .cache import Cache , CacheFile
2525import pysonar_scanner .cache as cache
26+ from pysonar_scanner .configuration .properties import SONAR_USER_HOME
2627
2728
2829class TestCacheFile (unittest .TestCase ):
@@ -52,7 +53,10 @@ def test_get_file(self):
5253 self .assertEqual (cache_file .checksum , "123" )
5354
5455 def test_get_default (self ):
55- self .assertEqual (cache .get_default ().cache_folder , pathlib .Path .home () / ".sonar-scanner/cache" )
56+ self .assertEqual (cache .get_cache ({}).cache_folder , pathlib .Path .home () / ".sonar/cache" )
57+
58+ def test_uses_user_home (self ):
59+ self .assertEqual (cache .get_cache ({SONAR_USER_HOME : "my/home" }).cache_folder , pathlib .Path ("my/home" ) / "cache" )
5660
5761 def test_exists (self ):
5862 cache = Cache .create_cache (pathlib .Path ("/folder1/folder2/" ))
Original file line number Diff line number Diff line change @@ -45,7 +45,7 @@ class TestJREProvisioner(pyfakefs.TestCase):
4545 def setUp (self ):
4646 self .setUpPyfakefs (allow_root_user = False )
4747
48- self .cache = cache .get_default ( )
48+ self .cache = cache .get_cache ({} )
4949 self .api = sq_api_utils .get_sq_server ()
5050
5151 self .__setup_zip_file ()
Original file line number Diff line number Diff line change 2929
3030from pysonar_scanner import cache
3131from pysonar_scanner import scannerengine
32- from pysonar_scanner .api import SQVersion
33- from pysonar_scanner .exceptions import ChecksumException , SQTooOldException
34- from pysonar_scanner .jre import JREResolvedPath , JREResolver
32+ from pysonar_scanner .exceptions import ChecksumException
3533from pysonar_scanner .scannerengine import (
3634 LogLine ,
37- ScannerEngine ,
3835 ScannerEngineProvisioner ,
3936 default_log_line_listener ,
4037)
You can’t perform that action at this time.
0 commit comments