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 testSetProperty() { String key = "System2Test.testSetProperty"; String value = randomUUID().toString(); System2.INSTANCE.setProperty(key, value); assertThat(System2.INSTANCE.property(key)).isEqualTo(value); }
@Test public void testProperty() { String expected = System.getProperty("java.version"); assertThat(System2.INSTANCE.property("java.version")).isNotNull().isEqualTo(expected); }
@Test public void createTempFolderDefault() throws Exception { System2 system = mock(System2.class); tempFolderProvider = new GlobalTempFolderProvider(system); File userHome = temp.newFolder(); when(system.envVariable("SONAR_USER_HOME")).thenReturn(null); when(system.property("user.home")).thenReturn(userHome.getAbsolutePath().toString()); // if nothing is defined, it will be in {user.home}/.sonar/.sonartmp File defaultSonarHome = new File(userHome.getAbsolutePath(), ".sonar"); File workingDir = new File(defaultSonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile(); try { TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(Collections.<String, String>emptyMap())); tempFolder.newDir(); tempFolder.newFile(); assertThat(getCreatedTempDir(workingDir)).exists(); assertThat(getCreatedTempDir(workingDir).list()).hasSize(2); } finally { FileUtils.deleteQuietly(workingDir); } }
/** * Checks if a proxy was passed with command line parameters or configured in the system. * If only an HTTP proxy was configured then it's properties are copied to the HTTPS proxy (like SonarQube configuration) * @return True iff a proxy was configured to be used in the plugin. */ public boolean isProxyConnectionEnabled() { return system2.property(HTTP_PROXY_HOSTNAME) != null || system2.property(HTTPS_PROXY_HOSTNAME) != null || system2.property(PROXY_SOCKS_HOSTNAME) != null; }
/** * Checks if a proxy was passed with command line parameters or configured in the system. * If only an HTTP proxy was configured then it's properties are copied to the HTTPS proxy (like SonarQube configuration) * * @return True iff a proxy was configured to be used in the plugin. */ public boolean isProxyConnectionEnabled() { if (configuration.getBoolean(GitLabPlugin.GITLAB_DISABLE_PROXY).orElse(false)) { return false; } return (system2.property(HTTP_PROXY_HOSTNAME) != null || system2.property(HTTPS_PROXY_HOSTNAME) != null || system2.property(PROXY_SOCKS_HOSTNAME) != null); }
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(); }
private Path findSonarHome(GlobalProperties 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(); }
public Proxy getHttpProxy() { try { if (system2.property(HTTP_PROXY_HOSTNAME) != null && system2.property(HTTPS_PROXY_HOSTNAME) == null) { System.setProperty(HTTPS_PROXY_HOSTNAME, system2.property(HTTP_PROXY_HOSTNAME)); System.setProperty(HTTPS_PROXY_PORT, system2.property(HTTP_PROXY_PORT)); } String proxyUser = system2.property(HTTP_PROXY_USER); String proxyPass = system2.property(HTTP_PROXY_PASS); if (proxyUser != null && proxyPass != null) { Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPass.toCharArray()); } }); } Proxy selectedProxy = ProxySelector.getDefault().select(new URI(url())).get(0); if (selectedProxy.type() == Proxy.Type.DIRECT) { LOG.debug("There was no suitable proxy found to connect to GitLab - direct connection is used "); } LOG.info("A proxy has been configured - {}", selectedProxy.toString()); return selectedProxy; } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to perform GitLab WS operation - url in wrong format: " + url(), e); } }
public Proxy getHttpProxy() { try { if (system2.property(HTTP_PROXY_HOSTNAME) != null && system2.property(HTTPS_PROXY_HOSTNAME) == null) { System.setProperty(HTTPS_PROXY_HOSTNAME, system2.property(HTTP_PROXY_HOSTNAME)); System.setProperty(HTTPS_PROXY_PORT, system2.property(HTTP_PROXY_PORT)); } String proxyUser = system2.property(HTTP_PROXY_USER); String proxyPass = system2.property(HTTP_PROXY_PASS); if (proxyUser != null && proxyPass != null) { Authenticator.setDefault( new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication( proxyUser, proxyPass.toCharArray()); } }); } Proxy selectedProxy = ProxySelector.getDefault().select(new URI(endpoint())).get(0); if (selectedProxy.type() == Proxy.Type.DIRECT) { LOG.debug("There was no suitable proxy found to connect to GitHub - direct connection is used "); } LOG.info("A proxy has been configured - {}", selectedProxy.toString()); return selectedProxy; } catch (URISyntaxException e) { throw new IllegalArgumentException("Unable to perform GitHub WS operation - endpoint in wrong format: " + endpoint(), e); } }