Replace usage of `com.google.common.collect.HashMultimap` with native Java equivalent
@@ -28,12 +28,15 @@ import static java.util.logging.Level.FINE;
import static java.util.logging.Level.FINER;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@@ -41,8 +44,6 @@ import hudson.util.RunList;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
-import com.google.common.collect.HashMultimap;
-
import hudson.Extension;
import hudson.model.Job;
import hudson.model.Run;
@@ -143,7 +144,7 @@ public class LogRotator extends BuildDiscarder {
@SuppressWarnings("rawtypes")
public void perform(Job<?,?> job) throws IOException, InterruptedException {
//Exceptions thrown by the deletion submethods are collated and reported
- HashMultimap<Run<?,?>, IOException> exceptionMap = HashMultimap.create();
+ Map<Run<?,?>, Set<IOException>> exceptionMap = new HashMap<>();
LOGGER.log(FINE, "Running the log rotation for {0} with numToKeep={1} daysToKeep={2} artifactNumToKeep={3} artifactDaysToKeep={4}", new Object[] {job, numToKeep, daysToKeep, artifactNumToKeep, artifactDaysToKeep});
@@ -164,7 +165,7 @@ public class LogRotator extends BuildDiscarder {
}
LOGGER.log(FINE, "{0} is to be removed", r);
try { r.delete(); }
- catch (IOException ex) { exceptionMap.put(r, ex); }
+ catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
}
@@ -179,7 +180,7 @@ public class LogRotator extends BuildDiscarder {
if (!shouldKeepRun(r, lsb, lstb)) {
LOGGER.log(FINE, "{0} is to be removed", r);
try { r.delete(); }
- catch (IOException ex) { exceptionMap.put(r, ex); }
+ catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
r = r.getNextBuild();
}
@@ -193,7 +194,7 @@ public class LogRotator extends BuildDiscarder {
}
LOGGER.log(FINE, "{0} is to be purged of artifacts", r);
try { r.deleteArtifacts(); }
- catch (IOException ex) { exceptionMap.put(r, ex); }
+ catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
}
@@ -208,7 +209,7 @@ public class LogRotator extends BuildDiscarder {
if (!shouldKeepRun(r, lsb, lstb)) {
LOGGER.log(FINE, "{0} is to be purged of artifacts", r);
try { r.deleteArtifacts(); }
- catch (IOException ex) { exceptionMap.put(r, ex); }
+ catch (IOException ex) { exceptionMap.computeIfAbsent(r, key -> new HashSet<>()).add(ex); }
}
r = r.getNextBuild();
}
@@ -220,7 +221,7 @@ public class LogRotator extends BuildDiscarder {
"Failed to rotate logs for [%s]",
exceptionMap.keySet().stream().map(Object::toString).collect(Collectors.joining(", "))
);
- throw new CompositeIOException(msg, new ArrayList<>(exceptionMap.values()));
+ throw new CompositeIOException(msg, exceptionMap.values().stream().flatMap(Collection::stream).collect(Collectors.toList()));
}
}
