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:
David Pursehouse
2019-06-15 16:15:21 +09:00
parent 4fa34cfbfc
commit 29c8ee6440
5 changed files with 27 additions and 26 deletions

View File

@@ -25,7 +25,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
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.UnsafeSanitizedContentOrdainer; 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.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@@ -42,7 +42,7 @@ public class IndexServlet extends HttpServlet {
@Nullable private final String cdnPath; @Nullable private final String cdnPath;
@Nullable private final String faviconPath; @Nullable private final String faviconPath;
private final GerritApi gerritApi; private final GerritApi gerritApi;
private final SoyTofu soyTofu; private final SoySauce soySauce;
private final Function<String, SanitizedContent> urlOrdainer; private final Function<String, SanitizedContent> urlOrdainer;
IndexServlet( IndexServlet(
@@ -54,11 +54,11 @@ public class IndexServlet extends HttpServlet {
this.cdnPath = cdnPath; this.cdnPath = cdnPath;
this.faviconPath = faviconPath; this.faviconPath = faviconPath;
this.gerritApi = gerritApi; this.gerritApi = gerritApi;
this.soyTofu = this.soySauce =
SoyFileSet.builder() SoyFileSet.builder()
.add(Resources.getResource("com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy")) .add(Resources.getResource("com/google/gerrit/httpd/raw/PolyGerritIndexHtml.soy"))
.build() .build()
.compileToTofu(); .compileTemplates();
this.urlOrdainer = this.urlOrdainer =
(s) -> (s) ->
UnsafeSanitizedContentOrdainer.ordainAsSafe( UnsafeSanitizedContentOrdainer.ordainAsSafe(
@@ -67,7 +67,7 @@ public class IndexServlet extends HttpServlet {
@Override @Override
protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException { protected void doGet(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
SoyTofu.Renderer renderer; SoySauce.Renderer renderer;
try { try {
Map<String, String[]> parameterMap = req.getParameterMap(); Map<String, String[]> parameterMap = req.getParameterMap();
// TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent // TODO(hiesel): Remove URL ordainer as parameter once Soy is consistent
@@ -75,9 +75,9 @@ public class IndexServlet extends HttpServlet {
IndexHtmlUtil.templateData( IndexHtmlUtil.templateData(
gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer); gerritApi, canonicalUrl, cdnPath, faviconPath, parameterMap, urlOrdainer);
renderer = renderer =
soyTofu soySauce
.newRenderer("com.google.gerrit.httpd.raw.Index") .renderTemplate("com.google.gerrit.httpd.raw.Index")
.setContentKind(SanitizedContent.ContentKind.HTML) .setExpectedContentKind(SanitizedContent.ContentKind.HTML)
.setData(templateData); .setData(templateData);
} catch (URISyntaxException | RestApiException e) { } catch (URISyntaxException | RestApiException e) {
throw new IOException(e); throw new IOException(e);
@@ -87,7 +87,7 @@ public class IndexServlet extends HttpServlet {
rsp.setContentType("text/html"); rsp.setContentType("text/html");
rsp.setStatus(SC_OK); rsp.setStatus(SC_OK);
try (OutputStream w = rsp.getOutputStream()) { try (OutputStream w = rsp.getOutputStream()) {
w.write(renderer.render().getBytes(UTF_8)); w.write(renderer.render().get().getBytes(UTF_8));
} }
} }
} }

View File

@@ -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.FromAddressGenerator;
import com.google.gerrit.server.mail.send.FromAddressGeneratorProvider; import com.google.gerrit.server.mail.send.FromAddressGeneratorProvider;
import com.google.gerrit.server.mail.send.InboundEmailRejectionSender; 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.mail.send.MailTemplates;
import com.google.gerrit.server.mime.FileTypeRegistry; import com.google.gerrit.server.mime.FileTypeRegistry;
import com.google.gerrit.server.mime.MimeUtilFileTypeRegistry; 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.Inject;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import com.google.inject.internal.UniqueAnnotations; 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 java.util.List;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.transport.PostReceiveHook; import org.eclipse.jgit.transport.PostReceiveHook;
@@ -281,7 +281,7 @@ public class GerritGlobalModule extends FactoryModule {
bind(ApprovalsUtil.class); 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(FromAddressGenerator.class).toProvider(FromAddressGeneratorProvider.class).in(SINGLETON);
bind(Boolean.class) bind(Boolean.class)
.annotatedWith(EnableReverseDnsLookup.class) .annotatedWith(EnableReverseDnsLookup.class)

View File

@@ -45,7 +45,7 @@ import com.google.gerrit.server.ssh.SshAdvertisedAddresses;
import com.google.gerrit.server.validators.OutgoingEmailValidationListener; import com.google.gerrit.server.validators.OutgoingEmailValidationListener;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; 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 java.util.List;
import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Config;
import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.PersonIdent;
@@ -75,7 +75,7 @@ public class EmailArguments {
final ChangeQueryBuilder queryBuilder; final ChangeQueryBuilder queryBuilder;
final ChangeData.Factory changeDataFactory; final ChangeData.Factory changeDataFactory;
final SoyTofu soyTofu; final SoySauce soySauce;
final EmailSettings settings; final EmailSettings settings;
final DynamicSet<OutgoingEmailValidationListener> outgoingEmailValidationListeners; final DynamicSet<OutgoingEmailValidationListener> outgoingEmailValidationListeners;
final Provider<InternalAccountQuery> accountQueryProvider; final Provider<InternalAccountQuery> accountQueryProvider;
@@ -105,7 +105,7 @@ public class EmailArguments {
AllProjectsName allProjectsName, AllProjectsName allProjectsName,
ChangeQueryBuilder queryBuilder, ChangeQueryBuilder queryBuilder,
ChangeData.Factory changeDataFactory, ChangeData.Factory changeDataFactory,
@MailTemplates SoyTofu soyTofu, @MailTemplates SoySauce soySauce,
EmailSettings settings, EmailSettings settings,
@SshAdvertisedAddresses List<String> sshAddresses, @SshAdvertisedAddresses List<String> sshAddresses,
SitePaths site, SitePaths site,
@@ -134,7 +134,7 @@ public class EmailArguments {
this.allProjectsName = allProjectsName; this.allProjectsName = allProjectsName;
this.queryBuilder = queryBuilder; this.queryBuilder = queryBuilder;
this.changeDataFactory = changeDataFactory; this.changeDataFactory = changeDataFactory;
this.soyTofu = soyTofu; this.soySauce = soySauce;
this.settings = settings; this.settings = settings;
this.sshAddresses = sshAddresses; this.sshAddresses = sshAddresses;
this.site = site; this.site = site;

View File

@@ -22,17 +22,17 @@ import com.google.inject.Provider;
import com.google.inject.ProvisionException; import com.google.inject.ProvisionException;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.google.template.soy.SoyFileSet; 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.shared.SoyAstCache;
import com.google.template.soy.tofu.SoyTofu;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
/** Configures Soy Tofu object for rendering email templates. */ /** Configures Soy Sauce object for rendering email templates. */
@Singleton @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. // Note: will fail to construct the tofu object if this array is empty.
private static final String[] TEMPLATES = { private static final String[] TEMPLATES = {
@@ -82,19 +82,19 @@ public class MailSoyTofuProvider implements Provider<SoyTofu> {
private final SoyAstCache cache; private final SoyAstCache cache;
@Inject @Inject
MailSoyTofuProvider(SitePaths site, SoyAstCache cache) { MailSoySauceProvider(SitePaths site, SoyAstCache cache) {
this.site = site; this.site = site;
this.cache = cache; this.cache = cache;
} }
@Override @Override
public SoyTofu get() throws ProvisionException { public SoySauce get() throws ProvisionException {
SoyFileSet.Builder builder = SoyFileSet.builder(); SoyFileSet.Builder builder = SoyFileSet.builder();
builder.setSoyAstCache(cache); builder.setSoyAstCache(cache);
for (String name : TEMPLATES) { for (String name : TEMPLATES) {
addTemplate(builder, name); addTemplate(builder, name);
} }
return builder.build().compileToTofu(); return builder.build().compileTemplates();
} }
private void addTemplate(SoyFileSet.Builder builder, String name) throws ProvisionException { private void addTemplate(SoyFileSet.Builder builder, String name) throws ProvisionException {

View File

@@ -543,11 +543,12 @@ public abstract class OutgoingEmail {
} }
private String soyTemplate(String name, SanitizedContent.ContentKind kind) { private String soyTemplate(String name, SanitizedContent.ContentKind kind) {
return args.soyTofu return args.soySauce
.newRenderer("com.google.gerrit.server.mail.template." + name) .renderTemplate("com.google.gerrit.server.mail.template." + name)
.setContentKind(kind) .setExpectedContentKind(kind)
.setData(soyContext) .setData(soyContext)
.render(); .render()
.get();
} }
protected String textTemplate(String name) { protected String textTemplate(String name) {