Skip to content

Commit

Permalink
Merge pull request #437 from jglick/CME
Browse files Browse the repository at this point in the history
Make `ContentContainer.contents` thread-safe
  • Loading branch information
Dohbedoh authored Feb 1, 2023
2 parents ce1fc0f + f36f899 commit 665d89f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/main/java/com/cloudbees/jenkins/support/SupportPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -568,13 +569,13 @@ private static List<Content> appendManifestContents(StringBuilder manifest,
errors.println();
}
}
return contentsContainer.contents;
return contentsContainer.getContents();

}

private static class ContentContainer extends Container {
private final List<Content> contents = new ArrayList<>();
private final Set<String> names = new TreeSet<>();
private final Set<String> names = new HashSet<>();

//The filter to return the names filtered
private final Optional<ContentFilter> maybeFilter;
Expand All @@ -583,24 +584,31 @@ private static class ContentContainer extends Container {
* We need the filter to be able to filter the contents written to the manifest
* @param maybeFilter filter to use when writing the name of the contents
*/
public ContentContainer(Optional<ContentFilter> maybeFilter) {
ContentContainer(Optional<ContentFilter> maybeFilter) {
this.maybeFilter = maybeFilter;
}

@Override
public void add(Content content) {
if (content != null) {
contents.add(content);
names.add(getNameFiltered(maybeFilter, content.getName(), content.getFilterableParameters()));
String name = getNameFiltered(maybeFilter, content.getName(), content.getFilterableParameters());
synchronized (this) {
contents.add(content);
names.add(name);
}
}
}

private Set<String> getLatestNames() {
synchronized Set<String> getLatestNames() {
Set<String> copy = new TreeSet<>(names);
names.clear();
return copy;
}

synchronized List<Content> getContents() {
return new ArrayList<>(contents);
}

}

public List<LogRecord> getAllLogRecords() {
Expand Down

0 comments on commit 665d89f

Please sign in to comment.