private List<File> getPotentialScripts(String scriptName, List<File> allScripts) { List<File> potentialScripts; boolean exactMatchFound = false; potentialScripts = new ArrayList<File>(); for (File scriptPath : allScripts) { String fileName = scriptPath.getName(); String scriptFileName = fileName.substring(0, fileName.length() - 7); // trim .groovy extension if (scriptFileName.endsWith("_")) { scriptsAllowedOutsideOfProject.add(scriptPath); scriptFileName = scriptFileName.substring(0, scriptFileName.length() - 1); } if (scriptFileName.equals(scriptName)) { potentialScripts.add(scriptPath); exactMatchFound = true; continue; } if (!exactMatchFound && ScriptNameResolver.resolvesTo(scriptName, scriptFileName)) { potentialScripts.add(scriptPath); } } return potentialScripts; }
@SuppressWarnings({"unchecked", "rawtypes"}) private int executeScriptWithCaching(CommandLine commandLine, String scriptName, String env) { List<Resource> potentialScripts; List<Resource> allScripts = getAvailableScripts(); GantBinding binding = new GantBinding(); binding.setVariable("scriptName", scriptName); setDefaultInputStream(binding); // Now find what scripts match the one requested by the user. boolean exactMatchFound = false; potentialScripts = new ArrayList<Resource>(); for (Resource scriptPath : allScripts) { String scriptFileName = scriptPath .getFilename() .substring(0, scriptPath.getFilename().length() - 7); // trim .groovy extension if (scriptFileName.endsWith("_")) { scriptsAllowedOutsideOfProject.add(scriptPath); scriptFileName = scriptFileName.substring(0, scriptFileName.length() - 1); } if (scriptFileName.equals(scriptName)) { potentialScripts.add(scriptPath); exactMatchFound = true; continue; } if (!exactMatchFound && ScriptNameResolver.resolvesTo(scriptName, scriptFileName)) { potentialScripts.add(scriptPath); } } // First try to load the script from its file. If there is no // file, then attempt to load it as a pre-compiled script. If // that fails, then let the user know and then exit. if (potentialScripts.size() > 0) { potentialScripts = (List) DefaultGroovyMethods.unique(potentialScripts); final Resource scriptFile = potentialScripts.get(0); if (!isGrailsProject() && !isExternalScript(scriptFile)) { return handleScriptExecutedOutsideProjectError(); } return executeScriptFile(commandLine, scriptName, env, binding, scriptFile); } return attemptPrecompiledScriptExecute(commandLine, scriptName, env, binding, allScripts); }