Skip to content

Commit

Permalink
[FIXED JENKINS-30135] Holds label expressions instead to label instan…
Browse files Browse the repository at this point in the history
…ces.
  • Loading branch information
ikedam committed Aug 30, 2015
1 parent 9cf81f2 commit aa54184
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
Expand Up @@ -23,6 +23,7 @@
*/
package jp.ikedam.jenkins.plugins.groovy_label_assignment;

import jenkins.model.Jenkins;
import hudson.model.Label;
import hudson.model.labels.LabelAssignmentAction;
import hudson.model.queue.SubTask;
Expand All @@ -32,16 +33,39 @@
*/
public class GroovyLabelAssignmentAction implements LabelAssignmentAction
{
private Label label;
@Deprecated
transient private Label label;

private final String labelString;

/**
* Constructor
*
* @param label assigned label.
* @param labelString assigned label expression.
* @since 1.1.1
*/
public GroovyLabelAssignmentAction(String labelString)
{
this.labelString = labelString;
}

/**
* @param label
* @deprecated use {@link GroovyLabelAssignmentAction#GroovyLabelAssignmentAction(String)}
*/
@Deprecated
public GroovyLabelAssignmentAction(Label label)
{
this.label = label;
this(label.getExpression());
}

private Object readResolve()
{
if(label != null)
{
return new GroovyLabelAssignmentAction(label.getExpression());
}
return this;
}

/**
Expand Down Expand Up @@ -89,7 +113,7 @@ public String getUrlName()
@Override
public Label getAssignedLabel(SubTask task)
{
return label;
return getAssignedLabel();
}


Expand All @@ -102,6 +126,15 @@ public Label getAssignedLabel(SubTask task)
*/
public Label getAssignedLabel()
{
return label;
return Jenkins.getInstance().getLabel(getLabelString());
}

/**
* @return the expression string for the assigned label.
* @since 1.1.1
*/
public String getLabelString()
{
return labelString;
}
}
Expand Up @@ -139,18 +139,17 @@ public boolean assignLabel(AbstractProject<?, ?> project, List<Action> actions)
return true;
}

Label label;
try
{
label = LabelExpression.parseExpression(labelString);
LabelExpression.parseExpression(labelString);
}
catch(ANTLRException e)
{
LOGGER.log(Level.SEVERE, String.format("%s: Invalid label string: %s", project.getName(), labelString), e);
return false;
}

LabelAssignmentAction labelAction = new GroovyLabelAssignmentAction(label);
LabelAssignmentAction labelAction = new GroovyLabelAssignmentAction(labelString);
actions.add(0, labelAction);

LOGGER.info(String.format("%s: label is modified to %s", project.getName(), labelString));
Expand Down
Expand Up @@ -29,7 +29,7 @@ THE SOFTWARE.
<t:summary icon="computer.png">
<l:pane title="${%Assigned Label}" width="3">
<f:block>
${it.assignedLabel.expression}
${it.labelString}
</f:block>
</l:pane>
</t:summary>
Expand Down

0 comments on commit aa54184

Please sign in to comment.