@@ -55,6 +55,11 @@ public PlasticSCM(String workspaceName, String selector, String workfolder, bool
55
55
this .useUpdate = useUpdate ;
56
56
}
57
57
58
+ /**
59
+ * This is a getter for Hudson only! Don't use it
60
+ * See getWorkspace() instead or better use the WorkSpaceConfig from getWorkspaceConfigurationForBuild()!
61
+ * @return the raw string that is set in build config
62
+ */
58
63
public String getWorkspaceName () {
59
64
return workspaceName ;
60
65
}
@@ -75,20 +80,57 @@ public boolean isUseUpdate() {
75
80
public ChangeLogParser createChangeLogParser () {
76
81
return new ChangeSetReader ();
77
82
}
78
-
79
- String getWorkspace (AbstractBuild <?,?> build , Computer computer ) {
83
+
84
+ protected WorkspaceConfiguration getWorkspaceConfigurationForBuild (AbstractBuild build )
85
+ {
86
+ return new WorkspaceConfiguration (
87
+ normalizeAndEvaluateWorkspaceNameStringForBuild (build ),
88
+ selector ,
89
+ workfolder
90
+ );
91
+ }
92
+
93
+ protected WorkspaceConfiguration getWorkspaceConfigurationForJob (Job job )
94
+ {
95
+ return new WorkspaceConfiguration (
96
+ normalizeAndEvaluateWorkspaceNameStringForJob (job ),
97
+ selector ,
98
+ workfolder
99
+ );
100
+ }
101
+
102
+ private String normalizeAndEvaluateWorkspaceNameStringForBuild (AbstractBuild <?,?> build ) {
80
103
normalizedWorkspace = workspaceName ;
81
-
104
+
82
105
if (build != null ) {
83
106
normalizedWorkspace = substituteBuildParameter (build , normalizedWorkspace );
84
- normalizedWorkspace = Util . replaceMacro ( normalizedWorkspace , new BuildVariableResolver ( build .getProject (), computer ) );
107
+ normalizedWorkspace = substituteJobParameter ( build .getProject (), normalizedWorkspace );
85
108
}
86
- normalizedWorkspace = normalizedWorkspace .replaceAll ("[\" /:<>\\ |\\ *\\ ?]+" , "_" );
87
- normalizedWorkspace = normalizedWorkspace .replaceAll ("[\\ .\\ s]+$" , "_" );
109
+ normalizedWorkspace = substituteInvalidCharacters (normalizedWorkspace );
110
+ return normalizedWorkspace ;
111
+ }
112
+
113
+ private String normalizeAndEvaluateWorkspaceNameStringForJob (Job <?,?> job ) {
114
+ normalizedWorkspace = workspaceName ;
115
+
116
+ if (job != null ) {
117
+ normalizedWorkspace = substituteJobParameter (job , normalizedWorkspace );
118
+ }
119
+ normalizedWorkspace = substituteInvalidCharacters (normalizedWorkspace );
88
120
89
121
return normalizedWorkspace ;
90
122
}
91
123
124
+ private String substituteInvalidCharacters (String text ) {
125
+ text = text .replaceAll ("[\" /:<>\\ |\\ *\\ ?]+" , "_" );
126
+ text = text .replaceAll ("[\\ .\\ s]+$" , "_" );
127
+ return text ;
128
+ }
129
+
130
+ private String substituteJobParameter (Job <?,?> prj , String text ) {
131
+ return Util .replaceMacro (text , new BuildVariableResolver (prj , Computer .currentComputer ()));
132
+ }
133
+
92
134
private String substituteBuildParameter (Run <?,?> run , String text ) {
93
135
if (run instanceof AbstractBuild <?,?>) {
94
136
AbstractBuild <?,?> build = (AbstractBuild <?,?>)run ;
@@ -104,7 +146,7 @@ private String substituteBuildParameter(Run<?,?> run, String text) {
104
146
public boolean checkout (AbstractBuild build , Launcher launcher , FilePath workspaceFilePath ,
105
147
BuildListener listener , File changelogFile ) throws IOException , InterruptedException {
106
148
Server server = new Server (new PlasticTool (getDescriptor ().getCmExecutable (), launcher , listener , workspaceFilePath ));
107
- WorkspaceConfiguration workspaceConfiguration = new WorkspaceConfiguration ( getWorkspace ( build , Computer . currentComputer ()), selector , workfolder );
149
+ WorkspaceConfiguration workspaceConfiguration = getWorkspaceConfigurationForBuild ( build );
108
150
109
151
if (build .getPreviousBuild () != null ) {
110
152
BuildWorkspaceConfiguration nodeConfiguration = new BuildWorkspaceConfigurationRetriever ().getLatestForNode (build .getBuiltOn (), build .getPreviousBuild ());
@@ -135,11 +177,13 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
135
177
@ Override
136
178
public boolean pollChanges (AbstractProject hudsonProject , Launcher launcher , FilePath workspaceFilePath , TaskListener listener ) throws IOException , InterruptedException {
137
179
Run <?,?> lastRun = hudsonProject .getLastBuild ();
180
+
138
181
if (lastRun == null ) {
139
182
return true ;
140
183
} else {
184
+ WorkspaceConfiguration workspaceConfiguration = getWorkspaceConfigurationForJob (lastRun .getParent ());
141
185
Server server = new Server (new PlasticTool (getDescriptor ().getCmExecutable (), launcher , listener , workspaceFilePath ));
142
- Workspace workspace = server .getWorkspaces ().getWorkspace (workspaceName );
186
+ Workspace workspace = server .getWorkspaces ().getWorkspace (workspaceConfiguration . getWorkspaceName () );
143
187
try {
144
188
return (workspace .getBriefHistory (lastRun .getTimestamp (), Calendar .getInstance ()).size () > 0 );
145
189
} catch (ParseException e ) {
0 commit comments