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

Commit

Permalink
[FIXED JENKINS-12223] [FIXED JENKINS-12309] Serialize distribution of
Browse files Browse the repository at this point in the history
warnings in build action.
  • Loading branch information
uhafner committed Feb 21, 2012
1 parent f4a2409 commit 3a7d4f7
Showing 1 changed file with 19 additions and 26 deletions.
45 changes: 19 additions & 26 deletions src/main/java/hudson/plugins/analysis/collector/AnalysisResult.java
Expand Up @@ -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;
Expand All @@ -22,8 +22,8 @@ public class AnalysisResult extends BuildResult {
/** 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();

Expand All @@ -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();
}

/**
Expand All @@ -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} */
Expand Down Expand Up @@ -90,10 +90,6 @@ private Map<String, Integer> countAnnotations() {
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.
*
Expand All @@ -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";
Expand All @@ -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;
}
}

0 comments on commit 3a7d4f7

Please sign in to comment.