Skip to content

Commit

Permalink
Make FolderComputation implement Loadable (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jan 24, 2024
2 parents 24ad197 + 38336fc commit b943ea6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.ExtensionList;
import hudson.Util;
import hudson.XmlFile;
import hudson.model.Action;
import hudson.model.BuildableItem;
import hudson.model.Cause;
Expand Down Expand Up @@ -216,13 +215,10 @@ public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOExcep
LOGGER.log(Level.WARNING, null, x);
}
synchronized (this) {
XmlFile file = computation.getDataFile();
if (file.exists()) {
try {
file.unmarshal(computation);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load " + file, e);
}
try {
computation.load();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to load " + computation, e);

Check warning on line 221 in src/main/java/com/cloudbees/hudson/plugins/folder/computed/ComputedFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 221 is not covered by tests
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import com.jcraft.jzlib.GZIPInputStream;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.AbortException;
import hudson.BulkChange;
Expand Down Expand Up @@ -76,6 +75,7 @@
import javax.servlet.ServletException;
import net.jcip.annotations.GuardedBy;
import java.nio.charset.StandardCharsets;
import jenkins.model.Loadable;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
Expand All @@ -89,7 +89,7 @@
* A particular “run” of {@link ComputedFolder}.
* @since 4.11-beta-1
*/
public class FolderComputation<I extends TopLevelItem> extends Actionable implements Queue.Executable, Saveable {
public class FolderComputation<I extends TopLevelItem> extends Actionable implements Queue.Executable, Saveable, Loadable {

/**
* Our logger.
Expand Down Expand Up @@ -203,6 +203,7 @@ public void run() {
*/
@Override
public void save() throws IOException {
LOGGER.fine(() -> "saving " + this);
if (BulkChange.contains(this)) {
return;
}
Expand All @@ -211,6 +212,15 @@ public void save() throws IOException {
SaveableListener.fireOnChange(this, dataFile);
}

@Override
public void load() throws IOException {
LOGGER.fine(() -> "loading " + this);
XmlFile dataFile = getDataFile();
if (dataFile.exists()) {

Check warning on line 219 in src/main/java/com/cloudbees/hudson/plugins/folder/computed/FolderComputation.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 219 is only partially covered, one branch is missing
dataFile.unmarshal(this);
}
}

@NonNull
public File getLogFile() {
return new File(folder.getComputationDir(), "computation.log");
Expand Down

0 comments on commit b943ea6

Please sign in to comment.