Github user bbende commented on a diff in the pull request:
https://github.com/apache/nifi-maven/pull/7#discussion_r240310495
--- Diff: src/main/java/org/apache/nifi/NarMojo.java ---
@@ -426,12 +479,260 @@
protected boolean cloneDuringInstanceClassLoading;
+ /**
+ * The {@link RepositorySystemSession} used for obtaining the local
and remote artifact repositories.
+ */
+ @Parameter(defaultValue = "${repositorySystemSession}", readonly =
true)
+ private RepositorySystemSession repoSession;
+
+
+ /**
+ * The {@link ProjectBuilder} used to generate the {@link
MavenProject} for the nar artifact the dependency tree is being generated for.
+ */
+ @Component
+ private ProjectBuilder projectBuilder;
+
+
+
@Override
- public void execute() throws MojoExecutionException,
MojoFailureException {
+ public void execute() throws MojoExecutionException {
copyDependencies();
+
+ try {
+ generateDocumentation();
+ } catch (final Throwable t) { // Catch Throwable in case a linkage
error such as NoClassDefFoundError occurs
+ getLog().warn("Could not generate extensions' documentation",
t);
+ }
+
makeNar();
}
+ private File getExtensionsDocumentationFile() {
+ final File directory = new File(projectBuildDirectory,
"META-INF/docs");
+ return new File(directory, "extension-docs.xml");
+ }
+
+ private void generateDocumentation() throws MojoExecutionException {
+ getLog().info("Generating documentation for NiFi extensions in the
NAR...");
+
+ // Create the ClassLoader for the NAR
+ final ExtensionClassLoaderFactory classLoaderFactory =
createClassLoaderFactory();
+
+ final ExtensionClassLoader extensionClassLoader;
+ try {
+ extensionClassLoader =
classLoaderFactory.createExtensionClassLoader();
+ } catch (final Exception e) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Unable to create a ClassLoader for
documenting extensions. If this NAR contains any NiFi Extensions, those
extensions will not be documented.", e);
+ } else {
+ getLog().warn("Unable to create a ClassLoader for
documenting extensions. If this NAR contains any NiFi Extensions, those
extensions will not be documented. " +
+ "Enable mvn DEBUG output for more information (mvn
-X).");
+ }
+
+ return;
+ }
+
+
+ final File docsFile = getExtensionsDocumentationFile();
+ createDirectory(docsFile.getParentFile());
+
+ final File additionalDetailsDir = new
File(docsFile.getParentFile(), "additional-details");
+ createDirectory(additionalDetailsDir);
+
+ try (final OutputStream out = new FileOutputStream(docsFile)) {
+
+ final XMLStreamWriter xmlWriter =
XMLOutputFactory.newInstance().createXMLStreamWriter(out, "UTF-8");
+ try {
+ xmlWriter.writeStartElement("extensions");
+
+ final String nifiApiVersion =
extensionClassLoader.getNiFiApiVersion();
+ xmlWriter.writeStartElement("nifiApiVersion");
+ xmlWriter.writeCharacters(nifiApiVersion);
+ xmlWriter.writeEndElement();
+
+ final Class<?> docWriterClass;
+ try {
+ docWriterClass =
Class.forName(DOCUMENTATION_WRITER_CLASS_NAME, false, extensionClassLoader);
--- End diff --
Should we do this before entering the try block on line 542 so that if the
doc writer class can't be found we won't write anything to the docs file?
---