Skip to content

Commit

Permalink
Merge pull request #567 from jglick/warnings
Browse files Browse the repository at this point in the history
Fixing various compiler/IDE warnings in `AboutJenkins`
  • Loading branch information
jglick authored Aug 12, 2024
2 parents 2445c06 + ab1e99d commit 550b336
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/main/java/com/cloudbees/jenkins/support/impl/AboutJenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.PluginWrapper;
import hudson.Util;
import hudson.lifecycle.Lifecycle;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Node;
import hudson.model.Slave;
Expand Down Expand Up @@ -85,11 +86,11 @@ public class AboutJenkins extends Component {

private static final Logger logger = Logger.getLogger(AboutJenkins.class.getName());

private final WeakHashMap<Node, String> agentVersionCache = new WeakHashMap<Node, String>();
private final WeakHashMap<Node, String> agentVersionCache = new WeakHashMap<>();

private final WeakHashMap<Node, String> javaInfoCache = new WeakHashMap<Node, String>();
private final WeakHashMap<Node, String> javaInfoCache = new WeakHashMap<>();

private final WeakHashMap<Node, String> agentDigestCache = new WeakHashMap<Node, String>();
private final WeakHashMap<Node, String> agentDigestCache = new WeakHashMap<>();

@NonNull
@Override
Expand All @@ -112,8 +113,8 @@ public ComponentCategory getCategory() {

@Override
public void addContents(@NonNull Container container) {
List<PluginWrapper> activePlugins = new ArrayList<PluginWrapper>();
List<PluginWrapper> disabledPlugins = new ArrayList<PluginWrapper>();
List<PluginWrapper> activePlugins = new ArrayList<>();
List<PluginWrapper> disabledPlugins = new ArrayList<>();
List<PluginWrapper> backupPlugins = new ArrayList<>();

populatePluginsLists(activePlugins, disabledPlugins, backupPlugins);
Expand Down Expand Up @@ -157,10 +158,11 @@ private static final class GetAgentDigest extends MasterToSlaveCallable<String,
private static final long serialVersionUID = 1L;
private final String rootPathName;

public GetAgentDigest(FilePath rootPath) {
GetAgentDigest(FilePath rootPath) {
this.rootPathName = rootPath.getRemote();
}

@Override
public String call() {
StringBuilder result = new StringBuilder();
final File rootPath = new File(this.rootPathName);
Expand Down Expand Up @@ -191,6 +193,7 @@ private static class GetAgentVersion extends MasterToSlaveCallable<String, Runti
},
justification =
"{Findbugs mis-diagnosing closeQuietly's built-in null check, https://github.com/spotbugs/spotbugs/issues/756}")
@Override
public String call() throws RuntimeException {
try (InputStream is =
hudson.remoting.Channel.class.getResourceAsStream("/jenkins/remoting/jenkins-version.properties")) {
Expand Down Expand Up @@ -223,6 +226,7 @@ private GetJavaInfo(String majorBullet, String minorBullet) {
this.passwordRedactor = PasswordRedactor.get();
}

@Override
public String call() throws RuntimeException {
return getInfo(null);
}
Expand Down Expand Up @@ -561,7 +565,7 @@ protected void printTo(PrintWriter out, ContentFilter filter) throws IOException

private static class IdentityContent extends PrintedContent {

public IdentityContent() {
IdentityContent() {
super("identity.md");
}

Expand All @@ -582,8 +586,7 @@ private static class Plugins extends PrintedContent {
private final Iterable<PluginWrapper> plugins;
private final Function<? super PluginWrapper, String> stringify;

public Plugins(
Iterable<PluginWrapper> plugins, String name, Function<? super PluginWrapper, String> stringify) {
Plugins(Iterable<PluginWrapper> plugins, String name, Function<? super PluginWrapper, String> stringify) {
super(name);
this.plugins = plugins;
this.stringify = stringify;
Expand All @@ -601,19 +604,19 @@ public boolean shouldBeFiltered() {
}

private static class ActivePlugins extends Plugins {
public ActivePlugins(Iterable<PluginWrapper> plugins) {
ActivePlugins(Iterable<PluginWrapper> plugins) {
super(plugins, "plugins/active.txt", w -> w.getShortName() + ":" + w.getVersion());
}
}

private static class DisabledPlugins extends Plugins {
public DisabledPlugins(Iterable<PluginWrapper> plugins) {
DisabledPlugins(Iterable<PluginWrapper> plugins) {
super(plugins, "plugins/disabled.txt", w -> w.getShortName() + ":" + w.getVersion());
}
}

private static class FailedPlugins extends PrintedContent {
public FailedPlugins() {
FailedPlugins() {
super("plugins/failed.txt");
}

Expand All @@ -635,7 +638,7 @@ public boolean shouldBeFiltered() {

private static class BackupPlugins extends Plugins {

public BackupPlugins(Iterable<PluginWrapper> plugins) {
BackupPlugins(Iterable<PluginWrapper> plugins) {
super(plugins, "plugins/backup.txt", w -> w.getShortName() + ":" + w.getBackupVersion());
}
}
Expand All @@ -644,7 +647,7 @@ private static class Dockerfile extends PrintedContent {
private final List<PluginWrapper> activated;
private final List<PluginWrapper> disabled;

public Dockerfile(List<PluginWrapper> activated, List<PluginWrapper> disabled) {
Dockerfile(List<PluginWrapper> activated, List<PluginWrapper> disabled) {
super("docker/Dockerfile");
this.activated = activated;
this.disabled = disabled;
Expand Down Expand Up @@ -749,7 +752,7 @@ protected void printTo(PrintWriter out, ContentFilter filter) throws IOException
out.println(" - Labels: " + ContentFilter.filter(filter, getLabelString(jenkins)));
out.println(" - Usage: `" + jenkins.getMode() + "`");
Optional.ofNullable(jenkins.toComputer())
.ifPresent(computer -> out.println(" - Marked Offline: " + computer.isTemporarilyOffline()));
.ifPresent(computer -> out.println(" - Marked Offline: " + isTemporarilyOffline(computer)));
if (jenkins.getChannel() == null) {
out.println(" - Status: offline");
} else {
Expand Down Expand Up @@ -789,7 +792,7 @@ protected void printTo(PrintWriter out, ContentFilter filter) throws IOException
}
Optional.ofNullable(node.toComputer())
.ifPresent(
computer -> out.println(" - Marked Offline: " + computer.isTemporarilyOffline()));
computer -> out.println(" - Marked Offline: " + isTemporarilyOffline(computer)));
VirtualChannel channel = node.getChannel();
if (channel == null) {
out.println(" - Status: off-line");
Expand Down Expand Up @@ -828,6 +831,11 @@ protected void printTo(PrintWriter out, ContentFilter filter) throws IOException
out.println();
}
}

@SuppressWarnings("deprecation")
private boolean isTemporarilyOffline(Computer computer) {
return computer.isTemporarilyOffline();
}
}

private static class ControllerChecksumsContent extends PrintedContent {
Expand Down Expand Up @@ -864,8 +872,7 @@ protected void printTo(PrintWriter out) throws IOException {
if (stapler != null) {
try {
final ServletContext servletContext = stapler.getServletContext();
Set<String> resourcePaths = (Set<String>) servletContext.getResourcePaths("/WEB-INF/lib");
for (String resourcePath : new TreeSet<String>(resourcePaths)) {
for (String resourcePath : new TreeSet<>(servletContext.getResourcePaths("/WEB-INF/lib"))) {
try {
out.println(Util.getDigestOf(servletContext.getResourceAsStream(resourcePath))
+ " war" // FIPS OK: Not security related.
Expand All @@ -886,8 +893,8 @@ protected void printTo(PrintWriter out) throws IOException {
logger.log(Level.WARNING, "Could not compute MD5 of war" + resourcePath, e);
}
}
resourcePaths = (Set<String>) servletContext.getResourcePaths("/WEB-INF/update-center-rootCAs");
for (String resourcePath : new TreeSet<String>(resourcePaths)) {
for (String resourcePath :
new TreeSet<>(servletContext.getResourcePaths("/WEB-INF/update-center-rootCAs"))) {
try {
out.println(Util.getDigestOf(servletContext.getResourceAsStream(resourcePath))
+ " war" // FIPS OK: Not security related.
Expand Down Expand Up @@ -967,7 +974,7 @@ private static Iterable<PluginWrapper> getPluginsSorted(PluginManager pluginMana
}

private static <T extends Comparable<T>> Iterable<T> listToSortedIterable(List<T> list) {
final List<T> sorted = new LinkedList<T>(list);
final List<T> sorted = new LinkedList<>(list);
Collections.sort(sorted);
return sorted;
}
Expand Down

0 comments on commit 550b336

Please sign in to comment.