-
Notifications
You must be signed in to change notification settings - Fork 123
/
FakeMaven.java
898 lines (831 loc) 路 28.2 KB
/
FakeMaven.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
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
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.maven;
import com.yegor256.tojos.TjSmart;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.concurrent.NotThreadSafe;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.cactoos.Input;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
import org.eolang.maven.hash.CommitHash;
import org.eolang.maven.hash.CommitHashesMap;
import org.eolang.maven.name.ObjectName;
import org.eolang.maven.name.OnDefault;
import org.eolang.maven.objectionary.Objectionaries;
import org.eolang.maven.rust.Names;
import org.eolang.maven.tojos.ForeignTojo;
import org.eolang.maven.tojos.ForeignTojos;
import org.eolang.maven.tojos.PlacedTojos;
import org.eolang.maven.util.HmBase;
import org.eolang.maven.util.Home;
/**
* Fake maven workspace that executes Mojos in order to test
* their behaviour and results.
* NOT thread-safe.
* @since 0.28.12
* @todo #2406:30min Fix {@link FakeMaven#allowedParams(Class)}
* This function configures parameters of executed Mojo in {@link FakeMaven#execute(Class)}
* and parameters those Mojos which are inside this executed Mojo.
* If executed Mojo doesn't have parameters that are inside other Mojos,
* other Mojos parameters will not be configured.
* We need to make sure that custom parameters can be configured too.
* We need to enable the test {@link AssembleMojoTest#configuresChildParameters(Path)}.
*/
@SuppressWarnings({
"PMD.TooManyMethods",
"PMD.CouplingBetweenObjects",
"JTCOP.RuleAllTestsHaveProductionClass",
"JTCOP.RuleCorrectTestName"
})
@NotThreadSafe
public final class FakeMaven {
/**
* Test workspace where we place all programs, files, compilation results, etc.
*/
private final Home workspace;
/**
* Mojos params.
*/
private final Map<String, Object> params;
/**
* Current program number.
* We can save several programs in workspace and each program has it's own number
* started from 0.
*/
private final AtomicInteger current;
/**
* Use default attributes if they are not set.
*/
private final boolean defaults;
/**
* Constructor.
*
* @param workspace Test temporary directory.
*/
public FakeMaven(final Path workspace) {
this(workspace, true);
}
/**
* Constructor.
*
* @param workspace Test temporary directory.
* @param defaults Use default attributes if they are not set.
*/
private FakeMaven(final Path workspace, final boolean defaults) {
this(
new HmBase(workspace),
new HashMap<>(),
new AtomicInteger(0),
defaults
);
}
/**
* The main constructor.
* @param workspace Test temporary directory.
* @param params Mojos params.
* @param current Current program number.
* @param defaults Use default attributes if they are not set.
* @checkstyle ParameterNumberCheck (10 lines)
*/
private FakeMaven(
final Home workspace,
final Map<String, Object> params,
final AtomicInteger current,
final boolean defaults
) {
this.workspace = workspace;
this.params = params;
this.current = current;
this.defaults = defaults;
}
/**
* Sets parameter for execution.
*
* @param param Parameter name
* @param value Parameter value
* @return The same maven instance.
*/
public FakeMaven with(final String param, final Object value) {
this.params.put(param, value);
return this;
}
/**
* Executes mojos in the workspace.
* You can use utility classes to run predefined maven pipelines:
* - {@link org.eolang.maven.FakeMaven.Parse} to parse eo code
* - {@link org.eolang.maven.FakeMaven.Optimize} to parse and optimize eo code
* - see other inner classes below.
* @param mojo Several mojos to execute.
* @return Workspace after executing Mojo.
* @throws IOException If some problem with filesystem is happened.
*/
public FakeMaven execute(final Iterable<Class<? extends AbstractMojo>> mojo)
throws IOException {
for (final Class<? extends AbstractMojo> clazz : mojo) {
this.execute(clazz);
}
return this;
}
/**
* Tojo for eo-foreign.* file.
*
* @return TjSmart of the current eo-foreign.file.
*/
public TjSmart foreign() {
return new TjSmart(
Catalogs.INSTANCE.make(this.foreignPath())
);
}
/**
* Executes Mojo in the workspace.
*
* @param mojo Mojo to execute.
* @param <T> Template for descendants of Mojo.
* @return Workspace after executing Mojo.
* @throws java.io.IOException If some problem with filesystem has happened.
* @checkstyle ExecutableStatementCountCheck (100 lines)
*/
public <T extends AbstractMojo> FakeMaven execute(final Class<T> mojo) throws IOException {
if (this.defaults) {
final Path transpiled = Paths.get("transpiled");
final Path placed = Paths.get("placed.json");
this.workspace.save(new TextOf(""), transpiled);
this.params.putIfAbsent("targetDir", this.targetPath().toFile());
this.params.putIfAbsent("foreign", this.foreignPath().toFile());
this.params.putIfAbsent("foreignFormat", "csv");
this.params.putIfAbsent("project", new MavenProjectStub());
this.params.putIfAbsent("transpiled", this.workspace.absolute(transpiled).toFile());
this.params.putIfAbsent("transpiledFormat", "csv");
this.params.putIfAbsent("skipZeroVersions", true);
this.params.putIfAbsent("discoverSelf", false);
this.params.putIfAbsent("withVersions", false);
this.params.putIfAbsent("ignoreVersionConflicts", false);
this.params.putIfAbsent("ignoreTransitive", true);
this.params.putIfAbsent("central", new DummyCentral());
this.params.putIfAbsent("placed", this.workspace.absolute(placed).toFile());
this.params.putIfAbsent("placedFormat", "json");
this.params.putIfAbsent(
"sourcesDir",
this.workspace.absolute(Paths.get(".")).toFile()
);
this.params.putIfAbsent(
"outputDir",
this.workspace.absolute(Paths.get("target").resolve("classes")).toFile()
);
this.params.putIfAbsent(
"cache",
this.workspace.absolute(Paths.get("eo")).resolve("cache/parsed")
);
this.params.putIfAbsent("generateSodgXmlFiles", true);
this.params.putIfAbsent("generateXemblyFiles", true);
this.params.putIfAbsent("generateGraphFiles", true);
this.params.putIfAbsent("generateDotFiles", true);
this.params.putIfAbsent("generateDotFiles", true);
this.params.putIfAbsent("generatedDir", this.generatedPath().toFile());
this.params.putIfAbsent("placedFormat", "csv");
this.params.putIfAbsent("plugin", FakeMaven.pluginDescriptor());
this.params.putIfAbsent("objectionaries", new Objectionaries.Fake());
this.params.putIfAbsent("rewriteBinaries", true);
this.params.putIfAbsent("offline", false);
this.params.putIfAbsent(
"eoPortalDir",
new File("../eo-runtime/src/main/rust/eo")
);
this.params.putIfAbsent("namesDir", this.generatedPath().resolve("names").toFile());
this.params.putIfAbsent(
"names",
new Names(((File) this.params.get("namesDir")).toPath())
);
this.params.putIfAbsent("hashes", new CommitHashesMap.Fake());
this.params.putIfAbsent(
"phiInputDir",
this.workspace.absolute(
Paths.get(String.format("target/%s", OptimizeMojo.DIR))
).toFile()
);
this.params.putIfAbsent(
"phiOutputDir",
this.workspace.absolute(Paths.get("target/phi")).toFile()
);
}
final Moja<T> moja = new Moja<>(mojo);
for (final Map.Entry<String, ?> entry : this.allowedParams(mojo).entrySet()) {
moja.with(entry.getKey(), entry.getValue());
}
moja.execute();
return this;
}
/**
* Adds eo program to a workspace.
* @param input Program as an input.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
public FakeMaven withProgram(final Input input) throws IOException {
return this.withProgram(new UncheckedText(new TextOf(input)).asString());
}
/**
* Path to compilation target directory.
* @return Path to target dir.
*/
public Path targetPath() {
return this.workspace.absolute(Paths.get("target"));
}
/**
* Path to generated directory.
* @return Path to generated dir.
*/
public Path generatedPath() {
return this.targetPath().resolve("generated");
}
/**
* Foreign tojos for eo-foreign.* file.
* @return Foreign tojos.
*/
ForeignTojos foreignTojos() {
return new ForeignTojos(
() -> Catalogs.INSTANCE.make(this.foreignPath()),
this::scope
);
}
/**
* Sets placed tojo attribute.
*
* @param binary Binary as class file or jar.
* @return The same maven instance.
*/
FakeMaven withPlacedBinary(final Path binary) {
this.placed().placeClass(binary, "", "test.jar");
return this;
}
/**
* Adds correct 'Hello world' program to workspace.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
FakeMaven withHelloWorld() throws IOException {
return this.withProgram(
"+alias stdout org.eolang.io.stdout",
"+package f\n",
"[x] > main",
" (stdout \"Hello!\" x).print > @"
);
}
/**
* Add the correct versioned 'Hello world' program to workspace.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
FakeMaven withVersionedHelloWorld() throws IOException {
return this.withProgram(
"+package f\n",
"[] > main",
" QQ.io.stdout|0.28.5 > @",
" \"Hello world\""
);
}
/**
* Add correct versioned program to workspace.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
FakeMaven withVersionedProgram() throws IOException {
return this.withProgram(
"+alias org.eolang.math.number",
"+alias org.eolang.txt.text",
"+home https://objectionary.home",
"+package f",
"+version 0.0.0\n",
"[args] > main",
" seq|0.28.4 > @",
" QQ.io.stdout|0.28.5",
" QQ.txt.sprintf|0.28.6",
" \"Number %d, text %s\"",
" number 2",
" text|0.28.7",
" \"text\"",
" nop"
);
}
/**
* Adds eo program to a workspace.
* @param program Program as a raw string.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
FakeMaven withProgram(final String... program) throws IOException {
return this.withProgram(
String.join("\n", program),
new OnDefault(FakeMaven.tojoId(this.current.get()))
);
}
/**
* Adds eo program to a workspace.
*
* @param path Path to the program
* @return The same maven instance
* @throws IOException If fails
*/
FakeMaven withProgram(final Path path) throws IOException {
return this.withProgram(new UncheckedText(new TextOf(path)).asString());
}
/**
* Adds eo program to a workspace.
* @param content EO program content.
* @param object Object name to save in tojos.
* @return The same maven instance.
* @throws IOException If method can't save eo program to the workspace.
*/
FakeMaven withProgram(final String content, final ObjectName object)
throws IOException {
final Path path = Paths.get(
String.format("foo/x/main%s.eo", FakeMaven.suffix(this.current.get()))
);
this.workspace.save(content, path);
final String scope = this.scope();
final String version = "0.25.0";
final Path source = this.workspace.absolute(path);
this.foreignTojos()
.add(object)
.withScope(scope)
.withVersion(version)
.withSource(source);
this.current.incrementAndGet();
return this;
}
/**
* Specify hash for all foreign tojos.
* @param hash Commit hash
* @return The same maven instance.
*/
FakeMaven allTojosWithHash(final CommitHash hash) {
this.foreignTojos().all().forEach(tojo -> tojo.withHash(hash));
return this;
}
/**
* Should we use defaults or not?
* @return The same maven instance.
*/
FakeMaven withoutDefaults() {
return new FakeMaven(this.workspace, this.params, this.current, false);
}
/**
* Path to eo-foreign.* file after all changes.
* @return Path to eo-foreign.* file.
*/
Path foreignPath() {
return this.workspace.absolute(Paths.get("eo-foreign.csv"));
}
/**
* Tojo for placed.json file.
*
* @return TjSmart of the current placed.json file.
*/
PlacedTojos placed() {
return new PlacedTojos(this.workspace.absolute(Paths.get("placed.json")));
}
/**
* Creates of the result map with all files and folders that was created
* or compiled during mojo execution.
*
* @return Map of "relative UNIX path" (key) - "absolute path" (value).
* @throws IOException If some problem with filesystem have happened.
*/
Map<String, Path> result() throws IOException {
final Path root = this.workspace.absolute(Paths.get(""));
return Files.walk(root).collect(
Collectors.toMap(
p -> String.join(
"/",
root.relativize(p).toString().split(Pattern.quote(File.separator))
),
Function.identity()
)
);
}
/**
* Retrieve the entry of the last program in the eo-foreign.csv file.
* @return Tojo entry.
*/
ForeignTojo programTojo() {
return this.foreignTojos().find(FakeMaven.tojoId(this.current.get() - 1));
}
/**
* The version of eo-maven-plugin for tests.
* @return Version.
*/
static String pluginVersion() {
return "1.0-TEST";
}
/**
* Suffix for the program name or path.
* - main_1.eo
* - foo.x.main100
* - main.eo
* @param index Number of the program.
* @return String suffix.
*/
static String suffix(final int index) {
final String suffix;
if (index == 0) {
suffix = "";
} else {
suffix = String.format("_%d", index);
}
return suffix;
}
/**
* Plugin descriptor with test version.
* @return Plugin descriptor.
*/
static PluginDescriptor pluginDescriptor() {
final PluginDescriptor descriptor = new PluginDescriptor();
descriptor.setGroupId("org.eolang");
descriptor.setArtifactId("eo-maven-plugin");
descriptor.setVersion(FakeMaven.pluginVersion());
return descriptor;
}
/**
* Ensures the map of allowed params for the Mojo.
*
* @param mojo Mojo
* @return Map of params that applicable to the Mojo
*/
private Map<String, ?> allowedParams(final Class<? extends AbstractMojo> mojo) {
final Map<String, Object> res = new HashMap<>();
final Set<String> allowed = FakeMaven.mojoFields(mojo, new HashSet<>());
for (final Map.Entry<String, Object> entry : this.params.entrySet()) {
if (allowed.contains(entry.getKey())) {
res.put(entry.getKey(), entry.getValue());
}
}
return res;
}
/**
* Returns the current scope that was set.
* @return The current scope.
*/
private String scope() {
return String.valueOf(this.params.getOrDefault("scope", "compile"));
}
/**
* The id of the program in tojos file.
* @param id Number of the program.
* @return String id.
*/
private static String tojoId(final int id) {
return String.format("foo.x.main%s", FakeMaven.suffix(id));
}
/**
* Looks for all declared fields for mojo and its parents.
*
* @param mojo Mojo or mojo parent.
* @param fields Already collected fields.
* @return All mojo and mojo parent fields.
*/
private static Set<String> mojoFields(final Class<?> mojo, final Set<String> fields) {
final Set<String> res;
if (mojo == null) {
res = fields;
} else {
Stream.of(mojo.getDeclaredFields()).map(Field::getName).forEach(fields::add);
res = mojoFields(mojo.getSuperclass(), fields);
}
return res;
}
/**
* Parse full pipeline.
*
* @since 0.28.12
*/
static final class Parse implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Collections.<Class<? extends AbstractMojo>>singletonList(
ParseMojo.class
).iterator();
}
}
/**
* Optimization full pipeline.
*
* @since 0.28.12
*/
static final class Optimize implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class
).iterator();
}
}
/**
* Check errors and warnings.
*
* @since 0.31.0
*/
static final class Verify implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
VerifyMojo.class
).iterator();
}
}
/**
* Latex full pipeline.
*
* @since 0.29.2
*/
static final class Latex implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
LatexMojo.class
).iterator();
}
}
/**
* Transpile full pipeline.
*
* @since 0.29.0
*/
static final class Transpile implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
TranspileMojo.class
).iterator();
}
}
/**
* Binarize full pipeline.
*
* @since 0.29.0
*/
static final class Binarize implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
BinarizeMojo.class
).iterator();
}
}
/**
* Parse rust insert pipeline.
*
* @since 0.29.0
*/
static final class BinarizeParse implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
BinarizeParseMojo.class
).iterator();
}
}
/**
* Resolve all eo dependencies.
*
* @since 0.29.0
*/
static final class Resolve implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
ResolveMojo.class
).iterator();
}
}
/**
* Translates EO program to Phi-calculus expression.
*
* @since 0.33.0
*/
static final class Phi implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
PhiMojo.class
).iterator();
}
}
/**
* Plan all eo dependencies full pipeline.
*
* @since 0.29.0
*/
static final class Place implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
ResolveMojo.class,
PlaceMojo.class
).iterator();
}
}
/**
* Sodg full pipeline.
*
* @since 0.29.0
*/
static final class Sodg implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
SodgMojo.class
).iterator();
}
}
/**
* Single register phase.
* @since 1.0
*/
static final class Register implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
RegisterMojo.class
).iterator();
}
}
/**
* Probe full pipeline.
*
* @since 0.29
*/
static final class Probe implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
DiscoverMojo.class,
ProbeMojo.class
).iterator();
}
}
/**
* Pull a full pipeline.
*
* @since 0.31
*/
static final class Pull implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
DiscoverMojo.class,
ProbeMojo.class,
PullMojo.class
).iterator();
}
}
/**
* Discovery pipeline.
*
* @since 0.31
*/
static final class Discover implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
DiscoverMojo.class
).iterator();
}
}
/**
* Printing pipeline.
*
* @since 0.33.0
*/
static final class Print implements Iterable<Class<? extends AbstractMojo>> {
@Override
public Iterator<Class<? extends AbstractMojo>> iterator() {
return Arrays.<Class<? extends AbstractMojo>>asList(
PrintMojo.class
).iterator();
}
}
/**
* The class for emulating of Maven Central repository.
* DummyCentral creates an empty dependency jar file under the path.
*
* @since 0.28.11
*/
private static final class DummyCentral implements BiConsumer<Dependency, Path> {
@Override
public void accept(
final Dependency dependency,
final Path path
) {
try {
Files.createDirectories(path);
final String other = DummyCentral.jarName(dependency);
Files.createFile(path.resolve(other));
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Can't save '%s' to '%s'", dependency, path),
ex
);
}
}
/**
* Dependency jar name.
*
* @param dependency Dependency
* @return Jar file name
*/
private static String jarName(final Dependency dependency) {
final List<String> parts = new ArrayList<>(3);
if (dependency.getArtifactId() != null && !dependency.getArtifactId().isEmpty()) {
parts.add(dependency.getArtifactId());
}
if (dependency.getVersion() != null && !dependency.getVersion().isEmpty()) {
parts.add(dependency.getVersion());
}
if (dependency.getClassifier() != null && !dependency.getClassifier().isEmpty()) {
parts.add(dependency.getClassifier());
}
return String.format("%s.jar", String.join("-", parts));
}
}
}