Search in sources :

Example 11 with DiffPluginImpl

use of aQute.bnd.differ.DiffPluginImpl in project bnd by bndtools.

the class DiffTest method testAPIStaticSuperClassChange.

public void testAPIStaticSuperClassChange() throws Exception {
    Jar older = new Jar(IO.getFile("../demo/generated/demo.jar"));
    Builder b = new Builder();
    b.addClasspath(IO.getFile("bin"));
    b.setExportPackage("test.api");
    b.build();
    assertTrue(b.check());
    Jar newer = b.getJar();
    Processor processor = new Processor();
    DiffPluginImpl differ = new DiffPluginImpl();
    Baseline baseline = new Baseline(processor, differ);
    Info info = baseline.baseline(newer, older, null).iterator().next();
    Diff field = info.packageDiff.get("test.api.B");
    show(field, 2);
    assertEquals(Delta.UNCHANGED, field.getDelta());
    b.close();
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Processor(aQute.bnd.osgi.Processor) Diff(aQute.bnd.service.diff.Diff) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Baseline(aQute.bnd.differ.Baseline) Info(aQute.bnd.differ.Baseline.Info)

Example 12 with DiffPluginImpl

use of aQute.bnd.differ.DiffPluginImpl in project bnd by bndtools.

the class BaselineMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        logger.debug("skip project as configured");
        return;
    }
    Artifact artifact = RepositoryUtils.toArtifact(project.getArtifact());
    List<RemoteRepository> aetherRepos = getRepositories(artifact);
    setupBase(artifact);
    try {
        if (base.getVersion() == null || base.getVersion().isEmpty()) {
            searchForBaseVersion(artifact, aetherRepos);
        }
        if (base.getVersion() != null && !base.getVersion().isEmpty()) {
            ArtifactResult artifactResult = locateBaseJar(aetherRepos);
            Reporter reporter;
            if (fullReport) {
                reporter = new ReporterAdapter(System.out);
                ((ReporterAdapter) reporter).setTrace(true);
            } else {
                reporter = new ReporterAdapter();
            }
            Baseline baseline = new Baseline(reporter, new DiffPluginImpl());
            if (checkFailures(artifact, artifactResult, baseline)) {
                if (continueOnError) {
                    logger.warn("The baselining check failed when checking {} against {} but the bnd-baseline-maven-plugin is configured not to fail the build.", artifact, artifactResult.getArtifact());
                } else {
                    throw new MojoExecutionException("The baselining plugin detected versioning errors");
                }
            } else {
                logger.info("Baselining check succeeded checking {} against {}", artifact, artifactResult.getArtifact());
            }
        } else {
            if (failOnMissing) {
                throw new MojoExecutionException("Unable to locate a previous version of the artifact");
            } else {
                logger.warn("No previous version of {} could be found to baseline against", artifact);
            }
        }
    } catch (RepositoryException re) {
        throw new MojoExecutionException("Unable to locate a previous version of the artifact", re);
    } catch (Exception e) {
        throw new MojoExecutionException("An error occurred while calculating the baseline", e);
    }
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReporterAdapter(aQute.libg.reporter.ReporterAdapter) Reporter(aQute.service.reporter.Reporter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) Baseline(aQute.bnd.differ.Baseline) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 13 with DiffPluginImpl

use of aQute.bnd.differ.DiffPluginImpl in project bnd by bndtools.

the class DiffCommand method diff.

public void diff(diffOptions options) throws Exception {
    DiffPluginImpl di = new DiffPluginImpl();
    List<String> args = options._arguments();
    if (args.size() == 0) {
        Project project = bnd.getProject();
        if (project != null) {
            for (Builder b : project.getSubBuilders()) {
                ProjectBuilder pb = (ProjectBuilder) b;
                // make sure remains before
                Jar older = pb.getBaselineJar();
                // disabling baselining
                // do not do
                pb.setProperty(Constants.BASELINE, "");
                // baselining in
                // build
                Jar newer = pb.build();
                di.setIgnore(pb.getProperty(Constants.DIFFIGNORE));
                diff(options, di, newer, older);
                bnd.getInfo(b);
            }
            bnd.getInfo(project);
            return;
        }
    } else if (options._arguments().size() == 1) {
        logger.debug("Show tree");
        showTree(bnd, options);
        return;
    }
    if (options._arguments().size() != 2) {
        throw new IllegalArgumentException("Requires 2 jar files input");
    }
    Jar newer = bnd.getJar(args.get(0));
    Jar older = bnd.getJar(args.get(1));
    diff(options, di, newer, older);
}
Also used : DiffPluginImpl(aQute.bnd.differ.DiffPluginImpl) Project(aQute.bnd.build.Project) ProjectBuilder(aQute.bnd.build.ProjectBuilder) ProjectBuilder(aQute.bnd.build.ProjectBuilder) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar)

Example 14 with DiffPluginImpl

use of aQute.bnd.differ.DiffPluginImpl 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 15 with DiffPluginImpl

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

Aggregations

DiffPluginImpl (aQute.bnd.differ.DiffPluginImpl)21 Jar (aQute.bnd.osgi.Jar)20 Baseline (aQute.bnd.differ.Baseline)15 BundleInfo (aQute.bnd.differ.Baseline.BundleInfo)12 Processor (aQute.bnd.osgi.Processor)11 Info (aQute.bnd.differ.Baseline.Info)9 ProjectBuilder (aQute.bnd.build.ProjectBuilder)5 Builder (aQute.bnd.osgi.Builder)5 Tree (aQute.bnd.service.diff.Tree)5 Diff (aQute.bnd.service.diff.Diff)4 ReporterAdapter (aQute.libg.reporter.ReporterAdapter)2 File (java.io.File)2 Project (aQute.bnd.build.Project)1 Instructions (aQute.bnd.osgi.Instructions)1 Differ (aQute.bnd.service.diff.Differ)1 Version (aQute.bnd.version.Version)1 Reporter (aQute.service.reporter.Reporter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1