From 1f6bda75fd129c64a5cdb5535f2265de0eabe8f7 Mon Sep 17 00:00:00 2001 From: Goktug Gokdogan Date: Tue, 26 Nov 2024 19:51:08 -0800 Subject: [PATCH] Remove soy dependency from WebFiles (#629) This is in preparation of removing soy dependency from rules_closure. --- .../bazel/rules/closure/webfiles/server/BUILD | 8 --- .../closure/webfiles/server/ListingPage.java | 68 +++++++++---------- .../rules/closure/webfiles/server/listing.soy | 59 ---------------- 3 files changed, 34 insertions(+), 101 deletions(-) delete mode 100644 java/io/bazel/rules/closure/webfiles/server/listing.soy diff --git a/java/io/bazel/rules/closure/webfiles/server/BUILD b/java/io/bazel/rules/closure/webfiles/server/BUILD index 30d746416c..8eed9b0779 100644 --- a/java/io/bazel/rules/closure/webfiles/server/BUILD +++ b/java/io/bazel/rules/closure/webfiles/server/BUILD @@ -16,7 +16,6 @@ licenses(["notice"]) load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_proto_library") -load("//closure:defs.bzl", "closure_java_template_library") java_library( name = "server", @@ -24,7 +23,6 @@ java_library( visibility = ["//:__subpackages__"], deps = [ ":build_info_java_proto", - ":listing", "//java/io/bazel/rules/closure:webpath", "//java/io/bazel/rules/closure/http", "//java/io/bazel/rules/closure/http/filter", @@ -33,7 +31,6 @@ java_library( "@com_google_dagger", "@com_google_guava", "@com_google_protobuf//:protobuf_java", - "@com_google_template_soy", ], ) @@ -54,8 +51,3 @@ java_proto_library( visibility = ["//visibility:public"], deps = [":build_info_proto"], ) - -closure_java_template_library( - name = "listing", - srcs = ["listing.soy"], -) diff --git a/java/io/bazel/rules/closure/webfiles/server/ListingPage.java b/java/io/bazel/rules/closure/webfiles/server/ListingPage.java index 9e3c2b4b01..706737a72c 100644 --- a/java/io/bazel/rules/closure/webfiles/server/ListingPage.java +++ b/java/io/bazel/rules/closure/webfiles/server/ListingPage.java @@ -14,17 +14,8 @@ package io.bazel.rules.closure.webfiles.server; -import static com.google.common.io.Resources.getResource; - -import com.google.common.base.Functions; -import com.google.common.base.Predicate; -import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableSet; import com.google.common.net.MediaType; -import com.google.template.soy.SoyFileSet; -import com.google.template.soy.data.SoyListData; -import com.google.template.soy.data.SoyMapData; -import com.google.template.soy.tofu.SoyTofu; import io.bazel.rules.closure.Webpath; import io.bazel.rules.closure.http.HttpResponse; import java.io.IOException; @@ -38,12 +29,6 @@ */ class ListingPage { - private static final SoyTofu TOFU = - SoyFileSet.builder() - .add(getResource(ListingSoyInfo.class, ListingSoyInfo.getInstance().getFileName())) - .build() - .compileToTofu(); - private final HttpResponse response; private final Metadata.Config config; private final ImmutableSet webpaths; @@ -56,25 +41,40 @@ class ListingPage { } void serve(final Webpath webpath) throws IOException { + StringBuilder builder = new StringBuilder(); + builder.append(""); + builder.append(""); + builder.append(""); + builder.append("

Bazel Closure Rules

"); + builder.append("

").append(config.get().getLabel()).append("

"); + builder.append("

"); + if (webpaths.isEmpty()) { + builder.append("No srcs found in transitive closure with path component prefix matching"); + builder.append("request path."); + } else { + webpaths.stream() + .filter(path -> path.startsWith(webpath)) + .forEach(path -> builder.append("" + path + "
")); + } response.setContentType(MediaType.HTML_UTF_8); - response.setPayload( - TOFU.newRenderer(ListingSoyInfo.LISTING) - .setData( - new SoyMapData( - ListingSoyInfo.ListingSoyTemplateInfo.LABEL, - config.get().getLabel(), - ListingSoyInfo.ListingSoyTemplateInfo.PATHS, - new SoyListData( - FluentIterable.from(webpaths) - .filter( - new Predicate() { - @Override - public boolean apply(Webpath path) { - return path.startsWith(webpath); - } - }) - .transform(Functions.toStringFunction())))) - .render() - .getBytes(StandardCharsets.UTF_8)); + response.setPayload(builder.toString().getBytes(StandardCharsets.UTF_8)); } } diff --git a/java/io/bazel/rules/closure/webfiles/server/listing.soy b/java/io/bazel/rules/closure/webfiles/server/listing.soy deleted file mode 100644 index 9ebed8fac4..0000000000 --- a/java/io/bazel/rules/closure/webfiles/server/listing.soy +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The Closure Rules Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -{namespace io.bazel.rules.closure.server} - - -/** - * Displays page listing paths in transitive closure. - */ -{template listing} - {@param label: string} - {@param paths: list} - - - -

Bazel Closure Rules

-

{$label}

-

- {if length($paths) != 0} - {for $path in $paths} - {$path}
- {/for} - {else} - No srcs found in transitive closure with path component prefix matching - request path. - {/if} -{/template}