1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.enforcer.rules;
20
21 import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule;
22 import org.apache.maven.model.InputLocation;
23 import org.apache.maven.project.MavenProject;
24
25
26
27
28
29
30
31 public abstract class AbstractStandardEnforcerRule extends AbstractEnforcerRule {
32
33 private String message;
34
35 public String getMessage() {
36 return message;
37 }
38
39 public void setMessage(String message) {
40 this.message = message;
41 }
42
43
44
45
46
47
48 private static String getProjectId(MavenProject project) {
49 StringBuilder buffer = new StringBuilder(128);
50
51 buffer.append(
52 (project.getGroupId() != null && project.getGroupId().length() > 0)
53 ? project.getGroupId()
54 : "[unknown-group-id]");
55 buffer.append(':');
56 buffer.append(
57 (project.getArtifactId() != null && project.getArtifactId().length() > 0)
58 ? project.getArtifactId()
59 : "[unknown-artifact-id]");
60 buffer.append(':');
61 buffer.append(
62 (project.getVersion() != null && project.getVersion().length() > 0)
63 ? project.getVersion()
64 : "[unknown-version]");
65
66 return buffer.toString();
67 }
68
69
70
71
72
73
74
75
76
77 protected static String formatLocation(MavenProject project, InputLocation location) {
78 StringBuilder buffer = new StringBuilder();
79
80 if (!location.getSource().getModelId().equals(getProjectId(project))) {
81 buffer.append(location.getSource().getModelId());
82
83 if (location.getSource().getLocation().length() > 0) {
84 if (buffer.length() > 0) {
85 buffer.append(", ");
86 }
87 buffer.append(location.getSource().getLocation());
88 }
89 }
90 if (location.getLineNumber() > 0) {
91 if (buffer.length() > 0) {
92 buffer.append(", ");
93 }
94 buffer.append("line ").append(location.getLineNumber());
95 }
96 if (location.getColumnNumber() > 0) {
97 if (buffer.length() > 0) {
98 buffer.append(", ");
99 }
100 buffer.append("column ").append(location.getColumnNumber());
101 }
102 return buffer.toString();
103 }
104 }