Skip to content
Permalink
Browse files

[FIXED JENKINS-30135] Holds label expressions instead to label instan…

…ces.
  • Loading branch information...
ikedam committed Aug 30, 2015
1 parent 9cf81f2 commit aa5418495e71e4e2728b709d78649492928fbbb4
@@ -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;
@@ -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;
}

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


@@ -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;
}
}
@@ -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));
@@ -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>

0 comments on commit aa54184

Please sign in to comment.
You can’t perform that action at this time.