Search in sources :

Example 6 with Info

use of aQute.bnd.differ.Baseline.Info in project bndtools by bndtools.

the class ReleaseHelper method updateProject.

public static void updateProject(ReleaseContext context) throws Exception {
    try (ProjectBuilder pb = context.getProject().getBuilder(null)) {
        for (Builder builder : pb.getSubBuilders()) {
            Baseline current = getBaselineForBuilder(builder, context);
            if (current == null) {
                continue;
            }
            for (Info info : current.getPackageInfos()) {
                context.getProject().setPackageInfo(info.packageName, info.suggestedVersion);
            }
            updateBundleVersion(context, current, builder);
        }
    }
}
Also used : ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info)

Example 7 with Info

use of aQute.bnd.differ.Baseline.Info in project bndtools by bndtools.

the class BaselineErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new LinkedList<MarkerData>();
    Info baselineInfo = (Info) location.details;
    IJavaProject javaProject = JavaCore.create(project);
    result.addAll(generatePackageInfoMarkers(baselineInfo, javaProject, location.message));
    result.addAll(generateStructuralChangeMarkers(baselineInfo, javaProject));
    return result;
}
Also used : MarkerData(org.bndtools.build.api.MarkerData) IJavaProject(org.eclipse.jdt.core.IJavaProject) Info(aQute.bnd.differ.Baseline.Info) LinkedList(java.util.LinkedList)

Example 8 with Info

use of aQute.bnd.differ.Baseline.Info in project bnd by bndtools.

the class BaselineMojo method checkFailures.

private boolean checkFailures(Artifact artifact, ArtifactResult artifactResult, Baseline baseline) throws Exception, IOException {
    StringBuffer sb = new StringBuffer();
    try (Formatter f = new Formatter(sb, Locale.US);
        Jar newer = new Jar(artifact.getFile());
        Jar older = new Jar(artifactResult.getArtifact().getFile())) {
        boolean failed = false;
        for (Info info : baseline.baseline(newer, older, null)) {
            if (info.mismatch) {
                failed = true;
                if (logger.isErrorEnabled()) {
                    sb.setLength(0);
                    f.format("Baseline mismatch for package %s, %s change. Current is %s, repo is %s, suggest %s or %s", info.packageName, info.packageDiff.getDelta(), info.newerVersion, info.olderVersion, info.suggestedVersion, info.suggestedIfProviders == null ? "-" : info.suggestedIfProviders);
                    if (fullReport) {
                        f.format("%n%#S", info.packageDiff);
                    }
                    logger.error(f.toString());
                }
            }
        }
        BundleInfo binfo = baseline.getBundleInfo();
        if (binfo.mismatch) {
            failed = true;
            if (logger.isErrorEnabled()) {
                sb.setLength(0);
                f.format("The bundle version change (%s to %s) is too low, the new version must be at least %s", binfo.olderVersion, binfo.newerVersion, binfo.suggestedVersion);
                if (fullReport) {
                    f.format("%n%#S", baseline.getDiff());
                }
                logger.error(f.toString());
            }
        }
        return failed;
    }
}
Also used : BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Formatter(java.util.Formatter) Jar(aQute.bnd.osgi.Jar) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info)

Example 9 with Info

use of aQute.bnd.differ.Baseline.Info in project bnd by bndtools.

the class BaselineCommands method _schema.

/**
	 * Create a schema of a set of jars outling the packages and their versions.
	 * This will create a list of packages with multiple versions, link to their
	 * specifications, and the deltas between versions.
	 * 
	 * <pre>
	 *  bnd package schema
	 * <file.jar>*
	 * </pre>
	 * 
	 * @param opts
	 * @throws Exception
	 */
