Source:
<code>private String getSparkHome(String sparkVersion) { String sparkHome = getSysProps().get("spark." + sparkVersion + ".home"); if (sparkHome == null) { info("Couldn't find spark." + sparkVersion + ".home property."); String sparkDir = getSysProps().get("spark.home.dir"); String sparkHomePrefix = getSysProps().get("spark.home.prefix") != null ? getSysProps().get("spark.home.prefix") : "*"; info(" Looking for spark at " + sparkDir + " directory with " + sparkHomePrefix + " prefix for " + sparkVersion + " version."); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(sparkDir); scanner.setIncludes( new String[]{sparkHomePrefix + sparkVersion.replace(".", "") + "*", sparkHomePrefix + sparkVersion + "*"}); scanner.scan(); String[] directories = scanner.getIncludedDirectories(); if (directories != null && directories.length > 0) { sparkHome = sparkDir + "/" + directories[directories.length - 1]; } else { scanner.setIncludes(new String[]{sparkHomePrefix + "*"}); scanner.scan(); String[] availableDirectories = scanner.getIncludedDirectories(); if (availableDirectories != null && availableDirectories.length > 0) { Set<String> availableVersions = Sets.newTreeSet(); for (String directory : availableDirectories) { String version = directory.replace(sparkHomePrefix, ""); availableVersions.add(version.contains(".") ? version.substring(0, 5) <START> : Joiner.on(".").join(version.substring(0, 3).split(""))); <END> } throw new RuntimeException( "SPARK version specified by User is not available. Available versions are : " + Joiner.on(",") .join(availableVersions)); } } } return sparkHome; }</code><technical_language>Including list of versions in exception message practical. potentially scenarios version 2.1.0 2.10.1 available. In case, practical distinguish version 2 Strings "210XX" "2101XX" correspond to. throw a RuntimeException point users internal wiki page for supported versions</technical_language>

Target:
private String getSparkHome(String sparkVersion) { String sparkHome = getSysProps().get("spark." + sparkVersion + ".home"); if (sparkHome == null) { info("Couldn't find spark." + sparkVersion + ".home property."); String sparkDir = getSysProps().get(SPARK_BASE_DIR); String sparkHomePrefix = getSysProps().get(SPARK_HOME_PREFIX) != null ? getSysProps().get(SPARK_HOME_PREFIX) : "*"; String replaceTo = getSysProps().get(SPARK_VERSION_REGEX_TO_REPLACE); String replaceWith = getSysProps().get(SPARK_VERSION_REGEX_TO_REPLACE_WITH) != null ? getSysProps() .get(SPARK_VERSION_REGEX_TO_REPLACE_WITH) : ""; String versionPatterToMatch = sparkHomePrefix + ( replaceTo != null ? sparkVersion .replace(replaceTo, replaceWith) : sparkVersion) + "*"; info("Looking for spark at " + sparkDir + " directory with " + sparkHomePrefix + " prefix for " + sparkVersion + " version."); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(sparkDir); scanner.setIncludes(new String[]{versionPatterToMatch}); scanner.scan(); String[] directories = scanner.getIncludedDirectories(); if (directories != null && directories.length > 0) { sparkHome = sparkDir + "/" + directories[directories.length - 1]; } else { String sparkReferenceDoc = getSysProps().get(SPARK_REFERENCE_DOCUMENT); String exceptionMessage = sparkReferenceDoc == null ? "SPARK version specified by User is not available." : "SPARK version specified by User is not available. Available versions are mentioned at: " + sparkReferenceDoc; throw new RuntimeException(exceptionMessage); } } return sparkHome; }