Search in sources :

Example 1 with LifeCyclePlugin

use of aQute.bnd.service.lifecycle.LifeCyclePlugin in project bnd by bndtools.

the class Workspace method addPlugin.

/**
	 * Add a plugin
	 * 
	 * @param plugin
	 * @throws Exception
	 */
public boolean addPlugin(Class<?> plugin, String alias, Map<String, String> parameters, boolean force) throws Exception {
    BndPlugin ann = plugin.getAnnotation(BndPlugin.class);
    if (alias == null) {
        if (ann != null)
            alias = ann.name();
        else {
            alias = Strings.getLastSegment(plugin.getName()).toLowerCase();
            if (alias.endsWith("plugin")) {
                alias = alias.substring(0, alias.length() - "plugin".length());
            }
        }
    }
    if (!Verifier.isBsn(alias)) {
        error("Not a valid plugin name %s", alias);
    }
    File ext = getFile(Workspace.CNFDIR + "/" + Workspace.EXT);
    IO.mkdirs(ext);
    File f = new File(ext, alias + ".bnd");
    if (!force) {
        if (f.exists()) {
            error("Plugin %s already exists", alias);
            return false;
        }
    } else {
        IO.delete(f);
    }
    Object l = plugin.getConstructor().newInstance();
    try (Formatter setup = new Formatter()) {
        setup.format(//
        "#\n" + //
        "# Plugin %s setup\n" + "#\n", alias);
        setup.format("-plugin.%s = %s", alias, plugin.getName());
        for (Map.Entry<String, String> e : parameters.entrySet()) {
            setup.format("; \\\n \t%s = '%s'", e.getKey(), escaped(e.getValue()));
        }
        setup.format("\n\n");
        String out = setup.toString();
        if (l instanceof LifeCyclePlugin) {
            out = ((LifeCyclePlugin) l).augmentSetup(out, alias, parameters);
            ((LifeCyclePlugin) l).init(this);
        }
        logger.debug("setup {}", out);
        IO.store(out, f);
    }
    refresh();
    for (LifeCyclePlugin lp : getPlugins(LifeCyclePlugin.class)) {
        lp.addedPlugin(this, plugin.getName(), alias, parameters);
    }
    return true;
}
Also used : LifeCyclePlugin(aQute.bnd.service.lifecycle.LifeCyclePlugin) Formatter(java.util.Formatter) BndPlugin(aQute.bnd.annotation.plugin.BndPlugin) File(java.io.File) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with LifeCyclePlugin

use of aQute.bnd.service.lifecycle.LifeCyclePlugin in project bnd by bndtools.

the class Workspace method createProject.

/**
	 * Create a project in this workspace
	 */
public Project createProject(String name) throws Exception {
    if (!Verifier.SYMBOLICNAME.matcher(name).matches()) {
        error("A project name is a Bundle Symbolic Name, this must therefore consist of only letters, digits and dots");
        return null;
    }
    File pdir = getFile(name);
    IO.mkdirs(pdir);
    IO.store("#\n#   " + name.toUpperCase().replace('.', ' ') + "\n#\n", getFile(pdir, Project.BNDFILE));
    Project p = new Project(this, pdir);
    IO.mkdirs(p.getTarget());
    IO.mkdirs(p.getOutput());
    IO.mkdirs(p.getTestOutput());
    for (File dir : p.getSourcePath()) {
        IO.mkdirs(dir);
    }
    IO.mkdirs(p.getTestSrc());
    for (LifeCyclePlugin l : getPlugins(LifeCyclePlugin.class)) l.created(p);
    if (!p.isValid()) {
        error("project %s is not valid", p);
    }
    return p;
}
Also used : LifeCyclePlugin(aQute.bnd.service.lifecycle.LifeCyclePlugin) File(java.io.File)

Aggregations

LifeCyclePlugin (aQute.bnd.service.lifecycle.LifeCyclePlugin)2 File (java.io.File)2 BndPlugin (aQute.bnd.annotation.plugin.BndPlugin)1 Formatter (java.util.Formatter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1