Source:
public static String resolveExecutionJarName(String workingDirectory, String userSpecifiedJarName, Logger log) { log.debug("Resolving execution jar name: working directory: " + workingDirectory + ", user specified name: " + userSpecifiedJarName); if (userSpecifiedJarName.endsWith(".jar")) userSpecifiedJarName = userSpecifiedJarName.replace(".jar", ""); String userSpecifiedJarPath = String.format("%s/%s", workingDirectory, userSpecifiedJarName); int lastIndexOfSlash = userSpecifiedJarPath.lastIndexOf("/"); final String jarname = userSpecifiedJarPath.substring(lastIndexOfSlash + 1); final String dirName = userSpecifiedJarPath.substring(0, lastIndexOfSlash); log.debug("Resolving execution jar name: dirname: " + dirName + ", jar name: " + jarname); File[] potentialExecutionJarList = new File(dirName).listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { if (name.startsWith(jarname.toString())) return true; else return false; } }); if (potentialExecutionJarList.length == 0) { throw new IllegalStateException("unable to find execution jar for Spark at path: " + userSpecifiedJarPath); } else if (potentialExecutionJarList.length > 1) { throw new IllegalStateException( "I find more than one matching instance of the execution jar at the path, don't know which one to use: " + userSpecifiedJarPath); } String resolvedJarName = potentialExecutionJarList[0].toString(); log.debug("Resolving execution jar name: resolvedJarName: " + resolvedJarName); return resolvedJarName; }

Target:
public static String resolveExecutionJarName(String workingDirectory, String userSpecifiedJarName, Logger log) { if (log.isDebugEnabled()) { String debugMsg = String.format( "Resolving execution jar name: working directory: %s, user specified name: %s", workingDirectory, userSpecifiedJarName); log.debug(debugMsg); } if (userSpecifiedJarName.endsWith(".jar")) userSpecifiedJarName = userSpecifiedJarName.replace(".jar", ""); String userSpecifiedJarPath = String.format("%s/%s", workingDirectory, userSpecifiedJarName); int lastIndexOfSlash = userSpecifiedJarPath.lastIndexOf("/"); final String jarPrefix = userSpecifiedJarPath.substring(lastIndexOfSlash + 1); final String dirName = userSpecifiedJarPath.substring(0, lastIndexOfSlash); if (log.isDebugEnabled()) { String debugMsg = String.format("Resolving execution jar name: dirname: %s, jar name: %s", dirName, jarPrefix); log.debug(debugMsg); } File[] potentialExecutionJarList; try { potentialExecutionJarList = getFilesInFolderByRegex(new File(dirName), jarPrefix + ".*jar"); } catch (FileNotFoundException e) { throw new IllegalStateException( "execution jar is suppose to be in this folder, but the folder doesn't exist: " + dirName); } if (potentialExecutionJarList.length == 0) { throw new IllegalStateException("unable to find execution jar for Spark at path: " + userSpecifiedJarPath + "*.jar"); } else if (potentialExecutionJarList.length > 1) { throw new IllegalStateException( "I find more than one matching instance of the execution jar at the path, don't know which one to use: " + userSpecifiedJarPath + "*.jar"); } String resolvedJarName = potentialExecutionJarList[0].toString(); log.debug("Resolving execution jar name: resolvedJarName: " + resolvedJarName); return resolvedJarName; }