Skip to content

Commit

Permalink
Removed stringtree-json dependency in favor of gson
Browse files Browse the repository at this point in the history
  • Loading branch information
mackdk committed Oct 28, 2024
1 parent 9003514 commit d494487
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 50 deletions.
6 changes: 3 additions & 3 deletions java/buildconf/build-props.xml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
commons-el commons-fileupload commons-io ${commons-lang} commons-logging ${commons-validator} ${hibernate5deps}
${commons-compress} ${javamail} smtp jdom ${jmock-jars}
${log4j-jars} oro redstone-xmlrpc-client redstone-xmlrpc ${struts-jars} ${tomcat-jars}
bcprov bcpg stringtree-json postgresql-jdbc ongres-scram/client ongres-scram/common
bcprov bcpg postgresql-jdbc ongres-scram/client ongres-scram/common
${stringprep-jars} taglibs-standard-impl taglibs-standard-jstlel
taglibs-standard-spec logdriver quartz slf4j-api log4j/log4j-slf4j-impl
concurrent velocity-engine-core simple-core mockobjects mockobjects-core mockobjects-jdk1.4-j2ee1.3 strutstest" />
Expand Down Expand Up @@ -201,7 +201,7 @@
commons-el commons-fileupload commons-io ${commons-lang} commons-logging ${commons-validator} ${hibernate5deps}
${commons-compress} ${tomcat-jars} ${javamail} jdom jsch
${log4j-jars} oro redstone-xmlrpc-client redstone-xmlrpc ${struts-jars}
stringtree-json postgresql-jdbc ongres-scram/client ongres-scram/common
postgresql-jdbc ongres-scram/client ongres-scram/common
${stringprep-jars} taglibs-standard-impl taglibs-standard-jstlel
taglibs-standard-spec quartz ${suse-common-jars} velocity-engine-core
concurrent simple-core snakeyaml simple-xml ${commons-jexl}" />
Expand All @@ -214,7 +214,7 @@
${commons-validator} concurrent dom4j ${hibernate5deps} ${jta11-jars}
${jaf} ${jasper-jars} ${javamail} ${jaxb} jdom ${other-jars}
${tomcat-jars} ${log4j-jars} redstone-xmlrpc-client redstone-xmlrpc
oro quartz stringtree-json sitemesh ${struts-jars}
oro quartz sitemesh ${struts-jars}
taglibs-standard-impl taglibs-standard-jstlel taglibs-standard-spec
postgresql-jdbc ongres-scram/client ongres-scram/common ${stringprep-jars}
snakeyaml simple-xml ${suse-common-jars} ${suse-runtime-jars}
Expand Down
1 change: 0 additions & 1 deletion java/buildconf/ivy/ivy-suse.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
<dependency org="suse" name="spy" rev="0.8.7" />
<dependency org="suse" name="statistics" rev="1.0.2" />
<dependency org="suse" name="stax2-api" rev="3.1.4" />
<dependency org="suse" name="stringtree-json" rev="2.0.9" />
<dependency org="suse" name="struts" rev="1.2.9" />
<dependency org="suse" name="taglibs-standard-impl" rev="1.2.5" />
<dependency org="suse" name="taglibs-standard-jstlel" rev="1.2.5" />
Expand Down
2 changes: 0 additions & 2 deletions java/buildconf/ivy/obs-maven-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ artifacts:
- artifact: stax2-api
package: woodstox
repository: Uyuni_Other
- artifact: stringtree-json
repository: Uyuni_Other
- artifact: struts
repository: Uyuni_Other
- artifact: taglibs-standard-impl
Expand Down
23 changes: 0 additions & 23 deletions java/code/src/com/redhat/rhn/common/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.xml.utils.XMLChar;
import org.stringtree.json.JSONReader;
import org.stringtree.json.JSONWriter;

import java.io.File;
import java.net.URLEncoder;
Expand Down Expand Up @@ -698,27 +696,6 @@ public static String toPlainText(String html) {
return helper.convert(html);
}

/**
* Converts an object to json representation
* @param obj any object
* @return the jsoned representation
*/
public static String toJson(Object obj) {
JSONWriter writer = new JSONWriter();
return writer.write(obj);
}

/**
* Converts a jsoned representation back to the object
* @param json json string
* @return the converted object.. The caller is expected to know the kind of
* returned object.
*/
public static Object jsonToObject(String json) {
JSONReader reader = new JSONReader();
return reader.read(json);
}

