Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
[JENKINS-24940] Persist the build number that introduced a new warning.
- Removed loading of reference build when computing new or fixed warnings.
- Added a new property for each warning that stores the build number this warning has been introduced.
- Changed serialization so that all fixed warnings are stored in a separate file.
  • Loading branch information
uhafner committed May 27, 2015
1 parent e7a42b2 commit c6f6e3e1cd55b87d848a1503abe2a76aef7f777d
@@ -22,6 +22,7 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import com.google.common.collect.Sets;
import com.thoughtworks.xstream.XStream;

import jenkins.model.Jenkins;
@@ -279,6 +280,7 @@ private void initialize(final BuildHistory history, final AbstractBuild<?, ?> bu

Set<FileAnnotation> allWarnings = result.getAnnotations();

// FIXME: why is there a flag to enable computation of new warnings?
Set<FileAnnotation> newWarnings = AnnotationDifferencer.getNewAnnotations(allWarnings, referenceResult.getAnnotations());
numberOfNewWarnings = newWarnings.size();
newWarningsReference = new WeakReference<Collection<FileAnnotation>>(newWarnings);
@@ -294,6 +296,11 @@ private void initialize(final BuildHistory history, final AbstractBuild<?, ?> bu
JavaProject container = new JavaProject();
container.addAnnotations(result.getAnnotations());

for (FileAnnotation newWarning : newWarnings) {
newWarning.setBuild(build.getNumber());
}
// FIXME: for the old warnings we need to find the introducing build by using the context hash code

project = new WeakReference<JavaProject>(container);

computeZeroWarningsHighScore(build, result);
@@ -500,14 +507,24 @@ public boolean canUseDeltaValues() {
}

/**
* Returns the serialization file.
* Returns the serialization file for all warnings.
*
* @return the serialization file.
*/
public final XmlFile getDataFile() {
return new XmlFile(getXStream(), new File(getOwner().getRootDir(), getSerializationFileName()));
}

/**
* Returns the serialization file for the fixed warnings.
*
* @return the serialization file.
*/
private XmlFile getFixedDataFile() {
return new XmlFile(getXStream(), new File(getOwner().getRootDir(),
getSerializationFileName().replace(".xml", "-fixed.xml")));
}

/**
* Returns the {@link XStream} to use.
*
@@ -650,8 +667,12 @@ public Set<FileAnnotation> getAnnotations(final Priority priority) {
*/
protected void serializeAnnotations(final Collection<FileAnnotation> annotations) {
try {
Collection<FileAnnotation> files = annotations;
getDataFile().write(files.toArray(new FileAnnotation[files.size()]));
getDataFile().write(annotations.toArray(new FileAnnotation[annotations.size()]));

Set<FileAnnotation> allAnnotations = new HashSet<FileAnnotation>();
allAnnotations.addAll(annotations);
Collection<FileAnnotation> fixedWarnings = history.getFixedWarnings(allAnnotations);
getFixedDataFile().write(fixedWarnings.toArray(new FileAnnotation[fixedWarnings.size()]));
}
catch (IOException exception) {
LOGGER.log(Level.SEVERE, "Failed to serialize the annotations of the build.", exception);
@@ -966,17 +987,21 @@ public Collection<FileAnnotation> getNewWarnings() {
}

/**
* Loads the results of the current and reference build, computes the new
* warnings and wraps them in a weak reference that might get removed by the
* garbage collector.
* Filters all warnings by the current build number and wraps them in a weak reference that might get
* removed by the garbage collector.
*
* @return the new warnings
*/
private Collection<FileAnnotation> loadNewWarnings() {
Collection<FileAnnotation> difference = history.getNewWarnings(getProject().getAnnotations());
newWarningsReference = new WeakReference<Collection<FileAnnotation>>(difference);
Set<FileAnnotation> newWarnings = new HashSet<FileAnnotation>();
for (FileAnnotation warning : getProject().getAnnotations()) {
if (warning.getBuild() == getOwner().getNumber()) {
newWarnings.add(warning);
}
}
newWarningsReference = new WeakReference<Collection<FileAnnotation>>(newWarnings);

return difference;
return newWarnings;
}

/**
@@ -985,12 +1010,52 @@ private Collection<FileAnnotation> loadNewWarnings() {
* @return the fixed warnings of this build.
*/
public Collection<FileAnnotation> getFixedWarnings() {
if (getFixedDataFile().exists()) {
return getFixedWarningsAfterRelease72();
}
else {
return getFixedWarningsBeforeRelease72();
}
}

private Collection<FileAnnotation> getFixedWarningsAfterRelease72() {
synchronized (projectLock) {
if (fixedWarningsReference == null) {
return loadFixedWarningsAfterRelease72();
}
Collection<FileAnnotation> result = fixedWarningsReference.get();
if (result == null) {
return loadFixedWarningsAfterRelease72();
}
return result;
}
}

private Collection<FileAnnotation> loadFixedWarningsAfterRelease72() {
Set<FileAnnotation> fixedWarnings;
try {
FileAnnotation[] annotations = (FileAnnotation[])getFixedDataFile().read();
fixedWarnings = Sets.newHashSet(annotations);

LOGGER.log(Level.FINE, "Loaded data file " + getFixedDataFile() + " for build " + getOwner().getNumber());
}
catch (IOException exception) {
LOGGER.log(Level.WARNING, "Failed to load " + getFixedDataFile(), exception);
fixedWarnings = new HashSet<FileAnnotation>();
}
fixedWarningsReference = new WeakReference<Collection<FileAnnotation>>(fixedWarnings);

return fixedWarnings;

}

private Collection<FileAnnotation> getFixedWarningsBeforeRelease72() {
if (fixedWarningsReference == null) {
return loadFixedWarnings();
return loadFixedWarningsBeforeRelease72();
}
Collection<FileAnnotation> result = fixedWarningsReference.get();
if (result == null) {
return loadFixedWarnings();
return loadFixedWarningsBeforeRelease72();
}
return result;
}
@@ -1002,7 +1067,7 @@ public Collection<FileAnnotation> getFixedWarnings() {
*
* @return the fixed warnings
*/
private Collection<FileAnnotation> loadFixedWarnings() {
private Collection<FileAnnotation> loadFixedWarningsBeforeRelease72() {
Collection<FileAnnotation> difference = history.getFixedWarnings(getProject().getAnnotations());
fixedWarningsReference = new WeakReference<Collection<FileAnnotation>>(difference);

@@ -75,6 +75,8 @@ public abstract class AbstractAnnotation implements FileAnnotation, Serializable
private int primaryColumnStart;
/** Column end of primary line range of warning. @since 1.38 */
private int primaryColumnEnd;
/** The build number in which this annotation has been introduced. @since 1.72 */
private int build;

/**
* Creates a new instance of <code>AbstractAnnotation</code>.
@@ -611,4 +613,14 @@ public String toString() {
public boolean isInConsoleLog() {
return fileName == null || StringUtils.isBlank(fileName.toString());
}

@Override
public void setBuild(final int build) {
this.build = build;
}

@Override
public int getBuild() {
return build;
}
}
@@ -71,33 +71,29 @@ public interface FileAnnotation extends Comparable<FileAnnotation> {
* in a master - slave scenario where the original file remains on the slave while this temporary file is
* transferred to the master.
*
* @param owner
* the owner that provides the root directory where the files are stored
* @param owner the owner that provides the root directory where the files are stored
* @return the temporary name
*/
String getTempName(AbstractBuild<?, ?> owner);

/**
* Sets the file name to the specified value.
*
* @param fileName
* the value to set
* @param fileName the value to set
*/
void setFileName(final String fileName);

/**
* Sets the pathname for this warning.
*
* @param workspacePath
* the workspace path
* @param workspacePath the workspace path
*/
void setPathName(final String workspacePath);

/**
* Checks if the file exists.
*
* @param owner
* the owner that provides the root directory where the files are stored
* @param owner the owner that provides the root directory where the files are stored
* @return <code>true</code>, if successful
*/
boolean canDisplayFile(AbstractBuild<?, ?> owner);
@@ -119,8 +115,7 @@ public interface FileAnnotation extends Comparable<FileAnnotation> {
/**
* Sets the name of the maven or ant module that contains this annotation.
*
* @param moduleName
* the name of the module that contains this annotation
* @param moduleName the name of the module that contains this annotation
*/
void setModuleName(String moduleName);

@@ -176,8 +171,7 @@ public interface FileAnnotation extends Comparable<FileAnnotation> {
/**
* Sets the context hash code to the specified value.
*
* @param contextHashCode
* the value to set
* @param contextHashCode the value to set
*/
void setContextHashCode(long contextHashCode);

@@ -201,8 +195,24 @@ public interface FileAnnotation extends Comparable<FileAnnotation> {
* Returns whether this annotation is in the console log or in a file in the filesystem.
*
* @return <code>true</code> if this annotation is in the console log, or <code>false</code> if this annotation is
* in a file in the filesystem.
* in a file in the filesystem.
* @since 1.53
*/
boolean isInConsoleLog();

/**
* Sets the build number in which this annotation has been introduced.
*
* @param build the build number introducing this annotation
* @since 1.72
*/
void setBuild(int build);

/**
* Returns the build number in which this annotation has been introduced.
*
* @return the build number introducing this annotation
* @since 1.72
*/
int getBuild();
}

0 comments on commit c6f6e3e

Please sign in to comment.