use of aQute.bnd.build.Container in project intellij-plugins by JetBrains.
the class BndProjectImporter method addEntry.
private void addEntry(ModifiableModuleModel moduleModel, LibraryTable.ModifiableModel libraryModel, ModifiableRootModel rootModel, Container dependency, DependencyScope scope) throws IllegalArgumentException {
File file = dependency.getFile();
String bsn = dependency.getBundleSymbolicName();
String version = dependency.getVersion();
String path = file.getPath();
if (path.contains(": ")) {
throw new IllegalArgumentException("Cannot resolve " + bsn + ":" + version + ": " + path);
}
if (JDK_DEPENDENCY.equals(bsn)) {
String name = BND_LIB_PREFIX + bsn + ":" + version;
if (FileUtil.isAncestor(myWorkspace.getBase(), file, true)) {
name += "-" + myProject.getName();
}
ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
Sdk jdk = jdkTable.findJdk(name);
if (jdk == null) {
jdk = jdkTable.createSdk(name, JavaSdk.getInstance());
SdkModificator jdkModel = jdk.getSdkModificator();
jdkModel.setHomePath(file.getParent());
jdkModel.setVersionString(version);
VirtualFile root = VirtualFileManager.getInstance().findFileByUrl(url(file));
assert root != null : file + " " + file.exists();
jdkModel.addRoot(root, OrderRootType.CLASSES);
VirtualFile srcRoot = VirtualFileManager.getInstance().findFileByUrl(url(file) + SRC_ROOT);
if (srcRoot != null)
jdkModel.addRoot(srcRoot, OrderRootType.SOURCES);
jdkModel.commitChanges();
jdkTable.addJdk(jdk);
}
rootModel.setSdk(jdk);
return;
}
ExportableOrderEntry entry;
switch(dependency.getType()) {
case PROJECT:
{
String name = dependency.getProject().getName();
Module module = moduleModel.findModuleByName(name);
if (module == null) {
throw new IllegalArgumentException("Unknown module '" + name + "'");
}
entry = (ModuleOrderEntry) ContainerUtil.find(rootModel.getOrderEntries(), e -> e instanceof ModuleOrderEntry && ((ModuleOrderEntry) e).getModule() == module);
if (entry == null) {
entry = rootModel.addModuleOrderEntry(module);
}
break;
}
case REPO:
{
String name = BND_LIB_PREFIX + bsn + ":" + version;
Library library = libraryModel.getLibraryByName(name);
if (library == null) {
library = libraryModel.createLibrary(name);
}
Library.ModifiableModel model = library.getModifiableModel();
for (String url : model.getUrls(OrderRootType.CLASSES)) model.removeRoot(url, OrderRootType.CLASSES);
for (String url : model.getUrls(OrderRootType.SOURCES)) model.removeRoot(url, OrderRootType.SOURCES);
model.addRoot(url(file), OrderRootType.CLASSES);
String srcRoot = mySourcesMap.get(path);
if (srcRoot != null) {
model.addRoot(url(file) + srcRoot, OrderRootType.SOURCES);
}
model.commit();
entry = rootModel.addLibraryEntry(library);
break;
}
case EXTERNAL:
{
Library library = rootModel.getModuleLibraryTable().createLibrary(file.getName());
Library.ModifiableModel model = library.getModifiableModel();
model.addRoot(url(file), OrderRootType.CLASSES);
String srcRoot = mySourcesMap.get(path);
if (srcRoot != null) {
model.addRoot(url(file) + srcRoot, OrderRootType.SOURCES);
}
model.commit();
entry = rootModel.findLibraryOrderEntry(library);
assert entry != null : library;
break;
}
default:
throw new IllegalArgumentException("Unknown dependency '" + dependency + "' of type " + dependency.getType());
}
entry.setScope(scope);
}
use of aQute.bnd.build.Container in project bnd by bndtools.
the class ResolveCommand method _find.
public void _find(FindOptions options, bnd bnd) throws Exception {
List<String> args = options._arguments();
for (String bndrun : args) {
Project p = bnd.getProject(options.project());
Workspace workspace = p == null ? bnd.getWorkspace(options.workspace()) : p.getWorkspace();
Run run = new Run(workspace, p != null ? p.getBase() : IO.work, IO.getFile(bndrun));
ProjectResolver pr = new ProjectResolver(run);
addClose(pr);
pr.resolve();
bnd.out.println("Resolved " + run);
for (Container c : pr.getRunBundles()) {
bnd.out.printf("%-30s %-20s %-6s %s\n", c.getBundleSymbolicName(), c.getVersion(), c.getType(), c.getFile());
}
}
}
use of aQute.bnd.build.Container in project bnd by bndtools.
the class SubsystemExporter method export.
@Override
public Map.Entry<String, Resource> export(String type, final Project project, Map<String, String> options) throws Exception {
Jar jar = new Jar(".");
project.addClose(jar);
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
manifest.getMainAttributes().putValue("Subsystem-ManifestVersion", "1");
List<Container> distro = project.getBundles(Strategy.LOWEST, project.getProperty(Constants.DISTRO), Constants.DISTRO);
List<File> distroFiles = getBundles(distro, project);
List<File> files = getBundles(project.getRunbundles(), project);
MultiMap<String, Attrs> imports = new MultiMap<String, Attrs>();
MultiMap<String, Attrs> exports = new MultiMap<String, Attrs>();
Parameters requirements = new Parameters();
Parameters capabilities = new Parameters();
for (File file : files) {
Domain domain = Domain.domain(file);
String bsn = domain.getBundleSymbolicName().getKey();
String version = domain.getBundleVersion();
for (Entry<String, Attrs> e : domain.getImportPackage().entrySet()) {
imports.add(e.getKey(), e.getValue());
}
for (Entry<String, Attrs> e : domain.getExportPackage().entrySet()) {
exports.add(e.getKey(), e.getValue());
}
String path = bsn + "-" + version + ".jar";
jar.putResource(path, new FileResource(file));
}
headers(project, manifest.getMainAttributes());
set(manifest.getMainAttributes(), SUBSYSTEM_TYPE, OSGI_SUBSYSTEM_FEATURE);
String ssn = project.getName();
Collection<String> bsns = project.getBsns();
if (bsns.size() > 0) {
ssn = bsns.iterator().next();
}
set(manifest.getMainAttributes(), SUBSYSTEM_SYMBOLIC_NAME, ssn);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
manifest.write(bout);
jar.putResource(OSGI_INF_SUBSYSTEM_MF, new EmbeddedResource(bout.toByteArray(), 0));
final JarResource jarResource = new JarResource(jar);
final String name = ssn + ".esa";
return new Map.Entry<String, Resource>() {
@Override
public String getKey() {
return name;
}
@Override
public Resource getValue() {
return jarResource;
}
@Override
public Resource setValue(Resource arg0) {
throw new UnsupportedOperationException();
}
};
}
use of aQute.bnd.build.Container in project bnd by bndtools.
the class LauncherTest method testJUnitLessTester.
/**
* Try out the new tester that does not contain JUnit
*/
public static void testJUnitLessTester() throws Exception {
Project project = getProject();
List<Container> bundles = project.getBundles(Strategy.HIGHEST, "biz.aQute.tester", "TESTER");
assertNotNull(bundles);
assertEquals(1, bundles.size());
project.setProperty(Constants.TESTPATH, "");
project.setProperty(Constants.TESTER, "biz.aQute.tester");
project.clear();
project.build();
assertTrue(project.check());
ProjectTester pt = project.getProjectTester();
pt.addTest("test.TestCase1");
pt.addTest("test.TestCase2:m1");
assertEquals(2, pt.test());
}
use of aQute.bnd.build.Container in project bnd by bndtools.
the class ProjectTest method testRunbundleDuplicates.
/**
* Duplicates in runbundles gave a bad error, should be ignored
*/
public void testRunbundleDuplicates() throws Exception {
Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
Project top = ws.getProject("p1");
top.setPedantic(true);
top.clear();
top.setProperty("-runbundles", "org.apache.felix.configadmin,org.apache.felix.configadmin");
Collection<Container> runbundles = top.getRunbundles();
assertTrue(top.check("Multiple bundles with the same final URL", "Duplicate name"));
assertNotNull(runbundles);
assertEquals(1, runbundles.size());
}
Aggregations