/**
* Convert a string of options (name value pairs separated by '=', where the
* pairs are seperated by 'separator'), into a map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.redhat.rhn.frontend.taglibs.list.ListTagHelper;
import com.redhat.rhn.manager.audit.AuditManager;

import com.suse.utils.Json;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts.action.ActionForm;
Expand All @@ -32,7 +34,6 @@
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.stringtree.json.JSONWriter;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -167,7 +168,6 @@ public ActionForward execute(ActionMapping mapping,
DateRangePicker.DatePickerResults dpresults;
DynaActionForm dform = (DynaActionForm)form;
HttpSession session = request.getSession(true);
JSONWriter jsonwr = new JSONWriter();
List<AuditDto> result = null;
long start, end;
Map<String, String[]> typemap;
Expand Down Expand Up @@ -280,7 +280,7 @@ else if (!submitted && request.getAttribute("machine") != null) {
// or this is what they asked for
if (result == null) {
typemap = AuditManager.getAuditTypeMap();
request.setAttribute("auJsonTypes", jsonwr.write(typemap));
request.setAttribute("auJsonTypes", Json.GSON.toJson(typemap));
request.setAttribute("machines", AuditManager.getMachines());
request.setAttribute("types", prepareAuditTypes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.redhat.rhn.manager.user.UserManager;

import com.suse.manager.webui.services.pillar.MinionPillarManager;
import com.suse.utils.Json;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -62,7 +63,6 @@
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.stringtree.json.JSONWriter;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -768,8 +768,6 @@ else if (original != null) {
}
ctx.getRequest().setAttribute("parentChannelChecksums", parentChannelChecksums);

JSONWriter json = new JSONWriter();

// base channel arches
List<Map<String, String>> channelArches = new ArrayList<>();
List<ChannelArch> arches = ChannelManager.getChannelArchitectures();
Expand All @@ -788,10 +786,10 @@ else if (original != null) {
.values());
for (String arch : uniqueParentChannelArches) {
archCompatMap.put(
arch, json.write(ChannelManager.compatibleChildChannelArches(arch)));
arch, Json.GSON.toJson(ChannelManager.compatibleChildChannelArches(arch)));
}
// empty string for when there is no parent, all arches are available
archCompatMap.put("", json.write(allArchConstruct));
archCompatMap.put("", Json.GSON.toJson(allArchConstruct));
ctx.getRequest().setAttribute("archCompatMap", archCompatMap);

// set the list of yum supported checksums
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import com.redhat.rhn.frontend.struts.ActionChainHelper;
import com.redhat.rhn.frontend.struts.RequestContext;

import com.suse.utils.Json;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.stringtree.json.JSONWriter;

import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -136,6 +137,6 @@ private String makeResult(boolean success, String messageId) {
Map<String, Object> result = new HashMap<>();
result.put(SUCCESS_FIELD, success);
result.put(TEXT_FIELD, LocalizationService.getInstance().getMessage(messageId));
return new JSONWriter().write(result);
return Json.GSON.toJson(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import com.redhat.rhn.testing.RhnMockHttpServletRequest;
import com.redhat.rhn.testing.TestUtils;

import com.suse.utils.Json;

import com.google.gson.reflect.TypeToken;

import org.junit.jupiter.api.Test;
import org.stringtree.json.JSONReader;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -81,8 +84,8 @@ public void testSave() throws Exception {
String resultString = saveAction.save(actionChain.getId(), newLabel,
deletedEntries, deletedSortOrders, reorderedSortOrders, request);

Map<String, Object> result = (Map<String, Object>) new JSONReader()
.read(resultString);
Map<String, Object> result = Json.GSON.fromJson(resultString,
new TypeToken<Map<String, Object>>() { }.getType());
assertEquals(true, result.get(ActionChainSaveAction.SUCCESS_FIELD));
assertEquals(LocalizationService.getInstance().getMessage("actionchain.jsp.saved"),
result.get(ActionChainSaveAction.TEXT_FIELD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts.action.DynaActionForm;
import org.stringtree.json.JSONWriter;

import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -105,8 +104,7 @@ public static void prepopulateActionChains(HttpServletRequest request) {
populateActionChain(result, placeholder);
}

String json = new JSONWriter().write(result);
request.setAttribute(EXISTING_ACTION_CHAINS_PROPERTY_NAME, json);
request.setAttribute(EXISTING_ACTION_CHAINS_PROPERTY_NAME, Json.GSON.toJson(result));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
import com.redhat.rhn.testing.BaseTestCaseWithUser;
import com.redhat.rhn.testing.TestUtils;

import com.suse.utils.Json;

import com.mockobjects.servlet.MockHttpServletRequest;

import org.apache.struts.action.DynaActionForm;
import org.junit.jupiter.api.Test;
import org.stringtree.json.JSONWriter;

import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -98,9 +99,8 @@ public void testPrepopulateActionChains() {
}

MockHttpServletRequest request = TestUtils.getRequestWithSessionAndUser();
String s = new JSONWriter().write(result);
request.addExpectedSetAttribute(
ActionChainHelper.EXISTING_ACTION_CHAINS_PROPERTY_NAME, s);
ActionChainHelper.EXISTING_ACTION_CHAINS_PROPERTY_NAME, Json.GSON.toJson(result));

ActionChainHelper.prepopulateActionChains(request);
}
Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.mackdk.drop-stringtree
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove stringtree-json dependency in favor of gson
2 changes: 0 additions & 2 deletions java/spacewalk-java.spec
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ BuildRequires: snakeyaml >= 1.33
BuildRequires: spark-core
BuildRequires: spark-template-jade
BuildRequires: statistics
BuildRequires: stringtree-json
BuildRequires: struts >= 1.2.9
BuildRequires: tomcat >= 7
BuildRequires: tomcat-lib >= 7
Expand Down Expand Up @@ -227,7 +226,6 @@ Requires: spacewalk-java-lib = %{version}
Requires: spark-core
Requires: spark-template-jade
Requires: statistics
Requires: stringtree-json
Requires: struts >= 1.2.9
Requires: sudo
Requires: susemanager-docs_en
Expand Down

0 comments on commit d494487

Please sign in to comment.