mirror of
https://github.com/SonarSource/sonarqube.git
synced 2024-08-03 08:18:00 +02:00
fix coding violations
This commit is contained in:
parent
9559e69e14
commit
2b560c35ab
@ -19,17 +19,7 @@
|
||||
*/
|
||||
package org.sonar.plugins.cpd;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.sourceforge.pmd.cpd.TokenEntry;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.sonar.api.batch.CpdMapping;
|
||||
@ -40,6 +30,9 @@ import org.sonar.api.resources.Project;
|
||||
import org.sonar.api.resources.Resource;
|
||||
import org.sonar.duplications.cpd.Match;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class CpdAnalyser {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CpdAnalyser.class);
|
||||
@ -84,7 +77,7 @@ public class CpdAnalyser {
|
||||
continue;
|
||||
}
|
||||
|
||||
firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount(), match);
|
||||
firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -116,8 +109,7 @@ public class CpdAnalyser {
|
||||
this.resource = resource;
|
||||
}
|
||||
|
||||
protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines,
|
||||
Match match) {
|
||||
protected void cumulate(Resource targetResource, int targetDuplicationStartLine, int duplicationStartLine, int duplicatedLines) {
|
||||
StringBuilder xml = new StringBuilder();
|
||||
xml.append("<duplication lines=\"").append(duplicatedLines).append("\" start=\"").append(duplicationStartLine)
|
||||
.append("\" target-start=\"").append(targetDuplicationStartLine).append("\" target-resource=\"")
|
||||
@ -125,7 +117,6 @@ public class CpdAnalyser {
|
||||
|
||||
duplicationXMLEntries.add(xml);
|
||||
|
||||
int duplicatedLinesBefore = this.duplicatedLines.size();
|
||||
for (int duplicatedLine = duplicationStartLine; duplicatedLine < duplicationStartLine + duplicatedLines; duplicatedLine++) {
|
||||
this.duplicatedLines.add(duplicatedLine);
|
||||
}
|
||||
|
@ -19,27 +19,10 @@
|
||||
*/
|
||||
package org.sonar.plugins.pmd;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.PMD;
|
||||
import net.sourceforge.pmd.PMDException;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSets;
|
||||
import net.sourceforge.pmd.SourceType;
|
||||
import net.sourceforge.pmd.*;
|
||||
import net.sourceforge.pmd.renderers.Renderer;
|
||||
import net.sourceforge.pmd.renderers.XMLRenderer;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -50,6 +33,9 @@ import org.sonar.api.resources.Project;
|
||||
import org.sonar.api.utils.TimeProfiler;
|
||||
import org.sonar.java.api.JavaUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public class PmdExecutor implements BatchExtension {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PmdExecutor.class);
|
||||
@ -147,13 +133,10 @@ public class PmdExecutor implements BatchExtension {
|
||||
xmlRenderer.start();
|
||||
xmlRenderer.renderFileReport(report);
|
||||
xmlRenderer.end();
|
||||
String buffer = stringwriter.toString();
|
||||
|
||||
File xmlReport = new File(project.getFileSystem().getSonarWorkingDirectory(), "pmd-result.xml");
|
||||
LOG.info("PMD output report: " + xmlReport.getAbsolutePath());
|
||||
Writer writer = new FileWriter(xmlReport);
|
||||
writer.write(buffer, 0, buffer.length());
|
||||
writer.close();
|
||||
FileUtils.write(xmlReport, stringwriter.toString());
|
||||
return xmlReport;
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class MatchAlgorithm {
|
||||
}
|
||||
cpdListener.phaseUpdate(CPDListener.GROUPING);
|
||||
matches = matchCollector.getMatches();
|
||||
matchCollector = null;
|
||||
|
||||
for (Match match : matches) {
|
||||
for (Iterator<TokenEntry> occurrences = match.iterator(); occurrences.hasNext();) {
|
||||
TokenEntry mark = occurrences.next();
|
||||
|
@ -27,7 +27,7 @@ public class Cycle {
|
||||
private int hashcode = 0;
|
||||
|
||||
public Cycle(List<Edge> edges) {
|
||||
this.edges = edges.toArray(new Edge[0]);
|
||||
this.edges = edges.toArray(new Edge[edges.size()]);
|
||||
for(Edge edge : edges) {
|
||||
hashcode += edge.hashCode();
|
||||
}
|
||||
|
@ -598,7 +598,7 @@ public class Measure {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o.getClass().equals(Measure.class))) {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
package org.sonar.api.utils;
|
||||
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.text.*;
|
||||
import java.util.Date;
|
||||
@ -33,8 +34,8 @@ public final class DateUtils {
|
||||
public static final String DATE_FORMAT = "yyyy-MM-dd";
|
||||
public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ";
|
||||
|
||||
private static final DateFormat dateFormat = new ThreadSafeDateFormat(DATE_FORMAT);
|
||||
private static final DateFormat dateTimeFormat = new ThreadSafeDateFormat(DATETIME_FORMAT);
|
||||
private static final ThreadSafeDateFormat dateFormat = new ThreadSafeDateFormat(DATE_FORMAT);
|
||||
private static final ThreadSafeDateFormat dateTimeFormat = new ThreadSafeDateFormat(DATETIME_FORMAT);
|
||||
|
||||
public static String formatDate(Date d) {
|
||||
return dateFormat.format(d);
|
||||
@ -69,9 +70,9 @@ public final class DateUtils {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
private final ThreadLocal cache = new ThreadLocal() {
|
||||
private final transient ThreadLocal cache = new ThreadLocal() {
|
||||
public Object get() {
|
||||
SoftReference softRef = (SoftReference) super.get();
|
||||
Reference softRef = (Reference)super.get();
|
||||
if (softRef == null || softRef.get() == null) {
|
||||
softRef = new SoftReference(new SimpleDateFormat(format));
|
||||
super.set(softRef);
|
||||
@ -81,7 +82,7 @@ public final class DateUtils {
|
||||
};
|
||||
|
||||
private DateFormat getDateFormat() {
|
||||
return (DateFormat) ((SoftReference) cache.get()).get();
|
||||
return (DateFormat) ((Reference)cache.get()).get();
|
||||
}
|
||||
|
||||
public StringBuffer format(Date date,StringBuffer toAppendTo, FieldPosition fieldPosition) {
|
||||
|
@ -29,7 +29,6 @@ import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.sonar.api.rules.RulePriority;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
@ -432,6 +431,9 @@ public final class KeyValueFormat {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated since 2.7 replaced by Converter
|
||||
*/
|
||||
@Deprecated
|
||||
public interface Transformer<KEY, VALUE> {
|
||||
KeyValue<KEY, VALUE> transform(String key, String value);
|
||||
@ -439,6 +441,7 @@ public final class KeyValueFormat {
|
||||
|
||||
/**
|
||||
* Implementation of Transformer<String, Double>
|
||||
* @deprecated since 2.7 replaced by Converter
|
||||
*/
|
||||
@Deprecated
|
||||
public static class StringNumberPairTransformer implements Transformer<String, Double> {
|
||||
|
@ -20,7 +20,8 @@
|
||||
package org.sonar.api.utils.command;
|
||||
|
||||
public final class CommandException extends RuntimeException {
|
||||
private Command command;
|
||||
|
||||
private transient Command command = null;
|
||||
|
||||
public CommandException(Command command, String message, Throwable throwable) {
|
||||
super(message + " [command: " + command + "]", throwable);
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
package org.sonar.server.rules;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.sonar.api.Plugins;
|
||||
import org.sonar.api.checks.profiles.Check;
|
||||
@ -42,23 +43,23 @@ public final class DeprecatedProfiles {
|
||||
private CheckProfileProvider[] deprecatedCheckProfileProviders;
|
||||
|
||||
public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) {
|
||||
this.deprecatedRepositories = r;
|
||||
this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r);
|
||||
this.plugins = plugins;
|
||||
this.ruleFinder = ruleFinder;
|
||||
this.deprecatedCheckProfiles = deprecatedCheckProfiles;
|
||||
this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders;
|
||||
this.deprecatedCheckProfiles = (CheckProfile[])ArrayUtils.clone(deprecatedCheckProfiles);
|
||||
this.deprecatedCheckProfileProviders = (CheckProfileProvider[])ArrayUtils.clone(deprecatedCheckProfileProviders);
|
||||
}
|
||||
|
||||
public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) {
|
||||
this.deprecatedRepositories = r;
|
||||
this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r);
|
||||
this.plugins = plugins;
|
||||
this.ruleFinder = ruleFinder;
|
||||
this.deprecatedCheckProfiles = deprecatedCheckProfiles;
|
||||
this.deprecatedCheckProfiles = (CheckProfile[])ArrayUtils.clone(deprecatedCheckProfiles);
|
||||
this.deprecatedCheckProfileProviders = new CheckProfileProvider[0];
|
||||
}
|
||||
|
||||
public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) {
|
||||
this.deprecatedRepositories = r;
|
||||
this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r);
|
||||
this.plugins = plugins;
|
||||
this.ruleFinder = ruleFinder;
|
||||
this.deprecatedCheckProfiles = new CheckProfile[0];
|
||||
@ -66,7 +67,7 @@ public final class DeprecatedProfiles {
|
||||
}
|
||||
|
||||
public DeprecatedProfiles(Plugins plugins, RuleFinder ruleFinder, RulesRepository[] r) {
|
||||
this.deprecatedRepositories = r;
|
||||
this.deprecatedRepositories = (RulesRepository[])ArrayUtils.clone(r);
|
||||
this.plugins = plugins;
|
||||
this.ruleFinder = ruleFinder;
|
||||
this.deprecatedCheckProfiles = new CheckProfile[0];
|
||||
|
@ -73,7 +73,7 @@ public class ViewProxy<V extends View> implements Comparable<ViewProxy> {
|
||||
|
||||
DefaultTab defaultTabAnnotation = AnnotationUtils.getClassAnnotation(view, DefaultTab.class);
|
||||
if (defaultTabAnnotation != null) {
|
||||
if (defaultTabAnnotation == null || defaultTabAnnotation.metrics().length == 0) {
|
||||
if (defaultTabAnnotation.metrics().length == 0) {
|
||||
isDefaultTab = true;
|
||||
defaultForMetrics = new String[0];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user