Repository: incubator-nifi Updated Branches: refs/heads/NIFI-271 afb4fe52b -> b612b6bcd
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java index 5306ddf..c6ed9fb 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java @@ -31,73 +31,72 @@ import org.junit.Test; public class ProcessorDocumentationWriterTest { - @Test - public void testFullyDocumentedProcessor() throws IOException { - FullyDocumentedProcessor processor = new FullyDocumentedProcessor(); - processor.initialize(new MockProcessorInitializationContext()); - - DocumentationWriter writer = new HtmlProcessorDocumentationWriter(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - writer.write(processor, baos, false); - - String results = new String(baos.toByteArray()); - XmlValidator.assertXmlValid(results); - - assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName()); - assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription()); - assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDisplayName()); - assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDescription()); - assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDisplayName()); - assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDescription()); - assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDefaultValue()); - assertContains(results, FullyDocumentedProcessor.RECURSE.getDisplayName()); - assertContains(results, FullyDocumentedProcessor.RECURSE.getDescription()); - - assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getName()); - assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription()); - assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName()); - assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription()); - assertContains(results, "Controller Service: "); - assertContains(results, "SampleService"); - - assertNotContains(results, "iconSecure.png"); - assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class) - .value()); - assertNotContains(results, "This component has no required or optional properties."); - assertNotContains(results, "No description provided."); - assertNotContains(results, "No Tags provided."); - assertNotContains(results, "Additional Details..."); - } - - @Test - public void testNakedProcessor() throws IOException { - NakedProcessor processor = new NakedProcessor(); - processor.initialize(new MockProcessorInitializationContext()); - - DocumentationWriter writer = new HtmlProcessorDocumentationWriter(); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - writer.write(processor, baos, false); - - String results = new String(baos.toByteArray()); - XmlValidator.assertXmlValid(results); - - // no description - assertContains(results, "No description provided."); - - // no tags - assertContains(results, "None."); - - // properties - assertContains(results, "This component has no required or optional properties."); - - // relationships - assertContains(results, "This processor has no relationships."); - - - } + @Test + public void testFullyDocumentedProcessor() throws IOException { + FullyDocumentedProcessor processor = new FullyDocumentedProcessor(); + processor.initialize(new MockProcessorInitializationContext()); + + DocumentationWriter writer = new HtmlProcessorDocumentationWriter(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + writer.write(processor, baos, false); + + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); + + assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDisplayName()); + assertContains(results, FullyDocumentedProcessor.DIRECTORY.getDescription()); + assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDisplayName()); + assertContains(results, FullyDocumentedProcessor.OPTIONAL_PROPERTY.getDescription()); + assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDisplayName()); + assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDescription()); + assertContains(results, FullyDocumentedProcessor.POLLING_INTERVAL.getDefaultValue()); + assertContains(results, FullyDocumentedProcessor.RECURSE.getDisplayName()); + assertContains(results, FullyDocumentedProcessor.RECURSE.getDescription()); + + assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getName()); + assertContains(results, FullyDocumentedProcessor.REL_SUCCESS.getDescription()); + assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getName()); + assertContains(results, FullyDocumentedProcessor.REL_FAILURE.getDescription()); + assertContains(results, "Controller Service: "); + assertContains(results, "SampleService"); + + assertNotContains(results, "iconSecure.png"); + assertContains(results, FullyDocumentedProcessor.class.getAnnotation(CapabilityDescription.class) + .value()); + assertNotContains(results, "This component has no required or optional properties."); + assertNotContains(results, "No description provided."); + assertNotContains(results, "No Tags provided."); + assertNotContains(results, "Additional Details..."); + } + + @Test + public void testNakedProcessor() throws IOException { + NakedProcessor processor = new NakedProcessor(); + processor.initialize(new MockProcessorInitializationContext()); + + DocumentationWriter writer = new HtmlProcessorDocumentationWriter(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + writer.write(processor, baos, false); + + String results = new String(baos.toByteArray()); + XmlValidator.assertXmlValid(results); + + // no description + assertContains(results, "No description provided."); + + // no tags + assertContains(results, "None."); + + // properties + assertContains(results, "This component has no required or optional properties."); + + // relationships + assertContains(results, "This processor has no relationships."); + + } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java index 6cb7499..8bddf98 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java @@ -28,23 +28,24 @@ import org.xml.sax.SAXException; /** * A helper class to validate xml documents. - * + * * */ public class XmlValidator { - public static void assertXmlValid(String xml) { - try { - DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml))); - } catch (SAXException | IOException | ParserConfigurationException e) { - Assert.fail(e.getMessage()); - } - } - public static void assertContains(String original, String subword) { - Assert.assertTrue(original + " did not contain: " + subword, original.contains(subword)); - } + public static void assertXmlValid(String xml) { + try { + DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml))); + } catch (SAXException | IOException | ParserConfigurationException e) { + Assert.fail(e.getMessage()); + } + } + + public static void assertContains(String original, String subword) { + Assert.assertTrue(original + " did not contain: " + subword, original.contains(subword)); + } - public static void assertNotContains(String original, String subword) { - Assert.assertFalse(original + " did contain: " + subword, original.contains(subword)); - } + public static void assertNotContains(String original, String subword) { + Assert.assertFalse(original + " did contain: " + subword, original.contains(subword)); + } } http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java index 6950eb8..9b1772b 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/ExtensionManager.java @@ -85,7 +85,7 @@ public class ExtensionManager { // consider each nar class loader for (final ClassLoader ncl : NarClassLoaders.getExtensionClassLoaders()) { - // Must set the context class loader to the nar classloader itself + // Must set the context class loader to the nar classloader itself // so that static initialization techniques that depend on the context class loader will work properly Thread.currentThread().setContextClassLoader(ncl); loadExtensions(ncl); @@ -100,7 +100,7 @@ public class ExtensionManager { /** * Loads extensions from the specified class loader. * - * @param classLoader + * @param classLoader from which to load extensions */ @SuppressWarnings("unchecked") private static void loadExtensions(final ClassLoader classLoader) { @@ -117,10 +117,10 @@ public class ExtensionManager { * Registers extension for the specified type from the specified * ClassLoader. * - * @param type - * @param classloaderMap - * @param classLoader - * @param classes + * @param type the extension type + * @param classloaderMap mapping of classname to classloader + * @param classLoader the classloader being mapped to + * @param classes to map to this classloader but which come from its ancestors */ private static void registerServiceClass(final Class<?> type, final Map<String, ClassLoader> classloaderMap, final ClassLoader classLoader, final Set<Class> classes) { final String className = type.getName(); @@ -157,7 +157,7 @@ public class ExtensionManager { * returns null it indicates the given type is not known or was not * detected. * - * @param classType + * @param classType to lookup the classloader of * @return String of fully qualified class name; null if not a detected type */ public static ClassLoader getClassLoader(final String classType) { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java index 946c26e..3331fd2 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoader.java @@ -49,10 +49,10 @@ import org.slf4j.LoggerFactory; * directory structure: * * <pre> - * +META-INF/ - * +-- bundled-dependencies/ - * +-- <JAR files> - * +-- MANIFEST.MF + * +META-INF/ + * +-- bundled-dependencies/ + * +-- <JAR files> + * +-- MANIFEST.MF * </pre> * </p> * @@ -134,7 +134,7 @@ public class NarClassLoader extends URLClassLoader { /** * Construct a nar class loader. * - * @param narWorkingDirectory + * @param narWorkingDirectory directory to explode nar contents to * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> @@ -152,8 +152,8 @@ public class NarClassLoader extends URLClassLoader { /** * Construct a nar class loader with the specific parent. * - * @param narWorkingDirectory - * @param parentClassLoader + * @param narWorkingDirectory directory to explode nar contents to + * @param parentClassLoader parent class loader of this nar * @throws IllegalArgumentException if the NAR is missing the Java Services * API file for <tt>FlowFileProcessor</tt> implementations. * @throws ClassNotFoundException if any of the <tt>FlowFileProcessor</tt> @@ -204,22 +204,22 @@ public class NarClassLoader extends URLClassLoader { if (!dependencies.isDirectory()) { LOGGER.warn(narWorkingDirectory + " does not contain META-INF/bundled-dependencies!"); } - + final File nativeDir = new File(dependencies, "native"); final File soFile = new File(nativeDir, libname + ".so"); - if ( soFile.exists() ) { + if (soFile.exists()) { return soFile.getAbsolutePath(); } else { final File dllFile = new File(nativeDir, libname + ".dll"); - if ( dllFile.exists() ) { + if (dllFile.exists()) { return dllFile.getAbsolutePath(); } } - + // not found in the nar. try system native dir return null; } - + @Override public String toString() { return NarClassLoader.class.getName() + "[" + narWorkingDirectory.getPath() + "]"; http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java index e7e01a8..a8d678d 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarClassLoaders.java @@ -56,9 +56,9 @@ public final class NarClassLoaders { * Subsequent attempts will be ignored. * * - * @param properties - * @throws java.io.IOException - * @throws java.lang.ClassNotFoundException + * @param properties properties object to initialize with + * @throws java.io.IOException ioe + * @throws java.lang.ClassNotFoundException cfne * @throws IllegalStateException if the class loaders have already been * created */ @@ -175,11 +175,11 @@ public final class NarClassLoaders { /** * Creates a new NarClassLoader. The parentClassLoader may be null. * - * @param narDirectory - * @param parentClassLoader - * @return - * @throws IOException - * @throws ClassNotFoundException + * @param narDirectory root directory of nar + * @param parentClassLoader parent classloader of nar + * @return the nar classloader + * @throws IOException ioe + * @throws ClassNotFoundException cfne */ private static ClassLoader createNarClassLoader(final File narDirectory, final ClassLoader parentClassLoader) throws IOException, ClassNotFoundException { logger.debug("Loading NAR file: " + narDirectory.getAbsolutePath()); @@ -192,9 +192,9 @@ public final class NarClassLoaders { * Loads the details for the specified NAR. The details will be extracted * from the manifest file. * - * @param narDirectory - * @return - * @throws IOException + * @param narDirectory the nar directory + * @return details about the NAR + * @throws IOException ioe */ private static NarDetails getNarDetails(final File narDirectory) throws IOException { final NarDetails narDetails = new NarDetails(); @@ -214,9 +214,7 @@ public final class NarClassLoaders { } /** - * Gets the framework class loader. - * - * @return + * @return the framework class loader * * @throws IllegalStateException if the frame class loader has not been * loaded @@ -230,12 +228,9 @@ public final class NarClassLoaders { } /** - * Gets the class loader for the specified working directory. Returns null - * when no class loader exists for the specified working directory. - * - * @param extensionWorkingDirectory - * @return - * + * @param extensionWorkingDirectory the directory + * @return the class loader for the specified working directory. Returns + * null when no class loader exists for the specified working directory * @throws IllegalStateException if the class loaders have not been loaded */ public static ClassLoader getExtensionClassLoader(final File extensionWorkingDirectory) { @@ -251,10 +246,7 @@ public final class NarClassLoaders { } /** - * Gets the extension class loaders. - * - * @return - * + * @return the extension class loaders * @throws IllegalStateException if the class loaders have not been loaded */ public static Set<ClassLoader> getExtensionClassLoaders() { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java index 3aaf839..f1fef15 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/nar/NarUnpacker.java @@ -169,10 +169,10 @@ public final class NarUnpacker { /** * Unpacks the specified nar into the specified base working directory. * - * @param nar - * @param baseWorkingDirectory - * @return - * @throws IOException + * @param nar the nar to unpack + * @param baseWorkingDirectory the directory to unpack to + * @return the directory to the unpacked NAR + * @throws IOException if unable to explode nar */ private static File unpackNar(final File nar, final File baseWorkingDirectory) throws IOException { final File narWorkingDirectory = new File(baseWorkingDirectory, nar.getName() + "-unpacked"); @@ -324,9 +324,9 @@ public final class NarUnpacker { /** * Calculates an md5 sum of the specified file. * - * @param file - * @return - * @throws IOException + * @param file to calculate the md5sum of + * @return the md5sum bytes + * @throws IOException if cannot read file */ private static byte[] calculateMd5sum(final File file) throws IOException { try (final FileInputStream inputStream = new FileInputStream(file)) { http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/b612b6bc/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java ---------------------------------------------------------------------- diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java index fb95dbf..42bea01 100644 --- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java +++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/main/java/org/apache/nifi/util/FileUtils.java @@ -52,9 +52,9 @@ public class FileUtils { * Deletes the given file. If the given file exists but could not be deleted * this will be printed as a warning to the given logger * - * @param file - * @param logger - * @return + * @param file to delete + * @param logger to notify + * @return true if deleted */ public static boolean deleteFile(final File file, final Logger logger) { return FileUtils.deleteFile(file, logger, 1); @@ -64,8 +64,8 @@ public class FileUtils { * Deletes the given file. If the given file exists but could not be deleted * this will be printed as a warning to the given logger * - * @param file - * @param logger + * @param file to delete + * @param logger to notify * @param attempts indicates how many times an attempt to delete should be * made * @return true if given file no longer exists @@ -101,9 +101,9 @@ public class FileUtils { * recursive) that match the given filename filter. If any file cannot be * deleted then this is printed at warn to the given logger. * - * @param directory + * @param directory to delete contents of * @param filter if null then no filter is used - * @param logger + * @param logger to notify */ public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger) { FileUtils.deleteFilesInDir(directory, filter, logger, false); @@ -114,10 +114,10 @@ public class FileUtils { * that match the given filename filter. If any file cannot be deleted then * this is printed at warn to the given logger. * - * @param directory + * @param directory to delete contents of * @param filter if null then no filter is used - * @param logger - * @param recurse + * @param logger to notify + * @param recurse true if should recurse */ public static void deleteFilesInDir(final File directory, final FilenameFilter filter, final Logger logger, final boolean recurse) { FileUtils.deleteFilesInDir(directory, filter, logger, recurse, false); @@ -128,9 +128,9 @@ public class FileUtils { * that match the given filename filter. If any file cannot be deleted then * this is printed at warn to the given logger. * - * @param directory + * @param directory to delete contents of * @param filter if null then no filter is used - * @param logger + * @param logger to notify * @param recurse will look for contents of sub directories. * @param deleteEmptyDirectories default is false; if true will delete * directories found that are empty @@ -157,9 +157,9 @@ public class FileUtils { /** * Deletes given files. * - * @param files + * @param files to delete * @param recurse will recurse - * @throws IOException + * @throws IOException if issues deleting files */ public static void deleteFiles(final Collection<File> files, final boolean recurse) throws IOException { for (final File file : files) {