Java Code Examples for groovy.lang.Closure#getProperty()

The following examples show how to use groovy.lang.Closure#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProjectDsl.java    From jira-groovioli with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Project findProject(@DelegatesTo(FindProjectHandler.class) Closure closure) {
    FindProjectHandler findProjectHandler = new FindProjectHandler();
    closure.setDelegate(findProjectHandler);
    closure.call();

    if (!findProjectHandler.isValid()) {
        throw new ScriptDslException("Invalid parameters for findProject");
    }

    ProjectManager projectManager = (ProjectManager) closure.getProperty("projectManager");
    if (StringUtils.isNotBlank(findProjectHandler.key)) {
        return projectManager.getProjectObjByKey(findProjectHandler.key);
    } else {
        return projectManager.getProjectObjByName(findProjectHandler.name);
    }
}
 
Example 2
Source File: FastTags.java    From restcommander with Apache License 2.0 6 votes vote down vote up
public static void _set(Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine) {
    // Simple case : #{set title:'Yop' /}
    for (Map.Entry<?, ?> entry : args.entrySet()) {
        Object key = entry.getKey();
        if (!key.toString().equals("arg")) {
            BaseTemplate.layoutData.get().put(key, (entry.getValue() != null && entry.getValue() instanceof String) ? __safe(template.template, entry.getValue()) : entry.getValue());
            return;
        }
    }
    // Body case
    Object name = args.get("arg");
    if (name != null && body != null) {
        Object oldOut = body.getProperty("out");
        StringWriter sw = new StringWriter();
        body.setProperty("out", new PrintWriter(sw));
        body.call();
        BaseTemplate.layoutData.get().put(name, sw.toString());
        body.setProperty("out", oldOut);
    }
}
 
Example 3
Source File: ConstantDsl.java    From jira-groovioli with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public IssueType findIssueType(@DelegatesTo(FindIssueTypeHandler.class) Closure closure) {
    FindIssueTypeHandler findIssueTypeHandler = new FindIssueTypeHandler();
    closure.setDelegate(findIssueTypeHandler);
    closure.call();

    ConstantsManager constantsManager = (ConstantsManager) closure.getProperty("constantsManager");
    Collection<IssueType> allIssueTypeObjects =  constantsManager.getAllIssueTypeObjects();
    for (IssueType issueType : allIssueTypeObjects) {
        if (issueType.getName().equals(findIssueTypeHandler.name)) {
            return issueType;
        }
    }
    return null;
}
 
Example 4
Source File: JavaExtensions.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public static String toString(Closure closure) {
    PrintWriter oldWriter = (PrintWriter) closure.getProperty("out");
    StringWriter newWriter = new StringWriter();
    closure.setProperty("out", new PrintWriter(newWriter));
    closure.call();
    closure.setProperty("out", oldWriter);
    return newWriter.toString();
}