incubator-any23-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mosta...@apache.org
Subject svn commit: r1304825 - in /incubator/any23/trunk: core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java
Date Sat, 24 Mar 2012 15:36:34 GMT
Author: mostarda
Date: Sat Mar 24 15:36:34 2012
New Revision: 1304825

URL: http://svn.apache.org/viewvc?rev=1304825&view=rev
Log:
Fixed issue in Any23PluginManager preventing Tool plugin detection.
Fixed Integration Test.
This commit is related to issues #ANY23-54 and #ANY23-34.

Modified:
    incubator/any23/trunk/core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java
    incubator/any23/trunk/plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java

Modified: incubator/any23/trunk/core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java?rev=1304825&r1=1304824&r2=1304825&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java
(original)
+++ incubator/any23/trunk/core/src/main/java/org/apache/any23/plugin/Any23PluginManager.java
Sat Mar 24 15:36:34 2012
@@ -17,7 +17,13 @@
 
 package org.apache.any23.plugin;
 
-import static java.util.ServiceLoader.load;
+import org.apache.any23.cli.Tool;
+import org.apache.any23.configuration.DefaultConfiguration;
+import org.apache.any23.extractor.ExtractorFactory;
+import org.apache.any23.extractor.ExtractorGroup;
+import org.apache.any23.extractor.ExtractorRegistry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.FilenameFilter;
@@ -31,13 +37,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
-import org.apache.any23.cli.Tool;
-import org.apache.any23.configuration.DefaultConfiguration;
-import org.apache.any23.extractor.ExtractorFactory;
-import org.apache.any23.extractor.ExtractorGroup;
-import org.apache.any23.extractor.ExtractorRegistry;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import static java.util.ServiceLoader.load;
 
 /**
  * The <i>Any23PluginManager</i> is responsible for inspecting
@@ -240,8 +240,6 @@ public class Any23PluginManager {
      * started with) and the dynamic classpath (the one specified using the load methods).
      *
      * @param <T> type of filtered class.
-     * @param packageName package name to look at classes, if <code>null</code>
all packages will be found.
-     * @param filter class filter to select classes, if <code>null</code> all
classes will be returned.
      * @return list of matching classes.
      * @throws IOException
      */
@@ -271,45 +269,57 @@ public class Any23PluginManager {
     }
 
     /**
-     * Configures a new list of extractors containing the extractors declared in <code>initialExtractorGroup</code>
-     * and also the extractors detected in classpath specified by <code>pluginLocations</code>.
+     * Loads plugins from a list of specified locations.
      *
-     * @param initialExtractorGroup initial list of extractors.
-     * @param pluginLocations
-     * @return full list of extractors.
-     * @throws java.io.IOException
-     * @throws IllegalAccessException
-     * @throws InstantiationException
+     * @param pluginLocations list of locations.
+     * @return a report about the loaded plugins.
      */
