@Override public String toString() { return "JavaCommand{" + "workDir=" + getWorkDir() + ", jvmOptions=" + jvmOptions + ", className='" + className + '\'' + ", classpath=" + classpath + ", arguments=" + getArguments() + ", envVariables=" + getEnvVariables() + ", suppressedEnvVariables=" + getSuppressedEnvVariables() + '}'; } }
public T setEsInstallation(EsInstallation esInstallation) { this.esInstallation = esInstallation; return castThis(); }
public CeJvmOptions(File tmpDir) { super(mandatoryOptions(tmpDir)); }
@Override public JavaCommand createCeCommand() { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); CeJvmOptions jvmOptions = new CeJvmOptions(tempDir) .addFromMandatoryProperty(props, CE_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, CE_JAVA_ADDITIONAL_OPTS.getKey()); addProxyJvmOptions(jvmOptions); JavaCommand<CeJvmOptions> command = new JavaCommand<CeJvmOptions>(ProcessId.COMPUTE_ENGINE, homeDir) .setReadsArgumentsFromFile(true) .setArguments(props.rawProperties()) .setJvmOptions(jvmOptions) .setClassName("org.sonar.ce.app.CeServer") .addClasspath("./lib/common/*"); String driverPath = props.value(JDBC_DRIVER_PATH.getKey()); if (driverPath != null) { command.addClasspath(driverPath); } command.suppressEnvVariable(ENV_VAR_JAVA_TOOL_OPTIONS); return command; }
private <T extends JvmOptions> void addProxyJvmOptions(JvmOptions<T> jvmOptions) { for (String key : PROXY_PROPERTY_KEYS) { getPropsValue(key).ifPresent(val -> jvmOptions.add("-D" + key + "=" + val)); } // defaults of HTTPS are the same than HTTP defaults setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_HOST.getKey(), HTTP_PROXY_HOST.getKey()); setSystemPropertyToDefaultIfNotSet(jvmOptions, HTTPS_PROXY_PORT.getKey(), HTTP_PROXY_PORT.getKey()); }
@Before public void setUp() throws Exception { File tempDir = temporaryFolder.newFolder(); esScriptCommand = new EsScriptCommand(ELASTICSEARCH, tempDir); webLeaderCommand = new JavaCommand(WEB_SERVER, tempDir); webFollowerCommand = new JavaCommand(WEB_SERVER, tempDir); ceCommand = new JavaCommand(COMPUTE_ENGINE, tempDir); }
private void setSystemPropertyToDefaultIfNotSet(JvmOptions jvmOptions, String httpsProperty, String httpProperty) { Optional<String> httpValue = getPropsValue(httpProperty); Optional<String> httpsValue = getPropsValue(httpsProperty); if (!httpsValue.isPresent() && httpValue.isPresent()) { jvmOptions.add("-D" + httpsProperty + "=" + httpValue.get()); } }
@Test @UseDataProvider("variousEmptyStrings") public void add_throws_IAE_if_argument_is_empty(String emptyString) { expectJvmOptionNotEmptyAndStartByDashIAE(); underTest.add(emptyString); }
@Test public void createWebCommand_adds_configured_jdbc_driver_to_classpath() throws Exception { Properties props = new Properties(); File driverFile = temp.newFile(); props.setProperty("sonar.jdbc.driverPath", driverFile.getAbsolutePath()); JavaCommand command = newFactory(props).createWebCommand(true); assertThat(command.getClasspath()) .containsExactlyInAnyOrder("./lib/common/*", driverFile.getAbsolutePath()); }
@Override public AbstractCommand<?> createEsCommand() { if (system2.isOsWindows()) { return createEsCommandForWindows(); } return createEsCommandForUnix(); }
@Test public void add_throws_NPE_if_argument_is_null() { expectJvmOptionNotNullNPE(); underTest.add(null); }
@Test @UseDataProvider("variousEmptyStrings") public void constructor_accepts_any_empty_option_value(String emptyString) { Map<String, String> mandatoryJvmOptions = shuffleThenToMap( Stream.of( IntStream.range(0, random.nextInt(10)).mapToObj(i -> new Option("-B", valueOf(i))), Stream.of(new Option("-prefix", emptyString))) .flatMap(s -> s)); new JvmOptions(mandatoryJvmOptions); }
@Test public void addFromMandatoryProperty_fails_with_IAE_if_property_contains_an_empty_value() { expectMissingPropertyIAE(this.randomPropertyName); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); }
public WebJvmOptions(File tmpDir) { super(mandatoryOptions(tmpDir)); }
public EsJvmOptions() { super(mandatoryOptions()); }
@Test public void constructor_throws_NPE_if_argument_is_null() { expectJvmOptionNotNullNPE(); new JvmOptions(null); }
@Test public void createEsCommand_throws_ISE_if_es_binary_is_not_found() { expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Cannot find elasticsearch binary"); newFactory(new Properties()).createEsCommand(); }
private CommandFactoryImpl newFactory(Properties userProps) { return newFactory(userProps, System2.INSTANCE); }
@Test public void add_throws_IAE_if_argument_does_not_start_with_dash() { expectJvmOptionNotEmptyAndStartByDashIAE(); underTest.add(randomAlphanumeric(3)); }
@Test public void addFromMandatoryProperty_fails_with_IAE_if_property_does_not_exist() { expectMissingPropertyIAE(this.randomPropertyName); underTest.addFromMandatoryProperty(new Props(properties), this.randomPropertyName); }