Search in sources :

Example 16 with Container

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) OsmorcFacetType(org.osmorc.facet.OsmorcFacetType) CompilerConfiguration(com.intellij.compiler.CompilerConfiguration) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) FacetUtil(com.intellij.facet.impl.FacetUtil) Refreshable(aQute.bnd.service.Refreshable) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) Library(com.intellij.openapi.roots.libraries.Library) Task(com.intellij.openapi.progress.Task) OsmorcFacet(org.osmorc.facet.OsmorcFacet) ZipFile(java.util.zip.ZipFile) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ZipEntry(java.util.zip.ZipEntry) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) JpsJavaCompilerOptions(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions) LanguageLevel(com.intellij.pom.java.LanguageLevel) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) ModifiableModelCommitter(com.intellij.openapi.roots.impl.ModifiableModelCommitter) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) OutputPathType(org.jetbrains.osgi.jps.model.OutputPathType) NotificationType(com.intellij.notification.NotificationType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) NotificationDisplayType(com.intellij.notification.NotificationDisplayType) java.util(java.util) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) ModuleManager(com.intellij.openapi.module.ModuleManager) ContainerUtil(com.intellij.util.containers.ContainerUtil) Container(aQute.bnd.build.Container) com.intellij.openapi.roots(com.intellij.openapi.roots) Workspace(aQute.bnd.build.Workspace) NotificationGroup(com.intellij.notification.NotificationGroup) ManifestGenerationMode(org.jetbrains.osgi.jps.model.ManifestGenerationMode) OsmorcBundle.message(org.osmorc.i18n.OsmorcBundle.message) Project(aQute.bnd.build.Project) StringUtil(com.intellij.openapi.util.text.StringUtil) JavacConfiguration(com.intellij.compiler.impl.javaCompiler.javac.JavacConfiguration) Key(com.intellij.openapi.util.Key) IOException(java.io.IOException) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) Attrs(aQute.bnd.header.Attrs) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) VfsUtil(com.intellij.openapi.vfs.VfsUtil) ObjectUtils(com.intellij.util.ObjectUtils) PathUtil(com.intellij.util.PathUtil) ModuleFileType(com.intellij.ide.highlighter.ModuleFileType) Condition(com.intellij.openapi.util.Condition) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 17 with Container

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());
        }
    }
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) ProjectResolver(biz.aQute.resolve.ProjectResolver) Run(aQute.bnd.build.Run) Workspace(aQute.bnd.build.Workspace)

Example 18 with Container

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();
        }
    };
}
Also used : Parameters(aQute.bnd.header.Parameters) JarResource(aQute.bnd.osgi.JarResource) Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) JarResource(aQute.bnd.osgi.JarResource) FileResource(aQute.bnd.osgi.FileResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) MultiMap(aQute.lib.collections.MultiMap) Container(aQute.bnd.build.Container) Entry(java.util.Map.Entry) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 19 with Container

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());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) ProjectTester(aQute.bnd.build.ProjectTester)

Example 20 with Container

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());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Workspace(aQute.bnd.build.Workspace)

Aggregations

Container (aQute.bnd.build.Container)28 Project (aQute.bnd.build.Project)19 Workspace (aQute.bnd.build.Workspace)16 ArrayList (java.util.ArrayList)14 File (java.io.File)8 Attrs (aQute.bnd.header.Attrs)5 Jar (aQute.bnd.osgi.Jar)5 Manifest (java.util.jar.Manifest)5 Run (aQute.bnd.build.Run)3 Domain (aQute.bnd.osgi.Domain)3 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)3 FileResource (aQute.bnd.osgi.FileResource)3 Parameters (aQute.bnd.header.Parameters)2 Builder (aQute.bnd.osgi.Builder)2 JarResource (aQute.bnd.osgi.JarResource)2 Resource (aQute.bnd.osgi.Resource)2 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)2 Version (aQute.bnd.version.Version)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 List (java.util.List)2