-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
DefaultJavaForkOptionsTest.groovy
executable file
·826 lines (644 loc) · 24.7 KB
/
DefaultJavaForkOptionsTest.groovy
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
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.gradle.api.internal.tasks.util
import com.google.common.collect.ImmutableSet
import org.gradle.api.file.FileCollection
import org.gradle.api.internal.file.TestFiles
import org.gradle.process.CommandLineArgumentProvider
import org.gradle.process.JavaForkOptions
import org.gradle.process.internal.DefaultJavaDebugOptions
import org.gradle.process.internal.DefaultJavaForkOptions
import org.gradle.test.fixtures.file.TestNameTestDirectoryProvider
import org.gradle.util.UsesNativeServices
import org.junit.Rule
import spock.lang.Specification
import java.nio.charset.Charset
import static org.gradle.api.internal.file.TestFiles.systemSpecificAbsolutePath
import static org.hamcrest.CoreMatchers.equalTo
import static org.hamcrest.CoreMatchers.nullValue
import static org.junit.Assert.assertThat
@UsesNativeServices
class DefaultJavaForkOptionsTest extends Specification {
@Rule
public final TestNameTestDirectoryProvider tmpDir = new TestNameTestDirectoryProvider()
private final resolver = TestFiles.pathToFileResolver(tmpDir.testDirectory)
private final fileCollectionFactory = TestFiles.fileCollectionFactory(tmpDir.testDirectory)
private DefaultJavaForkOptions options
def setup() {
options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
}
def "provides correct default values"() {
expect:
options.executable != null
options.jvmArgs.isEmpty()
options.systemProperties.isEmpty()
options.minHeapSize == null
options.maxHeapSize == null
options.bootstrapClasspath.files.isEmpty()
!options.enableAssertions
!options.debug
options.allJvmArgs == [fileEncodingProperty(), *localeProperties()]
}
def "converts jvmArgs to String on get"() {
when:
options.jvmArgs = [12, "${1 + 2}"]
then:
options.jvmArgs == ['12', '3']
}
def "setAllJvmArgs cleans jvmArgumentProviders"() {
def jvmArgumentProvider = new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return ['argFromProvider']
}
}
when:
options.jvmArgumentProviders << jvmArgumentProvider
then:
options.allJvmArgs == ['argFromProvider', fileEncodingProperty(), *localeProperties()]
when:
options.allJvmArgs = ['arg1']
then:
options.allJvmArgs == ['arg1', fileEncodingProperty(), *localeProperties()]
when:
options.jvmArgumentProviders << jvmArgumentProvider
then:
options.allJvmArgs == ['arg1', 'argFromProvider', fileEncodingProperty(), *localeProperties()]
when:
options.setAllJvmArgs(ImmutableSet.of("arg2"))
then:
options.allJvmArgs == ['arg2', fileEncodingProperty(), *localeProperties()]
}
def "can add jvmArgs"() {
when:
options.jvmArgs('arg1', 'arg2')
options.jvmArgs('arg3')
then:
options.jvmArgs == ['arg1', 'arg2', 'arg3']
}
def "can set system properties"() {
when:
options.systemProperties = [key: 12, key2: "value", key3: null]
then:
options.systemProperties == [key: 12, key2: "value", key3: null]
}
def "can add system properties"() {
when:
options.systemProperties(key: 12)
options.systemProperty('key2', 'value2')
then:
options.systemProperties == [key: 12, key2: 'value2']
}
def "all jvm args include system properties as string"() {
when:
options.systemProperties(key: 12, key2: null, "key3": 'value')
options.jvmArgs('arg1')
then:
options.allJvmArgs == ['-Dkey=12', '-Dkey2', '-Dkey3=value', 'arg1', fileEncodingProperty(), *localeProperties()]
}
def "system properties are updated when added using jvmArgs"() {
when:
options.systemProperties(key: 12)
options.jvmArgs('-Dkey=new value', '-Dkey2')
then:
options.systemProperties == [key: 'new value', key2: '']
when:
options.allJvmArgs = []
then:
options.systemProperties == [:]
when:
options.allJvmArgs = ['-Dkey=value']
then:
options.systemProperties == [key: 'value']
}
def "allJvmArgs includes minHeapSize"() {
when:
options.minHeapSize = '64m'
options.jvmArgs('arg1')
then:
options.allJvmArgs == ['arg1', '-Xms64m', fileEncodingProperty(), *localeProperties()]
}
def "allJvmArgs includes maxHeapSize"() {
when:
options.maxHeapSize = '1g'
options.jvmArgs('arg1')
then:
options.allJvmArgs == ['arg1', '-Xmx1g', fileEncodingProperty(), *localeProperties()]
}
def "allJvmArgs include jvmArgumentProviders"() {
when:
options.jvmArgumentProviders << new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return ['argFromProvider1', 'argFromProvider2']
}
}
options.jvmArgumentProviders << new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return ['argFromProvider3']
}
}
options.jvmArgs('arg1')
then:
options.allJvmArgs == ['arg1', 'argFromProvider1', 'argFromProvider2', 'argFromProvider3', fileEncodingProperty(), *localeProperties()]
}
def "minHeapSize is updated when set using jvmArgs"() {
when:
options.minHeapSize = '64m'
options.jvmArgs('-Xms128m')
then:
options.minHeapSize == '128m'
when:
options.allJvmArgs = []
then:
options.minHeapSize == null
when:
options.allJvmArgs = ['-Xms92m']
then:
options.minHeapSize == '92m'
}
def "maxHeapSizeIsUpdatedWhenSetUsingJvmArgs"() {
options.maxHeapSize = '1g'
options.jvmArgs('-Xmx1024m')
assertThat(options.maxHeapSize, equalTo('1024m'))
options.allJvmArgs = []
assertThat(options.maxHeapSize, nullValue())
options.allJvmArgs = ['-Xmx1g']
assertThat(options.maxHeapSize, equalTo('1g'))
}
def "allJvmArgs includes assertionsEnabled"() {
given:
assert options.allJvmArgs == [fileEncodingProperty(), *localeProperties()]
when:
options.enableAssertions = true
then:
options.allJvmArgs == [fileEncodingProperty(), *localeProperties(), '-ea']
}
def "assertionsEnabled is updated when set using jvmArgs"() {
when:
options.jvmArgs('-ea')
then:
options.enableAssertions
options.jvmArgs == []
when:
options.allJvmArgs = []
then:
!options.enableAssertions
when:
options.jvmArgs('-enableassertions')
then:
options.enableAssertions
when:
options.allJvmArgs = ['-da']
then:
!options.enableAssertions
}
def "allJvmArgs includes debug args"() {
given:
assert options.allJvmArgs == [fileEncodingProperty(), *localeProperties()]
when:
options.debug = true
then:
options.allJvmArgs == [fileEncodingProperty(), *localeProperties(), '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005']
}
def "can set debug options"() {
when:
options.debugOptions {
it.port.set(2233)
}
then:
options.debugOptions.port.get() == 2233
}
def "can set bootstrapClasspath"() {
def bootstrapClasspath = [:] as FileCollection
when:
options.bootstrapClasspath = bootstrapClasspath
then:
options.bootstrapClasspath.from == [bootstrapClasspath] as Set
}
def "can add to bootstrapClasspath"() {
def files = ['file1.jar', 'file2.jar'].collect { new File(it).canonicalFile }
when:
options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
options.bootstrapClasspath(files[0])
options.bootstrapClasspath(files[1])
then:
options.bootstrapClasspath.getFiles() == files as Set
}
def "allJvmArgs includes bootstrapClasspath"() {
when:
def files = ['file1.jar', 'file2.jar'].collect { new File(it).canonicalFile }
options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
options.bootstrapClasspath(files)
then:
options.allJvmArgs == ['-Xbootclasspath:' + files.join(System.properties['path.separator']), fileEncodingProperty(), *localeProperties()]
}
def "can set bootstrapClasspath via allJvmArgs"() {
def files = ['file1.jar', 'file2.jar'].collect { new File(it).canonicalFile }
when:
options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
options.bootstrapClasspath(files[0])
options.allJvmArgs = ['-Xbootclasspath:' + files[1]]
then:
options.bootstrapClasspath.files == [files[1]] as Set
}
def "can copy to target options"() {
JavaForkOptions target = Mock(JavaForkOptions)
given:
options.executable('executable')
options.jvmArgs('arg')
options.systemProperties(key: 12)
options.minHeapSize = '64m'
options.maxHeapSize = '1g'
options.jvmArgumentProviders << new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return ['argFromProvider']
}
}
when:
options.copyTo(target)
then:
1 * target.setExecutable('executable' as Object)
1 * target.setJvmArgs(['arg'])
1 * target.setSystemProperties([key: 12])
1 * target.setMinHeapSize('64m')
1 * target.setMaxHeapSize('1g')
1 * target.bootstrapClasspath(_)
1 * target.setEnableAssertions(false)
1 * target.getDebugOptions() >> new DefaultJavaDebugOptions()
then:
1 * target.jvmArgs(['argFromProvider'])
}
def "defaults are compatible"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
expect:
options.isCompatibleWith(other)
}
def "is compatible with identical options"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def settings = {
executable = "/foo/bar"
workingDir = new File("foo")
environment = ["FOO": "BAR"]
systemProperties = ["foo": "bar", "bar": "foo"]
minHeapSize = "128m"
maxHeapSize = "256m"
debug = true
}
when:
options.with settings
other.with settings
then:
options.isCompatibleWith(other)
}
def "is compatible with different representations of heap options"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
minHeapSize = "1024m"
maxHeapSize = "2g"
}
other.with {
minHeapSize = "1g"
maxHeapSize = "2048m"
}
then:
options.isCompatibleWith(other)
}
def "is compatible with lower heap requirements"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
minHeapSize = "128m"
maxHeapSize = "1024m"
}
other.with {
minHeapSize = "64m"
maxHeapSize = "512m"
}
then:
options.isCompatibleWith(other)
}
def "is not compatible with higher heap requirements"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
minHeapSize = "64m"
maxHeapSize = "512m"
}
other.with {
minHeapSize = "128m"
maxHeapSize = "1024m"
}
then:
!options.isCompatibleWith(other)
}
def "is compatible with the same set of jvm args"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.jvmArgs = ["-server", "-esa"]
other.jvmArgs = ["-esa", "-server"]
then:
options.isCompatibleWith(other)
}
def "is compatible with a subset of jvm args"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.jvmArgs = ["-server", "-esa"]
other.jvmArgs = ["-server"]
then:
options.isCompatibleWith(other)
}
def "is not compatible with a superset of jvm args"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.jvmArgs = ["-server"]
other.jvmArgs = ["-server", "-esa"]
then:
!options.isCompatibleWith(other)
}
def "is not compatible with a different set of jvm args"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.jvmArgs = ["-server", "-esa"]
other.jvmArgs = ["-client", "-esa"]
then:
!options.isCompatibleWith(other)
}
def "is compatible with same executable"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.executable = "foo"
other.executable = "foo"
then:
options.isCompatibleWith(other)
}
def "is not compatible with different executables"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.executable = "foo"
other.executable = "bar"
then:
!options.isCompatibleWith(other)
}
def "is compatible with same workingDir"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.workingDir = new File("foo")
other.workingDir = new File("foo")
then:
options.isCompatibleWith(other)
}
def "is not compatible with different workingDir"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.workingDir = new File("foo")
other.workingDir = new File("bar")
then:
!options.isCompatibleWith(other)
}
def "is compatible with same environment variables"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.environment = ["FOO": "bar", "BAR": "foo"]
other.environment = ["BAR": "foo", "FOO": "bar"]
then:
options.isCompatibleWith(other)
}
def "is not compatible with different environment variables"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.environment = ["FOO": "bar", "BAR": "foo"]
other.environment = ["BAZ": "foo", "FOO": "bar"]
then:
!options.isCompatibleWith(other)
}
def "is compatible with subset of environment variables"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.environment = ["FOO": "bar", "BAR": "foo"]
other.environment = ["FOO": "bar"]
then:
options.isCompatibleWith(other)
}
def "is not compatible with super set of environment variables"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.environment = ["FOO": "bar"]
other.environment = ["FOO": "bar", "BAR": "foo"]
then:
!options.isCompatibleWith(other)
}
def "is compatible with the same system properties"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.systemProperties = ["foo": "bar", "bar": "foo"]
other.systemProperties = ["bar": "foo", "foo": "bar"]
then:
options.isCompatibleWith(other)
}
def "is not compatible with different system properties"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.systemProperties = ["foo": "bar", "bar": "foo"]
other.systemProperties = ["baz": "foo", "foo": "bar"]
then:
!options.isCompatibleWith(other)
}
def "is compatible with subset of system properties"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.systemProperties = ["foo": "bar", "bar": "foo"]
other.systemProperties = ["foo": "bar"]
then:
options.isCompatibleWith(other)
}
def "is not compatible with super set of system properties"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.systemProperties = ["foo": "bar"]
other.systemProperties = ["foo": "bar", "bar": "foo"]
then:
!options.isCompatibleWith(other)
}
def "is compatible with same debug setting"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.debug = true
other.debug = true
then:
options.isCompatibleWith(other)
}
def "is not compatible with different debug setting"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.debug = true
other.debug = false
then:
!options.isCompatibleWith(other)
}
def "is compatible with same enableAssertions setting"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.enableAssertions = true
other.enableAssertions = true
then:
options.isCompatibleWith(other)
}
def "is not compatible with different enableAssertions setting"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.enableAssertions = true
other.enableAssertions = false
then:
!options.isCompatibleWith(other)
}
def "is compatible with same bootstrapClasspath"() {
def files = ['file1.jar', 'file2.jar'].collect { new File(it).canonicalFile }
def options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
workingDir = systemSpecificAbsolutePath("foo")
bootstrapClasspath(files)
}
other.with {
workingDir = systemSpecificAbsolutePath("foo")
bootstrapClasspath(files)
}
then:
options.isCompatibleWith(other)
}
def "is not compatible with different bootstrapClasspath"() {
def files1 = ['file1.jar', 'file2.jar'].collect { new File(it).canonicalFile }
def files2 = ['file2.jar', 'file3.jar'].collect { new File(it).canonicalFile }
def options = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
workingDir = systemSpecificAbsolutePath("foo")
bootstrapClasspath(files1)
}
other.with {
workingDir = systemSpecificAbsolutePath("foo")
bootstrapClasspath(files2)
}
then:
!options.isCompatibleWith(other)
}
def "string values are trimmed"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
executable = " foo"
minHeapSize = "128m "
maxHeapSize = "1g"
jvmArgs = [" -server", "-esa"]
}
other.with {
executable = "foo "
minHeapSize = "128m"
maxHeapSize = " 1g"
jvmArgs = [" -server", "-esa "]
}
then:
options.isCompatibleWith(other)
}
def "capitalization of memory options is irrelevant"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
minHeapSize = "128M"
maxHeapSize = "1g"
}
other.with {
minHeapSize = "128m"
maxHeapSize = "1G"
}
then:
options.isCompatibleWith(other)
}
def "capitalization of JVM args is relevant"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
options.with {
jvmArgs = ["-Server", "-esa"]
}
other.with {
jvmArgs = ["-server", "-esa"]
}
then:
!options.isCompatibleWith(other)
}
def "unspecified heap options are only compatible with unspecified heap options"() {
def other1 = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def other2 = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
other2.with {
minHeapSize = "128m"
maxHeapSize = "256m"
}
then:
options.isCompatibleWith(other1)
!options.isCompatibleWith(other2)
}
def "unspecified executable is only compatible with unspecified executable options"() {
def other1 = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def other2 = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
when:
other2.executable = "/foo/bar"
then:
options.isCompatibleWith(other1)
!options.isCompatibleWith(other2)
}
def "cannot determine compatibility with jvmArgumentProviders"() {
def other = new DefaultJavaForkOptions(resolver, fileCollectionFactory, new DefaultJavaDebugOptions())
def argumentProvider = new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
return ['argFromProvider']
}
}
if (currentHasProviders) {
options.jvmArgumentProviders << argumentProvider
}
if (otherHasProviders) {
other.jvmArgumentProviders << argumentProvider
}
when:
options.isCompatibleWith(other)
then:
def thrown = thrown(UnsupportedOperationException)
thrown.message.contains('Cannot compare options with jvmArgumentProviders.')
where:
currentHasProviders | otherHasProviders
true | false
false | true
true | true
}
private static String fileEncodingProperty(String encoding = Charset.defaultCharset().name()) {
return "-Dfile.encoding=$encoding"
}
private static List<String> localeProperties(Locale locale = Locale.default) {
["country", "language", "variant"].sort().collectEntries {
["user.$it", locale."$it"]
}.collect {
it.value ? "-D$it.key=$it.value" : "-D$it.key"
}
}
}