Skip to content

Commit

Permalink
Use functionality from XStream2 where possible (#8504)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Sep 20, 2023
1 parent af260cb commit 9edaffc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/jenkins/install/InstallUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static java.util.logging.Level.SEVERE;
import static java.util.logging.Level.WARNING;

import com.thoughtworks.xstream.XStream;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Functions;
Expand All @@ -37,6 +36,7 @@
import hudson.model.UpdateCenter.InstallationJob;
import hudson.model.UpdateCenter.UpdateCenterJob;
import hudson.util.VersionNumber;
import hudson.util.XStream2;
import jakarta.inject.Provider;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -289,7 +289,7 @@ private static String getCurrentExecVersion() {
if (installingPluginsFile == null || !installingPluginsFile.exists()) {
return null;
}
return (Map<String, String>) new XStream().fromXML(installingPluginsFile);
return (Map<String, String>) new XStream2().fromXML(installingPluginsFile);
}

/**
Expand Down Expand Up @@ -319,7 +319,7 @@ public static synchronized void persistInstallStatus(List<UpdateCenterJob> insta
}
}
try {
String installingPluginXml = new XStream().toXML(statuses);
String installingPluginXml = new XStream2().toXML(statuses);
Files.writeString(Util.fileToPath(installingPluginsFile), installingPluginXml, StandardCharsets.UTF_8);
} catch (IOException e) {
LOGGER.log(SEVERE, "Failed to save " + installingPluginsFile.getAbsolutePath(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Point read(XStream xs) {

@Test
public void ifWorkaroundNeeded() {
XStream xs = new XStream();
XStream xs = new XStream(XStream2.getDefaultDriver());
xs.allowTypes(new Class[] {Point.class});
final ConversionException e = assertThrows(ConversionException.class, () -> read(xs));
assertThat(e.getMessage(), containsString("No such field hudson.util.Point.z"));
Expand Down
3 changes: 2 additions & 1 deletion test/src/test/java/jenkins/security/ClassFilterImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import hudson.model.Saveable;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.XStream2;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -152,7 +153,7 @@ public void xstreamRequiresWhitelist() throws Exception {
config.save();
assertThat(config.getConfigFile().asString(), not(containsString("LinkedListMultimap")));
config.unrelated = "modified";
Files.writeString(config.getConfigFile().getFile().toPath(), new XStream().toXML(config), StandardCharsets.UTF_8);
Files.writeString(config.getConfigFile().getFile().toPath(), new XStream(XStream2.getDefaultDriver()).toXML(config), StandardCharsets.UTF_8);
assertThat(config.getConfigFile().asString(), allOf(containsString("LinkedListMultimap"), containsString("modified")));
config.obj = null;
config.unrelated = null;
Expand Down

0 comments on commit 9edaffc

Please sign in to comment.