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