1 package it.serendigity.maven.plugin.lifecycle.helper.vo;
2
3 import java.util.ArrayList;
4 import java.util.Arrays;
5 import java.util.EnumSet;
6 import java.util.List;
7 import java.util.Set;
8
9
10
11
12 public enum MavenExecutionAttribute {
13
14
15 PLAN_ORDER("execution-plan-order-id", "Plan order", "Execution plan order id", false),
16
17 LIFECYCLE("lifecycle", "Lifecycle"),
18
19 PHASE("phase", "Lifecycle phase"),
20
21 PLUGIN("plugin", "Plugin Artifact Id"),
22
23 PLUGIN_VERSION("plugin-version", "Plugin Version"),
24
25 PLUGIN_EXECUTION_ID("plugin-execution", "Plugin Execution Id"),
26
27 PLUGIN_GOAL("goal", "Plugin goal"),;
28
29 private final String code;
30 private final String shortDescription;
31 private final String description;
32 private final boolean groupByEnabled;
33
34 MavenExecutionAttribute( String code, String shortDescription, String description, boolean groupByEnabled ) {
35 this.code = code;
36 this.description = description;
37 this.shortDescription = shortDescription;
38 this.groupByEnabled = groupByEnabled;
39
40 }
41
42 MavenExecutionAttribute( String code, String description, boolean groupByEnabled ) {
43 this( code, description, description, groupByEnabled );
44
45 }
46
47 MavenExecutionAttribute( String code, String description ) {
48 this( code, description, true );
49 }
50
51 public static MavenExecutionAttribute fromCode( String name ) {
52 String ignoreCase = name.toLowerCase();
53
54 MavenExecutionAttribute[] values = values();
55
56 for ( MavenExecutionAttribute mavenExecutionAttribute : values ) {
57 if ( mavenExecutionAttribute.getCode().equals( ignoreCase ) ) {
58 return mavenExecutionAttribute;
59 }
60 }
61 return null;
62 }
63
64 public static Set<MavenExecutionAttribute> complementOf( MavenExecutionAttribute... excludes ) {
65 EnumSet<MavenExecutionAttribute> excludesEnum = EnumSet.noneOf( MavenExecutionAttribute.class );
66
67 if ( excludes != null ) {
68 excludesEnum.addAll( Arrays.asList( excludes ) );
69 }
70
71 return EnumSet.complementOf( excludesEnum );
72 }
73
74 public static Set<MavenExecutionAttribute> retrieveGroupByEnabled() {
75 EnumSet<MavenExecutionAttribute> result = EnumSet.noneOf( MavenExecutionAttribute.class );
76
77 MavenExecutionAttribute[] values = MavenExecutionAttribute.values();
78
79 for ( MavenExecutionAttribute v : values ) {
80 if ( v.isGroupByEnabled() ) {
81 result.add( v );
82 }
83 }
84
85 return result;
86
87 }
88
89 public static List<String> retrieveGroupByEnabledCode() {
90 List<String> result = new ArrayList<>();
91 Set<MavenExecutionAttribute> retrieveGroupByEnabled = retrieveGroupByEnabled();
92 retrieveGroupByEnabled.stream().forEach( p -> result.add( p.getCode() ) );
93
94 return result;
95 }
96
97 public String getCode() {
98 return code;
99 }
100
101 public String getDescription() {
102 return description;
103 }
104
105 public String getShortDescription() {
106 return shortDescription;
107 }
108
109 public boolean isGroupByEnabled() {
110 return groupByEnabled;
111 }
112
113 }