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();
}
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);
}
}
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);
}
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());
}
}
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);
}
}
}
Aggregations