NIFI-632 using NarCloseable instead of NarThreadContextClassLoader

to make sure the right classloader is being used when initializing
a component for documentation generation
This commit is contained in:
danbress 2015-06-08 22:05:49 -04:00
parent 995a01636e
commit 196da2b443
5 changed files with 21 additions and 25 deletions

View File

@ -26,10 +26,6 @@
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-framework-core-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-properties</artifactId>

View File

@ -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,15 +68,9 @@ 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<? extends ConfigurableComponent> componentClass = extensionClass
.asSubclass(ConfigurableComponent.class);
final Class<? extends ConfigurableComponent> componentClass = extensionClass.asSubclass(ConfigurableComponent.class);
try {
logger.debug("Documenting: " + componentClass);
document(explodedNiFiDocsDir, componentClass);
@ -86,9 +79,6 @@ public class DocGenerator {
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
/**

View File

@ -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;
try (NarCloseable narCloseable = NarCloseable.withNarLoader()) {
controllerService.initialize(new MockControllerServiceInitializationContext());
}
}
}

View File

@ -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;
try (NarCloseable narCloseable = NarCloseable.withNarLoader()) {
processor.initialize(new MockProcessorInitializationContext());
}
}
}

View File

@ -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;
try (NarCloseable narCloseable = NarCloseable.withNarLoader()) {
reportingTask.initialize(new MockReportingInitializationContext());
}
}
}