Search in sources :

Example 11 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class BndrunResolveContext method loadPath.

/**
	 * Add a path to the system resource. This is done by the bnd launcher for
	 * -runpath and it is also used for -distro.
	 */
public void loadPath(ResourceBuilder system, String path, String what) throws Exception {
    if (project != null) {
        List<Container> containers = Container.flatten(project.getBundles(Strategy.HIGHEST, path, what));
        for (Container c : containers) {
            Manifest manifest = c.getManifest();
            if (manifest != null) {
                ResourceBuilder rb = new ResourceBuilder();
                rb.addManifest(Domain.domain(manifest));
                addSystemResource(system, rb.build());
            }
        }
    } else {
        super.loadPath(system, path, what);
    }
}
Also used : Container(aQute.bnd.build.Container) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Manifest(java.util.jar.Manifest)

Example 12 with Container

use of aQute.bnd.build.Container in project bndtools by bndtools.

the class BndDependencySourceContainer method createSourceContainers.

@Override
protected ISourceContainer[] createSourceContainers() throws CoreException {
    List<ISourceContainer> result = new LinkedList<ISourceContainer>();
    ILaunchConfiguration config = getLaunchConfiguration();
    Set<String> projectsAdded = new HashSet<>();
    try {
        if (lastRun != null) {
            LaunchUtils.endRun(lastRun);
        }
        Run run = LaunchUtils.createRun(config);
        if (run != null) {
            Collection<Container> runbundles = run.getRunbundles();
            for (Container runbundle : runbundles) {
                if (runbundle.getType() == TYPE.PROJECT) {
                    String targetProjName = runbundle.getProject().getName();
                    if (projectsAdded.add(targetProjName)) {
                        IProject targetProj = ResourcesPlugin.getWorkspace().getRoot().getProject(targetProjName);
                        if (targetProj != null) {
                            IJavaProject targetJavaProj = JavaCore.create(targetProj);
                            result.add(new JavaProjectSourceContainer(targetJavaProj));
                        }
                    }
                } else if (runbundle.getType() == TYPE.REPO) {
                    IPath bundlePath = Central.toPath(runbundle.getFile());
                    IFile bundleFile = null;
                    if (bundlePath != null) {
                        bundleFile = ResourcesPlugin.getWorkspace().getRoot().getFile(bundlePath);
                    }
                    if (bundleFile != null) {
                        ISourceContainer sourceContainer = null;
                        // check to see if this archive came from a repo that encodes the source project name
                        final String sourceProjectName = runbundle.getAttributes().get("sourceProjectName");
                        if (sourceProjectName != null) {
                            try {
                                IProject sourceProject = ResourcesPlugin.getWorkspace().getRoot().getProject(sourceProjectName);
                                if (sourceProject.exists()) {
                                    IJavaProject javaSourceProject = JavaCore.create(sourceProject);
                                    sourceContainer = new JavaProjectSourceContainer(javaSourceProject);
                                }
                            } catch (Exception e) {
                                logger.logError("Error getting source java project", e);
                            }
                        }
                        if (sourceContainer == null) {
                            // default to archive source container
                            sourceContainer = new ArchiveSourceContainer(bundleFile, false);
                        }
                        result.add(sourceContainer);
                    } else {
                        ExternalArchiveSourceContainer container = new ExternalArchiveSourceContainer(runbundle.getFile().toString(), false);
                        result.add(container);
                    }
                }
            }
            lastRun = run;
        }
    } catch (Exception e) {
        logger.logError("Error querying Bnd dependency source containers.", e);
    }
    return result.toArray(new ISourceContainer[0]);
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Run(aQute.bnd.build.Run) JavaProjectSourceContainer(org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer) LinkedList(java.util.LinkedList) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer) Container(aQute.bnd.build.Container) JavaProjectSourceContainer(org.eclipse.jdt.launching.sourcelookup.containers.JavaProjectSourceContainer) CompositeSourceContainer(org.eclipse.debug.core.sourcelookup.containers.CompositeSourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) IJavaProject(org.eclipse.jdt.core.IJavaProject) ArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ArchiveSourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) ISourceContainer(org.eclipse.debug.core.sourcelookup.ISourceContainer) ExternalArchiveSourceContainer(org.eclipse.debug.core.sourcelookup.containers.ExternalArchiveSourceContainer) HashSet(java.util.HashSet)

Example 13 with Container

use of aQute.bnd.build.Container in project bndtools by bndtools.

the class BndContainerPage method createControl.

/*
     * (non-Javadoc)
     * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets .Composite)
     */
