|
@@ -7,7 +7,7 @@ |
|
|
import hudson.plugins.analysis.core.ResultAction; |
|
|
import hudson.plugins.analysis.util.model.FileAnnotation; |
|
|
|
|
|
import java.lang.ref.WeakReference; |
|
|
import java.io.IOException; |
|
|
import java.util.Map; |
|
|
|
|
|
import com.google.common.collect.Maps; |
|
@@ -22,8 +22,8 @@ |
|
|
/** Unique identifier of this class. */ |
|
|
private static final long serialVersionUID = 847650789493429154L; |
|
|
|
|
|
/** Number of annotations by origin mapping. */ |
|
|
private transient WeakReference<Map<String, Integer>> annotationsByOrigin; |
|
|
/** Number of annotations by origin mapping. Serialized @since 1.20. */ |
|
|
private Map<String, Integer> annotationsByOrigin; |
|
|
|
|
|
private transient Object mappingLock = new Object(); |
|
|
|
|
@@ -43,7 +43,7 @@ public AnalysisResult(final AbstractBuild<?, ?> build, final String defaultEncod |
|
|
final ParserResult result, final BuildHistory history) { |
|
|
super(build, defaultEncoding, result, history); |
|
|
|
|
|
annotationsByOrigin = newReference(countAnnotations()); |
|
|
annotationsByOrigin = countAnnotations(); |
|
|
} |
|
|
|
|
|
/** |
|
@@ -60,7 +60,7 @@ public AnalysisResult(final AbstractBuild<?, ?> build, final String defaultEncod |
|
|
final ParserResult result) { |
|
|
super(build, defaultEncoding, result); |
|
|
|
|
|
annotationsByOrigin = newReference(countAnnotations()); |
|
|
annotationsByOrigin = countAnnotations(); |
|
|
} |
|
|
|
|
|
/** {@inheritDoc} */ |
|
@@ -90,10 +90,6 @@ protected Object readResolve() { |
|
|
return mapping; |
|
|
} |
|
|
|
|
|
private WeakReference<Map<String, Integer>> newReference(final Map<String, Integer> mapping) { |
|
|
return new WeakReference<Map<String, Integer>>(mapping); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns a summary message for the summary.jelly file. |
|
|
* |
|
@@ -103,13 +99,11 @@ public String getSummary() { |
|
|
return AnalysisResultSummary.createSummary(this); |
|
|
} |
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
@Override |
|
|
protected String createDeltaMessage() { |
|
|
return AnalysisResultSummary.createDeltaMessage(this); |
|
|
} |
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
@Override |
|
|
protected String getSerializationFileName() { |
|
|
return "analysis.xml"; |
|
@@ -120,35 +114,34 @@ public String getDisplayName() { |
|
|
return Messages.Analysis_ProjectAction_Name(); |
|
|
} |
|
|
|
|
|
/** {@inheritDoc} */ |
|
|
@Override |
|
|
protected Class<? extends ResultAction<? extends BuildResult>> getResultActionType() { |
|
|
return AnalysisResultAction.class; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Returns the number of annotations from the specified origin. If there are no annotations |
|
|
* Returns the number of annotations from the specified origin. If there are |
|
|
* no annotations, then 0 is returned. |
|
|
* |
|
|
* @param origin |
|
|
* the origin |
|
|
* @return the number of annotations from the specified origin |
|
|
*/ |
|
|
public int getNumberOfAnnotationsByOrigin(final String origin) { |
|
|
Map<String, Integer> mapping = getMapping(); |
|
|
if (mapping.containsKey(origin)) { |
|
|
return mapping.get(origin); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
|
|
|
private Map<String, Integer> getMapping() { |
|
|
synchronized (mappingLock) { |
|
|
if (annotationsByOrigin == null || annotationsByOrigin.get() == null) { |
|
|
Map<String, Integer> mapping = countAnnotations(); |
|
|
annotationsByOrigin = newReference(mapping); |
|
|
return mapping; |
|
|
if (annotationsByOrigin == null) { |
|
|
annotationsByOrigin = countAnnotations(); |
|
|
try { |
|
|
getOwner().save(); |
|
|
} |
|
|
catch (IOException exception) { |
|
|
// ignore |
|
|
} |
|
|
} |
|
|
return annotationsByOrigin.get(); |
|
|
} |
|
|
if (annotationsByOrigin.containsKey(origin)) { |
|
|
return annotationsByOrigin.get(origin); |
|
|
} |
|
|
return 0; |
|
|
} |
|
|
}
|