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;
}
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;
}
Aggregations