Skip to content

Commit 50a9daf

Browse files
committed
MacroStringHelper methods are interruptable
Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
1 parent bdaca59 commit 50a9daf

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public static PerforceSCMDescriptor getInstance() {
452452
protected Depot getDepot(@Nonnull Launcher launcher, @Nonnull FilePath workspace,
453453
@CheckForNull AbstractProject project,
454454
@CheckForNull AbstractBuild build, @CheckForNull Node node)
455-
throws ParameterSubstitutionException {
455+
throws ParameterSubstitutionException, InterruptedException {
456456
HudsonP4ExecutorFactory p4Factory = new HudsonP4ExecutorFactory(launcher,workspace);
457457

458458
Depot depot = new Depot(p4Factory);
@@ -519,28 +519,25 @@ public void buildEnvVars(@Nonnull AbstractBuild build, @Nonnull Map<String, Stri
519519
super.buildEnvVars(build, env);
520520
try {
521521
env.put("P4PORT", MacroStringHelper.substituteParameters(p4Port, this, build, env));
522-
env.put("P4USER", MacroStringHelper.substituteParameters(p4User, this, build, env));
522+
env.put("P4USER", MacroStringHelper.substituteParameters(p4User, this, build, env));
523+
524+
// if we want to allow p4 commands in script steps this helps
525+
if (isExposeP4Passwd()) {
526+
PerforcePasswordEncryptor encryptor = new PerforcePasswordEncryptor();
527+
env.put("P4PASSWD", encryptor.decryptString(p4Passwd));
528+
}
529+
// this may help when tickets are used since we are
530+
// not storing the ticket on the client during login
531+
if (p4Ticket != null) {
532+
env.put("P4TICKET", p4Ticket);
533+
}
534+
535+
env.put("P4CLIENT", getConcurrentClientName(build.getWorkspace(), getEffectiveClientName(build, env)));
523536
} catch (ParameterSubstitutionException ex) {
524-
LOGGER.log(MacroStringHelper.SUBSTITUTION_ERROR_LEVEL, "Can't substitute P4USER or P4PORT", ex);
525-
//TODO: exit?
526-
}
527-
528-
// if we want to allow p4 commands in script steps this helps
529-
if (isExposeP4Passwd()) {
530-
PerforcePasswordEncryptor encryptor = new PerforcePasswordEncryptor();
531-
env.put("P4PASSWD", encryptor.decryptString(p4Passwd));
532-
}
533-
// this may help when tickets are used since we are
534-
// not storing the ticket on the client during login
535-
if (p4Ticket != null) {
536-
env.put("P4TICKET", p4Ticket);
537-
}
538-
539-
try {
540-
env.put("P4CLIENT", getConcurrentClientName(build.getWorkspace(), getEffectiveClientName(build, env)));
541-
} catch(ParameterSubstitutionException ex) {
542-
LOGGER.log(MacroStringHelper.SUBSTITUTION_ERROR_LEVEL, "Can't substitute P4CLIENT",ex);
537+
LOGGER.log(MacroStringHelper.SUBSTITUTION_ERROR_LEVEL, "Cannot build environent variables due to unresolved macros", ex);
543538
//TODO: exit?
539+
} catch (InterruptedException ex) {
540+
LOGGER.log(MacroStringHelper.SUBSTITUTION_ERROR_LEVEL, "Cannot build environment vars. The method has been interrupted");
544541
}
545542

546543
PerforceTagAction pta = build.getAction(PerforceTagAction.class);
@@ -660,7 +657,7 @@ private String getEffectiveProjectPath(
660657
@CheckForNull Node node,
661658
@Nonnull PrintStream log,
662659
@Nonnull Depot depot)
663-
throws PerforceException, ParameterSubstitutionException {
660+
throws PerforceException, ParameterSubstitutionException, InterruptedException {
664661
String effectiveProjectPath = useClientSpec
665662
? getEffectiveProjectPathFromFile(build, project, node, log, depot)
666663
: MacroStringHelper.substituteParameters(this.projectPath, this, build, project, node, null);
@@ -672,7 +669,8 @@ private String getEffectiveProjectPathFromFile(
672669
@CheckForNull AbstractBuild build,
673670
@CheckForNull AbstractProject project,
674671
@CheckForNull Node node,
675-
@Nonnull PrintStream log, @Nonnull Depot depot) throws PerforceException, ParameterSubstitutionException {
672+
@Nonnull PrintStream log, @Nonnull Depot depot)
673+
throws PerforceException, ParameterSubstitutionException, InterruptedException {
676674
String effectiveClientSpec =
677675
MacroStringHelper.substituteParameters(this.clientSpec, this, build, project, node, null);
678676
log.println("Read ClientSpec from: " + effectiveClientSpec);
@@ -1166,7 +1164,7 @@ private synchronized int getOrSetMatrixChangeSet(
11661164
@Nonnull AbstractBuild build,
11671165
@Nonnull Depot depot, int newestChange, String projectPath,
11681166
@Nonnull PrintStream log)
1169-
throws ParameterSubstitutionException
1167+
throws ParameterSubstitutionException, InterruptedException
11701168
{
11711169
int matrixLastChange = 0;
11721170
// special consideration for matrix builds
@@ -1427,7 +1425,7 @@ private SCMRevisionState getCurrentDepotRevisionState(
14271425
*/
14281426
private boolean isChangelistExcluded(Changelist changelist,
14291427
AbstractProject project, Node node, String view, PrintStream logger)
1430-
throws ParameterSubstitutionException
1428+
throws ParameterSubstitutionException, InterruptedException
14311429
{
14321430
if (changelist == null) {
14331431
return false;
@@ -1695,7 +1693,8 @@ else if (localPath.trim().equals(""))
16951693
return p4workspace;
16961694
}
16971695

1698-
private String getEffectiveClientName(AbstractBuild build, Map<String,String> env) throws ParameterSubstitutionException {
1696+
private String getEffectiveClientName(AbstractBuild build, Map<String,String> env)
1697+
throws ParameterSubstitutionException, InterruptedException {
16991698
Node buildNode = build.getBuiltOn();
17001699
FilePath workspace = build.getWorkspace();
17011700
String effectiveP4Client = this.p4Client;
@@ -2559,14 +2558,15 @@ public String getDecryptedP4Passwd() {
25592558
return encryptor.decryptString(p4Passwd);
25602559
}
25612560

2562-
public String getDecryptedP4Passwd(AbstractBuild build) throws ParameterSubstitutionException {
2561+
public String getDecryptedP4Passwd(AbstractBuild build)
2562+
throws ParameterSubstitutionException, InterruptedException {
25632563
return MacroStringHelper.substituteParameters(getDecryptedP4Passwd(), this, build, null);
25642564
}
25652565

25662566
/**
25672567
* @deprecated Use {@link #getDecryptedP4Passwd(hudson.model.AbstractProject, hudson.model.Node)} instead.
25682568
*/
2569-
public String getDecryptedP4Passwd(AbstractProject project) {
2569+
public String getDecryptedP4Passwd(AbstractProject project) throws InterruptedException {
25702570
try {
25712571
return getDecryptedP4Passwd(project, null);
25722572
} catch (ParameterSubstitutionException ex) {
@@ -2575,7 +2575,7 @@ public String getDecryptedP4Passwd(AbstractProject project) {
25752575
}
25762576

25772577
public String getDecryptedP4Passwd(@CheckForNull AbstractProject project, @CheckForNull Node node)
2578-
throws ParameterSubstitutionException {
2578+
throws ParameterSubstitutionException, InterruptedException {
25792579
return MacroStringHelper.substituteParameters(getDecryptedP4Passwd(),
25802580
this, project, node, null);
25812581
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public synchronized FormValidation doCheckTag(@QueryParameter String value) {
167167
/**
168168
* Invoked to actually tag the workspace.
169169
*/
170-
public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
170+
public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
171171
getACL().checkPermission(getPermission());
172172

173173
String tag = req.getParameter("name");
@@ -179,7 +179,7 @@ public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throw
179179
rsp.sendRedirect(".");
180180
}
181181

182-
public void tagBuild(String tagname, String description, String owner) throws IOException {
182+
public void tagBuild(String tagname, String description, String owner) throws IOException, InterruptedException {
183183
Label label = new Label();
184184
label.setName(tagname);
185185
label.setDescription(description);

src/main/java/hudson/plugins/perforce/utils/MacroStringHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static String substituteParameters(
7878
@CheckForNull AbstractProject project,
7979
@CheckForNull Node node,
8080
@CheckForNull Map<String, String> env)
81-
throws ParameterSubstitutionException {
81+
throws ParameterSubstitutionException, InterruptedException {
8282

8383
return build != null
8484
? substituteParameters(string, instance, build, env)
@@ -101,7 +101,7 @@ public static String substituteParameters(
101101
@CheckForNull AbstractProject project,
102102
@CheckForNull Node node,
103103
@CheckForNull Map<String, String> env)
104-
throws ParameterSubstitutionException {
104+
throws ParameterSubstitutionException, InterruptedException {
105105
if (string == null) return null;
106106
String result = substituteParametersNoCheck(string, instance, project, node, env);
107107
checkString(result);
@@ -139,7 +139,7 @@ public static String substituteParameters(
139139
@Nonnull PerforceSCM instance,
140140
@Nonnull AbstractBuild build,
141141
@CheckForNull Map<String, String> env)
142-
throws ParameterSubstitutionException {
142+
throws ParameterSubstitutionException, InterruptedException {
143143
if (string == null) return null;
144144
String result = substituteParametersNoCheck(string, instance, build, env);
145145
checkString(result);
@@ -207,7 +207,7 @@ private static String substituteParametersNoCheck (
207207
@Nonnull PerforceSCM instance,
208208
@CheckForNull AbstractProject project,
209209
@CheckForNull Node node,
210-
@CheckForNull Map<String, String> env) {
210+
@CheckForNull Map<String, String> env) throws InterruptedException {
211211

212212
if (!containsMacro(inputString)) { // do nothing for the missing macro
213213
return inputString;
@@ -247,7 +247,7 @@ private static String substituteParametersNoCheck(
247247
@Nonnull String inputString,
248248
@Nonnull PerforceSCM instance,
249249
@Nonnull AbstractBuild build,
250-
@CheckForNull Map<String, String> env) {
250+
@CheckForNull Map<String, String> env) throws InterruptedException {
251251

252252
if (!containsMacro(inputString)) {
253253
return inputString;

src/main/java/hudson/plugins/perforce/utils/NodeSubstitutionHelper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public class NodeSubstitutionHelper {
5959
/*package*/ static void getDefaultNodeSubstitutions(
6060
@Nonnull PerforceSCM instance,
6161
@CheckForNull Node node,
62-
@Nonnull Map<String, String> target) {
63-
62+
@Nonnull Map<String, String> target) throws InterruptedException {
6463
// Global node properties
6564
for (NodeProperty globalNodeProperty: Hudson.getInstance().getGlobalNodeProperties()) {
6665
if (globalNodeProperty instanceof EnvironmentVariablesNodeProperty) {
@@ -100,9 +99,6 @@ public class NodeSubstitutionHelper {
10099
target.putAll(env);
101100
} catch (IOException ex) {
102101
// Ignore exception
103-
} catch (InterruptedException ex) {
104-
// Ignore exception
105-
// TODO: Handle the exception
106102
}
107103
}
108104
}

0 commit comments

Comments
 (0)