Skip to content

Commit

Permalink
[JENKINS-50508] extract dependencies to the "Static Code Analysis Plu…
Browse files Browse the repository at this point in the history
…g-ins", to the package hudson.plugins.analysis.core or other plugins outside of org.jenkinsci.plugins.pipeline.maven.MavenPublisher sub classes to prevent class loading issues and NPE when the related plugins are not installed.
  • Loading branch information
Cyrille Le Clerc committed Apr 8, 2018
1 parent bef24d2 commit c0a4a2b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Expand Up @@ -63,10 +63,15 @@ public void setThresholdLimit(String thresholdLimit) {
this.thresholdLimit = thresholdLimit;
}

protected void setHealthAwarePublisherAttributes(HealthAwarePublisher healthAwarePublisher) {
healthAwarePublisher.setHealthy(this.healthy);
healthAwarePublisher.setUnHealthy(this.unHealthy);
healthAwarePublisher.setThresholdLimit(this.thresholdLimit);
/**
* WARNING due to <a href="https://issues.jenkins-ci.org/browse/JENKINS-50508">JENKINS-50508</a>, the MUST be NO reference to
* any class of the and of the <a href="https://wiki.jenkins.io/display/JENKINS/Static+Code+Analysis+Plug-ins">Static Code Analysis Plug-ins</a>
* and to its package "{@code hudson.plugins.analysis.core}".
*
* @param healthAwarePublisher typed as an @{code Object} instead of being typed as a {@code hudson.plugins.analysis.core.HealthAwarePublisher} due to JENKINS-50508
*/
protected void setHealthAwarePublisherAttributes(Object healthAwarePublisher) {
Helper.setHealthAwarePublisherAttributes(healthAwarePublisher, this);
}

/**
Expand All @@ -77,4 +82,17 @@ public static abstract class DescriptorImpl extends MavenPublisher.DescriptorImp
}


/**
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a>
*/
static class Helper {
protected static void setHealthAwarePublisherAttributes(Object healthAwarePublisherAsObject, AbstractHealthAwarePublisher abstractHealthAwarePublisher) {
if (healthAwarePublisherAsObject instanceof HealthAwarePublisher) {
HealthAwarePublisher healthAwarePublisher = (HealthAwarePublisher) healthAwarePublisherAsObject;
healthAwarePublisher.setHealthy(abstractHealthAwarePublisher.getHealthy());
healthAwarePublisher.setUnHealthy(abstractHealthAwarePublisher.getUnHealthy());
healthAwarePublisher.setThresholdLimit(abstractHealthAwarePublisher.getThresholdLimit());
}
}
}
}
Expand Up @@ -33,7 +33,6 @@
import hudson.plugins.findbugs.FindBugsPublisher;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
import org.jenkinsci.plugins.pipeline.maven.MavenSpyLogProcessor;
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down
Expand Up @@ -6,13 +6,9 @@
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
import hudson.plugins.tasks.TasksPublisher;
import hudson.plugins.tasks.TasksResultAction;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
import org.jenkinsci.plugins.pipeline.maven.util.XmlUtils;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
Expand Down Expand Up @@ -41,32 +37,32 @@ public class TasksScannerPublisher extends AbstractHealthAwarePublisher {
/**
* Coma separated high priority task identifiers
*
* @see TasksPublisher#getHigh()
* @see hudson.plugins.tasks.TasksPublisher#getHigh()
*/
private String highPriorityTaskIdentifiers = "";
/**
* @see TasksPublisher#getNormal()
* @see hudson.plugins.tasks.TasksPublisher#getNormal()
*/
private String normalPriorityTaskIdentifiers = "";
/**
* @see TasksPublisher#getLow()
* @see hudson.plugins.tasks.TasksPublisher#getLow()
*/
private String lowPriorityTaskIdentifiers = "";
/**
* @see TasksPublisher#getIgnoreCase()
* @see hudson.plugins.tasks.TasksPublisher#getIgnoreCase()
*/
private boolean ignoreCase = false;
/**
* @see TasksPublisher#getPattern()
* @see hudson.plugins.tasks.TasksPublisher#getPattern()
*/
private String pattern = "";
/**
* @see TasksPublisher#getExcludePattern()
* @see hudson.plugins.tasks.TasksPublisher#getExcludePattern()
*/
private String excludePattern = "";

/**
* @see TasksPublisher#getAsRegexp()
* @see hudson.plugins.tasks.TasksPublisher#getAsRegexp()
*/
private boolean asRegexp = false;

Expand Down Expand Up @@ -153,12 +149,12 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
}

// To avoid duplicates
TasksResultAction tasksResult = run.getAction(TasksResultAction.class);
hudson.plugins.tasks.TasksResultAction tasksResult = run.getAction(hudson.plugins.tasks.TasksResultAction.class);
if (tasksResult != null) {
run.removeAction(tasksResult);
}

TasksPublisher tasksPublisher = new TasksPublisher();
hudson.plugins.tasks.TasksPublisher tasksPublisher = new hudson.plugins.tasks.TasksPublisher();
String pattern = StringUtils.isEmpty(this.pattern)? XmlUtils.join(sourceDirectoriesPatterns, ",") : this.pattern;
tasksPublisher.setPattern(pattern);
tasksPublisher.setExcludePattern(StringUtils.trimToNull(this.excludePattern));
Expand Down

0 comments on commit c0a4a2b

Please sign in to comment.