private static File getSharedDir(Props props) { return props.nonNullValueAsFile(PROPERTY_SHARED_PATH); } }
private static File getSharedDir(Props props) { return props.nonNullValueAsFile(PROPERTY_SHARED_PATH); }
private static File buildConfDir(Props props) { File tempPath = props.nonNullValueAsFile(PATH_TEMP.getKey()); return new File(new File(tempPath, "conf"), "es"); }
private static File buildLogPath(Props props) { return props.nonNullValueAsFile(PATH_LOGS.getKey()); }
private static File ensurePropertyIsAbsolutePath(Props props, String propKey) { // default values are set by ProcessProperties String path = props.nonNullValue(propKey); File d = new File(path); if (!d.isAbsolute()) { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); d = new File(homeDir, path); LOG.trace("Overriding property {} from relative path '{}' to absolute path '{}'", propKey, path, d.getAbsolutePath()); props.set(propKey, d.getAbsolutePath()); } return d; }
private File createOrCleanTempDirectory(String propKey) throws IOException { File dir = settings.getProps().nonNullValueAsFile(propKey); LOG.info("Cleaning or creating temp directory {}", dir.getAbsolutePath()); if (!createDirectory(propKey)) { Files.walkFileTree(dir.toPath(), FOLLOW_LINKS, CleanTempDirFileVisitor.VISIT_MAX_DEPTH, new CleanTempDirFileVisitor(dir.toPath())); } return dir; }
private boolean createDirectory(String propKey) throws IOException { File dir = settings.getProps().nonNullValueAsFile(propKey); if (dir.exists()) { ensureIsNotAFile(propKey, dir); return false; } forceMkdir(dir); ensureIsNotAFile(propKey, dir); return true; }
@Override public File getTempDir() { return settings.getProps().nonNullValueAsFile(PATH_TEMP.getKey()); }
public RollingPolicy createRollingPolicy(Context ctx, Props props, String filenamePrefix) { String rollingPolicy = props.value(ROLLING_POLICY_PROPERTY, "time:yyyy-MM-dd"); int maxFiles = props.valueAsInt(MAX_FILES_PROPERTY, 7); File logsDir = props.nonNullValueAsFile(PATH_LOGS.getKey()); if (rollingPolicy.startsWith("time:")) { return new TimeRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "time:")); } else if (rollingPolicy.startsWith("size:")) { return new SizeRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "size:")); } else if ("none".equals(rollingPolicy)) { return new NoRollingPolicy(ctx, filenamePrefix, logsDir, maxFiles); } else { throw new MessageException(format("Unsupported value for property %s: %s", ROLLING_POLICY_PROPERTY, rollingPolicy)); } }
public StandardContext configure(Tomcat tomcat, Props props) { addStaticDir(tomcat, getContextPath(props) + "/deploy", new File(props.nonNullValueAsFile(PATH_DATA.getKey()), WEB_DEPLOY_PATH_RELATIVE_TO_DATA_DIR)); StandardContext webapp = addContext(tomcat, getContextPath(props), webappDir(props)); for (Map.Entry<Object, Object> entry : props.rawProperties().entrySet()) { String key = entry.getKey().toString(); webapp.addParameter(key, entry.getValue().toString()); } return webapp; }
public EsInstallation(Props props) { File sqHomeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); this.homeDirectory = new File(sqHomeDir, "elasticsearch"); this.outdatedSearchDirectories = buildOutdatedSearchDirs(props); this.dataDirectory = buildDataDir(props); this.confDirectory = buildConfDir(props); this.logDirectory = buildLogPath(props); }
@Test public void nonNullValueAsFile() throws IOException { File file = temp.newFile(); Props props = new Props(new Properties()); props.set("path", file.getAbsolutePath()); assertThat(props.nonNullValueAsFile("path")).isEqualTo(file); try { props.nonNullValueAsFile("other_path"); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Property other_path is not set"); } }
@Override public void accept(Props props) { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); Provider provider = resolveProviderAndEnforceNonnullJdbcUrl(props); String url = props.value(JDBC_URL.getKey()); checkUrlParameters(provider, url); String driverPath = driverPath(homeDir, provider); props.set(JDBC_DRIVER_PATH.getKey(), driverPath); }
@Test public void sets_driver_path_for_h2() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/h2/h2.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:h2:tcp://localhost:9092/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_postgresql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/postgresql/pg.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:postgresql://localhost/sonar"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_oracle() throws Exception { File driverFile = new File(homeDir, "extensions/jdbc-driver/oracle/ojdbc6.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:oracle:thin:@localhost/XE"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Test public void checkAndComplete_sets_driver_path_for_mssql() throws Exception { File driverFile = new File(homeDir, "lib/jdbc/mssql/sqljdbc4.jar"); FileUtils.touch(driverFile); Props props = newProps(JDBC_URL.getKey(), "jdbc:sqlserver://localhost/sonar;SelectMethod=Cursor"); underTest.accept(props); assertThat(props.nonNullValueAsFile(JDBC_DRIVER_PATH.getKey())).isEqualTo(driverFile); }
@Override public JavaCommand createWebCommand(boolean leader) { File homeDir = props.nonNullValueAsFile(PATH_HOME.getKey()); WebJvmOptions jvmOptions = new WebJvmOptions(tempDir) .addFromMandatoryProperty(props, WEB_JAVA_OPTS.getKey()) .addFromMandatoryProperty(props, WEB_JAVA_ADDITIONAL_OPTS.getKey()); addProxyJvmOptions(jvmOptions); JavaCommand<WebJvmOptions> command = new JavaCommand<WebJvmOptions>(ProcessId.WEB_SERVER, homeDir) .setReadsArgumentsFromFile(true) .setArguments(props.rawProperties()) .setJvmOptions(jvmOptions) // required for logback tomcat valve .setEnvVariable(PATH_LOGS.getKey(), props.nonNullValue(PATH_LOGS.getKey())) .setArgument("sonar.cluster.web.startupLeader", Boolean.toString(leader)) .setClassName("org.sonar.server.app.WebServer") .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; }
@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; }
public static ProcessEntryPoint createForArguments(String[] args) { Props props = ConfigurationUtils.loadPropsFromCommandLineArgs(args); ProcessCommands commands = new ProcessCommands( props.nonNullValueAsFile(PROPERTY_SHARED_PATH), Integer.parseInt(props.nonNullValue(PROPERTY_PROCESS_INDEX))); return new ProcessEntryPoint(props, new SystemExit(), commands); } }