Search in sources :

Example 1 with RepositoryListenerPlugin

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

the class OSGiRepositoryTest method testPolling.

public void testPolling(Workspace workspace) throws Exception {
    try (OSGiRepository r = new OSGiRepository()) {
        Map<String, String> map = new HashMap<>();
        map.put("locations", fnx.getBaseURI("/repo/minir5.xml").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);
        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);
        // not stale, default name
        assertNull(r.title(new Object[0]));
        System.out.println("1");
        Thread.sleep(3000);
        System.out.println("2");
        assertEquals(null, refreshed.get());
        System.out.println("3");
        // update the index file
        File index = IO.getFile(remote, "minir5.xml");
        long time = index.lastModified();
        String s = IO.collect(index);
        // change the sha
        s += " ";
        IO.store(s, index);
        System.out.println("5 " + index + " " + (index.lastModified() - time));
        // give the poller a chance
        Thread.sleep(3000);
        System.out.println("6");
        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 2 with RepositoryListenerPlugin

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

the class WorkspaceRepositoryChangeDetector method resourceChanged.

@Override
public void resourceChanged(IResourceChangeEvent event) {
    try {
        if (refresh.get())
            return;
        if (event.getType() == IResourceChangeEvent.POST_CHANGE) {
            RootFolderVisitor rootFolderVisitor = new RootFolderVisitor();
            event.getDelta().accept(rootFolderVisitor);
            if (refresh.getAndSet(false)) {
                WorkspaceJob job = new WorkspaceJob("Refresh Workspace Repository") {

                    @Override
                    public IStatus runInWorkspace(IProgressMonitor monitor) {
                        if (monitor == null)
                            monitor = new NullProgressMonitor();
                        List<RepositoryListenerPlugin> plugins = workspace.getPlugins(RepositoryListenerPlugin.class);
                        monitor.beginTask("Refresh ", plugins.size());
                        int n = 0;
                        for (RepositoryListenerPlugin rlp : plugins) try {
                            monitor.worked(n++);
                            rlp.repositoryRefreshed(repository);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        monitor.done();
                        return Status.OK_STATUS;
                    }
                };
                job.schedule(500);
            }
        }
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryListenerPlugin(aQute.bnd.service.RepositoryListenerPlugin) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with RepositoryListenerPlugin

use of aQute.bnd.service.RepositoryListenerPlugin 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)

Aggregations

RepositoryListenerPlugin (aQute.bnd.service.RepositoryListenerPlugin)3 HttpClient (aQute.bnd.http.HttpClient)2 Jar (aQute.bnd.osgi.Jar)2 Processor (aQute.bnd.osgi.Processor)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 Version (aQute.bnd.version.Version)2 File (java.io.File)2 HashMap (java.util.HashMap)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IOException (java.io.IOException)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1