protected String getGrailsPluginFileName() { String artifactId = project.getArtifactId(); String pluginName = GrailsNameUtils.getNameFromScript(project.getArtifactId()) + "GrailsPlugin.groovy"; String name = this.getBasedir() + File.separator + pluginName; if (new File(name).exists()) { return pluginName; } if (artifactId.startsWith("grails-")) { artifactId = artifactId.substring("grails-".length()); pluginName = GrailsNameUtils.getNameFromScript(artifactId) + "GrailsPlugin.groovy"; name = this.getBasedir() + File.separator + pluginName; if (new File(name).exists()) { return pluginName; } } return null; }
public int executeScriptWithCaching(CommandLine commandLine) { processSystemArguments(commandLine); System.setProperty("grails.cli.args", commandLine.getRemainingArgsLineSeparated()); return executeScriptWithCaching( commandLine, GrailsNameUtils.getNameFromScript(commandLine.getCommandName()), commandLine.getEnvironment()); }
private static ScriptAndArgs processAndReturnArguments(CommandLine commandLine) { ScriptAndArgs info = new ScriptAndArgs(); if (Environment.isSystemSet()) { info.env = Environment.getCurrent().getName(); } else if (commandLine.getEnvironment() != null) { info.env = commandLine.getEnvironment(); } info.inputName = commandLine.getCommandName(); info.name = GrailsNameUtils.getNameFromScript(commandLine.getCommandName()); return info; }
@SuppressWarnings({"unchecked", "rawtypes"}) private int executeScriptWithCaching(CommandLine commandLine, String scriptName, String env) { List<File> potentialScripts; List<File> allScripts = getAvailableScripts(); GantBinding binding = new GantBinding(); binding.setVariable("scriptName", scriptName); setDefaultInputStream(binding); // Now find what scripts match the one requested by the user. potentialScripts = getPotentialScripts(scriptName, allScripts); if (potentialScripts.size() == 0) { try { File aliasFile = new File(settings.getUserHome(), ".grails/.aliases"); if (aliasFile.exists()) { Properties aliasProperties = new Properties(); aliasProperties.load(new FileReader(aliasFile)); if (aliasProperties.containsKey(commandLine.getCommandName())) { String aliasValue = (String) aliasProperties.get(commandLine.getCommandName()); String[] aliasPieces = aliasValue.split(" "); String commandName = aliasPieces[0]; String correspondingScriptName = GrailsNameUtils.getNameFromScript(commandName); potentialScripts = getPotentialScripts(correspondingScriptName, allScripts); if (potentialScripts.size() > 0) { String[] additionalArgs = new String[aliasPieces.length - 1]; System.arraycopy(aliasPieces, 1, additionalArgs, 0, additionalArgs.length); insertArgumentsInFrontOfExistingArguments(commandLine, additionalArgs); } } } } catch (Exception e) { console.error(e); } } // 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 File scriptFile = potentialScripts.get(0); if (!isGrailsProject() && !isExternalScript(scriptFile)) { return handleScriptExecutedOutsideProjectError(); } return executeScriptFile(commandLine, scriptName, env, binding, scriptFile); } return attemptPrecompiledScriptExecute(commandLine, scriptName, env, binding, allScripts); }