You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2024/02/21 14:21:39 UTC

(logging-log4j-tools) 19/29: Rename template files

This is an automated email from the ASF dual-hosted git repository.

vy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-tools.git

commit 52399469ebf78cd1e16190b9572507de9eb50ec2
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Thu Feb 15 15:48:25 2024 +0100

    Rename template files
---
 .../log4j/docgen/generator/DocumentationFiles.java | 26 ++++++++++++++++++++++
 .../generator/DocumentationGeneratorArgs.java      | 17 +++++++++++---
 .../generator/DocumentationGeneratorTest.java      |  7 +++++-
 .../docgen/processor/AsciiDocConverterTest.java    |  2 +-
 .../{interface.ftl => interface.adoc.ftl}          |  2 +-
 .../templates/{license.ftl => license.adoc.ftl}    |  0
 .../templates/{plugin.ftl => plugin.adoc.ftl}      |  2 +-
 .../templates/{scalars.ftl => scalars.adoc.ftl}    |  2 +-
 8 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
new file mode 100644
index 0000000..43de35f
--- /dev/null
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationFiles.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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.
+ */
+package org.apache.logging.log4j.docgen.generator;
+
+final class DocumentationFiles {
+
+    private DocumentationFiles() {}
+
+    public static String templateFileNameExtension() {
+        return "ftl";
+    }
+}
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
index 789e317..b013797 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorArgs.java
@@ -21,6 +21,7 @@ import static java.util.Objects.requireNonNull;
 import java.nio.file.Path;
 import java.util.Set;
 import org.apache.logging.log4j.docgen.PluginSet;
+import org.jspecify.annotations.Nullable;
 
 public final class DocumentationGeneratorArgs {
 
@@ -45,9 +46,19 @@ public final class DocumentationGeneratorArgs {
             final Path outputDirectory) {
         this.pluginSets = requireNonNull(pluginSets, "pluginSets");
         this.templateDirectory = requireNonNull(templateDirectory, "templateDirectory");
-        this.scalarsTemplateName = requireNonNull(scalarsTemplateName, "scalarsTemplateName");
-        this.pluginTemplateName = requireNonNull(pluginTemplateName, "pluginTemplateName");
-        this.interfaceTemplateName = requireNonNull(interfaceTemplateName, "interfaceTemplateName");
+        this.scalarsTemplateName = requireValidTemplateName(scalarsTemplateName, "scalarsTemplateName");
+        this.pluginTemplateName = requireValidTemplateName(pluginTemplateName, "pluginTemplateName");
+        this.interfaceTemplateName = requireValidTemplateName(interfaceTemplateName, "interfaceTemplateName");
         this.outputDirectory = requireNonNull(outputDirectory, "outputDirectory");
     }
+
+    private static String requireValidTemplateName(@Nullable final String value, final String name) {
+        final String extension = '.' + DocumentationFiles.templateFileNameExtension();
+        if (value == null || !value.endsWith(extension)) {
+            final String message =
+                    String.format("was expecting `%s` to end with a `%s` suffix: `%s`", name, extension, value);
+            throw new IllegalArgumentException(message);
+        }
+        return value;
+    }
 }
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
index 7701c4f..22de8ee 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/generator/DocumentationGeneratorTest.java
@@ -39,7 +39,12 @@ public class DocumentationGeneratorTest {
         // Generate the documentation
         final Path templateDirectory = Paths.get("src/test/resources/templates");
         final DocumentationGeneratorArgs generatorArgs = new DocumentationGeneratorArgs(
-                Set.of(pluginSet), templateDirectory, "scalars.ftl", "plugin.ftl", "interface.ftl", outputDir);
+                Set.of(pluginSet),
+                templateDirectory,
+                "scalars.adoc.ftl",
+                "plugin.adoc.ftl",
+                "interface.adoc.ftl",
+                outputDir);
         DocumentationGenerator.generateDocumentation(generatorArgs);
 
         // Verify the output
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
index 90be680..a1e9233 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/AsciiDocConverterTest.java
@@ -51,7 +51,7 @@ import org.junit.jupiter.api.io.TempDir;
 
 public class AsciiDocConverterTest {
 
-    private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.ftl");
+    private static final Path LICENSE_PATH = Paths.get("src/test/resources/templates/license.adoc.ftl");
 
     private static final String TEST_CLASS_NAME = "JavadocExample";
 
diff --git a/log4j-docgen/src/test/resources/templates/interface.ftl b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
similarity index 97%
rename from log4j-docgen/src/test/resources/templates/interface.ftl
rename to log4j-docgen/src/test/resources/templates/interface.adoc.ftl
index b7fcb32..415107c 100644
--- a/log4j-docgen/src/test/resources/templates/interface.ftl
+++ b/log4j-docgen/src/test/resources/templates/interface.adoc.ftl
@@ -17,7 +17,7 @@
 -->
 <#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.model.AbstractType" -->
 <#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
 = ${type.className?keep_after_last('.')}
 <#if type.description??>
 
diff --git a/log4j-docgen/src/test/resources/templates/license.ftl b/log4j-docgen/src/test/resources/templates/license.adoc.ftl
similarity index 100%
rename from log4j-docgen/src/test/resources/templates/license.ftl
rename to log4j-docgen/src/test/resources/templates/license.adoc.ftl
diff --git a/log4j-docgen/src/test/resources/templates/plugin.ftl b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
similarity index 99%
rename from log4j-docgen/src/test/resources/templates/plugin.ftl
rename to log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
index 245a075..ab4b72b 100644
--- a/log4j-docgen/src/test/resources/templates/plugin.ftl
+++ b/log4j-docgen/src/test/resources/templates/plugin.adoc.ftl
@@ -17,7 +17,7 @@
 -->
 <#-- @ftlvariable name="type" type="org.apache.logging.log4j.docgen.PluginType" -->
 <#-- @ftlvariable name="lookup" type="org.apache.logging.log4j.docgen.generator.TypeLookup" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
 = ${type.name}
 
 ${type.description.text}
diff --git a/log4j-docgen/src/test/resources/templates/scalars.ftl b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
similarity index 97%
rename from log4j-docgen/src/test/resources/templates/scalars.ftl
rename to log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
index 1c50f18..42ca665 100644
--- a/log4j-docgen/src/test/resources/templates/scalars.ftl
+++ b/log4j-docgen/src/test/resources/templates/scalars.adoc.ftl
@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
 limitations under the License.
 -->
 <#-- @ftlvariable name="scalars" type="org.apache.logging.log4j.docgen.model.ScalarType[]" -->
-<#include "license.ftl">
+<#include "license.adoc.ftl">
 = Type converters
 
 Type converter plugins are used to convert simple `String` values into other types.