This repository was archived by the owner on May 9, 2023. It is now read-only.
forked from git-commit-id/git-commit-id-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformationRule.java
More file actions
137 lines (120 loc) · 3.76 KB
/
TransformationRule.java
File metadata and controls
137 lines (120 loc) · 3.76 KB
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
/*
* This file is part of git-commit-id-maven-plugin by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
*
* git-commit-id-maven-plugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* git-commit-id-maven-plugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with git-commit-id-maven-plugin. If not, see <http://www.gnu.org/licenses/>.
*/
package pl.project13.maven.git;
import org.apache.maven.plugins.annotations.Parameter;
/**
* This class represents a specific transformation logic the user wants to perform.
*
* Each {@code transformationRule} consist of
* two required fields {@code apply} and {@code action}.
* The {@code apply}-tag controls when the rule should
* be applied and can be set to {@code BEFORE} to have the rule being applied before or it can be
* set to {@code AFTER} to have the rule being applied after the replacement.
* The {@code action}-tag determines the string conversion rule that should be applied.
*
* Refer to https://github.com/git-commit-id/git-commit-id-maven-plugin/issues/317 for a use-case.
*/
public class TransformationRule {
/**
* Determines when the transformation should be taken place.
* Currently supported is
* - BEFORE_REGEX
* - AFTER_REGEX
*/
@Parameter(required = true)
private String apply;
private ApplyEnum applyRule;
protected enum ApplyEnum {
/**
* have the rule being applied before the replacement
*/
BEFORE,
/**
* have the rule being applied after the replacement
*/
AFTER,
;
}
/**
* Determines the action that should be performed as transformation.
* Currently supported is
* - LOWER_CASE
* - UPPER_CASE
*/
@Parameter(required = true)
private String action;
private ActionEnum actionRule;
protected enum ActionEnum {
LOWER_CASE {
@Override
protected String perform(String input) {
if (input != null) {
return input.toLowerCase();
}
return input;
}
},
UPPER_CASE {
@Override
protected String perform(String input) {
if (input != null) {
return input.toUpperCase();
}
return null;
}
},
;
protected abstract String perform(String input);
}
public TransformationRule() {
}
public TransformationRule(String apply, String action) {
this(ApplyEnum.valueOf(apply), ActionEnum.valueOf(action));
this.apply = apply;
this.action = action;
}
protected TransformationRule(ApplyEnum applyRule, ActionEnum actionRule) {
this.applyRule = applyRule;
this.actionRule = actionRule;
}
public String getApply() {
return apply;
}
public void setApply(String apply) {
this.applyRule = ApplyEnum.valueOf(apply);
this.apply = apply;
}
public ApplyEnum getApplyRule() {
if (applyRule == null) {
throw new IllegalStateException("The parameter 'apply' for TransformationRule is missing or invalid");
}
return applyRule;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.actionRule = ActionEnum.valueOf(action);
this.action = action;
}
public ActionEnum getActionRule() {
if (actionRule == null) {
throw new IllegalStateException("The parameter 'action' for TransformationRule is missing or invalid");
}
return actionRule;
}
}