Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[FIXED JENKINS-10027] Added new tokens for new and fixed warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jul 6, 2011
1 parent d6c5783 commit ad3664d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 23 deletions.
Expand Up @@ -12,15 +12,14 @@
public class AbstractAnnotationsCountTokenMacro extends AbstractTokenMacro {
/**
* Creates a new instance of {@link AbstractAnnotationsCountTokenMacro}.
*
* @param resultAction
* the associated action containing the build result
* @param tokenName
* the name of the token
* @param resultActions
* associated actions containing the build result
*/
public AbstractAnnotationsCountTokenMacro(final Class<? extends ResultAction<? extends BuildResult>> resultAction,
final String tokenName) {
super(resultAction, tokenName);
public AbstractAnnotationsCountTokenMacro(final String tokenName,
final Class<? extends ResultAction<? extends BuildResult>>... resultActions) {
super(tokenName, resultActions);
}

@Override
Expand Down
@@ -0,0 +1,30 @@
package hudson.plugins.analysis.tokens;

import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ResultAction;

/**
* Provides a token that evaluates to the number of fixed annotations found by a
* plug-in.
*
* @author Ulli Hafner
*/
public class AbstractFixedAnnotationsTokenMacro extends AbstractTokenMacro {
/**
* Creates a new instance of {@link AbstractFixedAnnotationsTokenMacro}.
* @param tokenName
* the name of the token
* @param resultActions
* associated actions containing the build result
*/
public AbstractFixedAnnotationsTokenMacro(final String tokenName,
final Class<? extends ResultAction<? extends BuildResult>>... resultActions) {
super(tokenName, resultActions);
}

@Override
protected String evaluate(final BuildResult result) {
return String.valueOf(result.getNumberOfFixedWarnings());
}
}

@@ -0,0 +1,30 @@
package hudson.plugins.analysis.tokens;

import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.ResultAction;

/**
* Provides a token that evaluates to the number of new annotations found by a
* plug-in.
*
* @author Ulli Hafner
*/
public class AbstractNewAnnotationsTokenMacro extends AbstractTokenMacro {
/**
* Creates a new instance of {@link AbstractNewAnnotationsTokenMacro}.
* @param tokenName
* the name of the token
* @param resultActions
* associated actions containing the build result
*/
public AbstractNewAnnotationsTokenMacro(final String tokenName,
final Class<? extends ResultAction<? extends BuildResult>>... resultActions) {
super(tokenName, resultActions);
}

@Override
protected String evaluate(final BuildResult result) {
return String.valueOf(result.getNumberOfNewWarnings());
}
}

Expand Up @@ -11,15 +11,14 @@
public class AbstractResultTokenMacro extends AbstractTokenMacro {
/**
* Creates a new instance of {@link AbstractResultTokenMacro}.
*
* @param resultAction
* the associated action containing the build result
* @param tokenName
* the name of the token
* @param resultActions
* associated actions containing the build result
*/
public AbstractResultTokenMacro(final Class<? extends ResultAction<? extends BuildResult>> resultAction,
final String tokenName) {
super(resultAction, tokenName);
public AbstractResultTokenMacro(final String tokenName,
final Class<? extends ResultAction<? extends BuildResult>>... resultActions) {
super(tokenName, resultActions);
}

@Override
Expand Down
Expand Up @@ -17,34 +17,35 @@
* @author Ulli Hafner
*/
public abstract class AbstractTokenMacro extends DataBoundTokenMacro {
private final Class<? extends ResultAction<? extends BuildResult>> resultAction;
private final Class<? extends ResultAction<? extends BuildResult>>[] resultActions;
private final String tokenName;

/**
* Creates a new instance of {@link AbstractTokenMacro}.
*
* @param resultAction
* the associated action containing the build result
* @param tokenName
* the name of the token
* @param resultActions
* associated action types containing the build result
*/
public AbstractTokenMacro(final Class<? extends ResultAction<? extends BuildResult>> resultAction,
final String tokenName) {
public AbstractTokenMacro(final String tokenName,
final Class<? extends ResultAction<? extends BuildResult>>... resultActions) {
super();

this.resultAction = resultAction;
this.resultActions = resultActions;
this.tokenName = tokenName;
}

@Override
public String evaluate(final AbstractBuild<?, ?> context, final TaskListener listener, final String macroName)
throws MacroEvaluationException, IOException, InterruptedException {
ResultAction<? extends BuildResult> action = context.getAction(resultAction);
if (action == null) {
return "";
for (Class<? extends ResultAction<? extends BuildResult>> resultActionType : resultActions) {
ResultAction<? extends BuildResult> action = context.getAction(resultActionType);
if (action != null) {
return evaluate(action.getResult());
}
}

return evaluate(action.getResult());
return "";
}

/**
Expand Down

0 comments on commit ad3664d

Please sign in to comment.