Search in sources :

Example 21 with FullBuildModel

use of hudson.plugins.violations.model.FullBuildModel in project violations-plugin by jenkinsci.

the class SimianParserTest method testOneFileMessage.

@Test
public void testOneFileMessage() throws Exception {
    FullBuildModel model = getFullBuildModel("onefile.xml");
    Iterator<Violation> iterator = model.getFileModel("java/hudson/maven/MavenBuild.java").getTypeMap().get("simian").descendingIterator();
    Violation v = iterator.next();
    assertEquals("Message in violation is incorrect", "Duplication of 6 lines from <a href='#line76'>line 76</a>.", v.getMessage());
    v = iterator.next();
    assertEquals("Message in violation is incorrect", "Duplication of 6 lines from <a href='#line93'>line 93</a>.", v.getMessage());
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 22 with FullBuildModel

use of hudson.plugins.violations.model.FullBuildModel in project violations-plugin by jenkinsci.

the class SimianParserTest method testTwoFilePopupMessage.

@Test
public void testTwoFilePopupMessage() throws Exception {
    FullBuildModel model = getFullBuildModel("twofile.xml");
    Iterator<Violation> iterator = model.getFileModel("java/hudson/maven/MavenBuild.java").getTypeMap().get(SimianParser.TYPE_NAME).descendingIterator();
    Violation v = iterator.next();
    assertEquals("Popup message in violation is incorrect", "Duplication of 6 lines from line 61 in MatrixRun.java.", v.getPopupMessage());
    iterator = model.getFileModel("java/hudson/matrix/MatrixRun.java").getTypeMap().get(SimianParser.TYPE_NAME).descendingIterator();
    v = iterator.next();
    assertEquals("Popup message in violation is incorrect", "Duplication of 6 lines from line 92 in MavenBuild.java.", v.getPopupMessage());
}
Also used : Violation(hudson.plugins.violations.model.Violation) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 23 with FullBuildModel

use of hudson.plugins.violations.model.FullBuildModel in project violations-plugin by jenkinsci.

the class StyleCopParserTest method testParseFullBuildModelFileStringStringArray.

@Test
public void testParseFullBuildModelFileStringStringArray() throws Exception {
    FullBuildModel model = getFullBuildModel("onefile.xml");
    assertEquals("Number of violations is incorrect", 3, model.getCountNumber(StyleCopParser.TYPE_NAME));
    assertEquals("Number of files is incorrect", 1, model.getFileModelMap().size());
}
Also used : FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 24 with FullBuildModel

use of hudson.plugins.violations.model.FullBuildModel in project violations-plugin by jenkinsci.

the class StyleCopParserTest method assertParsingVersion43.

@Test
public void assertParsingVersion43() throws Exception {
    FullBuildModel model = getFullBuildModel("stylecop-v4.3.xml");
    assertEquals("Number of violations is incorrect", 2, model.getCountNumber(StyleCopParser.TYPE_NAME));
    assertEquals("Number of files is incorrect", 1, model.getFileModelMap().size());
}
Also used : FullBuildModel(hudson.plugins.violations.model.FullBuildModel) ViolationsParserTest(hudson.plugins.violations.ViolationsParserTest) Test(org.junit.Test)

Example 25 with FullBuildModel

use of hudson.plugins.violations.model.FullBuildModel in project violations-plugin by jenkinsci.

the class ViolationsCollector method invoke.

/**
 * Create a report.
 *
 * @param workspace
 *            the current workspace.
 * @param channel
 *            the virtual channel.
 * @return the report.
 * @throws IOException
 *             if there is a problem.
 */
@Override
public ViolationsReport invoke(File workspace, VirtualChannel channel) throws IOException {
    this.workspace = workspace;
    // the given workspace
    if (!StringUtil.isBlank(config.getFauxProjectPath())) {
        this.workspace = new File(config.getFauxProjectPath());
        LOG.fine("Using faux workspace " + this.workspace);
    }
    String[] sourcePaths = null;
    if (mavenProject) {
        sourcePaths = new String[] { workspace.toString() + "/src/main/java" };
    } else {
        // get the source path directories (if any)
        sourcePaths = findAbsoluteDirs(workspace, config.getSourcePathPattern());
    }
    for (String sp : sourcePaths) {
        LOG.fine("Using extra sourcePath " + sp);
    }
    // Create the report
    ViolationsReport report = new ViolationsReport();
    report.setConfig(config);
    // Build up the model
    this.model = new FullBuildModel();
    for (String type : config.getTypeConfigs().keySet()) {
        TypeConfig c = config.getTypeConfigs().get(type);
        TypeDescriptor typeDescriptor = TypeDescriptor.TYPES.get(type);
        if (typeDescriptor == null) {
            continue;
        }
        if (mavenProject && (typeDescriptor.getMavenTargets() != null)) {
            doType(c, typeDescriptor, sourcePaths, report);
            continue;
        }
        if (empty(c.getPattern())) {
            continue;
        }
        doType(c, typeDescriptor, sourcePaths, report);
    }
    model.cleanup();
    // ----
    try {
        new GenerateXML(targetDir, model, config).execute();
    } catch (InterruptedException ex) {
        throw new IOException2(ex);
    }
    // ----
    for (String type : model.getTypeMap().keySet()) {
        report.getViolations().put(type, model.getCountNumber(type));
        doSeverities(report, type);
    }
    return report;
}
Also used : GenerateXML(hudson.plugins.violations.generate.GenerateXML) FullBuildModel(hudson.plugins.violations.model.FullBuildModel) File(java.io.File) IOException2(hudson.util.IOException2)

Aggregations

FullBuildModel (hudson.plugins.violations.model.FullBuildModel)25 ViolationsParserTest (hudson.plugins.violations.ViolationsParserTest)23 Test (org.junit.Test)23 Violation (hudson.plugins.violations.model.Violation)8 FullFileModel (hudson.plugins.violations.model.FullFileModel)3 Issue (org.jvnet.hudson.test.Issue)3 File (java.io.File)2 GenerateXML (hudson.plugins.violations.generate.GenerateXML)1 IOException2 (hudson.util.IOException2)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1