• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

git-commit-id / git-commit-id-maven-plugin / #219

04 Dec 2023 07:24PM CUT coverage: 71.134%. Remained the same
#219

push

web-flow
Merge pull request #676 from git-commit-id/dependabot/maven/org.apache.maven.plugins-maven-javadoc-plugin-3.6.3

Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.2 to 3.6.3

276 of 388 relevant lines covered (71.13%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/src/main/java/pl/project13/maven/validation/ValidationMojo.java
1
/*
2
 * This file is part of git-commit-id-maven-plugin by Konrad 'ktoso' Malawski <konrad.malawski@java.pl>
3
 *
4
 * git-commit-id-maven-plugin is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * git-commit-id-maven-plugin is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with git-commit-id-maven-plugin.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
package pl.project13.maven.validation;
19

20
import org.apache.maven.plugin.AbstractMojo;
21
import org.apache.maven.plugin.MojoExecutionException;
22
import org.apache.maven.plugins.annotations.LifecyclePhase;
23
import org.apache.maven.plugins.annotations.Mojo;
24
import org.apache.maven.plugins.annotations.Parameter;
25

26
import java.util.List;
27
import java.util.regex.Matcher;
28
import java.util.regex.Pattern;
29

30
/**
31
 * @since 2.2.2
32
 */
33
@Mojo(name = "validateRevision", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true)
34
public class ValidationMojo extends AbstractMojo {
1✔
35
  @Parameter(defaultValue = "true")
36
  private boolean validationShouldFailIfNoMatch;
37

38
  @Parameter
39
  private List<ValidationProperty> validationProperties;
40

41
  @Override
42
  public void execute() throws MojoExecutionException {
43
    if (validationProperties != null && validationShouldFailIfNoMatch) {
1✔
44
      for (ValidationProperty validationProperty: validationProperties) {
1✔
45
        String name = validationProperty.getName();
1✔
46
        String value = validationProperty.getValue();
1✔
47
        String shouldMatchTo = validationProperty.getShouldMatchTo();
1✔
48
        if ((value != null) && (shouldMatchTo != null)) {
1✔
49
          validateIfValueAndShouldMatchToMatches(name, value, shouldMatchTo);
1✔
50
        } else {
51
          printLogMessageWhenValueOrShouldMatchToIsEmpty(name, value, shouldMatchTo);
1✔
52
        }
53
      }
1✔
54
    }
55
  }
1✔
56

57
  private void validateIfValueAndShouldMatchToMatches(String name, String value, String shouldMatchTo) throws MojoExecutionException {
58
    Pattern pattern = Pattern.compile(shouldMatchTo);
1✔
59
    Matcher matcher = pattern.matcher(value);
1✔
60
    if (!matcher.find()) {
1✔
61
      String commonLogMessage = "Expected '" + value + "' to match with '" + shouldMatchTo + "'!";
1✔
62
      if (name != null) {
1✔
63
        throw new MojoExecutionException("Validation '" + name + "' failed! " + commonLogMessage);
1✔
64
      } else {
65
        throw new MojoExecutionException("Validation of an unidentified validation (please set the name property-tag to be able to identify the validation) failed! " + commonLogMessage);
×
66
      }
67
    }
68
  }
1✔
69

70
  private void printLogMessageWhenValueOrShouldMatchToIsEmpty(String name, String value, String shouldMatchTo) {
71
    String commonLogMessage = "since one of the values was null! (value = '" + value + "'; shouldMatchTo = '" + shouldMatchTo + "').";
1✔
72
    if (name != null) {
1✔
73
      getLog().warn("Skipping validation '" + name + "' " + commonLogMessage);
1✔
74
    } else {
75
      getLog().warn("Skipping an unidentified validation (please set the name property-tag to be able to identify the validation) " + commonLogMessage);
1✔
76
    }
77
  }
1✔
78

79
  public void setValidationShouldFailIfNoMatch(boolean validationShouldFailIfNoMatch) {
80
    this.validationShouldFailIfNoMatch = validationShouldFailIfNoMatch;
1✔
81
  }
1✔
82

83
  public void setValidationProperties(List<ValidationProperty> validationProperties) {
84
    this.validationProperties = validationProperties;
1✔
85
  }
1✔
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc