Search in sources :

Example 16 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class IndexedReposWithComms method testJpmRepoQuery.

public void testJpmRepoQuery() throws Exception {
    try (HttpTestServer ht = http()) {
        createSecureSocks5();
        Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/jpm"));
        assertNotNull(ws);
        ws.setProperty("repo", ht.getBaseURI().toASCIIString());
        ws.setProperty("tmp", tmp.toURI().getPath());
        ws.setProperty("-fixupmessages.jpmdeprecated", "aQute.bnd.jpm.Repository is deprecated");
        Repository plugin = ws.getPlugin(Repository.class);
        assertTrue(ws.check());
        assertNotNull(plugin);
        Set<ResourceDescriptor> query = plugin.query("bla");
        assertTrue(ws.check());
        assertTrue(query.size() > 0);
    }
}
Also used : Repository(aQute.bnd.jpm.Repository) HttpTestServer(aQute.http.testservers.HttpTestServer) Workspace(aQute.bnd.build.Workspace) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 17 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class IndexedReposWithComms method testJpmRepoDownload.

public void testJpmRepoDownload() throws Exception {
    try (HttpTestServer ht = http()) {
        createSecureSocks5();
        Workspace ws = Workspace.getWorkspace(aQute.lib.io.IO.getFile("workspaces/jpm"));
        assertNotNull(ws);
        ws.setProperty("repo", ht.getBaseURI().toASCIIString());
        ws.setProperty("tmp", tmp.toURI().getPath());
        Repository plugin = ws.getPlugin(Repository.class);
        ResourceDescriptor descriptor = plugin.getDescriptor("slf4j.simple", new Version("1.7.13"));
        assertNotNull(descriptor);
        File file = plugin.get("slf4j.simple", new Version("1.7.13"), null);
        assertTrue(file.isFile());
        byte[] digest = SHA256.digest(file).digest();
        assertTrue(Arrays.equals(descriptor.sha256, digest));
    }
}
Also used : Repository(aQute.bnd.jpm.Repository) Version(aQute.bnd.version.Version) HttpTestServer(aQute.http.testservers.HttpTestServer) File(java.io.File) Workspace(aQute.bnd.build.Workspace) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 18 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class ProjectBuilder method doBaseline.

/**
	 * Compare this builder's JAR with a baseline
	 * 
	 * @throws Exception
	 */
@Override
public void doBaseline(Jar dot) throws Exception {
    String diffignore = project.getProperty(Constants.DIFFIGNORE);
    logger.debug("ignore headers & paths {}", diffignore);
    differ.setIgnore(diffignore);
    Instructions diffpackages = new Instructions(new Parameters(project.getProperty(Constants.DIFFPACKAGES), this));
    logger.debug("diffpackages {}", diffpackages);
    try (Jar fromRepo = getBaselineJar()) {
        if (fromRepo == null) {
            logger.debug("No baseline jar {}", getProperty(Constants.BASELINE));
            return;
        }
        Version newer = new Version(getVersion());
        Version older = new Version(fromRepo.getVersion());
        if (!getBsn().equals(fromRepo.getBsn())) {
            error("The symbolic name of this project (%s) is not the same as the baseline: %s", getBsn(), fromRepo.getBsn());
            return;
        }
        if (newer.getWithoutQualifier().equals(older.getWithoutQualifier())) {
            RepositoryPlugin rr = getBaselineRepo();
            if (rr instanceof InfoRepository) {
                ResourceDescriptor descriptor = ((InfoRepository) rr).getDescriptor(getBsn(), older);
                if (descriptor != null && descriptor.phase != Phase.STAGING) {
                    error("Baselining %s against same version %s but the repository says the older repository version is not the required %s but is instead %s", getBsn(), getVersion(), Phase.STAGING, descriptor.phase);
                    return;
                }
            }
        }
        logger.debug("baseline {}-{} against: {}", getBsn(), getVersion(), fromRepo.getName());
        Baseline baseliner = new Baseline(this, differ);
        Set<Info> infos = baseliner.baseline(dot, fromRepo, diffpackages);
        if (infos.isEmpty())
            logger.debug("no deltas");
        StringBuffer sb = new StringBuffer();
        try (Formatter f = new Formatter(sb, Locale.US)) {
            for (Info info : infos) {
                if (!info.mismatch) {
                    continue;
                }
                sb.setLength(0);
                Diff packageDiff = info.packageDiff;
                f.format("Baseline mismatch for package %s, %s change. Current is %s, repo is %s, suggest %s or %s%n%#S", packageDiff.getName(), packageDiff.getDelta(), info.newerVersion, ((info.olderVersion != null) && info.olderVersion.equals(Version.LOWEST)) ? '-' : info.olderVersion, ((info.suggestedVersion != null) && info.suggestedVersion.compareTo(info.newerVersion) <= 0) ? "ok" : info.suggestedVersion, (info.suggestedIfProviders == null) ? "-" : info.suggestedIfProviders, packageDiff);
                SetLocation l = error("%s", f.toString());
                l.header(Constants.BASELINE);
                fillInLocationForPackageInfo(l.location(), packageDiff.getName());
                if (getPropertiesFile() != null)
                    l.file(getPropertiesFile().getAbsolutePath());
                l.details(info);
            }
            BundleInfo binfo = baseliner.getBundleInfo();
            if (binfo.mismatch) {
                sb.setLength(0);
                f.format("The bundle version (%s/%s) is too low, must be at least %s%n%#S", binfo.olderVersion, binfo.newerVersion, binfo.suggestedVersion, baseliner.getDiff());
                SetLocation error = error("%s", f.toString());
                error.context("Baselining");
                error.header(Constants.BUNDLE_VERSION);
                error.details(binfo);
                FileLine fl = getHeader(Pattern.compile("^" + Constants.BUNDLE_VERSION, Pattern.MULTILINE));
                if (fl != null) {
                    error.file(fl.file.getAbsolutePath());
                    error.line(fl.line);
                    error.length(fl.length);
                }
            }
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) Diff(aQute.bnd.service.diff.Diff) Formatter(java.util.Formatter) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) Instructions(aQute.bnd.osgi.Instructions) Baseline(aQute.bnd.differ.Baseline) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info) InfoRepository(aQute.bnd.service.repository.InfoRepository) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Example 19 with ResourceDescriptor

