Search in sources :

Example 1 with Action

use of aQute.bnd.service.action.Action in project bnd by bndtools.

the class Project method fillActions.

public void fillActions(Map<String, Action> all) {
    List<NamedAction> plugins = getPlugins(NamedAction.class);
    for (NamedAction a : plugins) all.put(a.getName(), a);
    Parameters actions = new Parameters(getProperty("-actions", DEFAULT_ACTIONS), this);
    for (Entry<String, Attrs> entry : actions.entrySet()) {
        String key = Processor.removeDuplicateMarker(entry.getKey());
        Action action;
        if (entry.getValue().get("script") != null) {
            // TODO check for the type
            action = new ScriptAction(entry.getValue().get("type"), entry.getValue().get("script"));
        } else {
            action = new ReflectAction(key);
        }
        String label = entry.getValue().get("label");
        all.put(label.toLowerCase(), action);
    }
}
Also used : NamedAction(aQute.bnd.service.action.NamedAction) Action(aQute.bnd.service.action.Action) NamedAction(aQute.bnd.service.action.NamedAction) Parameters(aQute.bnd.header.Parameters) Attrs(aQute.bnd.header.Attrs)

Example 2 with Action

use of aQute.bnd.service.action.Action in project bnd by bndtools.

the class Project method action.

public void action(String command, Object... args) throws Exception {
    Map<String, Action> actions = getActions();
    Action a = actions.get(command);
    if (a == null)
        a = new ReflectAction(command);
    before(this, command);
    try {
        if (args.length == 0)
            a.execute(this, command);
        else
            a.execute(this, args);
    } catch (Exception t) {
        after(this, command, t);
        throw t;
    }
}
Also used : Action(aQute.bnd.service.action.Action) NamedAction(aQute.bnd.service.action.NamedAction) IOException(java.io.IOException)

Example 3 with Action

use of aQute.bnd.service.action.Action in project bnd by bndtools.

the class bnd method _project.

@Description("Execute a Project action, or if no parms given, show information about the project")
public void _project(projectOptions options) throws Exception {
    Project project = getProject(options.project());
    if (project == null) {
        messages.NoProject();
        return;
    }
    List<String> l = new ArrayList<String>(options._arguments());
    if (l.isEmpty()) {
        err.printf("Name         %s\n", project.getName());
        err.printf("Actions      %s\n", project.getActions().keySet());
        err.printf("Directory    %s\n", project.getBase());
        err.printf("Depends on   %s\n", project.getDependson());
        err.printf("Sub builders %s\n", project.getSubBuilders());
        return;
    }
    String cmd = null;
    String arg = null;
    if (!l.isEmpty())
        cmd = l.remove(0);
    if (!l.isEmpty())
        arg = l.remove(0);
    if (!l.isEmpty()) {
        messages.MoreArgumentsThanNeeded_(options._arguments());
        return;
    }
    if (cmd == null) {
        messages.NoCommandForProject(project);
        return;
    }
    Action a = project.getActions().get(cmd);
    if (a != null) {
        a.execute(project, arg);
        getInfo(project);
        return;
    }
}
Also used : Project(aQute.bnd.build.Project) Action(aQute.bnd.service.action.Action) ArrayList(java.util.ArrayList) Description(aQute.lib.getopt.Description)

Aggregations

Action (aQute.bnd.service.action.Action)3 NamedAction (aQute.bnd.service.action.NamedAction)2 Project (aQute.bnd.build.Project)1 Attrs (aQute.bnd.header.Attrs)1 Parameters (aQute.bnd.header.Parameters)1 Description (aQute.lib.getopt.Description)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1