Search in sources :

Example 46 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bndtools by bndtools.

the class OSGiFrameworkContentProvider method inputChanged.

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    frameworks.clear();
    Workspace workspace = (Workspace) newInput;
    IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor(Plugin.PLUGIN_ID, "osgiFrameworks");
    for (IConfigurationElement element : configElements) {
        String frameworkName = element.getAttribute("name");
        String bsn = element.getAttribute("bsn");
        URL iconUrl = null;
        String iconPath = element.getAttribute("icon");
        if (iconPath != null) {
            Bundle contributorBundle = BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), element.getContributor().getName(), null);
            if (contributorBundle != null)
                iconUrl = contributorBundle.getEntry(iconPath);
        }
        List<RepositoryPlugin> repositories;
        try {
            repositories = (workspace != null) ? workspace.getRepositories() : Collections.<RepositoryPlugin>emptyList();
        } catch (Exception e) {
            throw Exceptions.duck(e);
        }
        for (RepositoryPlugin repo : repositories) {
            try {
                SortedSet<Version> versions = repo.versions(bsn);
                if (versions != null)
                    for (Version version : versions) {
                        try {
                            File framework = repo.get(bsn, version, null);
                            if (framework != null)
                                frameworks.add(new OSGiFramework(frameworkName, bsn, version, iconUrl));
                        } catch (Exception e) {
                            logger.logError(String.format("Error finding repository entry for OSGi framework %s, version %s.", bsn, version.toString()), e);
                        }
                    }
            } catch (Exception e) {
                logger.logError(String.format("Error searching repository for OSGi framework %s.", bsn), e);
            }
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) Version(aQute.bnd.version.Version) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 47 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class OSGiRepositoryTest method testPollingWithFile.

public void testPollingWithFile() throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", IO.getFile(remote, "minir5.xml").toURI().toString());
        map.put("cache", cache.getPath());
        map.put("max.stale", "10000");
        map.put("name", "test");
        map.put("poll.time", "1");
        r.setProperties(map);
        Processor p = new Processor();
        HttpClient httpClient = new HttpClient();
        httpClient.setCache(cache);
        httpClient.setRegistry(p);
        p.addBasicPlugin(httpClient);
        p.setBase(ws);
        p.addBasicPlugin(Workspace.createStandaloneWorkspace(p, ws.toURI()));
        r.setRegistry(p);
        final AtomicReference<RepositoryPlugin> refreshed = new AtomicReference<>();
        p.addBasicPlugin(new RepositoryListenerPlugin() {

            @Override
            public void repositoryRefreshed(RepositoryPlugin repository) {
                refreshed.set(repository);
            }

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

            @Override
            public void bundleRemoved(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }

            @Override
            public void bundleAdded(RepositoryPlugin repository, Jar jar, File file) {
            // TODO Auto-generated method stub
            }
        });
        File file = r.get("dummybundle", new Version("0"), null);
        assertNotNull(file);
        Thread.sleep(3000);
        assertEquals(null, refreshed.get());
        System.out.println("1");
        // update the index file
        File index = IO.getFile(remote, "minir5.xml");
        long time = index.lastModified();
        do {
            Thread.sleep(1000);
            String s = IO.collect(index);
            // change the sha
            s += " ";
            IO.store(s, index);
            System.out.println(index.lastModified());
        } while (index.lastModified() == time);
        System.out.println("2 ");
        // give the poller a chance
        Thread.sleep(3000);
        System.out.println("3 ");
        assertEquals(r, refreshed.get());
        assertEquals("test [stale]", r.title(new Object[0]));
        System.out.println(r.tooltip(new Object[0]));
    }
}
Also used : Processor(aQute.bnd.osgi.Processor) RepositoryListenerPlugin(aQute.bnd.service.RepositoryListenerPlugin) HashMap(java.util.HashMap) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) AtomicReference(java.util.concurrent.atomic.AtomicReference) Version(aQute.bnd.version.Version) HttpClient(aQute.bnd.http.HttpClient) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 48 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class ExportMojo method export.