use of aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor in project bnd by bndtools.

the class Workspace method addExtensions.

/**
	 * Add any extensions listed
	 * 
	 * @param list
	 */
@Override
protected void addExtensions(Set<Object> list) {
    //
    // <bsn>; version=<range>
    //
    Parameters extensions = getMergedParameters(EXTENSION);
    Map<DownloadBlocker, Attrs> blockers = new HashMap<DownloadBlocker, Attrs>();
    for (Entry<String, Attrs> i : extensions.entrySet()) {
        String bsn = removeDuplicateMarker(i.getKey());
        String stringRange = i.getValue().get(VERSION_ATTRIBUTE);
        logger.debug("Adding extension {}-{}", bsn, stringRange);
        if (stringRange == null)
            stringRange = Version.LOWEST.toString();
        else if (!VersionRange.isVersionRange(stringRange)) {
            error("Invalid version range %s on extension %s", stringRange, bsn);
            continue;
        }
        try {
            SortedSet<ResourceDescriptor> matches = resourceRepositoryImpl.find(null, bsn, new VersionRange(stringRange));
            if (matches.isEmpty()) {
                error("Extension %s;version=%s not found in base repo", bsn, stringRange);
                continue;
            }
            DownloadBlocker blocker = new DownloadBlocker(this);
            blockers.put(blocker, i.getValue());
            resourceRepositoryImpl.getResource(matches.last().id, blocker);
        } catch (Exception e) {
            error("Failed to load extension %s-%s, %s", bsn, stringRange, e);
        }
    }
    logger.debug("Found extensions {}", blockers);
    for (Entry<DownloadBlocker, Attrs> blocker : blockers.entrySet()) {
        try {
            String reason = blocker.getKey().getReason();
            if (reason != null) {
                error("Extension load failed: %s", reason);
                continue;
            }
            @SuppressWarnings("resource") URLClassLoader cl = new URLClassLoader(new URL[] { blocker.getKey().getFile().toURI().toURL() }, getClass().getClassLoader());
            Enumeration<URL> manifests = cl.getResources("META-INF/MANIFEST.MF");
            while (manifests.hasMoreElements()) {
                try (InputStream is = manifests.nextElement().openStream()) {
                    Manifest m = new Manifest(is);
                    Parameters activators = new Parameters(m.getMainAttributes().getValue("Extension-Activator"), this);
                    for (Entry<String, Attrs> e : activators.entrySet()) {
                        try {
                            Class<?> c = cl.loadClass(e.getKey());
                            ExtensionActivator extensionActivator = (ExtensionActivator) c.getConstructor().newInstance();
                            customize(extensionActivator, blocker.getValue());
                            List<?> plugins = extensionActivator.activate(this, blocker.getValue());
                            list.add(extensionActivator);
                            if (plugins != null)
                                for (Object plugin : plugins) {
                                    list.add(plugin);
                                }
                        } catch (ClassNotFoundException cnfe) {
                            error("Loading extension %s, extension activator missing: %s (ignored)", blocker, e.getKey());
                        }
                    }
                }
            }
        } catch (Exception e) {
            error("failed to install extension %s due to %s", blocker, e);
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) Attrs(aQute.bnd.header.Attrs) VersionRange(aQute.bnd.version.VersionRange) Manifest(java.util.jar.Manifest) IOException(java.io.IOException) TimeLimitExceededException(javax.naming.TimeLimitExceededException) URL(java.net.URL) ExtensionActivator(aQute.bnd.service.extension.ExtensionActivator) URLClassLoader(java.net.URLClassLoader) ResourceDescriptor(aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)

Aggregations

ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)19 File (java.io.File)10 Version (aQute.bnd.version.Version)7 IOException (java.io.IOException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Workspace (aQute.bnd.build.Workspace)3 Parameters (aQute.bnd.header.Parameters)3 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)3 DownloadListener (aQute.bnd.service.RepositoryPlugin.DownloadListener)3 InfoRepository (aQute.bnd.service.repository.InfoRepository)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 DownloadBlocker (aQute.bnd.build.DownloadBlocker)2 Attrs (aQute.bnd.header.Attrs)2 Repository (aQute.bnd.jpm.Repository)2 Jar (aQute.bnd.osgi.Jar)2 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)2 Listener (aQute.bnd.service.repository.ResourceRepository.Listener)2 ResourceRepositoryEvent (aQute.bnd.service.repository.ResourceRepository.ResourceRepositoryEvent)2