public void _schema(schemaOptions opts) throws Exception {
    MultiMap<String, PSpec> map = new MultiMap<String, PSpec>();
    Tag top = new Tag("jschema");
    int n = 1000;
    for (String spec : opts._arguments()) {
        File f = bnd.getFile(spec);
        if (!f.isFile()) {
            bnd.messages.NoSuchFile_(f);
        } else {
            // For each specification jar we found
            logger.debug("spec {}", f);
            // spec
            Jar jar = new Jar(f);
            Manifest m = jar.getManifest();
            Attributes main = m.getMainAttributes();
            Tag specTag = new Tag(top, "specification");
            specTag.addAttribute("jar", spec);
            specTag.addAttribute("name", main.getValue("Specification-Name"));
            specTag.addAttribute("title", main.getValue("Specification-Title"));
            specTag.addAttribute("jsr", main.getValue("Specification-JSR"));
            specTag.addAttribute("url", main.getValue("Specification-URL"));
            specTag.addAttribute("version", main.getValue("Specification-Version"));
            specTag.addAttribute("vendor", main.getValue("Specification-Vendor"));
            specTag.addAttribute("id", n);
            specTag.addContent(main.getValue(Constants.BUNDLE_DESCRIPTION));
            Parameters exports = OSGiHeader.parseHeader(m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE));
            // Create a map with versions. Ensure import ranges overwrite
            // the
            // exported versions
            Parameters versions = new Parameters();
            versions.putAll(exports);
            versions.putAll(OSGiHeader.parseHeader(m.getMainAttributes().getValue(Constants.IMPORT_PACKAGE)));
            Analyzer analyzer = new Analyzer();
            analyzer.setJar(jar);
            analyzer.analyze();
            Tree tree = differ.tree(analyzer);
            for (Entry<String, Attrs> entry : exports.entrySet()) {
                // For each exported package in the specification JAR
                Attrs attrs = entry.getValue();
                String packageName = entry.getKey();
                PackageRef packageRef = analyzer.getPackageRef(packageName);
                String version = attrs.get(Constants.VERSION_ATTRIBUTE);
                PSpec pspec = new PSpec();
                pspec.packageName = packageName;
                pspec.version = new Version(version);
                pspec.id = n;
                pspec.attrs = attrs;
                pspec.tree = tree;
                Collection<PackageRef> uses = analyzer.getUses().get(packageRef);
                if (uses != null) {
                    for (PackageRef x : uses) {
                        if (x.isJava())
                            continue;
                        String imp = x.getFQN();
                        if (imp.equals(packageName))
                            continue;
                        String v = null;
                        if (versions.containsKey(imp))
                            v = versions.get(imp).get(Constants.VERSION_ATTRIBUTE);
                        pspec.uses.put(imp, v);
                    }
                }
                map.add(packageName, pspec);
            }
            jar.close();
            n++;
        }
    }
    // We now gather all the information about all packages in the map.
    // Next phase is generating the XML. Sorting the packages is
    // important because XSLT is brain dead.
    SortedList<String> names = new SortedList<String>(map.keySet());
    Tag packagesTag = new Tag(top, "packages");
    Tag baselineTag = new Tag(top, "baseline");
    for (String pname : names) {
        // For each distinct package name
        SortedList<PSpec> specs = new SortedList<PSpec>(map.get(pname));
        PSpec older = null;
        Parameters olderExport = null;
        for (PSpec newer : specs) {
            // For each package in the total set
            Tag pack = new Tag(packagesTag, "package");
            pack.addAttribute("name", newer.packageName);
            pack.addAttribute("version", newer.version);
            pack.addAttribute("spec", newer.id);
            Parameters newerExport = new Parameters();
            newerExport.put(pname, newer.attrs);
            if (older != null) {
                String compareId = newer.packageName + "-" + newer.id + "-" + older.id;
                pack.addAttribute("delta", compareId);
                logger.debug(" newer={} older={}", newerExport, olderExport);
                Set<Info> infos = baseline.baseline(newer.tree, newerExport, older.tree, olderExport, new Instructions(pname));
                for (Info info : infos) {
                    Tag tag = getTag(info);
                    tag.addAttribute("id", compareId);
                    tag.addAttribute("newerSpec", newer.id);
                    tag.addAttribute("olderSpec", older.id);
                    baselineTag.addContent(tag);
                }
                older.tree = null;
                older.attrs = null;
                older = newer;
            }
            for (Entry<String, String> uses : newer.uses.entrySet()) {
                Tag reference = new Tag(pack, "import");
                reference.addAttribute("name", uses.getKey());
                reference.addAttribute("version", uses.getValue());
            }
            older = newer;
            olderExport = newerExport;
        }
    }
    String o = opts.output("schema.xml");
    File of = bnd.getFile(o);
    File pof = of.getParentFile();
    IO.mkdirs(pof);
    try (PrintWriter pw = IO.writer(of, UTF_8)) {
        pw.print("<?xml version='1.0' encoding='UTF-8'?>\n");
        top.print(0, pw);
    }
    if (opts.xsl() != null) {
        URL home = bnd.getBase().toURI().toURL();
        URL xslt = new URL(home, opts.xsl());
        String path = of.getAbsolutePath();
        if (path.endsWith(".xml"))
            path = path.substring(0, path.length() - 4);
        path = path + ".html";
        File html = new File(path);
        logger.debug("xslt {} {} {} {}", xslt, of, html, html.exists());
        try (OutputStream out = IO.outputStream(html);
            InputStream in = xslt.openStream()) {
            Transformer transformer = transformerFactory.newTransformer(new StreamSource(in));
            transformer.transform(new StreamSource(of), new StreamResult(out));
        }
    }
}
Also used : Transformer(javax.xml.transform.Transformer) OutputStream(java.io.OutputStream) Attributes(java.util.jar.Attributes) Attrs(aQute.bnd.header.Attrs) SortedList(aQute.lib.collections.SortedList) Analyzer(aQute.bnd.osgi.Analyzer) URL(java.net.URL) MultiMap(aQute.lib.collections.MultiMap) Version(aQute.bnd.version.Version) Tree(aQute.bnd.service.diff.Tree) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) PrintWriter(java.io.PrintWriter) Parameters(aQute.bnd.header.Parameters) StreamResult(javax.xml.transform.stream.StreamResult) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Instructions(aQute.bnd.osgi.Instructions) Manifest(java.util.jar.Manifest) Info(aQute.bnd.differ.Baseline.Info) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Jar(aQute.bnd.osgi.Jar) Tag(aQute.lib.tag.Tag) File(java.io.File)

