Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test cases for FindBugs, Checkstyle and PMD #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand All @@ -9,15 +10,17 @@
</parent>

<artifactId>violations</artifactId>
<version>0.7.15-SNAPSHOT</version>
<version>0.8.0-alpha-1-SNAPSHOT</version>
<packaging>hpi</packaging>

<name>Jenkins Violations plugin</name>
<description>This plug-in generates reports static code violation detectors such as checkstyle, pmd, cpd, findbugs, codenarc, fxcop, stylecop and simian.</description>
<url>https://wiki.jenkins-ci.org/display/JENKINS/Violations</url>

<scm>
<connection>scm:git:git://github.com/jenkinsci/violations-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/violations-plugin.git</developerConnection>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>http://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
</scm>

<properties>
Expand All @@ -36,6 +39,12 @@
<id>peterkittreilly</id>
<name>Peter Reilly</name>
</developer>
<developer>
<id>tomasbjerre</id>
<name>Tomas Bjerre</name>
<email>[email protected]</email>
<url>http://bjurr.se</url>
</developer>
</developers>

<contributors>
Expand All @@ -55,18 +64,44 @@
<timezone>+1</timezone>
</contributor>
</contributors>


<licenses>
<license>
<name>MIT License</name>
<url>http://opensource.org/licenses/MIT</url>
</license>
</licenses>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>1.2</version>
<version>3.0.1</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<xmlOutput>false</xmlOutput>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

Expand All @@ -75,7 +110,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>1.2</version>
<version>3.0.1</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<xmlOutput>false</xmlOutput>
Expand Down Expand Up @@ -104,11 +139,23 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/hudson/plugins/violations/TypeDescriptor.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package hudson.plugins.violations;

