@@ -3442,31 +3442,59 @@ public void close() {
3442
3442
}
3443
3443
3444
3444
/**
3445
- * A sink that stores all elements in a memory map. In case of multi-release jars, this memory
3446
- * storage aims to retain the non-versioned class file.
3445
+ * A sink that stores all elements in a memory map.
3447
3446
*/
3448
- @ HashCodeAndEqualsPlugin .Enhance
3449
3447
class InMemory implements Target , Sink {
3450
3448
3449
+ @ MaybeNull
3450
+ private final ClassFileVersion classFileVersion ;
3451
+
3451
3452
/**
3452
3453
* The map for storing all elements being received.
3453
3454
*/
3454
3455
private final Map <String , byte []> storage ;
3455
3456
3457
+ private final Map <String , Integer > versions ;
3458
+
3456
3459
/**
3457
3460
* Creates a new in-memory storage.
3458
3461
*/
3459
3462
public InMemory () {
3460
3463
this (new HashMap <String , byte []>());
3461
3464
}
3462
3465
3466
+ /**
3467
+ * Creates a new in-memory storage.
3468
+ *
3469
+ * @param classFileVersion The class file version to consider as the maximum version when accepting
3470
+ * multi-release classes or {@code null} if multi-release versions should
3471
+ * be discarded.
3472
+ */
3473
+ public InMemory (@ MaybeNull ClassFileVersion classFileVersion ) {
3474
+ this (classFileVersion , new HashMap <String , byte []>());
3475
+ }
3476
+
3463
3477
/**
3464
3478
* Creates a new in-memory storage.
3465
3479
*
3466
3480
* @param storage The map for storing all elements being received.
3467
3481
*/
3468
3482
public InMemory (Map <String , byte []> storage ) {
3483
+ this (null , storage );
3484
+ }
3485
+
3486
+ /**
3487
+ * Creates a new in-memory storage.
3488
+ *
3489
+ * @param classFileVersion The class file version to consider as the maximum version when accepting
3490
+ * multi-release classes or {@code null} if multi-release versions should
3491
+ * be discarded.
3492
+ * @param storage The map for storing all elements being received.
3493
+ */
3494
+ public InMemory (@ MaybeNull ClassFileVersion classFileVersion , Map <String , byte []> storage ) {
3495
+ this .classFileVersion = classFileVersion ;
3469
3496
this .storage = storage ;
3497
+ versions = new HashMap <String , Integer >();
3470
3498
}
3471
3499
3472
3500
/**
@@ -3490,18 +3518,25 @@ public Sink write(@MaybeNull Manifest manifest) throws IOException {
3490
3518
*/
3491
3519
public void store (Map <TypeDescription , byte []> binaryRepresentations ) {
3492
3520
for (Map .Entry <TypeDescription , byte []> entry : binaryRepresentations .entrySet ()) {
3493
- storage .put (entry .getKey ().getInternalName () + CLASS_FILE_EXTENSION , entry .getValue ());
3521
+ String name = entry .getKey ().getInternalName () + CLASS_FILE_EXTENSION ;
3522
+ if (!storage .containsKey (name )) {
3523
+ storage .put (name , entry .getValue ());
3524
+ }
3494
3525
}
3495
3526
}
3496
3527
3497
3528
/**
3498
3529
* {@inheritDoc}
3499
3530
*/
3500
3531
public void store (int version , Map <TypeDescription , byte []> binaryRepresentations ) throws IOException {
3501
- for (Map .Entry <TypeDescription , byte []> entry : binaryRepresentations .entrySet ()) {
3502
- String name = entry .getKey ().getInternalName () + CLASS_FILE_EXTENSION ;
3503
- if (!storage .containsKey (name )) {
3504
- storage .put (name , entry .getValue ());
3532
+ if (classFileVersion != null && version <= classFileVersion .getJavaVersion ()) {
3533
+ for (Map .Entry <TypeDescription , byte []> entry : binaryRepresentations .entrySet ()) {
3534
+ String name = entry .getKey ().getInternalName () + CLASS_FILE_EXTENSION ;
3535
+ Integer current = versions .get (name );
3536
+ if (current == null || current < version ) {
3537
+ versions .put (name , version );
3538
+ storage .put (name , entry .getValue ());
3539
+ }
3505
3540
}
3506
3541
}
3507
3542
}
0 commit comments