Skip to content
Permalink
Browse files

[FIXED JENKINS-21769] Don't load classes of optional plug-ins.

  • Loading branch information
uhafner committed Mar 9, 2014
1 parent ec464aa commit 2a79a3df74e5d61384cf00bd101f5d2c3a9eb04d
@@ -1,36 +1,26 @@
package hudson.plugins.analysis.collector; // NOPMD

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Launcher;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixBuild;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.plugins.analysis.collector.handler.*;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.core.HealthAwarePublisher;
import hudson.plugins.analysis.core.ParserResult;
import hudson.plugins.analysis.core.ResultAction;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.util.PluginLogger;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.checkstyle.CheckStyleMavenResultAction;
import hudson.plugins.checkstyle.CheckStyleResultAction;
import hudson.plugins.dry.DryMavenResultAction;
import hudson.plugins.dry.DryResultAction;
import hudson.plugins.findbugs.FindBugsMavenResultAction;
import hudson.plugins.findbugs.FindBugsResultAction;
import hudson.plugins.pmd.PmdMavenResultAction;
import hudson.plugins.pmd.PmdResultAction;
import hudson.plugins.tasks.TasksMavenResultAction;
import hudson.plugins.tasks.TasksResultAction;
import hudson.plugins.warnings.WarningsResultAction;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.kohsuke.stapler.DataBoundConstructor;

