Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Undo unintentional changes made in r381751. Thanks, Jerome, for catching this!

Douglass Cuttingaa84ab48dd36
diff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.java
index c3dfac5cf..47abd5a4b 100644
--- a/src/java/org/apache/nutch/crawl/Crawl.java
+++ b/src/java/org/apache/nutch/crawl/Crawl.java
@@ -44,11 +44,11 @@ public class Crawl {
/* Perform complete crawling and indexing given a set of root urls. */
- public static boolean doMain(String args[]) throws Exception {
+ public static void main(String args[]) throws Exception {
if (args.length < 1) {
System.out.println
("Usage: Crawl <urlDir> [-dir d] [-threads n] [-depth i] [-topN N]");
- return false;
+ return;
}
Configuration conf = NutchConfiguration.create();
@@ -122,22 +122,5 @@ public class Crawl {
new IndexMerger(fs, fs.listFiles(indexes), index, tmpDir, job).merge();
LOG.info("crawl finished: " + dir);
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}
diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.java
index dd1806e9c..2bce1a98c 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDb.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java
@@ -90,31 +90,17 @@ public class CrawlDb extends Configured {
fs.delete(old);
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
CrawlDb crawlDb = new CrawlDb(NutchConfiguration.create());
if (args.length < 2) {
System.err.println("Usage: <crawldb> <segment>");
- return false;
+ return;
}
crawlDb.update(new File(args[0]), new File(args[1]));
-
- return true;
}
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
+
+
}
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
index 6fbec7ccd..a4fa9009b 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
@@ -20,7 +20,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.TreeMap;
-import java.util.logging.*;
+import java.util.logging.Logger;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.io.LongWritable;
@@ -241,7 +241,7 @@ public class CrawlDbReader {
JobClient.runJob(job);
}
- public static boolean doMain(String[] args) throws IOException {
+ public static void main(String[] args) throws IOException {
CrawlDbReader dbr = new CrawlDbReader();
if (args.length < 1) {
@@ -250,7 +250,7 @@ public class CrawlDbReader {
System.err.println("\t-stats\tprint overall statistics to System.out");
System.err.println("\t-dump <out_dir>\tdump the whole db to a text file in <out_dir>");
System.err.println("\t-url <url>\tprint information on <url> to System.out");
- return false;
+ return;
}
String param = null;
String crawlDb = args[0];
@@ -266,24 +266,8 @@ public class CrawlDbReader {
dbr.readUrl(crawlDb, param, conf);
} else {
System.err.println("\nError: wrong argument " + args[i]);
- return false;
}
}
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : -1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(-1);
- }
+ return;
}
}
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index 3c315bd57..19ce50ac4 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -237,10 +237,10 @@ public class Generator extends Configured {
/**
* Generate a fetchlist from the pagedb and linkdb
*/
- public static boolean doMain(String args[]) throws Exception {
+ public static void main(String args[]) throws Exception {
if (args.length < 2) {
System.out.println("Usage: Generator <crawldb> <segments_dir> [-topN N] [-numFetchers numFetchers] [-adddays numDays]");
- return false;
+ return;
}
File dbDir = new File(args[0]);
@@ -266,22 +266,5 @@ public class Generator extends Configured {
LOG.info("topN: " + topN);
Generator gen = new Generator(NutchConfiguration.create());
gen.generate(dbDir, segmentsDir, numFetchers, topN, curTime);
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}
diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.java
index 95744e8c2..673017c67 100644
--- a/src/java/org/apache/nutch/crawl/Injector.java
+++ b/src/java/org/apache/nutch/crawl/Injector.java
@@ -127,31 +127,15 @@ public class Injector extends Configured {
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
Injector injector = new Injector(NutchConfiguration.create());
if (args.length < 2) {
System.err.println("Usage: Injector <crawldb> <url_dir>");
- return false;
+ return;
}
injector.inject(new File(args[0]), new File(args[1]));
-
- return true;
}
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
}
diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.java
index f2c53386e..9cf550397 100644
--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java
+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java
@@ -29,7 +29,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.util.NutchConfiguration;
import org.apache.nutch.util.NutchJob;
-import java.util.logging.*;
+import java.util.logging.Logger;
/** . */
public class LinkDbReader implements Closeable {
@@ -96,12 +96,12 @@ public class LinkDbReader implements Closeable {
JobClient.runJob(job);
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("LinkDbReader <linkdb> {-dump <out_dir> | -url <url>)");
System.err.println("\t-dump <out_dir>\tdump whole link db to a text file in <out_dir>");
System.err.println("\t-url <url>\tprint information about <url> to System.out");
- return false;
+ return;
}
Configuration conf = NutchConfiguration.create();
if (args[1].equals("-dump")) {
@@ -118,24 +118,7 @@ public class LinkDbReader implements Closeable {
}
} else {
System.err.println("Error: wrong argument " + args[1]);
- return false;
- }
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
+ return;
}
}
}
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index 967ce5f01..387029d88 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -369,13 +369,13 @@ public class Fetcher extends Configured implements MapRunnable {
/** Run the fetcher. */
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
String usage = "Usage: Fetcher <segment> [-threads n] [-noParsing]";
if (args.length < 1) {
System.err.println(usage);
- return false;
+ System.exit(-1);
}
File segment = new File(args[0]);
@@ -399,21 +399,5 @@ public class Fetcher extends Configured implements MapRunnable {
fetcher.fetch(segment, threads, parsing); // run the Fetcher
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}
diff --git a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
index 40bb2a04d..6471d7b4d 100644
--- a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
+++ b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
@@ -343,12 +343,12 @@ public class DeleteDuplicates extends Configured
LOG.info("Dedup: done");
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
DeleteDuplicates dedup = new DeleteDuplicates(NutchConfiguration.create());
if (args.length < 1) {
System.err.println("Usage: <indexes> ...");
- return false;
+ return;
}
File[] indexes = new File[args.length];
@@ -357,22 +357,6 @@ public class DeleteDuplicates extends Configured
}
dedup.dedup(indexes);
-
- return true;
}
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
}
diff --git a/src/java/org/apache/nutch/indexer/IndexMerger.java b/src/java/org/apache/nutch/indexer/IndexMerger.java
index 0104b0701..ed7d1cec2 100644
--- a/src/java/org/apache/nutch/indexer/IndexMerger.java
+++ b/src/java/org/apache/nutch/indexer/IndexMerger.java
@@ -105,11 +105,11 @@ public class IndexMerger {
/**
* Create an index for the input files in the named directory.
*/
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
String usage = "IndexMerger [-workingdir <workingdir>] outputIndex indexesDir...";
if (args.length < 2) {
System.err.println("Usage: " + usage);
- return false;
+ return;
}
//
@@ -148,22 +148,5 @@ public class IndexMerger {
merger.merge();
LOG.info("done merging");
FileUtil.fullyDelete(workDir, conf);
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}
diff --git a/src/java/org/apache/nutch/indexer/Indexer.java b/src/java/org/apache/nutch/indexer/Indexer.java
index 9575397e8..c4937131d 100644
--- a/src/java/org/apache/nutch/indexer/Indexer.java
+++ b/src/java/org/apache/nutch/indexer/Indexer.java
@@ -269,12 +269,12 @@ public class Indexer extends Configured implements Reducer {
LOG.info("Indexer: done");
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
Indexer indexer = new Indexer(NutchConfiguration.create());
if (args.length < 4) {
System.err.println("Usage: <index> <crawldb> <linkdb> <segment> ...");
- return false;
+ return;
}
File[] segments = new File[args.length-3];
@@ -284,22 +284,6 @@ public class Indexer extends Configured implements Reducer {
indexer.index(new File(args[0]), new File(args[1]), new File(args[2]),
segments);
-
- return true;
}
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
}
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index 6709810b4..76dce6a9f 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -104,36 +104,19 @@ public class ParseSegment extends Configured implements Mapper, Reducer {
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
File segment;
String usage = "Usage: ParseSegment segment";
if (args.length == 0) {
System.err.println(usage);
- return false;
+ System.exit(-1);
}
segment = new File(args[0]);
ParseSegment parseSegment = new ParseSegment(NutchConfiguration.create());
parseSegment.parse(segment);
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}
diff --git a/src/java/org/apache/nutch/plugin/PluginRepository.java b/src/java/org/apache/nutch/plugin/PluginRepository.java
index 636ffcccf..c35afa039 100644
--- a/src/java/org/apache/nutch/plugin/PluginRepository.java
+++ b/src/java/org/apache/nutch/plugin/PluginRepository.java
@@ -26,7 +26,7 @@ import java.util.WeakHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.logging.*;
+import java.util.logging.Logger;
import java.util.regex.Pattern;
// Nutch imports
@@ -400,10 +400,10 @@ public class PluginRepository {
* selected class.
* @throws Exception
*/
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage: PluginRepository pluginId className [arg1 arg2 ...]");
- return false;
+ return;
}
Configuration conf = NutchConfiguration.create();
PluginRepository repo = new PluginRepository(conf);
@@ -411,7 +411,7 @@ public class PluginRepository {
PluginDescriptor d = repo.getPluginDescriptor(args[0]);
if (d == null) {
System.err.println("Plugin '" + args[0] + "' not present or inactive.");
- return false;
+ return;
}
ClassLoader cl = d.getClassLoader();
// args[1] - class name
@@ -420,34 +420,17 @@ public class PluginRepository {
clazz = Class.forName(args[1], true, cl);
} catch (Exception e) {
System.err.println("Could not load the class '" + args[1] + ": " + e.getMessage());
- return false;
+ return;
}
Method m = null;
try {
m = clazz.getMethod("main", new Class[]{args.getClass()});
} catch (Exception e) {
System.err.println("Could not find the 'main(String[])' method in class " + args[1] + ": " + e.getMessage());
- return false;
+ return;
}
String[] subargs = new String[args.length - 2];
System.arraycopy(args, 2, subargs, 0, subargs.length);
m.invoke(null, new Object[]{subargs});
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
}
- }
}
diff --git a/src/java/org/apache/nutch/searcher/DistributedSearch.java b/src/java/org/apache/nutch/searcher/DistributedSearch.java
index 928ddd635..839943f0f 100644
--- a/src/java/org/apache/nutch/searcher/DistributedSearch.java
+++ b/src/java/org/apache/nutch/searcher/DistributedSearch.java
@@ -19,7 +19,7 @@ package org.apache.nutch.searcher;
import java.net.InetSocketAddress;
import java.io.*;
import java.util.*;
-import java.util.logging.*;
+import java.util.logging.Logger;
import java.lang.reflect.Method;
import org.apache.nutch.parse.ParseData;
@@ -53,12 +53,12 @@ public class DistributedSearch {
private Server() {}
/** Runs a search server. */
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
String usage = "DistributedSearch$Server <port> <index dir>";
if (args.length == 0 || args.length > 2) {
System.err.println(usage);
- return false;
+ System.exit(-1);
}
int port = Integer.parseInt(args[0]);
@@ -70,24 +70,8 @@ public class DistributedSearch {
org.apache.hadoop.ipc.Server server = RPC.getServer(bean, port, 10, true, conf);
server.start();
server.join();
-
- return true;
}
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
}
/** The search client. */
@@ -327,12 +311,12 @@ public class DistributedSearch {
return getRemote(hit).getFetchDate(hit);
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
String usage = "DistributedSearch$Client query <host> <port> ...";
if (args.length == 0) {
System.err.println(usage);
- return false;
+ System.exit(-1);
}
Query query = Query.parse(args[0], NutchConfiguration.create());
@@ -352,7 +336,6 @@ public class DistributedSearch {
System.out.println(" "+i+" "+ client.getDetails(hits.getHit(i)));
}
- return true;
}
public void run() {
@@ -379,20 +362,5 @@ public class DistributedSearch {
running = false;
interrupt();
}
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
- }
}
}
diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.java
index d815d011f..ba320e1b8 100644
--- a/src/java/org/apache/nutch/segment/SegmentReader.java
+++ b/src/java/org/apache/nutch/segment/SegmentReader.java
@@ -25,7 +25,7 @@ import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Iterator;
-import java.util.logging.*;
+import java.util.logging.Logger;
import org.apache.nutch.crawl.CrawlDatum;
import org.apache.hadoop.fs.FileSystem;
@@ -221,7 +221,7 @@ public class SegmentReader extends Configured implements Reducer {
}
}
- public static boolean doMain(String[] args) throws Exception {
+ public static void main(String[] args) throws Exception {
Configuration conf = NutchConfiguration.create();
SegmentReader segmentReader = new SegmentReader(conf);
@@ -229,25 +229,8 @@ public class SegmentReader extends Configured implements Reducer {
if (args.length == 0) {
System.err.println(usage);
- return false;
+ System.exit(-1);
}
segmentReader.reader(new File(args[0]));
-
- return true;
- }
-
- /**
- * main() wrapper that returns proper exit status
- */
- public static void main(String[] args) {
- Runtime rt = Runtime.getRuntime();
- try {
- boolean status = doMain(args);
- rt.exit(status ? 0 : 1);
- }
- catch (Exception e) {
- LOG.log(Level.SEVERE, "error, caught Exception in main()", e);
- rt.exit(1);
- }
}
}