forked from bndtools/bnd
/
BaselineTest.java
721 lines (578 loc) · 22.4 KB
/
BaselineTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
package test.baseline;
import static aQute.bnd.osgi.Constants.BUNDLE_SYMBOLICNAME;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import aQute.bnd.build.Project;
import aQute.bnd.build.ProjectBuilder;
import aQute.bnd.build.Workspace;
import aQute.bnd.differ.Baseline;
import aQute.bnd.differ.Baseline.BundleInfo;
import aQute.bnd.differ.Baseline.Info;
import aQute.bnd.differ.DiffPluginImpl;
import aQute.bnd.osgi.Analyzer;
import aQute.bnd.osgi.Builder;
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Jar;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.Verifier;
import aQute.bnd.service.RepositoryPlugin;
import aQute.bnd.service.diff.Delta;
import aQute.bnd.service.diff.Diff;
import aQute.bnd.service.diff.Tree;
import aQute.bnd.test.jupiter.InjectTemporaryDirectory;
import aQute.bnd.version.Version;
import aQute.lib.collections.SortedList;
import aQute.lib.io.IO;
import aQute.libg.reporter.ReporterAdapter;
@SuppressWarnings("resource")
public class BaselineTest {
Workspace workspace;
private Workspace getWorkspace(File tmp) throws Exception {
if (workspace != null)
return workspace;
IO.copy(IO.getFile("testresources/ws"), tmp);
return workspace = new Workspace(tmp);
}
@AfterEach
protected void tearDown() throws Exception {
IO.close(workspace);
workspace = null;
}
/**
* Test 2 jars compiled with different compilers
*/
@Test
public void testCompilerEnumDifference() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar ecj = new Jar(IO.getFile("jar/baseline/com.example.baseline.ecj.jar"));
Jar javac = new Jar(IO.getFile("jar/baseline/com.example.baseline.javac.jar"));) {
Tree tecj = diff.tree(ecj);
Tree tjavac = diff.tree(javac);
Diff d = tecj.diff(tjavac);
assertEquals(Delta.UNCHANGED, d.getDelta());
}
}
/**
* Test skipping classes when there is source
*/
@Test
public void testClassesDiffWithSource() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar jar = new Jar(IO.getFile("jar/osgi.jar")); Jar out = new Jar(".");) {
out.putResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java",
jar.getResource("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
out.putResource("org/osgi/application/ApplicationContext.class",
jar.getResource("org/osgi/application/ApplicationContext.class"));
try (Analyzer a = new Analyzer(out)) {
a.addClasspath(out);
Tree tree = diff.tree(a);
Tree src = tree.get("<resources>")
.get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java")
.getChildren()[0];
assertNotNull(src);
assertNull(tree.get("<resources>")
.get("org/osgi/application/ApplicationContext.class"));
}
}
}
@Test
public void testClassesDiffWithoutSource() throws Exception {
DiffPluginImpl diff = new DiffPluginImpl();
try (Jar jar = new Jar(IO.getFile("jar/osgi.jar")); Jar out = new Jar(".");) {
for (String path : jar.getResources()
.keySet()) {
if (!path.startsWith("OSGI-OPT/src/"))
out.putResource(path, jar.getResource(path));
}
try (Analyzer a = new Analyzer(out)) {
a.addClasspath(out);
Tree tree = diff.tree(a);
assertNull(tree.get("<resources>")
.get("OSGI-OPT/src/org/osgi/application/ApplicationContext.java"));
assertNotNull(tree.get("<resources>")
.get("org/osgi/application/ApplicationContext.class"));
}
}
}
@Test
public void testJava8DefaultMethods() throws Exception {
try (Builder older = new Builder(); Builder newer = new Builder();) {
older.addClasspath(IO.getFile("java8/older/bin"));
older.setExportPackage("*;version=1.0");
newer.addClasspath(IO.getFile("java8/newer/bin"));
newer.setExportPackage("*;version=1.0");
try (Jar o = older.build(); Jar n = newer.build();) {
assertTrue(older.check());
assertTrue(newer.check());
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(older, differ);
Set<Info> infoSet = baseline.baseline(n, o, null);
assertEquals(1, infoSet.size());
for (Info info : infoSet) {
assertTrue(info.mismatch);
assertEquals(new Version(1, 1, 0), info.suggestedVersion);
assertEquals(info.packageName, "api_default_methods");
}
}
}
}
@Test
public void testNoMismatchForZeroMajor() throws Exception {
try (Builder older = new Builder(); Builder newer = new Builder();) {
older.addClasspath(IO.getFile("java8/older/bin"));
older.setExportPackage("*;version=0.1");
newer.addClasspath(IO.getFile("java8/newer/bin"));
newer.setExportPackage("*;version=0.1");
try (Jar o = older.build(); Jar n = newer.build();) {
assertTrue(older.check());
assertTrue(newer.check());
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(older, differ);
Set<Info> infoSet = baseline.baseline(n, o, null);
assertEquals(1, infoSet.size());
for (Info info : infoSet) {
assertFalse(info.mismatch);
assertEquals(new Version(0, 2, 0), info.suggestedVersion);
assertEquals(info.packageName, "api_default_methods");
}
}
}
}
/**
* 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.
*/
@Test
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);
}
}
}
/**
* When a JAR is build the manifest is not set in the resources but in a
* instance var.
*
* @throws Exception
*/
@Test
public void testPrematureJar() throws Exception {
File file = IO.getFile(new File(""), "jar/osgi.jar");
try (Builder b1 = new Builder(); Builder b2 = new Builder();) {
b1.addClasspath(file);
b1.setProperty(Constants.BUNDLE_VERSION, "1.0.0.${tstamp}");
b1.setExportPackage("org.osgi.service.event");
try (Jar j1 = b1.build();) {
assertTrue(b1.check());
File tmp = new File("tmp.jar");
j1.write(tmp);
try (Jar j11 = new Jar(tmp);) {
Thread.sleep(2000);
b2.addClasspath(file);
b2.setProperty(Constants.BUNDLE_VERSION, "1.0.0.${tstamp}");
b2.setExportPackage("org.osgi.service.event");
try (Jar j2 = b2.build();) {
assertTrue(b2.check());
DiffPluginImpl differ = new DiffPluginImpl();
ReporterAdapter ra = new ReporterAdapter();
Baseline baseline = new Baseline(ra, differ);
ra.setTrace(true);
ra.setPedantic(true);
Set<Info> infos = baseline.baseline(j2, j11, null);
print(baseline.getDiff(), " ");
assertEquals(Delta.UNCHANGED, baseline.getDiff()
.getDelta());
}
} finally {
tmp.delete();
}
}
}
}
static Pattern VERSION_HEADER_P = Pattern.compile("Bundle-Header:(" + Verifier.VERSION_STRING + ")",
Pattern.CASE_INSENSITIVE);
void print(Diff diff, String indent) {
if (diff.getDelta() == Delta.UNCHANGED)
return;
System.out.println(indent + " " + diff);
for (Diff sub : diff.getChildren()) {
print(sub, indent + " ");
}
}
/**
* In repo:
*
* <pre>
* p3-1.1.0.jar p3-1.2.0.jar
* </pre>
*
* @throws Exception
*/
@Test
public void testRepository(@InjectTemporaryDirectory
File tmp) throws Exception {
Jar v1_2_0_a = mock(Jar.class);
when(v1_2_0_a.getVersion()).thenReturn("1.2.0.b");
when(v1_2_0_a.getBsn()).thenReturn("p3");
RepositoryPlugin repo = mock(RepositoryPlugin.class);
when(repo.get(anyString(), any(Version.class), anyMap()))
.thenReturn(IO.getFile("testresources/ws/cnf/releaserepo/p3/p3-1.2.0.jar"));
System.out.printf("get %s%n", repo.get("p3", new Version("1.2.0.b"), new HashMap<>()));
when(repo.canWrite()).thenReturn(true);
when(repo.getName()).thenReturn("Baseline");
when(repo.versions("p3")).thenReturn(new SortedList<>(new Version("1.1.0.a"), new Version("1.1.0.b"),
new Version("1.2.0.a"), new Version("1.2.0.b")));
getWorkspace(tmp).addBasicPlugin(repo);
Project p3 = getWorkspace(tmp).getProject("p3");
p3.setBundleVersion("1.3.0");
ProjectBuilder builder = (ProjectBuilder) p3.getBuilder(null)
.getSubBuilder();
builder.setProperty(Constants.BASELINE, "*");
builder.setProperty(Constants.BASELINEREPO, "Baseline");
// Nothing specified
Jar jar = builder.getBaselineJar();
assertEquals("1.2.0", new Version(jar.getVersion()).getWithoutQualifier()
.toString());
if (!builder.check())
fail(builder.getErrors()
.toString());
{
// check for error when repository contains later versions
builder = (ProjectBuilder) p3.getBuilder(null)
.getSubBuilder();
builder.setBundleVersion("1.1.3");
builder.setTrace(true);
builder.setProperty(Constants.BASELINE, "*");
builder.setProperty(Constants.BASELINEREPO, "Baseline");
jar = builder.getBaselineJar();
assertNull(jar);
if (!builder.check("The baseline version 1.2.0.b is higher than the current version 1.1.3 for p3"))
fail(builder.getErrors()
.toString());
}
{
// check for no error when repository has the same version
builder = (ProjectBuilder) p3.getBuilder(null)
.getSubBuilder();
builder.setBundleVersion("1.2.0.b");
builder.setTrace(true);
builder.setProperty(Constants.BASELINE, "*");
builder.setProperty(Constants.BASELINEREPO, "Baseline");
jar = builder.getBaselineJar();
assertNotNull(jar);
if (!builder.check())
fail(builder.getErrors()
.toString());
}
{
// check for no error when repository has the same version
builder = (ProjectBuilder) p3.getBuilder(null)
.getSubBuilder();
builder.setBundleVersion("1.2.0.b");
builder.setTrace(true);
builder.setProperty(Constants.BASELINE, "*");
builder.setProperty(Constants.BASELINEREPO, "Baseline");
builder.build();
if (!builder.check("The bundle version \\(1.2.0/1.2.0\\) is too low, must be at least 1.3.0"))
fail(builder.getErrors()
.toString());
}
}
/**
* Check what happens when there is nothing in the repo ... We do not
* generate an error when version <=1.0.0, otherwise we generate an error.
*
* @throws Exception
*/
@Test
public void testNothingInRepo(@InjectTemporaryDirectory
File tmp) throws Exception {
try {
RepositoryPlugin repo = mock(RepositoryPlugin.class);
when(repo.canWrite()).thenReturn(true);
when(repo.getName()).thenReturn("Baseline");
when(repo.versions("p3")).thenReturn(new TreeSet<>());
getWorkspace(tmp).addBasicPlugin(repo);
Project p3 = getWorkspace(tmp).getProject("p3");
p3.setProperty(Constants.BASELINE, "*");
p3.setProperty(Constants.BASELINEREPO, "Baseline");
p3.setBundleVersion("0");
p3.build();
assertTrue(p3.check());
p3.setBundleVersion("1.0.0.XXXXXX");
p3.build();
assertTrue(p3.check());
p3.setBundleVersion("1.0.1");
p3.build();
assertTrue(p3.check("There is no baseline for p3 in the baseline repo"));
p3.setBundleVersion("1.1");
p3.build();
assertTrue(p3.check("There is no baseline for p3 in the baseline repo"));
p3.setBundleVersion("2.0.0.XXXXXX");
p3.build();
assertTrue(p3.check());
p3.setBundleVersion("2.0.1");
p3.build();
assertTrue(p3.check("There is no baseline for p3 in the baseline repo"));
p3.setBundleVersion("2.1");
p3.build();
assertTrue(p3.check("There is no baseline for p3 in the baseline repo"));
} finally {
IO.delete(tmp);
}
}
// Adding a method to a ProviderType produces a MINOR bump (1.0.0 -> 1.1.0)
@Test
public void testProviderTypeBump() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("testresources/api-orig.jar"));
Jar newer = new Jar(IO.getFile("testresources/api-providerbump.jar"));) {
Set<Info> infoSet = baseline.baseline(newer, older, null);
System.out.println(differ.tree(newer)
.get("<api>"));
assertEquals(1, infoSet.size());
Info info = infoSet.iterator()
.next();
assertTrue(info.mismatch);
assertEquals("dummy.api", info.packageName);
assertEquals("1.1.0", info.suggestedVersion.toString());
}
}
// Adding a method to a ConsumerType produces a MINOR bump (1.0.0 -> 2.0.0)
@Test
public void testConsumerTypeBump() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("testresources/api-orig.jar"));
Jar newer = new Jar(IO.getFile("testresources/api-consumerbump.jar"));) {
Set<Info> infoSet = baseline.baseline(newer, older, null);
assertEquals(1, infoSet.size());
Info info = infoSet.iterator()
.next();
assertTrue(info.mismatch);
assertEquals("dummy.api", info.packageName);
assertEquals("2.0.0", info.suggestedVersion.toString());
}
}
// Adding a method to a ProviderType produces a MINOR bump (1.0.0 -> 1.1.0)
@Test
public void testBundleVersionBump() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("testresources/api-orig.jar"));
Jar newer = new Jar(IO.getFile("testresources/api-providerbump.jar"));) {
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertTrue(bundleInfo.mismatch);
assertEquals("1.1.0", bundleInfo.suggestedVersion.toString());
}
}
// Adding a method to a ProviderType produces a MINOR bump (1.0.0 -> 1.1.0)
// in package, but bundle version should be ignored
@Test
public void testBundleVersionDiffignore() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
differ.setIgnore("Bundle-Version");
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("testresources/api-orig.jar"));
Jar newer = new Jar(IO.getFile("testresources/api-providerbump.jar"));) {
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertFalse(bundleInfo.mismatch);
}
}
// Adding a method to a ProviderType produces a MINOR bump (1.0.0 -> 1.1.0)
@Test
public void testBundleVersionBumpDifferentSymbolicNames() throws Exception {
Processor processor = new Processor();
DiffPluginImpl differ = new DiffPluginImpl();
Baseline baseline = new Baseline(processor, differ);
try (Jar older = new Jar(IO.getFile("testresources/api-orig.jar"));
Jar newer = new Jar(IO.getFile("testresources/api-providerbump.jar"));) {
newer.getManifest()
.getMainAttributes()
.putValue(BUNDLE_SYMBOLICNAME, "a.different.name");
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertFalse(bundleInfo.mismatch);
assertEquals(newer.getVersion(), bundleInfo.suggestedVersion.toString());
}
}
// Adding a method to an exported class produces a MINOR bump (1.0.0 ->
// 1.1.0)
@Test
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());
}
}
// Adding a method to an exported class and unexporting a package produces a
// MINOR bump (1.0.0 -> 1.1.0)
@Test
public void testMinorAndRemovedChange() 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-and-removed-change-1.0.1.jar"));) {
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertTrue(bundleInfo.mismatch);
assertEquals("2.0.0", bundleInfo.suggestedVersion.toString());
}
}
// Deleting a protected field on a ProviderType API class produces a MINOR
// bump (1.0.0 -> 1.1.0)
@Test
public void testProviderProtectedFieldRemovedChange() 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/provider-deletion-1.0.0.jar"));
Jar newer = new Jar(IO.getFile("jar/baseline/provider-deletion-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();
assertTrue(change.mismatch);
assertEquals("bnd.baseline.test", change.packageName);
assertEquals("1.1.0", change.suggestedVersion.toString());
}
}
// Moving a package from the root into a jar on the Bundle-ClassPath
// should not result in DELETED
@Test
public void testMovePackageToBundleClassPath() 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/com.liferay.calendar.api-2.0.5.jar"));
Jar newer = new Jar(IO.getFile("jar/baseline/com.liferay.calendar.api-2.1.0.jar"));) {
baseline.baseline(newer, older, null);
BundleInfo bundleInfo = baseline.getBundleInfo();
assertFalse(bundleInfo.mismatch);
assertEquals("2.1.0", bundleInfo.suggestedVersion.toString());
Set<Info> packageInfos = baseline.getPackageInfos();
assertEquals(12, packageInfos.size());
Info change = packageInfos.iterator()
.next();
assertFalse(change.mismatch);
assertEquals("com.google.ical.iter", change.packageName);
assertEquals("20110304.0.0", change.suggestedVersion.toString());
}
}
// 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.
@Test
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<Diff> children = packageDiff.getChildren();
assertEquals(5, children.size());
Iterator<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());
}
}
// This tests the scenario where the return type of an interface method is
// expanded through generics.
// e.g. from:
// Foo getFoo();
// to:
// <T extends Foo> T getFoo();
// or:
// <T extends Foo & Comparable<Foo>> T getFoo();
@Test
public void testExpandErasureOfMethodReturn() 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/expanding-erasure-1.0.0.jar"));
Jar newer = new Jar(IO.getFile("jar/baseline/expanding-erasure-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("bnd.test", change.packageName);
assertEquals("1.0.0", change.suggestedVersion.toString());
Diff packageDiff = change.packageDiff;
Collection<Diff> children = packageDiff.getChildren();
assertEquals(4, children.size());
Iterator<Diff> iterator = children.iterator();
Diff diff = iterator.next();
assertEquals(Delta.UNCHANGED, diff.getDelta());
}
}
}