/**
* Collects the results of the various analysis plug-ins.
@@ -212,27 +202,22 @@ public boolean isWarningsActivated() {
pluginResults = new ArrayList<Class<? extends ResultAction<? extends BuildResult>>>();

if (AnalysisDescriptor.isCheckStyleInstalled() && isCheckStyleActivated()) {
pluginResults.add(CheckStyleResultAction.class);
pluginResults.add(CheckStyleMavenResultAction.class);
pluginResults.addAll(new CheckStyleHandler().getResultActions());
}
if (AnalysisDescriptor.isDryInstalled() && isDryActivated()) {
pluginResults.add(DryResultAction.class);
pluginResults.add(DryMavenResultAction.class);
pluginResults.addAll(new DryHandler().getResultActions());
}
if (AnalysisDescriptor.isFindBugsInstalled() && isFindBugsActivated()) {
pluginResults.add(FindBugsResultAction.class);
pluginResults.add(FindBugsMavenResultAction.class);
pluginResults.addAll(new FindBugsHandler().getResultActions());
}
if (AnalysisDescriptor.isPmdInstalled() && isPmdActivated()) {
pluginResults.add(PmdResultAction.class);
pluginResults.add(PmdMavenResultAction.class);
pluginResults.addAll(new PmdHandler().getResultActions());
}
if (AnalysisDescriptor.isOpenTasksInstalled() && isOpenTasksActivated()) {
pluginResults.add(TasksResultAction.class);
pluginResults.add(TasksMavenResultAction.class);
pluginResults.addAll(new TasksHandler().getResultActions());
}
if (AnalysisDescriptor.isWarningsInstalled() && isWarningsActivated()) {
pluginResults.add(WarningsResultAction.class);
pluginResults.addAll(new WarningsHandler().getResultActions());
}

return pluginResults;
@@ -5,15 +5,9 @@
import edu.umd.cs.findbugs.annotations.SuppressWarnings;

import hudson.model.Job;

import hudson.plugins.analysis.collector.handler.*;
import hudson.plugins.analysis.core.AbstractProjectAction;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.checkstyle.CheckStyleProjectAction;
import hudson.plugins.dry.DryProjectAction;
import hudson.plugins.findbugs.FindBugsProjectAction;
import hudson.plugins.pmd.PmdProjectAction;
import hudson.plugins.tasks.TasksProjectAction;
import hudson.plugins.warnings.AggregatedWarningsProjectAction;

/**
* Aggregates the warnings of the analysis plug-in from a single job.
@@ -138,7 +132,7 @@ public boolean isWarningsActivated() {
*/
public String getCheckStyle(final Job<?, ?> job) {
if (isCheckStyleActivated()) {
return getWarnings(job, CheckStyleProjectAction.class, "checkstyle");
return getWarnings(job, new CheckStyleHandler());
}
return NO_RESULTS_FOUND;
}
@@ -152,7 +146,7 @@ public String getCheckStyle(final Job<?, ?> job) {
*/
public String getDry(final Job<?, ?> job) {
if (isDryActivated()) {
return getWarnings(job, DryProjectAction.class, "dry");
return getWarnings(job, new DryHandler());
}
return NO_RESULTS_FOUND;
}
@@ -166,7 +160,7 @@ public String getDry(final Job<?, ?> job) {
*/
public String getFindBugs(final Job<?, ?> job) {
if (isFindBugsActivated()) {
return getWarnings(job, FindBugsProjectAction.class, "findbugs");
return getWarnings(job, new FindBugsHandler());
}
return NO_RESULTS_FOUND;
}
@@ -180,7 +174,7 @@ public String getFindBugs(final Job<?, ?> job) {
*/
public String getPmd(final Job<?, ?> job) {
if (isPmdActivated()) {
return getWarnings(job, PmdProjectAction.class, "pmd");
return getWarnings(job, new PmdHandler());
}
return NO_RESULTS_FOUND;
}
@@ -194,7 +188,7 @@ public String getPmd(final Job<?, ?> job) {
*/
public String getTasks(final Job<?, ?> job) {
if (isOpenTasksActivated()) {
return getWarnings(job, TasksProjectAction.class, "tasks");
return getWarnings(job, new TasksHandler());
}
return NO_RESULTS_FOUND;
}
@@ -208,7 +202,7 @@ public String getTasks(final Job<?, ?> job) {
*/
public String getCompilerWarnings(final Job<?, ?> job) {
if (isWarningsActivated()) {
return getWarnings(job, AggregatedWarningsProjectAction.class, "warnings");
return getWarnings(job, new WarningsHandler());
}
return NO_RESULTS_FOUND;
}
@@ -232,24 +226,22 @@ public String getTotal(final Job<?, ?> job) {
/**
* Returns the warnings for the specified action.
*
*
* @param job
* the job to get the action from
* @param actionType
* the type of the action
* @param plugin
* the plug-in that is target of the link
* @param handler
* the analysis plug-in handler
* @return the number of warnings
*/
@SuppressWarnings("NP")
private String getWarnings(final Job<?, ?> job, final Class<? extends AbstractProjectAction<?>> actionType,
final String plugin) {
AbstractProjectAction<?> action = job.getAction(actionType);
private String getWarnings(final Job<?, ?> job, final AnalysisHandler handler) {
AbstractProjectAction<?> action = job.getAction(handler.getProjectActionType());
if (action != null && action.hasValidResults()) {
BuildResult result = action.getLastAction().getResult();
int numberOfAnnotations = result.getNumberOfAnnotations();
String value;
if (numberOfAnnotations > 0) {
value = String.format("<a href=\"%s%s\">%d</a>", getJobPrefix(job), plugin, numberOfAnnotations);
value = String.format("<a href=\"%s%s\">%d</a>", getJobPrefix(job), handler.getUrl(), numberOfAnnotations);
}
else {
value = String.valueOf(numberOfAnnotations);
@@ -275,7 +267,7 @@ private String getJobPrefix(final Job<?, ?> job) {
*/
public boolean hasCheckStyle(final Job<?, ?> job) {
if (isCheckStyleActivated()) {
return hasAction(job, CheckStyleProjectAction.class);
return hasAction(job, new CheckStyleHandler());
}
return false;
}
@@ -289,7 +281,7 @@ public boolean hasCheckStyle(final Job<?, ?> job) {
*/
public boolean hasDry(final Job<?, ?> job) {
if (isDryActivated()) {
return hasAction(job, DryProjectAction.class);
return hasAction(job, new DryHandler());
}
return false;
}
@@ -303,7 +295,7 @@ public boolean hasDry(final Job<?, ?> job) {
*/
public boolean hasFindBugs(final Job<?, ?> job) {
if (isFindBugsActivated()) {
return hasAction(job, FindBugsProjectAction.class);
return hasAction(job, new FindBugsHandler());
}
return false;
}
@@ -317,7 +309,7 @@ public boolean hasFindBugs(final Job<?, ?> job) {
*/
public boolean hasPmd(final Job<?, ?> job) {
if (isPmdActivated()) {
return hasAction(job, PmdProjectAction.class);
return hasAction(job, new PmdHandler());
}
return false;
}
@@ -331,7 +323,7 @@ public boolean hasPmd(final Job<?, ?> job) {
*/
public boolean hasTasks(final Job<?, ?> job) {
if (isOpenTasksActivated()) {
return hasAction(job, TasksProjectAction.class);
return hasAction(job, new TasksHandler());
}
return false;
}
@@ -345,13 +337,13 @@ public boolean hasTasks(final Job<?, ?> job) {
*/
public boolean hasCompilerWarnings(final Job<?, ?> job) {
if (isWarningsActivated()) {
return hasAction(job, AggregatedWarningsProjectAction.class);
return hasAction(job, new WarningsHandler());
}
return false;
}

private boolean hasAction(final Job<?, ?> job, final Class<? extends AbstractProjectAction<?>> actionType) {
AbstractProjectAction<?> action = job.getAction(actionType);
private boolean hasAction(final Job<?, ?> job, final AnalysisHandler handler) {
AbstractProjectAction<?> action = job.getAction(handler.getProjectActionType());

return action != null && action.hasValidResults();
}
@@ -1,25 +1,17 @@
package hudson.plugins.analysis.collector;

import jenkins.model.Jenkins;

import org.jvnet.localizer.Localizable;
import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import jenkins.model.Jenkins;

import hudson.Extension;
import hudson.model.Job;

import hudson.plugins.analysis.collector.handler.*;
import hudson.plugins.analysis.core.PluginDescriptor;
import hudson.plugins.analysis.util.HtmlPrinter;
import hudson.plugins.checkstyle.CheckStyleDescriptor;
import hudson.plugins.dry.DryDescriptor;
import hudson.plugins.findbugs.FindBugsDescriptor;
import hudson.plugins.pmd.PmdDescriptor;
import hudson.plugins.tasks.TasksDescriptor;
import hudson.plugins.warnings.WarningsDescriptor;

import hudson.views.ListViewColumnDescriptor;
import hudson.views.ListViewColumn;
import hudson.views.ListViewColumnDescriptor;

/**
* A column that shows the total number of warnings in a job.
@@ -131,33 +123,31 @@ public String getDetails(final Job<?, ?> job) {
HtmlPrinter printer = new HtmlPrinter();
printer.append("<table>");
if (isCheckStyleActivated()) {
printLine(printer, hudson.plugins.checkstyle.Messages._Checkstyle_Detail_header(),
warningsAggregator.getCheckStyle(job), CheckStyleDescriptor.class);
printLine(printer, new CheckStyleHandler(), warningsAggregator.getCheckStyle(job));
}
if (isDryActivated()) {
printLine(printer, hudson.plugins.dry.Messages._DRY_Detail_header(),
warningsAggregator.getDry(job), DryDescriptor.class);
printLine(printer, new DryHandler(), warningsAggregator.getDry(job));
}
if (isFindBugsActivated()) {
printLine(printer, hudson.plugins.findbugs.Messages._FindBugs_Detail_header(),
warningsAggregator.getFindBugs(job), FindBugsDescriptor.class);
printLine(printer, new FindBugsHandler(), warningsAggregator.getFindBugs(job));
}
if (isPmdActivated()) {
printLine(printer, hudson.plugins.pmd.Messages._PMD_Detail_header(),
warningsAggregator.getPmd(job), PmdDescriptor.class);
printLine(printer, new PmdHandler(), warningsAggregator.getPmd(job));
}
if (isOpenTasksActivated()) {
printLine(printer, hudson.plugins.tasks.Messages._Tasks_ProjectAction_Name(),
warningsAggregator.getTasks(job), TasksDescriptor.class);
printLine(printer, new TasksHandler(), warningsAggregator.getTasks(job));
}
if (isWarningsActivated()) {
printLine(printer, hudson.plugins.warnings.Messages._Warnings_ProjectAction_Name(),
warningsAggregator.getCompilerWarnings(job), WarningsDescriptor.class);
printLine(printer, new WarningsHandler(), warningsAggregator.getCompilerWarnings(job));
}
printer.append("</table>");
return printer.toString();
}

private void printLine(final HtmlPrinter printer, final AnalysisHandler handler, final String warnings) {
printLine(printer, handler.getDetailHeader(), warnings, handler.getDescriptor());
}

private void printLine(final HtmlPrinter printer, final Localizable header, final String warnings,
final Class<? extends PluginDescriptor> descriptor) {
PluginDescriptor pluginDescriptor = Jenkins.getInstance().getDescriptorByType(descriptor);
@@ -0,0 +1,52 @@
package hudson.plugins.analysis.collector.handler;

import java.util.Collection;

import org.jvnet.localizer.Localizable;

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

/**
* Handles access to the individual plug-in results.
*
* @author Ulli Hafner
*/
public interface AnalysisHandler {
/**
* Returns the class of the project action of the plug-in.
*
* @return project action class
*/
Class<? extends AbstractProjectAction<?>> getProjectActionType();

/**
* Returns the URL of the plugin.
*
* @return plug-in URL
*/
String getUrl();

/**
* Returns the header of the plug-in details.
*
* @return localized header of the details
*/
Localizable getDetailHeader();

/**
* Returns the descriptor of the plug-in.
*
* @return plugin descriptor
*/
Class<? extends PluginDescriptor> getDescriptor();

/**
* Returns the class of the project action of the plug-in.
*
* @return project action class
*/
Collection<? extends Class<? extends ResultAction<? extends BuildResult>>> getResultActions();
}

0 comments on commit 2a79a3d

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