All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jwat.tools.JWATTools Maven / Gradle / Ivy

Go to download

JWAT-Tools uses the available JWAT libraries to make high level tasks available either from command-line or programmatically. Common tasks include: Test, Compress, Decompress, CDX, Arc2Warc. More specialised tasks include: Changed, ContainerMD, Delete, Extract, Interval, PathIndex, Unpack, Headers2CDX.

There is a newer version: 0.7.1
Show newest version
package org.jwat.tools;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jwat.tools.tasks.Task;
import org.jwat.tools.tasks.TaskCLI;
import org.jwat.tools.tasks.UnpackTaskCLI;
import org.jwat.tools.tasks.arc2warc.Arc2WarcTaskCLI;
import org.jwat.tools.tasks.cdx.CDXTaskCLI;
import org.jwat.tools.tasks.changed.ChangedTaskCLI;
import org.jwat.tools.tasks.compress.CompressTaskCLI;
import org.jwat.tools.tasks.containermd.ContainerMDTaskCLI;
import org.jwat.tools.tasks.decompress.DecompressTaskCLI;
import org.jwat.tools.tasks.delete.DeleteTaskCLI;
import org.jwat.tools.tasks.extract.ExtractTaskCLI;
import org.jwat.tools.tasks.headers2cdx.Headers2CDXTaskCLI;
import org.jwat.tools.tasks.interval.IntervalTaskCLI;
import org.jwat.tools.tasks.pathindex.PathIndexTaskCLI;
import org.jwat.tools.tasks.test.TestTaskCLI;

import com.antiaction.common.cli.Argument;
import com.antiaction.common.cli.ArgumentParser;
import com.antiaction.common.cli.ArgumentParserException;
import com.antiaction.common.cli.CommandLine;
import com.antiaction.common.cli.Options;

public class JWATTools {

	public static final int A_WORKERS = 1;
	public static final int A_QUEUE_FIRST = 2;
	public static final int A_QUIET = 3;
	public static final int A_COMMAND = 4;
	public static final int A_FILES = 5;

	public static void main(String[] args) {
		JWATTools tools = new JWATTools();
		tools.Main( args );
	}

	public class Command {
		Class task;
	}

	public static List> commandList = new ArrayList>();

	public static Map> commandMap = new HashMap>();

	public static Options options = new Options();

	public static int maxCommandNameLength = 0;

	public static void addCommands(Class[] tasks) {
		try {
			for (int i=0; i maxCommandNameLength) {
					maxCommandNameLength = commandName.length();
				}
			}
		} catch (SecurityException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (NoSuchFieldException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
			System.exit(1);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	@SuppressWarnings("unchecked")
	public static void configure_cli() {
		Class[] tasks = new Class[] {
				HelpTaskCLI.class,
				Arc2WarcTaskCLI.class,
				CDXTaskCLI.class,
				ChangedTaskCLI.class,
				CompressTaskCLI.class,
				ContainerMDTaskCLI.class,
				DecompressTaskCLI.class,
				DeleteTaskCLI.class,
				ExtractTaskCLI.class,
				IntervalTaskCLI.class,
				PathIndexTaskCLI.class,
				TestTaskCLI.class,
				UnpackTaskCLI.class,
				Headers2CDXTaskCLI.class
		};
		addCommands((Class[])tasks);
	}

	public static void show_commands() {
		Collections.sort(commandList, new Comparator>() {
			@Override
			public int compare(Class t1, Class t2) {
				Field commandNameField;
				try {
					commandNameField = t1.getField("commandName");
					String n1 = (String)commandNameField.get(null);
					commandNameField = t2.getField("commandName");
					String n2 = (String)commandNameField.get(null);
					return n1.compareTo(n2);
				} catch (SecurityException e) {
				} catch (NoSuchFieldException e) {
				} catch (IllegalArgumentException e) {
				} catch (IllegalAccessException e) {
				}
				return 0;
			}
		});
		System.out.println("Commands:");
		Field commandNameField;
		Field commandDescriptionField;
		for (int i=0; i  set the amount of worker thread(s) (defaults to 1)");
		System.out.println("");
		*/
		System.out.println("See 'jwattools help ' for more information on a specific command.");
	}

	public static void show_help() {
		Package pkg = Package.getPackage("org.jwat.tools");
		String version = null;
		if (pkg != null) {
			version = pkg.getSpecificationVersion();
		}
		if (version == null) {
			version = "N/A";
		}
		System.out.println("JWATTools v" + version);
		System.out.println("usage: JWATTools  []");
		System.out.println("");
		show_commands();
	}

	public void Main(String[] args) {
		CommandLine cmdLine = null;
		configure_cli();
		try {
			options.addOption(null, "--queue-first", A_QUEUE_FIRST, 0, null);
			options.addOption("-w", "--workers", A_WORKERS, 0, null).setValueRequired();
			options.addNamedArgument( "command", A_COMMAND, 0, 1).setStopParsing();
			cmdLine = ArgumentParser.parse(args, options, null);
			/*
			for ( int i=0; i clazz = commandMap.get(commandStr);
			if (clazz != null) {
				try {
					TaskCLI taskcli = clazz.newInstance();
					taskcli.runtask(cmdLine);
				}
				catch (InstantiationException e) {
					e.printStackTrace();
				}
				catch (IllegalAccessException e) {
					e.printStackTrace();
				}
			}
			else {
				System.out.println("Unknown command -- " + commandStr);
			}
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy