aQute.bnd.plugin.eclipse.EclipsePlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
package aQute.bnd.plugin.eclipse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import aQute.bnd.annotation.plugin.BndPlugin;
import aQute.bnd.build.Project;
import aQute.bnd.build.Workspace;
import aQute.bnd.service.lifecycle.LifeCyclePlugin;
import aQute.lib.io.IO;
/**
* This plugin creates a build.xml file in the project when a project gets
* created. You can either store a template under cnf/ant/project.xml or a
* default is taken.
*/
@BndPlugin(name = "eclipse")
public class EclipsePlugin extends LifeCyclePlugin {
@Override
public void created(Project p) throws IOException {
Workspace workspace = p.getWorkspace();
copy("project", ".project", p);
copy("classpath", ".classpath", p);
}
private void copy(String source, String dest, Project p) throws IOException {
File d = p.getFile(dest);
if (d.isFile()) {
return;
}
File f = p.getWorkspace().getFile("eclipse/" + source + ".tmpl");
InputStream in;
if (f.isFile()) {
in = new FileInputStream(f);
} else {
in = EclipsePlugin.class.getResourceAsStream(source);
if (in == null) {
p.error("Cannot find Eclipse default for %s", source);
return;
}
}
String s = IO.collect(in);
String process = p.getReplacer().process(s);
d.getParentFile().mkdirs();
IO.store(process, d);
}
@Override
public String toString() {
return "EclipsePlugin";
}
@Override
public void init(Workspace ws) throws Exception {
Project p = new Project(ws, ws.getFile("cnf"));
created(p);
for (Project pp : ws.getAllProjects()) {
created(pp);
}
}
}