From 196da2b443645f5029ab9d8ddf381e3a58e42969 Mon Sep 17 00:00:00 2001 From: danbress Date: Mon, 8 Jun 2015 22:05:49 -0400 Subject: [PATCH] NIFI-632 using NarCloseable instead of NarThreadContextClassLoader to make sure the right classloader is being used when initializing a component for documentation generation --- .../nifi-framework/nifi-documentation/pom.xml | 4 --- .../nifi/documentation/DocGenerator.java | 26 ++++++------------- .../init/ControllerServiceInitializer.java | 6 ++++- .../init/ProcessorInitializer.java | 5 +++- .../init/ReportingTaskingInitializer.java | 5 +++- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/pom.xml b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/pom.xml index 66febbbb73..340f2c54b3 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/pom.xml +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/pom.xml @@ -26,10 +26,6 @@ org.apache.nifi nifi-api - - org.apache.nifi - nifi-framework-core-api - org.apache.nifi nifi-properties diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java index c817bfa11a..7c32bf8004 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java @@ -33,7 +33,6 @@ import org.apache.nifi.documentation.init.ControllerServiceInitializer; import org.apache.nifi.documentation.init.ProcessorInitializer; import org.apache.nifi.documentation.init.ReportingTaskingInitializer; import org.apache.nifi.nar.ExtensionManager; -import org.apache.nifi.nar.NarThreadContextClassLoader; import org.apache.nifi.processor.Processor; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.ReportingTask; @@ -69,25 +68,16 @@ public class DocGenerator { logger.debug("Generating documentation for: " + extensionClasses.size() + " components in: " + explodedNiFiDocsDir); - // save the original class loader and use a NarThreadContextClassLoader - final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(NarThreadContextClassLoader.getInstance()); - - for (final Class extensionClass : extensionClasses) { - if (ConfigurableComponent.class.isAssignableFrom(extensionClass)) { - final Class componentClass = extensionClass - .asSubclass(ConfigurableComponent.class); - try { - logger.debug("Documenting: " + componentClass); - document(explodedNiFiDocsDir, componentClass); - } catch (Exception e) { - logger.warn("Unable to document: " + componentClass, e); - } + for (final Class extensionClass : extensionClasses) { + if (ConfigurableComponent.class.isAssignableFrom(extensionClass)) { + final Class componentClass = extensionClass.asSubclass(ConfigurableComponent.class); + try { + logger.debug("Documenting: " + componentClass); + document(explodedNiFiDocsDir, componentClass); + } catch (Exception e) { + logger.warn("Unable to document: " + componentClass, e); } } - } finally { - Thread.currentThread().setContextClassLoader(originalClassLoader); } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java index 3c66485923..0f654ecbd9 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ControllerServiceInitializer.java @@ -20,6 +20,7 @@ import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.controller.ControllerService; import org.apache.nifi.documentation.ConfigurableComponentInitializer; import org.apache.nifi.documentation.mock.MockControllerServiceInitializationContext; +import org.apache.nifi.nar.NarCloseable; import org.apache.nifi.reporting.InitializationException; /** @@ -33,6 +34,9 @@ public class ControllerServiceInitializer implements ConfigurableComponentInitia @Override public void initialize(ConfigurableComponent component) throws InitializationException { ControllerService controllerService = (ControllerService) component; - controllerService.initialize(new MockControllerServiceInitializationContext()); + + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { + controllerService.initialize(new MockControllerServiceInitializationContext()); + } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java index 07e9c3ab8f..331db7132a 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ProcessorInitializer.java @@ -19,6 +19,7 @@ package org.apache.nifi.documentation.init; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.documentation.ConfigurableComponentInitializer; import org.apache.nifi.documentation.mock.MockProcessorInitializationContext; +import org.apache.nifi.nar.NarCloseable; import org.apache.nifi.processor.Processor; /** @@ -31,7 +32,9 @@ public class ProcessorInitializer implements ConfigurableComponentInitializer { @Override public void initialize(ConfigurableComponent component) { Processor processor = (Processor) component; - processor.initialize(new MockProcessorInitializationContext()); + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { + processor.initialize(new MockProcessorInitializationContext()); + } } } diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java index 6fcfca91da..49291a7231 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/init/ReportingTaskingInitializer.java @@ -19,6 +19,7 @@ package org.apache.nifi.documentation.init; import org.apache.nifi.components.ConfigurableComponent; import org.apache.nifi.documentation.ConfigurableComponentInitializer; import org.apache.nifi.documentation.mock.MockReportingInitializationContext; +import org.apache.nifi.nar.NarCloseable; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.reporting.ReportingTask; @@ -32,6 +33,8 @@ public class ReportingTaskingInitializer implements ConfigurableComponentInitial @Override public void initialize(ConfigurableComponent component) throws InitializationException { ReportingTask reportingTask = (ReportingTask) component; - reportingTask.initialize(new MockReportingInitializationContext()); + try (NarCloseable narCloseable = NarCloseable.withNarLoader()) { + reportingTask.initialize(new MockReportingInitializationContext()); + } } }