+    public synchronized String loadPlugins(File... pluginLocations) {
+        final StringBuilder report = new StringBuilder();
+        report.append("\nLoading plugins from locations {\n");
+        for (File pluginLocation : pluginLocations) {
+            report.append(pluginLocation.getAbsolutePath()).append('\n');
+        }
+        report.append("}\n");
+
+        final Throwable[] errors = loadFiles(pluginLocations);
+        if (errors.length > 0) {
+            report.append("The following errors occurred while loading plugins {\n");
+            for (Throwable error : errors) {
+                report.append(error);
+                report.append("\n\n\n");
+            }
+            report.append("}\n");
+        }
+        return report.toString();
+    }
+
+    /**
+        * Configures a new list of extractors containing the extractors declared in <code>initialExtractorGroup</code>
+        * and also the extractors detected in classpath specified by <code>pluginLocations</code>.
+        *
+        * @param initialExtractorGroup initial list of extractors.
+        * @param pluginLocations
+        * @return full list of extractors.
+        * @throws java.io.IOException
+        * @throws IllegalAccessException
+        * @throws InstantiationException
+        */
     public synchronized ExtractorGroup configureExtractors(
             final ExtractorGroup initialExtractorGroup,
             final File... pluginLocations
     ) throws IOException, IllegalAccessException, InstantiationException {
-        if(initialExtractorGroup == null) throw new NullPointerException("inExtractorGroup
cannot be null");
+        if (initialExtractorGroup == null) throw new NullPointerException("inExtractorGroup
cannot be null");
+
+        final String pluginsReport = loadPlugins(pluginLocations);
+        logger.info(pluginsReport);
 
         final StringBuilder report = new StringBuilder();
         try {
-            report.append("\nLoading plugins from locations {\n");
-            for (File pluginLocation : pluginLocations) {
-                report.append(pluginLocation.getAbsolutePath()).append('\n');
-            }
-            report.append("}\n");
-
-            final Throwable[] errors = loadFiles(pluginLocations);
-            if (errors.length > 0) {
-                report.append("The following errors occurred while loading plugins {\n");
-                for (Throwable error : errors) {
-                    report.append(error);
-                    report.append("\n\n\n");
-                }
-                report.append("}\n");
-            }
-
             final List<ExtractorFactory<?>> newFactoryList = new ArrayList<ExtractorFactory<?>>();
-
-            Iterator<ExtractorPlugin> extarctors = getExtractors();
-            while (extarctors.hasNext()) {
-                ExtractorFactory<?> factory = extarctors.next().getExtractorFactory();
+            Iterator<ExtractorPlugin> extractors = getExtractors();
+            while (extractors.hasNext()) {
+                ExtractorFactory<?> factory = extractors.next().getExtractorFactory();
 
                 report.append("\n - found plugin: ").append(factory.getExtractorName()).append("\n");
 
@@ -364,6 +374,19 @@ public class Any23PluginManager {
     }
 
     /**
+     * Returns an {@link Iterator} of tools that have been detected within the given list
of locations.
+     *
+     * @param pluginLocations list of plugin locations.
+     * @return set of detected tools.
+     * @throws IOException
+     */
+    public synchronized Iterator<Tool> getApplicableTools(File... pluginLocations)
throws IOException {
+        final String report = loadPlugins(pluginLocations);
+        logger.info(report);
+        return getTools();
+    }
+
+    /**
      * Converts a column separated list of dirs in a list of files.
      *
      * @param pluginDirsList

Modified: incubator/any23/trunk/plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java?rev=1304825&r1=1304824&r2=1304825&view=diff
==============================================================================
--- incubator/any23/trunk/plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java
(original)
+++ incubator/any23/trunk/plugins/integration-test/src/test/java/org/apache/any23/plugin/PluginIT.java
Sat Mar 24 15:36:34 2012
@@ -17,8 +17,6 @@
 
 package org.apache.any23.plugin;
 
-import static org.junit.Assert.*;
-
 import org.apache.any23.cli.Crawler;
 import org.apache.any23.cli.Tool;
 import org.apache.any23.extractor.ExtractorGroup;
@@ -32,6 +30,9 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Integration test for plugins.
  *
@@ -41,12 +42,16 @@ public class PluginIT {
 
     private static final int NUM_OF_EXTRACTORS = 23;
 
-    private static final String PLUGIN_LOCATION = "target/plugins-build/";
+    private static final String PLUGIN_DIR = "target/plugins-build/";
+
+    private static final File HTML_SCRAPER_TARGET_DIR       = new File(PLUGIN_DIR + "html-scraper/target/classes");
+    private static final File HTML_SCRAPER_DEPENDENCY_DIR   = new File(PLUGIN_DIR + "html-scraper/target/dependency");
 
-    private static final File HTML_SCRAPER_TARGET_DIR     = new File(PLUGIN_LOCATION + "html-scraper/target/classes");
-    private static final File HTML_SCRAPER_DEPENDENCY_DIR = new File(PLUGIN_LOCATION + "html-scraper/target/dependency");
-    private static final File OFFICE_SCRAPER_TARGET_DIR     = new File(PLUGIN_LOCATION +
"office-scraper/target/classes");
-    private static final File OFFICE_SCRAPER_DEPENDENCY_DIR = new File(PLUGIN_LOCATION +
"office-scraper/target/dependency");
+    private static final File OFFICE_SCRAPER_TARGET_DIR     = new File(PLUGIN_DIR + "office-scraper/target/classes");
+    private static final File OFFICE_SCRAPER_DEPENDENCY_DIR = new File(PLUGIN_DIR + "office-scraper/target/dependency");
+
+    private static final File CRAWLER_TARGET_DIR     = new File(PLUGIN_DIR + "basic-crawler/target/classes");
+    private static final File CRAWLER_DEPENDENCY_DIR = new File(PLUGIN_DIR + "basic-crawler/target/dependency");
 
     private Any23PluginManager manager;
 
@@ -61,7 +66,7 @@ public class PluginIT {
     }
 
     /**
-     * <i>Extractor</i> plugins detection testing.
+     * {@link org.apache.any23.extractor.Extractor} plugins detection testing.
      *
      * @throws IOException
      * @throws InstantiationException
@@ -75,27 +80,32 @@ public class PluginIT {
                 OFFICE_SCRAPER_TARGET_DIR,
                 OFFICE_SCRAPER_DEPENDENCY_DIR // Required to satisfy class dependencies.
         );
-        assertEquals( NUM_OF_EXTRACTORS + 2,        // HTMLScraper Plugin, OfficeScraper
Plugin.
-                      extractorGroup.getNumOfExtractors()
+        assertEquals(NUM_OF_EXTRACTORS + 2,        // HTMLScraper Plugin, OfficeScraper Plugin.
+                extractorGroup.getNumOfExtractors()
         );
     }
 
     /**
-     * <i>CLI</i> plugins detection testing.
+     * {@link Tool} plugins detection testing.
      *
      * @throws IOException
      */
     @Test
     public void testDetectCLIPlugins() throws IOException {
-        final Iterator<Tool> tools = manager.getTools();
+        final Iterator<Tool> tools = manager.getApplicableTools(CRAWLER_TARGET_DIR,
CRAWLER_DEPENDENCY_DIR);
         final Set<String> toolClasses = new HashSet<String>();
         Tool tool;
         while(tools.hasNext()) {
             tool = tools.next();
             assertTrue("Found duplicate tool.", toolClasses.add(tool.getClass().getName()));
         }
-        assertTrue( "Expected " + Crawler.class.getName() + " plugin be detected, but not
found int the built classpath",
-                    toolClasses.contains( Crawler.class.getName() ) );
+        assertTrue(
+                String.format(
+                        "Expected [%s] plugin be detected, but not found int the built classpath",
+                        Crawler.class.getName()
+                ),
+                toolClasses.contains(Crawler.class.getName())
+        );
         assertEquals(7 + 1, toolClasses.size());
     }
 



Mime
View raw message