Search in sources :

Example 1 with RepositoryPlugin

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

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

the class bnd method _release.

/**
	 * Release the project
	 * 
	 * @throws Exception
	 */
@Description("Release this project")
public void _release(releaseOptions options) throws Exception {
    Set<Project> projects = new LinkedHashSet<Project>();
    Workspace ws = Workspace.findWorkspace(getBase());
    if (ws == null) {
        error("Workspace option was specified but cannot find a workspace from %s", getBase());
        return;
    }
    if (options.workspace()) {
        projects.addAll(ws.getAllProjects());
    }
    Project project = getProject(options.project());
    if (project != null) {
        projects.add(project);
    }
    if (projects.isEmpty()) {
        error("Cannot find any projects");
        return;
    }
    String repo = options.repo();
    if (repo != null) {
        RepositoryPlugin repository = ws.getRepository(repo);
        if (repository == null) {
            error("No such release repo %s%nFound:%n%s", repository, Strings.join("\n", ws.getRepositories()));
        }
    }
    for (Project p : projects) {
        if (repo != null) {
            p.setProperty(Constants.RELEASEREPO, repo);
        }
        p.release(options.test());
    }
    getInfo(project);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Project(aQute.bnd.build.Project) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Workspace(aQute.bnd.build.Workspace) Description(aQute.lib.getopt.Description)

Example 3 with RepositoryPlugin

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

the class bnd method _bsn2url.

public void _bsn2url(Bsn2UrlOptions opts) throws Exception {
    Project p = getProject(opts.project());
    if (p == null) {
        error("You need to be in a project or specify the project with -p/--project");
        return;
    }
    MultiMap<String, Version> revisions = new MultiMap<String, Version>();
    for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
        if (!(repo instanceof InfoRepository))
            continue;
        for (String bsn : repo.list(null)) {
            revisions.addAll(bsn, repo.versions(bsn));
        }
    }
    for (List<Version> versions : revisions.values()) {
        Collections.sort(versions, Collections.reverseOrder());
    }
    List<String> files = opts._arguments();
    for (String f : files) {
        try (BufferedReader r = IO.reader(getFile(f))) {
            String line;
            nextLine: while ((line = r.readLine()) != null) {
                Matcher matcher = LINE_P.matcher(line);
                if (!matcher.matches())
                    continue nextLine;
                line = matcher.group(1);
                Parameters bundles = new Parameters(line, this);
                for (Map.Entry<String, Attrs> entry : bundles.entrySet()) {
                    String bsn = entry.getKey();
                    VersionRange range = new VersionRange(entry.getValue().getVersion());
                    List<Version> versions = revisions.get(bsn);
                    if (versions == null) {
                        error("No for versions for %s", bsn);
                        break nextLine;
                    }
                    for (Version version : versions) {
                        if (range.includes(version)) {
                            for (RepositoryPlugin repo : p.getPlugins(RepositoryPlugin.class)) {
                                if (!(repo instanceof InfoRepository))
                                    continue;
                                InfoRepository rp = (InfoRepository) repo;
                                ResourceDescriptor descriptor = rp.getDescriptor(bsn, version);
                                if (descriptor == null) {
                                    error("Found bundle, but no descriptor %s;version=%s", bsn, version);
                                    return;
                                }
                                out.println(descriptor.url + " #" + descriptor.bsn + ";version=" + descriptor.version);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            error("failed to create url list from file %s : %s", f, e);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Matcher(java.util.regex.Matcher) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) VersionRange(aQute.bnd.version.VersionRange) InfoRepository(aQute.bnd.service.repository.InfoRepository) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) Project(aQute.bnd.build.Project) MultiMap(aQute.lib.collections.MultiMap) Entry(java.util.Map.Entry) Version(aQute.bnd.version.Version) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ExtList(aQute.lib.collections.ExtList) List(java.util.List) SortedList(aQute.lib.collections.SortedList) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 4 with RepositoryPlugin

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

the class Workspace method _repodigests.

/**
	 * Return the repository signature digests. These digests are a unique id
	 * for the contents of the repository
	 */
public Object _repodigests(String[] args) throws Exception {
    Macro.verifyCommand(args, "${repodigests;[;<repo names>]...}, get the repository digests", null, 1, 10000);
    List<RepositoryPlugin> repos = getRepositories();
    if (args.length > 1) {
        repos: for (Iterator<RepositoryPlugin> it = repos.iterator(); it.hasNext(); ) {
            String name = it.next().getName();
            for (int i = 1; i < args.length; i++) {
                if (name.equals(args[i])) {
                    continue repos;
                }
            }
            it.remove();
        }
    }
    List<String> digests = new ArrayList<String>();
    for (RepositoryPlugin repo : repos) {
        try {
            if (repo instanceof RepositoryDigest) {
                byte[] digest = ((RepositoryDigest) repo).getDigest();
                digests.add(Hex.toHexString(digest));
            } else {
                if (args.length != 1)
                    error("Specified repo %s for ${repodigests} was named but it is not found", repo.getName());
            }
        } catch (Exception e) {
            if (args.length != 1)
                error("Specified repo %s for digests is not found", repo.getName());
        // else Ignore
        }
    }
    return join(digests, ",");
}
Also used : RepositoryDigest(aQute.bnd.service.repository.RepositoryDigest) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException)

Example 5 with RepositoryPlugin

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

the class AetherRepsitoryTests method testSourceLookup.

public void testSourceLookup() throws Exception {
    RepositoryPlugin repo = createRepo();
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("version", "2.5");
    attrs.put("bsn", "javax.servlet:servlet-api");
    File file = repo.get("servlet-api.source", new Version(2, 5, 0), attrs, listener);
    assertTrue(file.exists());
    assertEquals("servlet-api-2.5-sources.jar", file.getName());
}
Also used : HashMap(java.util.HashMap) Version(aQute.bnd.version.Version) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File)

Aggregations

RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)67 Version (aQute.bnd.version.Version)26 File (java.io.File)26 Workspace (aQute.bnd.build.Workspace)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 Project (aQute.bnd.build.Project)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 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IStatus (org.eclipse.core.runtime.IStatus)5 Parameters (aQute.bnd.header.Parameters)4 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 Status (org.eclipse.core.runtime.Status)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4