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:43 UTC
(logging-log4j-tools) 23/29: Report the source on `DescriptorGenerator` failures
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 757d118571dd71183daa33ebc1c4d2d9c5108521
Author: Volkan Yazıcı <vo...@yazi.ci>
AuthorDate: Mon Feb 19 14:19:24 2024 +0100
Report the source on `DescriptorGenerator` failures
---
.../docgen/processor/DescriptorGenerator.java | 50 ++++++++++++++--------
.../docgen/processor/AsciiDocConverterTest.java | 2 +-
.../docgen/processor/DescriptorGeneratorTest.java | 10 ++++-
.../example/JavadocExample.java | 26 +++++++++++
4 files changed, 69 insertions(+), 19 deletions(-)
diff --git a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
index 03d0e04..1ae19e3 100644
--- a/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
+++ b/log4j-docgen/src/main/java/org/apache/logging/log4j/docgen/processor/DescriptorGenerator.java
@@ -182,31 +182,47 @@ public class DescriptorGenerator extends AbstractProcessor {
}
private void addPluginDocumentation(final Element element) {
- if (element instanceof TypeElement) {
- final PluginType pluginType = new PluginType();
- pluginType.setName(annotations.getPluginSpecifiedName(element).orElseGet(() -> element.getSimpleName()
- .toString()));
- pluginType.setNamespace(
- annotations.getPluginSpecifiedNamespace(element).orElse("Core"));
- populatePlugin((TypeElement) element, pluginType);
- pluginSet.addPlugin(pluginType);
- } else {
- messager.printMessage(Diagnostic.Kind.WARNING, "Found @Plugin annotation on unexpected element.", element);
+ try {
+ if (element instanceof TypeElement) {
+ final PluginType pluginType = new PluginType();
+ pluginType.setName(annotations.getPluginSpecifiedName(element).orElseGet(() -> element.getSimpleName()
+ .toString()));
+ pluginType.setNamespace(
+ annotations.getPluginSpecifiedNamespace(element).orElse("Core"));
+ populatePlugin((TypeElement) element, pluginType);
+ pluginSet.addPlugin(pluginType);
+ } else {
+ messager.printMessage(
+ Diagnostic.Kind.WARNING, "Found @Plugin annotation on unexpected element.", element);
+ }
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
}
}
private void addAbstractTypeDocumentation(final QualifiedNameable element) {
- final AbstractType abstractType = new AbstractType();
- populateAbstractType(element, abstractType);
- if (!abstractType.getDescription().getText().isEmpty()) {
- pluginSet.addAbstractType(abstractType);
+ try {
+ final AbstractType abstractType = new AbstractType();
+ populateAbstractType(element, abstractType);
+ if (!abstractType.getDescription().getText().isEmpty()) {
+ pluginSet.addAbstractType(abstractType);
+ }
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
}
}
private void addScalarTypeDocumentation(final TypeElement element) {
- final ScalarType scalarType = new ScalarType();
- populateScalarType(element, scalarType);
- pluginSet.addScalar(scalarType);
+ try {
+ final ScalarType scalarType = new ScalarType();
+ populateScalarType(element, scalarType);
+ pluginSet.addScalar(scalarType);
+ } catch (final Exception error) {
+ final String message = String.format("failed to process element `%s`", element);
+ throw new RuntimeException(message, error);
+ }
}
private void writePluginDescriptor() {
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 a1e9233..b650aaf 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
@@ -120,7 +120,7 @@ public class AsciiDocConverterTest {
if (ElementKind.CLASS.equals(element.getKind())
&& TEST_CLASS_NAME.equals(element.getSimpleName().toString())) {
final FileObject output = fileManager.getFileForOutput(
- StandardLocation.CLASS_OUTPUT, "", "JavadocExample.adoc", null);
+ StandardLocation.CLASS_OUTPUT, "", TEST_CLASS_NAME + ".adoc", null);
final String asciiDoc = converter.toAsciiDoc(element);
assertThat(asciiDoc).isNotNull();
try (final OutputStream os = output.openOutputStream()) {
diff --git a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
index 180041a..201d68c 100644
--- a/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
+++ b/log4j-docgen/src/test/java/org/apache/logging/log4j/docgen/processor/DescriptorGeneratorTest.java
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.docgen.processor;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -54,6 +55,13 @@ public class DescriptorGeneratorTest {
test(outputDir, Paths.get("src/test/resources/plugins-using-log4j3"));
}
+ @Test
+ void failure_source_should_be_reported(@TempDir(cleanup = CleanupMode.ON_SUCCESS) final Path outputDir) {
+ assertThatThrownBy(() -> test(outputDir, Paths.get("src/test/resources/javadoc-invalid-input")))
+ .hasMessageContaining("failed to process element `example.JavadocExample`")
+ .hasRootCauseMessage("A <li> tag must be a child of a <ol> or <ul> tag.");
+ }
+
private static void test(final Path outputDir, final Path sourceDir) throws Exception {
final Path modelloGeneratedSchema = Paths.get("target/generated-site/resources/xsd/plugins-0.1.0.xsd");
final Path expectedDescriptor = Paths.get("src/test/resources/generated-plugins.xml");
@@ -79,7 +87,7 @@ public class DescriptorGeneratorTest {
sources = fileManager.getJavaFileObjects(sourceFiles);
}
- // Set the target path used by `DocGenProcessor` to dump the generated files
+ // Set the target path used by `DescriptorGenerator` to dump the generated files
fileManager.setLocationFromPaths(StandardLocation.CLASS_OUTPUT, Set.of(outputDir));
// Compile the sources
diff --git a/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.java b/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.java
new file mode 100644
index 0000000..3d6f0b2
--- /dev/null
+++ b/log4j-docgen/src/test/resources/javadoc-invalid-input/example/JavadocExample.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 example;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+
+/**
+ * Example class containing invalid JavaDoc
+ * <li>This should not be allowed
+ */
+@Plugin(name = "Foo", category = "Bar")
+public class JavadocExample {}