Made params for assigning blame results final
@@ -5,11 +5,13 @@ import hudson.model.Run;
import hudson.plugins.analysis.core.BuildResult;
import hudson.plugins.analysis.util.model.FileAnnotation;
import hudson.scm.SCM;
+import org.eclipse.jgit.blame.BlameResult;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.revwalk.RevCommit;
import java.io.File;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Set;
+import java.util.*;
/**
* A base class for blame functionality.
@@ -19,8 +21,11 @@ import java.util.Set;
public abstract class AbstractBlamer implements BlameInterface{
/** Indicator for a bad Path */
protected static final String BAD_PATH = "/";
+ /** The current run */
protected final Run <?, ?> run;
+ /** the current workspace */
protected final FilePath workspace;
+ /** The PluginLogger to log ,essages */
protected final PluginLogger logger;
public AbstractBlamer(final Run<?, ?> run, final FilePath workspace, final PluginLogger logger)
@@ -65,4 +70,54 @@ public abstract class AbstractBlamer implements BlameInterface{
return pathsByFileName;
}
+
+ /**
+ * Assigns the BlameResults to the annotations.
+ *
+ * @param annotations The annotations that should be blamed
+ * @param pathsByFileName the annotations by filename
+ * @param blameResults the results of the blaming
+ */
+ protected void assignBlameResults(final Set<FileAnnotation> annotations,final HashMap<String, String> pathsByFileName, final HashMap<String, BlameResult> blameResults)
+ {
+ HashSet<String> missingBlame = new HashSet<String>();
+ for (final FileAnnotation annot : annotations) {
+ if (annot.getPrimaryLineNumber() <= 0) {
+ continue;
+ }
+ String child = pathsByFileName.get(annot.getFileName());
+ if (BAD_PATH.equals(child)) {
+ continue;
+ }
+ BlameResult blame = blameResults.get(child);
+ if (blame == null) {
+ continue;
+ }
+ int zeroline = annot.getPrimaryLineNumber() - 1;
+ try {
+ PersonIdent who = blame.getSourceAuthor(zeroline);
+ RevCommit commit = blame.getSourceCommit(zeroline);
+ if (who == null) {
+ missingBlame.add(child);
+ }
+ else {
+ annot.setAuthorName(who.getName());
+ annot.setAuthorEmail(who.getEmailAddress());
+ }
+ annot.setAuthorCommitId(commit == null ? null : commit.getName());
+ }
+ catch (ArrayIndexOutOfBoundsException e) {
+ logger.log("Blame details were out of bounds for line number " + annot.getPrimaryLineNumber() + " in file " + child);
+ }
+ }
+
+ if (!missingBlame.isEmpty()) {
+ ArrayList<String> l = new ArrayList<String>(missingBlame);
+ Collections.sort(l);
+ for (final String child : l) {
+ logger.log("Blame details were incomplete for file: " + child);
+ }
+ }
+ }
+
}
