Skip to content

Commit 2da2bf9

Browse files
committed
Merge pull request #54 from jenkinsci/variables_handling_refactoring
Variables handling refactoring
2 parents 5707a77 + a35f1fe commit 2da2bf9

File tree

8 files changed

+666
-305
lines changed

8 files changed

+666
-305
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ work
66
.classpath
77
.settings
88
.project
9-
.DS_Store
9+
.DS_Store
10+
11+
# Coverity
12+
/cov-int

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@
120120
<artifactId>commons-codec</artifactId>
121121
<version>1.4</version>
122122
</dependency>
123-
</dependencies>
123+
<dependency>
124+
<groupId>com.google.code.findbugs</groupId>
125+
<artifactId>jsr305</artifactId>
126+
<version>2.0.1</version>
127+
<type>jar</type>
128+
</dependency>
129+
</dependencies>
124130

125131
<distributionManagement>
126132
<repository>

src/main/java/hudson/plugins/perforce/PerforceSCM.java

Lines changed: 231 additions & 224 deletions
Large diffs are not rendered by default.

src/main/java/hudson/plugins/perforce/PerforceTagAction.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.regex.Matcher;
2020
import java.util.regex.Pattern;
2121
import java.util.List;
22+
import javax.annotation.CheckForNull;
2223
import org.kohsuke.stapler.QueryParameter;
2324
import org.kohsuke.stapler.export.Exported;
2425
import org.kohsuke.stapler.export.ExportedBean;
@@ -144,6 +145,14 @@ public String isInvalidTag(String tag) {
144145
}
145146
return null;
146147
}
148+
149+
@CheckForNull
150+
public PerforceSCM getSCM() {
151+
if(this.getBuild().getProject().getScm() instanceof PerforceSCM){
152+
return (PerforceSCM)this.getBuild().getProject().getScm();
153+
}
154+
return null;
155+
}
147156

148157
/**
149158
* Checks if the value is a valid Perforce tag (label) name.
@@ -158,7 +167,7 @@ public synchronized FormValidation doCheckTag(@QueryParameter String value) {
158167
/**
159168
* Invoked to actually tag the workspace.
160169
*/
161-
public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
170+
public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
162171
getACL().checkPermission(getPermission());
163172

164173
String tag = req.getParameter("name");
@@ -170,16 +179,16 @@ public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throw
170179
rsp.sendRedirect(".");
171180
}
172181

173-
public void tagBuild(String tagname, String description, String owner) throws IOException {
182+
public void tagBuild(String tagname, String description, String owner) throws IOException, InterruptedException {
174183
Label label = new Label();
175184
label.setName(tagname);
176185
label.setDescription(description);
177186
label.setRevision(new Integer(changeNumber).toString());
178187
if(owner!=null && !owner.equals("")) label.setOwner(owner);
179188

180-
if(this.getBuild().getProject().getScm() instanceof PerforceSCM){
181-
PerforceSCM scm = (PerforceSCM)this.getBuild().getProject().getScm();
182-
depot.setPassword(scm.getDecryptedP4Passwd(this.getBuild().getProject()));
189+
PerforceSCM scm = getSCM();
190+
if(scm != null){
191+
depot.setPassword(scm.getDecryptedP4Passwd(this.getBuild().getProject(), this.getBuild().getBuiltOn()));
183192
}
184193

185194
//Only take the depot paths and add them to the view.

src/main/java/hudson/plugins/perforce/PerforceTagNotifier.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,20 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
110110
return false;
111111
}
112112
}
113+
114+
PerforceSCM scm = tagAction.getSCM();
115+
if (scm == null) {
116+
listener.getLogger().println("Cannot retrieve the Perforce SCM");
117+
return false;
118+
}
113119

114120
listener.getLogger().println("Labelling Build in Perforce using " + rawLabelName);
115121

116122
String labelName, labelDesc, labelOwner;
117123
try {
118-
labelName = MacroStringHelper.substituteParameters(rawLabelName, build, null);
119-
labelDesc = MacroStringHelper.substituteParameters(rawLabelDesc, build, null);
120-
labelOwner = MacroStringHelper.substituteParameters(rawLabelOwner, build, null);
124+
labelName = MacroStringHelper.substituteParameters(rawLabelName, scm, build, null);
125+
labelDesc = MacroStringHelper.substituteParameters(rawLabelDesc, scm, build, null);
126+
labelOwner = MacroStringHelper.substituteParameters(rawLabelOwner, scm, build, null);
121127
} catch (ParameterSubstitutionException ex) {
122128
listener.getLogger().println("Parameter substitution error in label items. "+ex.getMessage());
123129
return false;

0 commit comments

Comments
 (0)