/** * Bind the runner to a project component. * The project and self are the only beans set. * @param component to become <code>self</code> */ public void bindToComponentMinimum(ProjectComponent component) { project = component.getProject(); addBean("project", project); addBean("self", component); }
/** * Bind the runner to a project component. * Properties, targets and references are all added as beans; * project is bound to project, and self to the component. * @param component to become <code>self</code> */ public void bindToComponent(ProjectComponent component) { project = component.getProject(); addBeans(project.getProperties()); addBeans(project.getUserProperties()); addBeans(project.getCopyOfTargets()); addBeans(project.getCopyOfReferences()); addBean("project", project); addBean("self", component); }
/** * Add a list of named objects to the list to be exported to the script * * @param dictionary a map of objects to be placed into the script context * indexed by String names. */ public void addBeans(Map<String, ?> dictionary) { dictionary.forEach((k, v) -> { try { addBean(k, v); } catch (BuildException ex) { // The key is in the dictionary but cannot be retrieved // This is usually due references that refer to tasks // that have not been taskdefed in the current run. // Ignore } }); }
/** * Executes the script. * This is called by the script instance to execute the script for this * definition. * * @param attributes collection of attributes * @param elements a list of nested element values. * @param instance the script instance; can be null */ public void executeScript(Map<String, String> attributes, Map<String, List<Object>> elements, ScriptDefBase instance) { ScriptRunnerBase runner = helper.getScriptRunner(); runner.addBean("attributes", attributes); runner.addBean("elements", elements); runner.addBean("project", getProject()); if (instance != null) { runner.addBean("self", instance); } runner.executeScript("scriptdef_" + name); }
/** * Method that each selector will implement to create their selection * behaviour. If there is a problem with the setup of a selector, it can * throw a BuildException to indicate the problem. * * @param basedir A java.io.File object for the base directory * @param filename The name of the file to check * @param file A File object for this filename * * @return whether the file should be selected or not */ @Override public boolean isSelected(File basedir, String filename, File file) { init(); setSelected(true); this.file = file; this.basedir = basedir; this.filename = filename; runner.addBean("basedir", basedir); runner.addBean("filename", filename); runner.addBean("file", file); runner.executeScript("ant_selector"); return isSelected(); }
/** * Returns an array containing the target filename(s) for the given source * file. * * <p>if the given rule doesn't apply to the source file, implementation * must return null. SourceFileScanner will then omit the source file in * question.</p> * * @param sourceFileName the name of the source file relative to some given * basedirectory. * @return an array of strings if the rule applies to the source file, or * null if it does not. */ @Override public String[] mapFileName(String sourceFileName) { initScriptRunner(); getRunner().addBean("source", sourceFileName); clear(); executeScript("ant_mapper"); if (files.isEmpty()) { return null; } return files.toArray(new String[files.size()]); } }