Migrate from SoyTofu to SoySauce
SoyTofu is deprecated in soy version 2019-04-18. Replace it with SoySauce as recommended. Change-Id: I054c3a4a97c1e0eb7488646abee4f437d26b1ce8
This commit is contained in:
@@ -25,7 +25,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.template.soy.SoyFileSet;
|
||||
import com.google.template.soy.data.SanitizedContent;
|
||||
import com.google.template.soy.data.UnsafeSanitizedContentOrdainer;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import com.google.template.soy.jbcsrc.api.SoySauce;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -42,7 +42,7 @@ public class IndexServlet extends HttpServlet {
|
||||
@Nullable private final String cdnPath;
|
||||
@Nullable private final String faviconPath;
|
||||
private final GerritApi gerritApi;
|
||||
private final SoyTofu soyTofu;
|
||||
private final SoySauce soySauce;
|
||||
private final Function<String, SanitizedContent> urlOrdainer;
|
||||
|
||||
IndexServlet(
|
||||
@@ -54,11 +54,11 @@ public class IndexServlet extends HttpServlet {
|
||||
this.cdnPath = cdnPath;
|
||||
this.faviconPath = faviconPath;
|
||||
this.gerritApi = gerritApi;
|
||||
this.soyTofu =
|
||||
this.soySauce =
|
||||
SoyFileSet.builder()
|
||||
.add(Resources.getResource("com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy"))
|
||||
.build()
|
||||
.compileToTofu();
|
||||
.compileTemplates();
|
||||
this.urlOrdainer =
|
||||
(s) ->
|
||||
UnsafeSanitizedContentOrdainer.ordainAsSafe(
|
||||
@@ -67,7 +67,7 @@ public class IndexServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||
SoyTofu.Renderer renderer;
|
||||
SoySauce.Renderer renderer;
|
||||
try {
|
||||
Map<String, String[]> parameterMap = req.getParameterMap();
|
||||
// TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent
|
||||
@@ -75,9 +75,9 @@ public class IndexServlet extends HttpServlet {
|
||||
IndexHtmlUtil.templateData(
|
||||
gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer);
|
||||
renderer =
|
||||
soyTofu
|
||||
.newRenderer("com.google.gerrit.httpd.raw.Index")
|
||||
.setContentKind(SanitizedContent.ContentKind.HTML)
|
||||
soySauce
|
||||
.renderTemplate("com.google.gerrit.httpd.raw.Index")
|
||||
.setExpectedContentKind(SanitizedContent.ContentKind.HTML)
|
||||
.setData(templateData);
|
||||
} catch (URISyntaxException | RestApiException e) {
|
||||
throw new IOException(e);
|
||||
@@ -87,7 +87,7 @@ public class IndexServlet extends HttpServlet {
|
||||
rsp.setContentType("text/html");
|
||||
rsp.setStatus(SC_OK);
|
||||
try (OutputStream w = rsp.getOutputStream()) {
|
||||
w.write(renderer.render().getBytes(UTF_8));
|
||||
w.write(renderer.render().get().getBytes(UTF_8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ import com.google.gerrit.server.mail.MailFilter;
|
||||
import com.google.gerrit.server.mail.send.FromAddressGenerator;
|
||||
import com.google.gerrit.server.mail.send.FromAddressGeneratorProvider;
|
||||
import com.google.gerrit.server.mail.send.InboundEmailRejectionSender;
|
||||
import com.google.gerrit.server.mail.send.MailSoyTofuProvider;
|
||||
import com.google.gerrit.server.mail.send.MailSoySauceProvider;
|
||||
import com.google.gerrit.server.mail.send.MailTemplates;
|
||||
import com.google.gerrit.server.mime.FileTypeRegistry;
|
||||
import com.google.gerrit.server.mime.MimeUtilFileTypeRegistry;
|
||||
@@ -191,7 +191,7 @@ import com.google.gitiles.blame.cache.BlameCacheImpl;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.internal.UniqueAnnotations;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import com.google.template.soy.jbcsrc.api.SoySauce;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.transport.PostReceiveHook;
|
||||
@@ -281,7 +281,7 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
|
||||
bind(ApprovalsUtil.class);
|
||||
|
||||
bind(SoyTofu.class).annotatedWith(MailTemplates.class).toProvider(MailSoyTofuProvider.class);
|
||||
bind(SoySauce.class).annotatedWith(MailTemplates.class).toProvider(MailSoySauceProvider.class);
|
||||
bind(FromAddressGenerator.class).toProvider(FromAddressGeneratorProvider.class).in(SINGLETON);
|
||||
bind(Boolean.class)
|
||||
.annotatedWith(EnableReverseDnsLookup.class)
|
||||
|
||||
@@ -45,7 +45,7 @@ import com.google.gerrit.server.ssh.SshAdvertisedAddresses;
|
||||
import com.google.gerrit.server.validators.OutgoingEmailValidationListener;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import com.google.template.soy.jbcsrc.api.SoySauce;
|
||||
import java.util.List;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
@@ -75,7 +75,7 @@ public class EmailArguments {
|
||||
|
||||
final ChangeQueryBuilder queryBuilder;
|
||||
final ChangeData.Factory changeDataFactory;
|
||||
final SoyTofu soyTofu;
|
||||
final SoySauce soySauce;
|
||||
final EmailSettings settings;
|
||||
final DynamicSet<OutgoingEmailValidationListener> outgoingEmailValidationListeners;
|
||||
final Provider<InternalAccountQuery> accountQueryProvider;
|
||||
@@ -105,7 +105,7 @@ public class EmailArguments {
|
||||
AllProjectsName allProjectsName,
|
||||
ChangeQueryBuilder queryBuilder,
|
||||
ChangeData.Factory changeDataFactory,
|
||||
@MailTemplates SoyTofu soyTofu,
|
||||
@MailTemplates SoySauce soySauce,
|
||||
EmailSettings settings,
|
||||
@SshAdvertisedAddresses List<String> sshAddresses,
|
||||
SitePaths site,
|
||||
@@ -134,7 +134,7 @@ public class EmailArguments {
|
||||
this.allProjectsName = allProjectsName;
|
||||
this.queryBuilder = queryBuilder;
|
||||
this.changeDataFactory = changeDataFactory;
|
||||
this.soyTofu = soyTofu;
|
||||
this.soySauce = soySauce;
|
||||
this.settings = settings;
|
||||
this.sshAddresses = sshAddresses;
|
||||
this.site = site;
|
||||
|
||||
@@ -22,17 +22,17 @@ import com.google.inject.Provider;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.template.soy.SoyFileSet;
|
||||
import com.google.template.soy.jbcsrc.api.SoySauce;
|
||||
import com.google.template.soy.shared.SoyAstCache;
|
||||
import com.google.template.soy.tofu.SoyTofu;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/** Configures Soy Tofu object for rendering email templates. */
|
||||
/** Configures Soy Sauce object for rendering email templates. */
|
||||
@Singleton
|
||||
public class MailSoyTofuProvider implements Provider<SoyTofu> {
|
||||
public class MailSoySauceProvider implements Provider<SoySauce> {
|
||||
|
||||
// Note: will fail to construct the tofu object if this array is empty.
|
||||
private static final String[] TEMPLATES = {
|
||||
@@ -82,19 +82,19 @@ public class MailSoyTofuProvider implements Provider<SoyTofu> {
|
||||
private final SoyAstCache cache;
|
||||
|
||||
@Inject
|
||||
MailSoyTofuProvider(SitePaths site, SoyAstCache cache) {
|
||||
MailSoySauceProvider(SitePaths site, SoyAstCache cache) {
|
||||
this.site = site;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoyTofu get() throws ProvisionException {
|
||||
public SoySauce get() throws ProvisionException {
|
||||
SoyFileSet.Builder builder = SoyFileSet.builder();
|
||||
builder.setSoyAstCache(cache);
|
||||
for (String name : TEMPLATES) {
|
||||
addTemplate(builder, name);
|
||||
}
|
||||
return builder.build().compileToTofu();
|
||||
return builder.build().compileTemplates();
|
||||
}
|
||||
|
||||
private void addTemplate(SoyFileSet.Builder builder, String name) throws ProvisionException {
|
||||
@@ -543,11 +543,12 @@ public abstract class OutgoingEmail {
|
||||
}
|
||||
|
||||
private String soyTemplate(String name, SanitizedContent.ContentKind kind) {
|
||||
return args.soyTofu
|
||||
.newRenderer("com.google.gerrit.server.mail.template." + name)
|
||||
.setContentKind(kind)
|
||||
return args.soySauce
|
||||
.renderTemplate("com.google.gerrit.server.mail.template." + name)
|
||||
.setExpectedContentKind(kind)
|
||||
.setData(soyContext)
|
||||
.render();
|
||||
.render()
|
||||
.get();
|
||||
}
|
||||
|
||||
protected String textTemplate(String name) {
|
||||
|
||||
Reference in New Issue
Block a user