private void export(File runFile, FileSetRepository fileSetRepository) throws Exception {
    if (!runFile.exists()) {
        logger.error("Could not find bnd run file {}", runFile);
        errors++;
        return;
    }
    String bndrun = getNamePart(runFile);
    File temporaryDir = new File(targetDir, "tmp/export/" + bndrun);
    File cnf = new File(temporaryDir, Workspace.CNFDIR);
    IO.mkdirs(cnf);
    try (Bndrun run = Bndrun.createBndrun(null, runFile)) {
        run.setBase(temporaryDir);
        Workspace workspace = run.getWorkspace();
        workspace.setBuildDir(cnf);
        workspace.setOffline(session.getSettings().isOffline());
        workspace.addBasicPlugin(fileSetRepository);
        for (RepositoryPlugin repo : workspace.getRepositories()) {
            repo.list(null);
        }
        run.getInfo(workspace);
        report(run);
        if (!run.isOk()) {
            return;
        }
        if (resolve) {
            try {
                String runBundles = run.resolve(failOnChanges, false);
                if (!run.isOk()) {
                    return;
                }
                run.setProperty(Constants.RUNBUNDLES, runBundles);
            } catch (ResolutionException re) {
                logger.error("Unresolved requirements: {}", ResolveProcess.format(re.getUnresolvedRequirements()));
                throw re;
            } finally {
                report(run);
            }
        }
        try {
            if (bundlesOnly) {
                File runbundlesDir = new File(targetDir, "export/" + bndrun);
                IO.mkdirs(runbundlesDir);
                run.exportRunbundles(null, runbundlesDir);
            } else {
                File executableJar = new File(targetDir, bndrun + ".jar");
                run.export(null, false, executableJar);
            }
        } finally {
            report(run);
        }
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File) Bndrun(biz.aQute.resolve.Bndrun) Workspace(aQute.bnd.build.Workspace)

Example 49 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bnd by bndtools.

the class ResolverMojo method resolve.

private void resolve(File runFile, FileSetRepository fileSetRepository) throws Exception {
    if (!runFile.exists()) {
        logger.error("Could not find bnd run file {}", runFile);
        errors++;
        return;
    }
    String bndrun = getNamePart(runFile);
    File temporaryDir = new File(targetDir, "tmp/resolve/" + bndrun);
    File cnf = new File(temporaryDir, Workspace.CNFDIR);
    IO.mkdirs(cnf);
    try (Bndrun run = Bndrun.createBndrun(null, runFile)) {
        run.setBase(temporaryDir);
        Workspace workspace = run.getWorkspace();
        workspace.setBuildDir(cnf);
        workspace.setOffline(session.getSettings().isOffline());
        workspace.addBasicPlugin(fileSetRepository);
        for (RepositoryPlugin repo : workspace.getRepositories()) {
            repo.list(null);
        }
        run.getInfo(workspace);
        report(run);
        if (!run.isOk()) {
            return;
        }
        try {
            run.resolve(failOnChanges, true);
        } catch (ResolutionException re) {
            logger.error("Unresolved requirements: {}", ResolveProcess.format(re.getUnresolvedRequirements()));
            throw re;
        } finally {
            report(run);
        }
    }
}
Also used : ResolutionException(org.osgi.service.resolver.ResolutionException) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File) Bndrun(biz.aQute.resolve.Bndrun) Workspace(aQute.bnd.build.Workspace)

Example 50 with RepositoryPlugin

use of aQute.bnd.service.RepositoryPlugin in project bndtools by bndtools.

the class AddFilesToRepositoryWizard method addPages.

@Override
public void addPages() {
    if (repository == null) {
        addPage(repoSelectionPage);
        repoSelectionPage.addPropertyChangeListener(LocalRepositorySelectionPage.PROP_SELECTED_REPO, new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                repository = (RepositoryPlugin) evt.getNewValue();
            }
        });
    }
    addPage(fileSelectionPage);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin)

Aggregations

RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)62 Version (aQute.bnd.version.Version)25 File (java.io.File)24 Workspace (aQute.bnd.build.Workspace)12 IOException (java.io.IOException)10 Project (aQute.bnd.build.Project)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 Jar (aQute.bnd.osgi.Jar)7 CoreException (org.eclipse.core.runtime.CoreException)7 RemoteRepositoryPlugin (aQute.bnd.service.RemoteRepositoryPlugin)5 VersionRange (aQute.bnd.version.VersionRange)5 Description (aQute.lib.getopt.Description)5 Parameters (aQute.bnd.header.Parameters)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 PartInitException (org.eclipse.ui.PartInitException)4 Attrs (aQute.bnd.header.Attrs)3