Example 10 with Info

use of aQute.bnd.differ.Baseline.Info in project bnd by bndtools.

the class BaselineTest method testCutOffInheritance.

// This tests the scenario where a super type is injected into the class
// hierarchy but the super class comes from outside the bundle so that the
// baseline cannot find it. Since the class hierarchy was cut off, the
// baseline would _forget_ that every class inherits from Object, and _lose_
// Object's methods if not directly implemented.
public void testCutOffInheritance() throws Exception {
    Processor processor = new Processor();
    DiffPluginImpl differ = new DiffPluginImpl();
    Baseline baseline = new Baseline(processor, differ);
    try (Jar older = new Jar(IO.getFile("jar/baseline/inheritance-change-1.0.0.jar"));
        Jar newer = new Jar(IO.getFile("jar/baseline/inheritance-change-1.1.0.jar"))) {
        baseline.baseline(newer, older, null);
        BundleInfo bundleInfo = baseline.getBundleInfo();
        assertFalse(bundleInfo.mismatch);
        assertEquals("1.1.0", bundleInfo.suggestedVersion.toString());
        Set<Info> packageInfos = baseline.getPackageInfos();
        assertEquals(1, packageInfos.size());
        Info change = packageInfos.iterator().next();
        assertFalse(change.mismatch);
        assertEquals("example", change.packageName);
        assertEquals("1.1.0", change.suggestedVersion.toString());
        Diff packageDiff = change.packageDiff;
        Collection<? extends Diff> children = packageDiff.getChildren();
        assertEquals(5, children.size());
        Iterator<? extends Diff> iterator = children.iterator();
        Diff diff = iterator.next();
        assertEquals(Delta.MICRO, diff.getDelta());
        diff = iterator.next();
        assertEquals(Delta.MICRO, diff.getDelta());
        diff = iterator.next();
        assertEquals(Delta.MINOR, diff.getDelta());
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Processor(aQute.bnd.osgi.Processor) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Diff(aQute.bnd.service.diff.Diff) Jar(aQute.bnd.osgi.Jar) Baseline(aQute.bnd.differ.Baseline) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info)

Aggregations

Info (aQute.bnd.differ.Baseline.Info)22 Baseline (aQute.bnd.differ.Baseline)16 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)13 Jar (aQute.bnd.osgi.Jar)13 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)10 Processor (aQute.bnd.osgi.Processor)8 Builder (aQute.bnd.osgi.Builder)5 ProjectBuilder (aQute.bnd.build.ProjectBuilder)4 Diff (aQute.bnd.service.diff.Diff)4 Version (aQute.bnd.version.Version)4 Instructions (aQute.bnd.osgi.Instructions)3 MultiMap (aQute.lib.collections.MultiMap)3 Parameters (aQute.bnd.header.Parameters)2 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)2 File (java.io.File)2 Formatter (java.util.Formatter)2 Map (java.util.Map)2 Manifest (java.util.jar.Manifest)2 Attrs (aQute.bnd.header.Attrs)1 Analyzer (aQute.bnd.osgi.Analyzer)1