*/
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;
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);
continue;
}
- firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount(), match);
+ firstFileData.cumulate(secondFile, secondLine, firstLine, match.getLineCount());
}
}
}
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=\"")
duplicationXMLEntries.add(xml);
- int duplicatedLinesBefore = this.duplicatedLines.size();
for (int duplicatedLine = duplicationStartLine; duplicatedLine < duplicationStartLine + duplicatedLines; duplicatedLine++) {
this.duplicatedLines.add(duplicatedLine);
}
*/
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;
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);
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;
}
}
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();
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();
}
if (this == o) {
return true;
}
- if (!(o.getClass().equals(Measure.class))) {
+ if (o == null || getClass() != o.getClass()) {
return false;
}
*/
package org.sonar.api.utils;
+import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.text.*;
import java.util.Date;
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);
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);
};
private DateFormat getDateFormat() {
- return (DateFormat) ((SoftReference) cache.get()).get();
+ return (DateFormat) ((Reference)cache.get()).get();
}
public StringBuffer format(Date date,StringBuffer toAppendTo, FieldPosition fieldPosition) {
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.*;
}
+ /**
+ * @deprecated since 2.7 replaced by Converter
+ */
@Deprecated
public interface Transformer<KEY, VALUE> {
KeyValue<KEY, VALUE> transform(String key, String value);
/**
* Implementation of Transformer<String, Double>
+ * @deprecated since 2.7 replaced by Converter
*/
@Deprecated
public static class StringNumberPairTransformer implements Transformer<String, Double> {
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);
*/
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;
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];
}
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];
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];