Search in sources :

Example 6 with BundleInfo

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

the class BundleVersionErrorHandler method generateMarkerData.

@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
    List<MarkerData> result = new LinkedList<MarkerData>();
    IFile bndFile = null;
    LineLocation loc = null;
    BundleInfo info = (BundleInfo) location.details;
    try (ProjectBuilder pb = model.getBuilder(null)) {
        for (Builder builder : pb.getSubBuilders()) {
            if (builder.getBsn().equals(info.bsn)) {
                File propsFile = builder.getPropertiesFile();
                // Try to find in the sub-bundle file
                if (propsFile != null) {
                    bndFile = project.getWorkspace().getRoot().getFileForLocation(new Path(propsFile.getAbsolutePath()));
                    if (bndFile != null) {
                        loc = findBundleVersionHeader(bndFile);
                    }
                }
                if (loc == null) {
                    // Not found in sub-bundle file, try bnd.bnd
                    bndFile = project.getFile(Project.BNDFILE);
                    loc = findBundleVersionHeader(bndFile);
                }
                if (loc == null) {
                    // Not found in bnd.bnd, try build.bnd. Marker will appear on bnd.bnd
                    IFile buildFile = Central.getWorkspaceBuildFile();
                    loc = findBundleVersionHeader(buildFile);
                    if (loc != null) {
                        loc = new LineLocation();
                        loc.lineNum = 1;
                        loc.start = 1;
                        loc.end = 1;
                    }
                }
                if (loc == null) {
                    // Not found in build.bnd, try included files. Marker will appear on bnd.bnd
                    List<File> extensions = Central.getWorkspace().getIncluded();
                    if (extensions != null) {
                        for (File extension : extensions) {
                            loc = findBundleVersionHeader(Central.toResource(extension));
                            if (loc != null) {
                                loc = new LineLocation();
                                loc.lineNum = 1;
                                loc.start = 1;
                                loc.end = 1;
                                break;
                            }
                        }
                    }
                }
                if (loc != null) {
                    Map<String, Object> attribs = new HashMap<String, Object>();
                    attribs.put(IMarker.MESSAGE, location.message);
                    attribs.put(IMarker.LINE_NUMBER, loc.lineNum);
                    attribs.put(IMarker.CHAR_START, loc.start);
                    attribs.put(IMarker.CHAR_END, loc.end);
                    String qualifier = null;
                    String currentVersion = builder.getUnprocessedProperty(Constants.BUNDLE_VERSION, "");
                    if (currentVersion != null) {
                        Matcher m = VERSION_ACCEPTING_MACRO.matcher(currentVersion);
                        if (m.matches()) {
                            qualifier = m.group(4);
                        }
                    }
                    attribs.put(PROP_SUGGESTED_VERSION, info.suggestedVersion.toString() + (qualifier != null ? '.' + qualifier : ""));
                    result.add(new MarkerData(bndFile, attribs, true, BndtoolsConstants.MARKER_JAVA_BASELINE));
                }
            }
        }
    }
    return result;
}
Also used : Path(org.eclipse.core.runtime.Path) MarkerData(org.bndtools.build.api.MarkerData) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) LinkedList(java.util.LinkedList) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) ProjectBuilder(aQute.bnd.build.ProjectBuilder) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 7 with BundleInfo

use of aQute.bnd.differ.Baseline.BundleInfo 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 8 with BundleInfo

use of aQute.bnd.differ.Baseline.BundleInfo 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)

Example 9 with BundleInfo

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

the class BaselineTest method testIgnoreResourceDiff.

/**
	 * Check if we can ignore resources in the baseline. First build two jars
	 * that are identical except for the b/b resource. Then do baseline on them.
	 */
public void testIgnoreResourceDiff() throws Exception {
    Processor processor = new Processor();
    DiffPluginImpl differ = new DiffPluginImpl();
    differ.setIgnore("b/b");
    Baseline baseline = new Baseline(processor, differ);
    try (Builder a = new Builder();
        Builder b = new Builder()) {
        a.setProperty("-includeresource", "a/a;literal='aa',b/b;literal='bb'");
        a.setProperty("-resourceonly", "true");
        b.setProperty("-includeresource", "a/a;literal='aa',b/b;literal='bbb'");
        b.setProperty("-resourceonly", "true");
        try (Jar aj = a.build();
            Jar bj = b.build()) {
            Set<Info> infoSet = baseline.baseline(aj, bj, null);
            BundleInfo binfo = baseline.getBundleInfo();
            assertFalse(binfo.mismatch);
        }
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Processor(aQute.bnd.osgi.Processor) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Baseline(aQute.bnd.differ.Baseline) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Info(aQute.bnd.differ.Baseline.Info)

Example 10 with BundleInfo

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

the class BaselineTest method testMinorChange.

// Adding a method to an exported class produces a MINOR bump (1.0.0 -> 1.1.0)
public void testMinorChange() throws Exception {
    Processor processor = new Processor();
    DiffPluginImpl differ = new DiffPluginImpl();
    Baseline baseline = new Baseline(processor, differ);
    try (Jar older = new Jar(IO.getFile("testresources/minor-and-removed-change-1.0.0.jar"));
        Jar newer = new Jar(IO.getFile("testresources/minor-change-1.0.1.jar"))) {
        baseline.baseline(newer, older, null);
        BundleInfo bundleInfo = baseline.getBundleInfo();
        assertTrue(bundleInfo.mismatch);
        assertEquals("1.1.0", bundleInfo.suggestedVersion.toString());
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Processor(aQute.bnd.osgi.Processor) BundleInfo(aQute.bnd.differ.Baseline.BundleInfo) Jar(aQute.bnd.osgi.Jar) Baseline(aQute.bnd.differ.Baseline)

Aggregations

BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)12 Jar (aQute.bnd.osgi.Jar)10 Baseline (aQute.bnd.differ.Baseline)9 DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)8 Processor (aQute.bnd.osgi.Processor)8 Info (aQute.bnd.differ.Baseline.Info)7 ProjectBuilder (aQute.bnd.build.ProjectBuilder)2 Builder (aQute.bnd.osgi.Builder)2 Diff (aQute.bnd.service.diff.Diff)2 Formatter (java.util.Formatter)2 Parameters (aQute.bnd.header.Parameters)1 Instructions (aQute.bnd.osgi.Instructions)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 InfoRepository (aQute.bnd.service.repository.InfoRepository)1 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)1 Version (aQute.bnd.version.Version)1 MultiMap (aQute.lib.collections.MultiMap)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1