|
24 | 24 | import org.gradle.internal.isolation.IsolatableFactory; |
25 | 25 | import org.gradle.internal.operations.*; |
26 | 26 | import org.gradle.internal.reflect.Instantiator; |
| 27 | +import org.gradle.internal.serialize.Decoder; |
27 | 28 | import org.gradle.internal.serialize.InputStreamBackedDecoder; |
28 | 29 | import org.gradle.internal.serialize.OutputStreamBackedEncoder; |
29 | 30 | import org.gradle.internal.serialize.Serializer; |
|
34 | 35 | import org.gradle.workers.WorkQueue; |
35 | 36 | import org.gradle.workers.WorkerExecutor; |
36 | 37 | import org.gradle.workers.internal.ActionExecutionSpecFactory; |
37 | | -import org.gradle.workers.internal.IsolatableSerializerRegistry; |
38 | 38 |
|
39 | 39 | import javax.annotation.Nullable; |
40 | 40 | import java.io.ByteArrayInputStream; |
|
55 | 55 | * Service managing the cached isolators and their backing queue |
56 | 56 | */ |
57 | 57 | public abstract class CachedQueueService |
58 | | - implements BuildService<BuildServiceParameters.None>, AutoCloseable, BuildOperationListener { |
| 58 | + implements ICachedQueueService, BuildService<BuildServiceParameters.None>, AutoCloseable, BuildOperationListener { |
59 | 59 |
|
60 | 60 | static CachedQueueService INSTANCE; |
61 | 61 |
|
@@ -299,14 +299,14 @@ void doExecuteWorkAction(ActualTaskInfo<?> info) { |
299 | 299 |
|
300 | 300 | Isolatable<WorkParameters> paramIsol = serviceRegistry.get(IsolatableFactory.class).isolate(parametersUnsafe); |
301 | 301 |
|
302 | | - IsolatableSerializerRegistry isolatableSerializerRegistry = this.serviceRegistry.get(IsolatableSerializerRegistry.class); |
| 302 | + IsolatableSerializerRegistryWrapper isolatableSerializerRegistry = getIsolatableSerializerRegistryWrapper(); |
303 | 303 |
|
304 | 304 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
305 | 305 | Serializer serializer = isolatableSerializerRegistry.build(paramIsol.getClass()); |
306 | 306 | try { |
307 | 307 | serializer.write(new OutputStreamBackedEncoder(bos), paramIsol); |
308 | 308 | } catch (Exception e) { |
309 | | - passThrowableAlong(e); |
| 309 | + throw new RuntimeException("Failed to serialize " + info.workActionClass.getName() + " " + parameterTypeNotIsolated.getName() + " with " + parametersUnsafe.getClass(), e); |
310 | 310 | } |
311 | 311 |
|
312 | 312 | String prefix = parametersUnsafe instanceof CachedIsolatedWorkQueue.WorkQueueParameters ? ((CachedIsolatedWorkQueue.WorkQueueParameters) parametersUnsafe) |
@@ -635,17 +635,71 @@ public void markForErasure() { |
635 | 635 |
|
636 | 636 |
|
637 | 637 | /** |
638 | | - * Construc |
| 638 | + * Construct a new WorkQueue |
639 | 639 | * |
640 | 640 | * @param workerExecutor the worker executor to use |
641 | 641 | * @param extraClasspathElement the classpath elements to use |
642 | 642 | * @return a new {@link WorkQueue} |
643 | 643 | */ |
644 | 644 | public WorkQueue newWorkQueue(WorkerExecutor workerExecutor, FileCollection extraClasspathElement) { |
| 645 | + Objects.requireNonNull(workerExecutor, "worker executor must not be null"); |
| 646 | + Objects.requireNonNull(serviceRegistry, "serviceRegistry must not be null"); |
645 | 647 | return new CachedIsolatedWorkQueue(workerExecutor.noIsolation(), |
646 | 648 | serviceRegistry.get(InstantiatorFactory.class), |
647 | 649 | Objects.requireNonNull(serviceRegistry, "serviceRegistry"), |
648 | 650 | this.providerSelf, |
649 | 651 | extraClasspathElement); |
650 | 652 | } |
| 653 | + |
| 654 | + // Gradle Version compat |
| 655 | + protected IsolatableSerializerRegistryWrapper getIsolatableSerializerRegistryWrapper() { |
| 656 | + return new IsolatableSerializerRegistryWrapper(this.serviceRegistry.get(getIsolatableSerializerRegistryClass())); |
| 657 | + } |
| 658 | + |
| 659 | + protected Class<?> getIsolatableSerializerRegistryClass() { |
| 660 | + try { |
| 661 | + return Class.forName("org.gradle.workers.internal.IsolatableSerializerRegistry"); |
| 662 | + } |
| 663 | + catch (ClassNotFoundException e) { |
| 664 | + try { |
| 665 | + return Class.forName("org.gradle.internal.snapshot.impl.IsolatableSerializerRegistry"); |
| 666 | + } |
| 667 | + catch (ClassNotFoundException ex) { |
| 668 | + throw new IllegalStateException(ex); |
| 669 | + } |
| 670 | + } |
| 671 | + } |
| 672 | + |
| 673 | + /** |
| 674 | + * Wrapper around gradle internals. |
| 675 | + * Must not refer to gradle internal classes to avoid errors during plugin-ASM-phase |
| 676 | + */ |
| 677 | + protected static class IsolatableSerializerRegistryWrapper { |
| 678 | + |
| 679 | + final Object instance; |
| 680 | + |
| 681 | + IsolatableSerializerRegistryWrapper(Object instance) { |
| 682 | + this.instance = instance; |
| 683 | + } |
| 684 | + |
| 685 | + <T> Serializer<T> build(Class<T> baseType) { |
| 686 | + try { |
| 687 | + return (Serializer<T>) instance.getClass().getMethod("build", Class.class) |
| 688 | + .invoke(instance, baseType); |
| 689 | + } |
| 690 | + catch (ReflectiveOperationException e) { |
| 691 | + throw new IllegalStateException("Failed to wrap IsolatableSerializerRegistry", e); |
| 692 | + } |
| 693 | + } |
| 694 | + |
| 695 | + Isolatable<?> readIsolatable(Decoder decoder) { |
| 696 | + try { |
| 697 | + return (Isolatable<?>) instance.getClass().getMethod("readIsolatable", Decoder.class) |
| 698 | + .invoke(instance, decoder); |
| 699 | + } |
| 700 | + catch (ReflectiveOperationException e) { |
| 701 | + throw new IllegalStateException("Failed to wrap IsolatableSerializerRegistry", e); |
| 702 | + } |
| 703 | + } |
| 704 | + } |
651 | 705 | } |
0 commit comments