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 public class ScmResult implements Serializable {
29 private static final long serialVersionUID = 7037918334820621525L;
30
31 private final boolean success;
32
33 private final String providerMessage;
34
35 private final String commandOutput;
36
37 private final String commandLine;
38
39 public static final String PASSWORD_PLACE_HOLDER = "********";
40
41
42 private Pattern patternForUserColonPasswordAtHost = Pattern.compile("^.*:(.*)@.*$", Pattern.DOTALL);
43
44
45
46
47
48
49
50
51
52 public ScmResult(ScmResult scmResult) {
53 this.commandLine = scmResult.commandLine;
54
55 this.providerMessage = scmResult.providerMessage;
56
57 this.commandOutput = masked(scmResult.commandOutput);
58
59 this.success = scmResult.success;
60 }
61
62
63
64
65
66
67
68
69
70 public ScmResult(String commandLine, String providerMessage, String commandOutput, boolean success) {
71 this.commandLine = commandLine;
72
73 this.providerMessage = providerMessage;
74
75 this.commandOutput = masked(commandOutput);
76
77 this.success = success;
78 }
79
80
81
82
83 public boolean isSuccess() {
84 return success;
85 }
86
87
88
89
90
91 public String getProviderMessage() {
92 return providerMessage;
93 }
94
95
96
97
98
99 public String getCommandOutput() {
100 return commandOutput;
101 }
102
103
104
105
106 public String getCommandLine() {
107 return commandLine;
108 }
109
110 private String masked(String commandOutput) {
111 if (null != commandOutput) {
112 final Matcher passwordMatcher = patternForUserColonPasswordAtHost.matcher(commandOutput);
113 if (passwordMatcher.find()) {
114
115 final String clearPassword = passwordMatcher.group(1);
116
117 commandOutput = commandOutput.replace(clearPassword, PASSWORD_PLACE_HOLDER);
118 }
119 }
120 return commandOutput;
121 }
122 }