1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm;
20
21 import java.io.Serializable;
22 import java.util.regex.Matcher;
23 import java.util.regex.Pattern;
24
25
26
27
28
29 public class ScmResult implements Serializable {
30 private static final long serialVersionUID = 7037918334820621525L;
31
32 private final boolean success;
33
34 private final String providerMessage;
35
36 private final String commandOutput;
37
38 private final String commandLine;
39
40 public static final String PASSWORD_PLACE_HOLDER = "********";
41
42
43 private Pattern patternForUserColonPasswordAtHost = Pattern.compile("^.*:(.*)@.*$", Pattern.DOTALL);
44
45
46
47
48
49
50
51
52
53 public ScmResult(ScmResult scmResult) {
54 this.commandLine = scmResult.commandLine;
55
56 this.providerMessage = scmResult.providerMessage;
57
58 this.commandOutput = masked(scmResult.commandOutput);
59
60 this.success = scmResult.success;
61 }
62
63
64
65
66
67
68
69
70
71 public ScmResult(String commandLine, String providerMessage, String commandOutput, boolean success) {
72 this.commandLine = commandLine;
73
74 this.providerMessage = providerMessage;
75
76 this.commandOutput = masked(commandOutput);
77
78 this.success = success;
79 }
80
81
82
83
84 public boolean isSuccess() {
85 return success;
86 }
87
88
89
90
91
92 public String getProviderMessage() {
93 return providerMessage;
94 }
95
96
97
98
99
100 public String getCommandOutput() {
101 return commandOutput;
102 }
103
104
105
106
107 public String getCommandLine() {
108 return commandLine;
109 }
110
111 private String masked(String commandOutput) {
112 if (null != commandOutput) {
113 final Matcher passwordMatcher = patternForUserColonPasswordAtHost.matcher(commandOutput);
114 if (passwordMatcher.find()) {
115
116 final String clearPassword = passwordMatcher.group(1);
117
118 commandOutput = commandOutput.replace(clearPassword, PASSWORD_PLACE_HOLDER);
119 }
120 }
121 return commandOutput;
122 }
123 }