import hudson.plugins.violations.types.checkstyle.CheckstyleDescriptor;
import hudson.plugins.violations.types.codenarc.CodenarcDescriptor;
import hudson.plugins.violations.types.cpd.CPDDescriptor;
import hudson.plugins.violations.types.cpplint.CppLintDescriptor;
import hudson.plugins.violations.types.csslint.CssLintDescriptor;
import hudson.plugins.violations.types.findbugs.FindBugsDescriptor;
import hudson.plugins.violations.types.fxcop.FxCopDescriptor;
import hudson.plugins.violations.types.gendarme.GendarmeDescriptor;
import hudson.plugins.violations.types.jcreport.JcReportDescriptor;
import hudson.plugins.violations.types.jslint.JsLintDescriptor;
import hudson.plugins.violations.types.pep8.Pep8Descriptor;
import hudson.plugins.violations.types.perlcritic.PerlCriticDescriptor;
import hudson.plugins.violations.types.pmd.PMDDescriptor;
import hudson.plugins.violations.types.pyflakes.PyflakesDescriptor;
import hudson.plugins.violations.types.pylint.PyLintDescriptor;
import hudson.plugins.violations.types.resharper.ReSharperDescriptor;
import hudson.plugins.violations.types.simian.SimianDescriptor;
import hudson.plugins.violations.types.stylecop.StyleCopDescriptor;
import hudson.plugins.violations.types.xmllint.XmllintDescriptor;
Expand All @@ -34,7 +30,7 @@ public abstract class TypeDescriptor {

/**
* Create a type descriptor for a type.
*
*
* @param name
* the name of the type.
*/
Expand All @@ -44,7 +40,7 @@ protected TypeDescriptor(final String name) {

/**
* Get the name of the type.
*
*
* @return the type name.
*/
public String getName() {
Expand All @@ -53,27 +49,33 @@ public String getName() {

/**
* Get a new parser for the type.
*
*
* @return a new parser object.
*/
public abstract ViolationsParser createParser();

/** The map of types to type descriptors. */
public static final TreeMap<String, TypeDescriptor> TYPES = new TreeMap<String, TypeDescriptor>();
public static TreeMap<String, TypeDescriptor> TYPES;

/**
* Add a violations type descriptor.
*
*
* @param t
* the violations type descriptor to add.
*/
public static void addDescriptor(final TypeDescriptor t) {
@SuppressWarnings("unchecked")
public static synchronized <T> T addDescriptor(final TypeDescriptor t) {
if (TYPES == null)
TYPES = new TreeMap<String, TypeDescriptor>();
if (TYPES.containsKey(t.getName()))
return (T) t;
TYPES.put(t.getName(), t);
return (T) t;
}

/**
* Get a detailed description of a violation source.
*
*
* @param source
* the code name for the violation.
* @return a detailed description, if available, null otherwise.
Expand All @@ -84,18 +86,15 @@ public String getDetailForSource(final String source) {

/**
* Get a list of target xml files to look for for this particular type.
*
*
* @return a list filenames to look for in the target target directory.
*/
public List<String> getMavenTargets() {
return null;
}

static {
addDescriptor(FindBugsDescriptor.DESCRIPTOR);
addDescriptor(PMDDescriptor.DESCRIPTOR);
addDescriptor(CPDDescriptor.DESCRIPTOR);
addDescriptor(CheckstyleDescriptor.DESCRIPTOR);
addDescriptor(PyLintDescriptor.DESCRIPTOR);
addDescriptor(CppLintDescriptor.DESCRIPTOR);
addDescriptor(FxCopDescriptor.DESCRIPTOR);
Expand All @@ -108,7 +107,6 @@ public List<String> getMavenTargets() {
addDescriptor(CodenarcDescriptor.DESCRIPTOR);
addDescriptor(Pep8Descriptor.DESCRIPTOR);
addDescriptor(PerlCriticDescriptor.DESCRIPTOR);
addDescriptor(ReSharperDescriptor.DESCRIPTOR);
addDescriptor(PyflakesDescriptor.DESCRIPTOR);
addDescriptor(XmllintDescriptor.DESCRIPTOR);
addDescriptor(ZptlintDescriptor.DESCRIPTOR);
Expand Down
81 changes: 48 additions & 33 deletions src/main/java/hudson/plugins/violations/ViolationsPublisher.java
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
package hudson.plugins.violations;

import hudson.Extension;
import hudson.tasks.BuildStepMonitor;
import java.io.File;
import java.io.IOException;

import hudson.FilePath;
import hudson.Launcher;

import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.plugins.violations.hudson.ViolationsFreestyleDescriptor;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;

import hudson.plugins.violations.hudson.ViolationsFreestyleDescriptor;
import hudson.tasks.BuildStepDescriptor;
import java.io.File;
import java.io.IOException;

import com.google.common.annotations.VisibleForTesting;

/**
* Generats HTML and XML reports from checkstyle, pmd and findbugs
* report xml files.
* Generats HTML and XML reports from checkstyle, pmd and findbugs report xml
* files.
*
* @author Peter Reilly
*/
public class ViolationsPublisher extends Recorder {

private static final String VIOLATIONS = "violations";

private final ViolationsConfig config =
new ViolationsConfig();
private final ViolationsConfig config = new ViolationsConfig();

/**
* Get the configuration object for this violations publisher.
*
* @return the config.
*/
public ViolationsConfig getConfig() {
return config;
}

/**
* Get a copy of the configuration.
* This is used to configure a new publisher in the config.jelly
* script.
* Get a copy of the configuration. This is used to configure a new
* publisher in the config.jelly script.
*
* @return a copy o the config.
*/
public ViolationsConfig getOldConfig() {
Expand All @@ -52,51 +51,68 @@ public ViolationsConfig getOldConfig() {

/**
* Called by hudson at the end of a build.
* @param build the build
* @param launcher the launcher
* @param listener for reporting errors
*
* @param build
* the build
* @param launcher
* the launcher
* @param listener
* for reporting errors
* @return true always.
* @throws InterruptedException
* if user cancels the operation
* @throws IOException
* if problem parsing the xml files
*/
@Override
public boolean perform(
AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
BuildListener listener) throws InterruptedException, IOException {

FilePath htmlPath = new FilePath(
new File(build.getProject().getRootDir(), VIOLATIONS));
FilePath targetPath = new FilePath(
new File(build.getRootDir(), VIOLATIONS));
FilePath htmlPath = new FilePath(new File(build.getProject()
.getRootDir(), VIOLATIONS));
FilePath targetPath = new FilePath(new File(build.getRootDir(),
VIOLATIONS));

ViolationsReport report = build.getWorkspace().act(
new ViolationsCollector(false, targetPath, htmlPath, config));
FilePath workspace = build.getWorkspace();

build.getActions().add(
createBuildAction(workspace, targetPath, htmlPath, config,
build));
return true;
}

@VisibleForTesting
static ViolationsBuildAction createBuildAction(FilePath workspace,
FilePath targetPath, FilePath htmlPath, ViolationsConfig config,
AbstractBuild<?, ?> build) throws IOException, InterruptedException {
ViolationsReport report = workspace.act(new ViolationsCollector(false,
targetPath, htmlPath, config));
report.setConfig(config);
report.setBuild(build);
report.setBuildResult();
build.getActions().add(
new ViolationsBuildAction(build, report));
return true;
return new ViolationsBuildAction(build, report);
}

/**
* Create a project action for a project.
* @param project the project to create the action for.
*
* @param project
* the project to create the action for.
* @return the created violations project action.
*/
@Override
public Action getProjectAction(AbstractProject<?, ?> project) {
return new ViolationsProjectAction(project);
}

@Override
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
}

/**
* Get the descriptor.
*
* @return the violations publisher descriptor.
*/
@Override
Expand All @@ -106,7 +122,6 @@ public BuildStepDescriptor<Publisher> getDescriptor() {

/** The descriptor for this publisher - used in project config page. */
@Extension
public static final BuildStepDescriptor<Publisher> DESCRIPTOR
= new ViolationsFreestyleDescriptor();
public static final BuildStepDescriptor<Publisher> DESCRIPTOR = new ViolationsFreestyleDescriptor();

}
Loading