Apache Nutch is an extensible and scalable web crawler
NUTCH-2995 Upgrade to crawler-commons 1.4
Sebastian Nagela24ec5c5b761
diff --git a/ivy/ivy.xml b/ivy/ivy.xmlindex 269f521c8..18a6df230 100644--- a/ivy/ivy.xml+++ b/ivy/ivy.xml@@ -65,7 +65,7 @@<dependency org="com.google.guava" name="guava" rev="31.1-jre" />- <dependency org="com.github.crawler-commons" name="crawler-commons" rev="1.3" />+ <dependency org="com.github.crawler-commons" name="crawler-commons" rev="1.4" /><dependency org="com.google.code.gson" name="gson" rev="2.9.1"/><dependency org="com.martinkl.warc" name="warc-hadoop" rev="0.1.0">diff --git a/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java b/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.javaindex 93bb51b22..265abf934 100644--- a/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java+++ b/src/plugin/lib-http/src/test/org/apache/nutch/protocol/http/api/TestRobotRulesParser.java@@ -22,32 +22,37 @@ import org.junit.Test;import crawlercommons.robots.BaseRobotRules;/**- * JUnit test case which tests 1. that robots filtering is performed correctly- * as per the agent name 2. that crawl delay is extracted correctly from the- * robots file- *+ * JUnit test case which tests+ * <ol>+ * <li>that robots filtering is performed correctly as per the agent name</li>+ * <li>that crawl delay is extracted correctly from the robots.txt file</li>+ * </ol>*/public class TestRobotRulesParser {private static final String CONTENT_TYPE = "text/plain";- private static final String SINGLE_AGENT = "Agent1";- private static final String MULTIPLE_AGENTS = "Agent2, Agent1";+ private static final String SINGLE_AGENT1 = "Agent1";+ private static final String SINGLE_AGENT2 = "Agent2";+ private static final String MULTIPLE_AGENTS = "Agent2, Agent1"; // rules are merged for both agentsprivate static final String UNKNOWN_AGENT = "AgentABC";private static final String CR = "\r";- private static final String ROBOTS_STRING = "User-Agent: Agent1 #foo" + CR- + "Disallow: /a" + CR + "Disallow: /b/a" + CR + "#Disallow: /c"- + CR- + "Crawl-delay: 10"- + CR // set crawl delay for Agent1 as 10 sec- + "" + CR + "" + CR + "User-Agent: Agent2" + CR + "Disallow: /a/bloh"- + CR + "Disallow: /c" + CR + "Disallow: /foo" + CR + "Crawl-delay: 20"- + CR + "" + CR + "User-Agent: *" + CR + "Disallow: /foo/bar/" + CR; // no- // crawl- // delay- // for- // other- // agents+ private static final String ROBOTS_STRING = //+ "User-Agent: Agent1 #foo" + CR //+ + "Disallow: /a" + CR //+ + "Disallow: /b/a" + CR //+ + "#Disallow: /c" + CR //+ + "Crawl-delay: 10" + CR // set crawl delay for Agent1 as 10 seconds+ + "" + CR //+ + "" + CR //+ + "User-Agent: Agent2" + CR //+ + "Disallow: /a/bloh" + CR //+ + "Disallow: /c" + CR //+ + "Disallow: /foo" + CR //+ + "Crawl-delay: 20" + CR // Agent2: 20 seconds+ + "" + CR //+ + "User-Agent: *" + CR //+ + "Disallow: /foo/bar/" + CR; // no crawl delay for other agentsprivate static final String[] TEST_PATHS = new String[] {"http://example.com/a", "http://example.com/a/bloh/foo.html",@@ -55,7 +60,8 @@ public class TestRobotRulesParser {"http://example.com/b/a/index.html","http://example.com/foo/bar/baz.html" };- private static final boolean[] RESULTS = new boolean[] { false, // /a+ private static final boolean[] RESULTS_AGENT1 = new boolean[] { //+ false, // /afalse, // /a/bloh/foo.htmltrue, // /btrue, // /c@@ -63,6 +69,24 @@ public class TestRobotRulesParser {true // /foo/bar/baz.html};+ private static final boolean[] RESULTS_AGENT2 = new boolean[] { //+ true, // /a+ false, // /a/bloh/foo.html+ true, // /b+ false, // /c+ true, // /b/a/index.html+ false // /foo/bar/baz.html+ };++ private static final boolean[] RESULTS_AGENT1_AND_AGENT2 = new boolean[] { //+ false, // /a+ false, // /a/bloh/foo.html+ true, // /b+ false, // /c+ false, // /b/a/index.html+ false // /foo/bar/baz.html+ };+private HttpRobotRulesParser parser;private BaseRobotRules rules;@@ -74,17 +98,29 @@ public class TestRobotRulesParser {* Test that the robots rules are interpreted correctly by the robots rules* parser.*/+ @Deprecated@Test- public void testRobotsAgent() {+ public void testRobotsAgentDeprecatedAPIMethod() {+ rules = parser.parseRules("testRobotsAgent", ROBOTS_STRING.getBytes(),+ CONTENT_TYPE, SINGLE_AGENT1);++ for (int counter = 0; counter < TEST_PATHS.length; counter++) {+ Assert.assertTrue(+ "testing on agent (" + SINGLE_AGENT1 + "), and " + "path "+ + TEST_PATHS[counter] + " got "+ + rules.isAllowed(TEST_PATHS[counter]),+ rules.isAllowed(TEST_PATHS[counter]) == RESULTS_AGENT1[counter]);+ }+rules = parser.parseRules("testRobotsAgent", ROBOTS_STRING.getBytes(),- CONTENT_TYPE, SINGLE_AGENT);+ CONTENT_TYPE, SINGLE_AGENT2);for (int counter = 0; counter < TEST_PATHS.length; counter++) {Assert.assertTrue(- "testing on agent (" + SINGLE_AGENT + "), and " + "path "+ "testing on agent (" + SINGLE_AGENT2 + "), and " + "path "+ TEST_PATHS[counter] + " got "+ rules.isAllowed(TEST_PATHS[counter]),- rules.isAllowed(TEST_PATHS[counter]) == RESULTS[counter]);+ rules.isAllowed(TEST_PATHS[counter]) == RESULTS_AGENT2[counter]);}rules = parser.parseRules("testRobotsAgent", ROBOTS_STRING.getBytes(),@@ -95,7 +131,7 @@ public class TestRobotRulesParser {"testing on agents (" + MULTIPLE_AGENTS + "), and " + "path "+ TEST_PATHS[counter] + " got "+ rules.isAllowed(TEST_PATHS[counter]),- rules.isAllowed(TEST_PATHS[counter]) == RESULTS[counter]);+ rules.isAllowed(TEST_PATHS[counter]) == RESULTS_AGENT1_AND_AGENT2[counter]);}}@@ -104,15 +140,23 @@ public class TestRobotRulesParser {* agent. If its not specified for a given agent, default value must be* returned.*/+ @Deprecated@Test- public void testCrawlDelay() {- // for SINGLE_AGENT, the crawl delay of 10 sec ie. 10000 msec must be+ public void testCrawlDelayDeprecatedAPIMethod() {+ // for SINGLE_AGENT1, the crawl delay of 10 seconds, i.e. 10000 msec must be// returned by the parserrules = parser.parseRules("testCrawlDelay", ROBOTS_STRING.getBytes(),- CONTENT_TYPE, SINGLE_AGENT);- Assert.assertTrue("testing crawl delay for agent " + SINGLE_AGENT + " : ",+ CONTENT_TYPE, SINGLE_AGENT1);+ Assert.assertTrue("testing crawl delay for agent " + SINGLE_AGENT1 + " : ",(rules.getCrawlDelay() == 10000));+ // for SINGLE_AGENT2, the crawl delay of 20 seconds, i.e. 20000 msec must be+ // returned by the parser+ rules = parser.parseRules("testCrawlDelay", ROBOTS_STRING.getBytes(),+ CONTENT_TYPE, SINGLE_AGENT2);+ Assert.assertTrue("testing crawl delay for agent " + SINGLE_AGENT2 + " : ",+ (rules.getCrawlDelay() == 20000));+// for UNKNOWN_AGENT, the default crawl delay must be returned.rules = parser.parseRules("testCrawlDelay", ROBOTS_STRING.getBytes(),CONTENT_TYPE, UNKNOWN_AGENT);