Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,12 @@
final class BanDuplicateNamespacesPass implements CompilerFileSetPass {
private static final SoyErrorKind DUPLICATE_NAMESPACE =
SoyErrorKind.of(
"Found another file ''{0}'' with the same namespace. All files must have unique"
+ " namespaces.",
"Namespace collision with: {0}. All files must have unique namespaces.",
Impression.ERROR_BAN_DUPLICATE_NAMESPACES_PASS_DUPLICATE_NAMESPACE);
private static final SoyErrorKind DUPLICATE_NAMESPACE_WARNING =
SoyErrorKind.of(
"Found another file ''{0}'' with the same namespace. All files should have unique"
+ " namespaces. This will soon become an error.",
"Namespace collision with: {0}. All files should have unique namespaces. This will soon"
+ " become an error.",
Impression.WARNING_BAN_DUPLICATE_NAMESPACES_PASS_DUPLICATE_NAMESPACE_WARNING);
private static final SoyErrorKind NAMESPACE_COLLISION =
SoyErrorKind.of(
Expand All @@ -79,7 +78,10 @@ public Result run(ImmutableList<SoyFileNode> sourceFiles, IdGenerator nodeIdGen)
if (filePaths.size() > 1) {
String filePath = sourceFile.getFilePath().path();
String otherFiles =
filePaths.stream().filter(path -> !path.equals(filePath)).collect(joining(", "));
filePaths.stream()
.filter(path -> !path.equals(filePath))
.map(path -> "'" + path + "'")
.collect(joining(", "));
if (NamespaceExemptions.isKnownDuplicateNamespace(sourceFile.getNamespace())) {
errorReporter.warn(
sourceFile.getNamespaceDeclaration().getSourceLocation(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.common.base.Joiner;
import com.google.template.soy.SoyFileSetParser.ParseResult;
import com.google.template.soy.base.SourceFilePath;
import com.google.template.soy.base.internal.SoyFileSupplier;
Expand All @@ -37,32 +36,28 @@ public void externOnlyDuplicateNamespace_reportsError() {
ParseResult unused =
SoyFileSetParserBuilder.forSuppliers(
SoyFileSupplier.Factory.create(
Joiner.on("\n")
.join(
"{namespace my.duplicate.namespace.testing}",
"{template t}",
"{/template}"),
"""
{namespace my.duplicate.namespace.testing}
{template t}
{/template}\
""",
SourceFilePath.forTest("file1.soy")),
SoyFileSupplier.Factory.create(
Joiner.on("\n")
.join(
"{namespace my.duplicate.namespace.testing}",
"{extern myExtern: (s: string) => string}",
" {jsimpl namespace=\"goog.string\" function=\"capitalize\" /}",
"{/extern}"),
"""
{namespace my.duplicate.namespace.testing}
{extern myExtern: (s: string) => string}
{jsimpl namespace="goog.string" function="capitalize" /}
{/extern}\
""",
SourceFilePath.forTest("file2.soy")))
.errorReporter(errorReporter)
.build()
.parse();

assertThat(errorReporter.getErrors()).hasSize(2);
assertThat(errorReporter.getErrors().get(0).message())
.isEqualTo(
"Found another file 'file2.soy' with the same namespace. All files must have unique"
+ " namespaces.");
.isEqualTo("Namespace collision with: 'file2.soy'. All files must have unique namespaces.");
assertThat(errorReporter.getErrors().get(1).message())
.isEqualTo(
"Found another file 'file1.soy' with the same namespace. All files must have unique"
+ " namespaces.");
.isEqualTo("Namespace collision with: 'file1.soy'. All files must have unique namespaces.");
}
}
Loading