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.gerrit.common.Nullable;
|
||||||
import com.google.template.soy.SoyFileSet;
|
import com.google.template.soy.SoyFileSet;
|
||||||
import com.google.template.soy.data.SanitizedContent;
|
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.data.UnsafeSanitizedContentOrdainer;
|
||||||
import com.google.template.soy.tofu.SoyTofu;
|
import com.google.template.soy.tofu.SoyTofu;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import javax.servlet.http.HttpServlet;
|
import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -74,8 +75,8 @@ public class IndexServlet extends HttpServlet {
|
|||||||
return uri.getPath().replaceAll("/$", "");
|
return uri.getPath().replaceAll("/$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static SoyMapData getTemplateData(String canonicalURL, String cdnPath, String faviconPath)
|
static Map<String, String> getTemplateData(
|
||||||
throws URISyntaxException {
|
String canonicalURL, String cdnPath, String faviconPath) throws URISyntaxException {
|
||||||
String canonicalPath = computeCanonicalPath(canonicalURL);
|
String canonicalPath = computeCanonicalPath(canonicalURL);
|
||||||
|
|
||||||
String staticPath = "";
|
String staticPath = "";
|
||||||
@@ -91,9 +92,10 @@ public class IndexServlet extends HttpServlet {
|
|||||||
UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
||||||
staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
staticPath, SanitizedContent.ContentKind.TRUSTED_RESOURCE_URI);
|
||||||
|
|
||||||
return new SoyMapData(
|
Map<String, String> data = new HashMap<>();
|
||||||
"canonicalPath", canonicalPath,
|
data.put("canonicalPath", canonicalPath);
|
||||||
"staticResourcePath", sanitizedStaticPath,
|
data.put("staticResourcePath", sanitizedStaticPath.coerceToString());
|
||||||
"faviconPath", faviconPath);
|
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.permissions.PermissionBackendException;
|
||||||
import com.google.gerrit.server.project.ProjectState;
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
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.io.IOException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
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
|
* a 'type' key which maps to one of 'common', 'add' or 'remove' and a 'text' key which maps to
|
||||||
* the line's content.
|
* the line's content.
|
||||||
*/
|
*/
|
||||||
private SoyListData getDiffTemplateData() {
|
private List<Map<String, String>> getDiffTemplateData() {
|
||||||
SoyListData result = new SoyListData();
|
List<Map<String, String>> result = new ArrayList<>();
|
||||||
Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
|
Splitter lineSplitter = Splitter.on(System.getProperty("line.separator"));
|
||||||
for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
|
for (String diffLine : lineSplitter.split(getUnifiedDiff())) {
|
||||||
SoyMapData lineData = new SoyMapData();
|
Map<String, String> lineData = new HashMap<>();
|
||||||
lineData.put("text", diffLine);
|
lineData.put("text", diffLine);
|
||||||
|
|
||||||
// Skip empty lines and lines that look like diff headers.
|
// 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 static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
import com.google.gerrit.testing.GerritBaseTests;
|
import com.google.gerrit.testing.GerritBaseTests;
|
||||||
import com.google.template.soy.data.SoyMapData;
|
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Map;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class IndexServletTest extends GerritBaseTests {
|
public class IndexServletTest extends GerritBaseTests {
|
||||||
@@ -38,35 +38,34 @@ public class IndexServletTest extends GerritBaseTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noPathAndNoCDN() throws URISyntaxException {
|
public void noPathAndNoCDN() throws URISyntaxException {
|
||||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
Map<String, String> data = IndexServlet.getTemplateData("http://example.com/", null, null);
|
||||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("");
|
assertThat(data.get("staticResourcePath")).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathAndNoCDN() throws URISyntaxException {
|
public void pathAndNoCDN() throws URISyntaxException {
|
||||||
SoyMapData data = IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
Map<String, String> data =
|
||||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
IndexServlet.getTemplateData("http://example.com/gerrit/", null, null);
|
||||||
assertThat(data.getSingle("staticResourcePath").stringValue()).isEqualTo("/gerrit");
|
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||||
|
assertThat(data.get("staticResourcePath")).isEqualTo("/gerrit");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noPathAndCDN() throws URISyntaxException {
|
public void noPathAndCDN() throws URISyntaxException {
|
||||||
SoyMapData data =
|
Map<String, String> data =
|
||||||
IndexServlet.getTemplateData("http://example.com/", "http://my-cdn.com/foo/bar/", null);
|
IndexServlet.getTemplateData("http://example.com/", "http://my-cdn.com/foo/bar/", null);
|
||||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("");
|
assertThat(data.get("canonicalPath")).isEqualTo("");
|
||||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
assertThat(data.get("staticResourcePath")).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void pathAndCDN() throws URISyntaxException {
|
public void pathAndCDN() throws URISyntaxException {
|
||||||
SoyMapData data =
|
Map<String, String> data =
|
||||||
IndexServlet.getTemplateData(
|
IndexServlet.getTemplateData(
|
||||||
"http://example.com/gerrit", "http://my-cdn.com/foo/bar/", null);
|
"http://example.com/gerrit", "http://my-cdn.com/foo/bar/", null);
|
||||||
assertThat(data.getSingle("canonicalPath").stringValue()).isEqualTo("/gerrit");
|
assertThat(data.get("canonicalPath")).isEqualTo("/gerrit");
|
||||||
assertThat(data.getSingle("staticResourcePath").stringValue())
|
assertThat(data.get("staticResourcePath")).isEqualTo("http://my-cdn.com/foo/bar/");
|
||||||
.isEqualTo("http://my-cdn.com/foo/bar/");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user