@Before public void prepare() { globalServerSettings = mock(GlobalServerSettings.class); scannerProps = new ScannerProperties(Collections.<String, String>emptyMap()); }
@Override public String get() { return getKeyWithBranch(); }
@Test public void testProfileProp() { when(loader.load(eq("project"), eq("custom"))).thenReturn(response); when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom")); QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props); assertResponse(qps); verify(loader).load(eq("project"), eq("custom")); verifyNoMoreInteractions(loader); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + QualityProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); }
public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps, PropertyDefinitions propertyDefinitions) { if (globalConfig == null) { Map<String, String> mergedSettings = new LinkedHashMap<>(); mergedSettings.putAll(globalServerSettings.properties()); mergedSettings.putAll(scannerProps.properties()); globalConfig = new GlobalConfiguration(propertyDefinitions, scannerProps.getEncryption(), mergedSettings); } return globalConfig; } }
@Test public void test_copy_of_properties() { Map<String, String> map = Maps.newHashMap(); map.put("foo", "bar"); ScannerProperties underTest = new ScannerProperties(map); assertThat(underTest.properties()).containsOnly(entry("foo", "bar")); assertThat(underTest.properties()).isNotSameAs(map); map.put("put", "after_copy"); assertThat(underTest.properties()).hasSize(1); } }
@CheckForNull private static String getSonarProfile(ScannerProperties props) { String profile = props.property(QualityProfiles.SONAR_PROFILE_PROP); if (profile != null) { LOG.warn("Ability to set quality profile from command line using '" + QualityProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); } return profile; }
public DefaultAnalysisMode(ScannerProperties props, GlobalAnalysisMode analysisMode) { this.analysisMode = analysisMode; this.analysisProps = props.properties(); load(); printFlags(); }
public GlobalAnalysisMode(ScannerProperties props) { String mode = props.property(CoreProperties.ANALYSIS_MODE); validate(mode); issues = CoreProperties.ANALYSIS_MODE_ISSUES.equals(mode) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(mode); mediumTestMode = "true".equals(props.property(MEDIUM_TEST_ENABLED)); if (preview) { LOG.info("Preview mode"); LOG.warn("The use of the preview mode (sonar.analysis.mode=preview) is deprecated. This mode will be dropped in the future."); } else if (issues) { LOG.info("Issues mode"); LOG.warn("The use of the issues mode (sonar.analysis.mode=issues) is deprecated. This mode will be dropped in the future."); } if (mediumTestMode) { LOG.info("Medium test mode"); } }
public GlobalConfiguration provide(GlobalServerSettings globalServerSettings, ScannerProperties scannerProps, PropertyDefinitions propertyDefinitions) { if (globalConfig == null) { Map<String, String> mergedSettings = new LinkedHashMap<>(); mergedSettings.putAll(globalServerSettings.properties()); mergedSettings.putAll(scannerProps.properties()); globalConfig = new GlobalConfiguration(propertyDefinitions, scannerProps.getEncryption(), mergedSettings); } return globalConfig; } }
public ProjectReactor execute() { Profiler profiler = Profiler.create(LOG).startInfo("Process project properties"); Map<String, Map<String, String>> propertiesByModuleIdPath = new HashMap<>(); extractPropertiesByModule(propertiesByModuleIdPath, "", "", new HashMap<>(scannerProps.properties())); ProjectDefinition rootProject = createModuleDefinition(propertiesByModuleIdPath.get(""), null); rootProjectWorkDir = rootProject.getWorkDir(); defineChildren(rootProject, propertiesByModuleIdPath, ""); cleanAndCheckProjectDefinitions(rootProject); profiler.stopDebug(); return new ProjectReactor(rootProject); }
private GlobalAnalysisMode createMode(String key, String value) { Map<String, String> map = new HashMap<>(); if (key != null) { map.put(key, value); } ScannerProperties props = new ScannerProperties(map); return new GlobalAnalysisMode(props); } }
@Override public Map<String, String> loadProjectSettings() { return load(scannerProperties.getKeyWithBranch()); }
private Path findSonarHome(ScannerProperties props) { String home = props.property("sonar.userHome"); if (home != null) { return Paths.get(home).toAbsolutePath(); } home = system.envVariable("SONAR_USER_HOME"); if (home != null) { return Paths.get(home).toAbsolutePath(); } home = system.property("user.home"); return Paths.get(home, ".sonar").toAbsolutePath(); }
@Test public void testProfilePropDefault() { when(projectRepo.exists()).thenReturn(false); when(loader.loadDefault(eq("custom"))).thenReturn(response); when(props.property(QualityProfiles.SONAR_PROFILE_PROP)).thenReturn("custom"); when(props.properties()).thenReturn(ImmutableMap.of(QualityProfiles.SONAR_PROFILE_PROP, "custom")); QualityProfiles qps = qualityProfileProvider.provide(loader, projectRepo, props); assertResponse(qps); verify(loader).loadDefault(eq("custom")); verifyNoMoreInteractions(loader); assertThat(logTester.logs(LoggerLevel.WARN)).contains("Ability to set quality profile from command line using '" + QualityProfiles.SONAR_PROFILE_PROP + "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server."); }
public DefaultAnalysisMode(ScannerProperties props, GlobalAnalysisMode analysisMode) { this.analysisMode = analysisMode; this.analysisProps = props.properties(); load(); printFlags(); }
@Test public void build_singleton() { System2 system = mock(System2.class); ScannerProperties settings = new ScannerProperties(new HashMap<>()); ScannerWsClient first = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system); ScannerWsClient second = underTest.provide(settings, env, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap())), system); assertThat(first).isSameAs(second); } }
@Before public void setUp() { MockitoAnnotations.initMocks(this); Map<String, FileData> fileMap = Maps.newHashMap(); project = new SingleProjectRepository(fileMap, new Date()); provider = new ProjectRepositoriesProvider(); when(props.getKeyWithBranch()).thenReturn("key"); }
public TempFolder provide(ScannerProperties scannerProps) { if (tempFolder == null) { String workingPathName = StringUtils.defaultIfBlank(scannerProps.property(CoreProperties.GLOBAL_WORKING_DIRECTORY), CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE); Path workingPath = Paths.get(workingPathName); if (!workingPath.isAbsolute()) { Path home = findSonarHome(scannerProps); workingPath = home.resolve(workingPath).normalize(); } try { cleanTempFolders(workingPath); } catch (IOException e) { LOG.error(String.format("failed to clean global working directory: %s", workingPath), e); } Path tempDir = createTempFolder(workingPath); tempFolder = new DefaultTempFolder(tempDir.toFile(), true); } return tempFolder; }