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

Commit

Permalink
Fixed several warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Dec 11, 2013
1 parent 5c55ea4 commit ee5c050
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/plugins/dry/parser/DuplicateCode.java
Expand Up @@ -139,7 +139,7 @@ public int length() {

/** {@inheritDoc} */
public String getToolTip() {
StringBuilder message = new StringBuilder();
StringBuilder message = new StringBuilder(512);
message.append("<p>");
message.append(Messages.DRY_Duplications_Header());
message.append("<ul>");
Expand Down
@@ -1,13 +1,5 @@
package hudson.plugins.dry.parser;

import hudson.FilePath;
import hudson.plugins.analysis.core.AnnotationParser;
import hudson.plugins.analysis.util.ContextHashCode;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.dry.parser.cpd.CpdParser;
import hudson.plugins.dry.parser.dupfinder.DupFinderParser;
import hudson.plugins.dry.parser.simian.SimianParser;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -23,6 +15,14 @@
import com.google.common.collect.Sets;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;
import hudson.FilePath;

import hudson.plugins.analysis.core.AnnotationParser;
import hudson.plugins.analysis.util.ContextHashCode;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.plugins.dry.parser.cpd.CpdParser;
import hudson.plugins.dry.parser.dupfinder.DupFinderParser;
import hudson.plugins.dry.parser.simian.SimianParser;

/**
* Registry for duplication parsers.
Expand Down Expand Up @@ -120,19 +120,19 @@ public Collection<FileAnnotation> parse(final File file, final String moduleName
}

/**
* Gets full file path
* @param annotation the annotation
* Gets full file path.
*
* @param annotation
* the annotation
* @return results full file path
*/
private String getFullPath(final FileAnnotation annotation) {
String fileName = annotation.getFileName();
File file = new File(fileName);
if(file.isAbsolute())
{
if (file.isAbsolute()) {
return fileName;
}
else
{
else {
FilePath filePath = new FilePath(new File(workspacePath));
FilePath fullPath = filePath.child(fileName);
return fullPath.getRemote();
Expand Down
Expand Up @@ -64,7 +64,8 @@ public boolean accepts(final InputStream file) {
}

@Override
public Collection<DuplicateCode> parse(final InputStream file, final String moduleName) throws InvocationTargetException {
public Collection<DuplicateCode> parse(final InputStream file, final String moduleName)
throws InvocationTargetException {
try {
Digester digester = new Digester();

Expand Down Expand Up @@ -98,7 +99,7 @@ public Collection<DuplicateCode> parse(final InputStream file, final String modu
digester.addSetNext(offsetRangeXPath, "setOffsetRange", Range.class.getName());

Object result = digester.parse(file);
if (result != duplications) {
if (result != duplications) { // NOPMD
throw new SAXException("Input stream is not a valid Reshaper DupFinder file.");
}

Expand Down Expand Up @@ -129,18 +130,13 @@ private Collection<DuplicateCode> convert(final List<Duplicate> duplications, fi
for (Duplicate duplication : duplications) {
List<DuplicateCode> codeBlocks = new ArrayList<DuplicateCode>();
Collection<Fragment> fragments = duplication.getFragments();
for (Fragment fragment : fragments)
{
for (Fragment fragment : fragments) {
Range lineRange = fragment.getLineRange();
int count = lineRange.getEnd() - lineRange.getStart() + 1;
DuplicateCode annotation = new DuplicateCode(
getPriority(count),
lineRange.getStart(),
count,
DuplicateCode annotation = new DuplicateCode(getPriority(count), lineRange.getStart(), count,
fragment.getFileName());
String text = fragment.getText();
if(text != null)
{
if (text != null) {
annotation.setSourceCode(text);
}
annotation.setModuleName(moduleName);
Expand Down
Expand Up @@ -6,13 +6,9 @@
* @author Rafal Jasica
*/
public class Fragment {
/** The file name. */
private String fileName;
/** The text. */
private String text;
/** The line range */
private Range lineRange;
/** The offset range */
private Range offsetRange;

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/hudson/plugins/dry/parser/dupfinder/Range.java
Expand Up @@ -6,9 +6,7 @@
* @author Rafal Jasica
*/
public class Range {
/** The start */
private int start;
/** The end */
private int end;

/**
Expand Down
Expand Up @@ -150,8 +150,11 @@ public void scanOtherFile() {
assertFalse("Parser does accept invalid CPD file.", acceptsFile("otherfile.xml"));
}

/**
* Checks whether we accept a file with Windows encoding.
*/
@Test
public void assertCanReadWindowsFile() throws InvocationTargetException {
public void assertCanReadWindowsFile() {
String fileName = "pmd-cpd.xml";
assertTrue(VALID_CPD_FILE, acceptsFile(fileName));
}
Expand Down
Expand Up @@ -36,16 +36,28 @@ public class DupFinderParserTest {
/** Error message. */
private static final String WRONG_WARNING_PROPERTY = "Wrong warning property";

/**
* Checks whether we accept a file with Windows encoding.
*/
@Test
public void assertCanReadWindowsFile() throws InvocationTargetException {
public void assertCanReadWindowsFile() {
assertTrue(INVALID_CPD_FILE, acceptsFile("sorucecode.xml"));
}

/**
* Checks whether we accept a file with normal encoding.
*/
@Test
public void scanOtherFile() {
assertFalse(INVALID_CPD_FILE, acceptsFile("otherfile.xml"));
}

/**
* Checks whether we can parse a file with source code snippet.
*
* @throws InvocationTargetException
* Signals a test failure
*/
@Test
public void scanFileWithSourceCode() throws InvocationTargetException {
String fileName = "sorucecode.xml";
Expand Down Expand Up @@ -74,6 +86,12 @@ else if (first.getPrimaryLineNumber() == PUBLISHER_LINE) {
}
}

/**
* Checks whether we can parse a file without source code snippet.
*
* @throws InvocationTargetException
* Signals a test failure
*/
@Test
public void scanFileWithoutSourceCode() throws InvocationTargetException {
String fileName = "withoutsourcode.xml";
Expand Down

0 comments on commit ee5c050

Please sign in to comment.