@Override
public void createControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NULL);
    composite.setLayout(new FormLayout());
    composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL));
    composite.setFont(parent.getFont());
    setControl(composite);
    final Button wCreate = new Button(composite, SWT.NONE);
    wCreate.setEnabled(model == null);
    final FormData fd_wCreate = new FormData();
    fd_wCreate.bottom = new FormAttachment(100, -5);
    fd_wCreate.right = new FormAttachment(100, -4);
    wCreate.setLayoutData(fd_wCreate);
    wCreate.setText("Create bnd.bnd");
    final TableViewer tableViewer = new TableViewer(composite, SWT.BORDER);
    table = tableViewer.getTable();
    final FormData fd_table = new FormData();
    fd_table.top = new FormAttachment(0, 3);
    fd_table.left = new FormAttachment(0, 3);
    fd_table.right = new FormAttachment(100, -4);
    fd_table.bottom = new FormAttachment(100, -37);
    table.setLayoutData(fd_table);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    final TableColumn wBsn = new TableColumn(table, SWT.NONE);
    wBsn.setWidth(200);
    wBsn.setText("Bundle Symbolic Name");
    final TableColumn wVersion = new TableColumn(table, SWT.NONE);
    wVersion.setWidth(100);
    wVersion.setText("Version");
    final TableColumn wOptions = new TableColumn(table, SWT.NONE);
    wOptions.setWidth(200);
    wOptions.setText("Options");
    final TableColumn wFile = new TableColumn(table, SWT.NONE);
    wFile.setWidth(100);
    wFile.setText("File");
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public Object[] getElements(Object inputElement) {
            if (model != null)
                try {
                    return model.getBuildpath().toArray();
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            return new Object[0];
        }

        @Override
        public void dispose() {
        // TODO Auto-generated method stub
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            Container c = (Container) element;
            switch(columnIndex) {
                case 0:
                    return c.getBundleSymbolicName();
                case 1:
                    return c.getVersion();
                case 2:
                    return c.getError();
                case 3:
                    return c.getFile() + " (" + (c.getFile() != null && c.getFile().exists() ? "exists" : "?") + ")";
                default:
                    break;
            }
            return null;
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        // TODO Auto-generated method stub
        }

        @Override
        public void dispose() {
        // TODO Auto-generated method stub
        }

        @Override
        public boolean isLabelProperty(Object element, String property) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public void removeListener(ILabelProviderListener listener) {
        // TODO Auto-generated method stub
        }
    });
    tableViewer.setInput(model);
    wCreate.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            System.out.println("defw selected");
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            wCreate.setEnabled(!createBnd());
            tableViewer.setInput(model);
        }
    });
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Image(org.eclipse.swt.graphics.Image) TableColumn(org.eclipse.swt.widgets.TableColumn) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Container(aQute.bnd.build.Container) Button(org.eclipse.swt.widgets.Button) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class ContainerTest method testBundleClasspath.

public void testBundleClasspath() throws Exception {
    try (Builder b = new Builder()) {
        b.addClasspath(new File("bin"));
        b.setBundleClasspath(".,osgi.jar");
        b.setIncludeResource("jar/osgi.jar");
        b.setExportPackage("test.annotation");
        b.setProperty("Hello", "World");
        b.build();
        assertTrue(b.check());
        File testjar = IO.getFile(tmp, "test.jar");
        b.getJar().write(testjar);
        Attrs attrs = new Attrs();
        attrs.put("expand-bcp", "true");
        Container c = new Container(testjar, null, attrs);
        List<File> files = new ArrayList<>();
        c.contributeFiles(files, b);
        assertEquals(2, files.size());
        assertEquals(files.get(0).getCanonicalFile(), testjar.getCanonicalFile());
    }
}
Also used : Container(aQute.bnd.build.Container) Builder(aQute.bnd.osgi.Builder) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) File(java.io.File)

Example 15 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class ProjectTest method testWildcardBuildPathWithRepoFilter.

public void testWildcardBuildPathWithRepoFilter() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project project = ws.getProject("repofilter");
    assertNotNull(project);
    project.setProperty("-buildpath", "*; repo=Relea*");
    ArrayList<Container> buildpath = new ArrayList<Container>(project.getBuildpath());
    assertEquals(2, buildpath.size());
    assertEquals(Container.TYPE.REPO, buildpath.get(0).getType());
    assertEquals("org.apache.felix.configadmin", buildpath.get(0).getBundleSymbolicName());
    assertEquals(Container.TYPE.REPO, buildpath.get(1).getType());
    assertEquals("p3", buildpath.get(1).getBundleSymbolicName());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) ArrayList(java.util.ArrayList) 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