Stop using deprecated SoyListData and SoyMapData
Per the deprecation notices, users of these classes should use normal List and Map instead. The Soy rendering APIs can automatically handle conversion of native Java types. Change-Id: I101e455fea721a7cb083dd2b26c59e5e7527acf8
This commit is contained in:
@@ -22,13 +22,14 @@ import com.google.common.io.Resources;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.template.soy.SoyFileSet;
|
||||
import com.google.template.soy.data.SanitizedContent;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -74,8 +75,8 @@ public class IndexServlet extends HttpServlet {
|
||||
return uri.getPath().replaceAll("/$", "");
|
||||
}
|
||||
|
||||
static SoyMapData getTemplateData(String canonicalURL, String cdnPath, String faviconPath)
|
||||
throws URISyntaxException {
|
||||
static Map<String, String> getTemplateData(
|
||||
String canonicalURL, String cdnPath, String faviconPath) throws URISyntaxException {
|
||||
String canonicalPath = computeCanonicalPath(canonicalURL);
|
||||
|
||||
String staticPath = "";
|
||||
@@ -91,9 +92,10 @@ public class IndexServlet extends HttpServlet {
|
||||
UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
||||
staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
||||
|
||||
return new SoyMapData(
|
||||
"canonicalPath", canonicalPath,
|
||||
"staticResourcePath", sanitizedStaticPath,
|
||||
"faviconPath", faviconPath);
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("canonicalPath", canonicalPath);
|
||||
data.put("staticResourcePath", sanitizedStaticPath.coerceToString());
|
||||
data.put("faviconPath", faviconPath);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@@ -44,15 +44,15 @@ import com.google.gerrit.server.permissions.GlobalPermission;
|
||||
import com.google.gerrit.server.permissions.PermissionBackendException;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gerrit.server.query.change.ChangeData;
|
||||
import com.google.template.soy.data.SoyListData;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
@@ -563,11 +563,11 @@ public abstract class ChangeEmail extends NotificationEmail {
|
||||
* a 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to
|
||||
* the line's content.
|
||||
*/
|
||||
private SoyListData getDiffTemplateData() {
|
||||
SoyListData result = new SoyListData();
|
||||
private List<Map<String, String>> getDiffTemplateData() {
|
||||
List<Map<String, String>> result = new ArrayList<>();
|
||||
Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
|
||||
for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
|
||||
SoyMapData lineData = new SoyMapData();
|
||||
Map<String, String> lineData = new HashMap<>();
|
||||
lineData.put("text", diffLine);
|
||||
|
||||
// Skip empty lines and lines that look like diff headers.
|
||||
|
@@ -18,8 +18,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import com.google.gerrit.testing.GerritBaseTests;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IndexServletTest extends GerritBaseTests {
|
||||
@@ -38,35 +38,34 @@ public class IndexServletTest extends GerritBaseTests {
|
||||
|
||||
@Test
|
||||
public void noPathAndNoCDN() throws URISyntaxException {
|
||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("");
|
||||
Map<String, String> data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||
assertThat(data.get("staticResourcePath")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathAndNoCDN() throws URISyntaxException {
|
||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("/gerrit");
|
||||
Map<String, String> data =
|
||||
IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||
assertThat(data.get("staticResourcePath")).isEqualTo("/gerrit");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noPathAndCDN() throws URISyntaxException {
|
||||
SoyMapData data =
|
||||
Map<String, String> data =
|
||||
IndexServlet.getTemplateData("http://example.com/", "http://my-cdn.com/foo/bar/", null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||
assertThat(data.get("staticResourcePath")).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathAndCDN() throws URISyntaxException {
|
||||
SoyMapData data =
|
||||
Map<String, String> data =
|
||||
IndexServlet.getTemplateData(
|
||||
"http://example.com/gerrit", "http://my-cdn.com/foo/bar/", null);
|
||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||
assertThat(data.get("staticResourcePath")).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user