ruper2/src/java/core/org/krysalis/ruper2/tool Tool.java,NONE,1.1 FileTool.java,NONE,1.1 RepositoryTool.java,NONE,1.1 ResourceTool.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/tool
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/tool

Added Files:
	Tool.java FileTool.java RepositoryTool.java ResourceTool.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: Tool.java ---
/*
 * Created on Aug 29, 2003
 */
package org.krysalis.ruper2.tool;

import java.io.PrintWriter;

import org.krysalis.ruper2.log.LogConstant;
import org.krysalis.ruper2.log.Logger;
import org.krysalis.ruper2.log.StandardLogListener;
import org.krysalis.version.util.SystemUtils;
import org.krysalis.version.util.cli.CommandLine;
import org.krysalis.version.util.cli.CommandLineParser;
import org.krysalis.version.util.cli.Option;
import org.krysalis.version.util.cli.Options;
import org.krysalis.version.util.cli.ParseException;
import org.krysalis.version.util.debug.DebugUtils;

/**
 * @author ajack
 */
public abstract class Tool {

	private static Option l_debugOption = null;
	private static Option l_verboseOption = null;
	private static Option l_helpOption = null;
	private static Options l_options = null;

	private static boolean l_debug = false;
	private static boolean l_verbose = false;
	private static boolean l_help = false;

	static {
		l_helpOption = new Option("h", "help", false, "print help");
		l_debugOption = new Option("d", "debug", false, "debug output");
		l_verboseOption = new Option("v", "verbose", false, "verbose output");

		l_options = new Options();
		l_options.addOption(l_helpOption);
		l_options.addOption(l_verboseOption);
	}

	protected Options getOptions() {
		return l_options;
	}

	protected PrintWriter getOutput() {
		return SystemUtils.getSystemOut();
	}

	protected abstract void init();

	protected void printHelp() {
		getOptions().display();
	}
	protected abstract void execute(CommandLine cmdline) throws Exception;

	protected CommandLine parseCommandLine(String args[]) {
		CommandLine cmdline = null;

		try {
			CommandLineParser parser = new CommandLineParser();

			parser.setStrict(false);
			cmdline = parser.parse(l_options, args);

			l_help = cmdline.isSet(l_helpOption);
			l_verbose = cmdline.isSet(l_verboseOption);
			l_debug = cmdline.isSet(l_debugOption);
		}
		catch (ParseException exp) {
			System.err.println("Bad Command Line. Reason: " + exp.getMessage());
			printHelp();
			System.exit(1);
		}

		return cmdline;
	}

	public void run(String args[]) {

		//:TODO:Hack
		DebugUtils.enableCommonsLogging();

		init();

		CommandLine cmdline = parseCommandLine(args);

		if (l_help) {
			printHelp();
			System.exit(0);
		}

		// Set logging context
		int level = LogConstant.INFO;
		if (l_verbose || l_debug)
			level = l_debug ? LogConstant.DEBUG : LogConstant.VERBOSE;
		Logger logger =
			logger = Logger.pushContext(level,new StandardLogListener());

		try {
			execute(cmdline);
		}
		catch (ParseException pe) {
			SystemUtils.getSystemErr().println(
				"Error: " + pe.getLocalizedMessage());
			printHelp();
			cmdline.print();
			System.exit(1);
		}
		catch (Exception exc) {
			exc.printStackTrace();
		}
		finally {
			Logger.popContext(logger);
		}
	}
}

--- NEW FILE: FileTool.java ---
/**
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 */
package org.krysalis.ruper2.tool;

import org.krysalis.ruper2.api.tool.FileUpdater;
import org.krysalis.ruper2.log.Logger;
import org.krysalis.ruper2.query.ResourceResult;
import org.krysalis.version.util.cli.CommandLine;
import org.krysalis.version.util.cli.Option;
import org.krysalis.version.util.debug.DebugUtils;

/**
 */
public class FileTool extends Tool {

	private static Option l_fileOption = null;

	static {
		l_fileOption = new Option("f", "file", true, "Filename");
	}

	protected void init() {
		getOptions().addOption(l_fileOption);
	}

	public void execute(CommandLine cmdline) throws Exception {

		String fileName = cmdline.getMandatoryOptionValue(l_fileOption);

		FileUpdater fu = new FileUpdater();

		getOutput().println("File: [" + fileName + "]");

		ResourceResult result = fu.determineFilesUpdates(fileName);

		if (Logger.getLog().isDebug())
			DebugUtils.dump(result);
	}

	public static void main(String[] args) {
		(new FileTool()).run(args);
	}
}

--- NEW FILE: RepositoryTool.java ---
/**
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 */
package org.krysalis.ruper2.tool;

import org.krysalis.ruper2.impl.ResourceUpdaterContext;
import org.krysalis.ruper2.repository.DefaultRepository;
import org.krysalis.ruper2.repository.RepositoryWrapper;
import org.krysalis.ruper2.resource.ResourceGroup;
import org.krysalis.ruper2.util.select.AllSelector;
import org.krysalis.version.util.cli.CommandLine;
import org.krysalis.version.util.debug.DebugUtils;

/**
 */
public class RepositoryTool extends Tool {

	protected void init()
	{
	}
	

	public void execute(CommandLine cmdline) throws Exception {

		//:TODO: Get from Manager/Factory, testing/playing hack...
		RepositoryWrapper repo =
			new RepositoryWrapper(
				DefaultRepository.getLocalTestRepository(),
				ResourceUpdaterContext.getTestContext());

		DebugUtils.dump(
			repo.listResources(
				new ResourceGroup("junit"),
				AllSelector.getInstance()));
	}

	public static void main(String[] args) {
		(new RepositoryTool()).run(args);
	}
}

--- NEW FILE: ResourceTool.java ---
/**
 * Copyright (C) The Apache Software Foundation. All rights reserved.        *
 * ------------------------------------------------------------------------- *
 * This software is published under the terms of the Apache Software License *
 * version 1.1, a copy of which has been included  with this distribution in *
 * the LICENSE file.                                                         *
 */
package org.krysalis.ruper2.tool;

import org.krysalis.ruper2.ResourceUpdater;
import org.krysalis.ruper2.query.ResourceRequest;
import org.krysalis.ruper2.query.ResourceResult;
import org.krysalis.ruper2.query.ResourceSpecifierRequest;
import org.krysalis.ruper2.resource.ResourceSpecifier;
import org.krysalis.version.util.cli.CommandLine;
import org.krysalis.version.util.cli.Option;
import org.krysalis.version.util.debug.DebugUtils;

/**
 */
public class ResourceTool extends Tool {

	private static Option l_resourceOption = null;

	static {

		l_resourceOption = new Option("r", "resource", false, "resource");

	}

	protected void init() {
		getOptions().addOption(l_resourceOption);
	}

	public void execute(CommandLine cmdline) throws Exception {

		String resource = cmdline.getMandatoryOptionValue(l_resourceOption);

		ResourceUpdater ru = new ResourceUpdater();
		
		ResourceSpecifier specifier = new ResourceSpecifier(resource);
		ResourceRequest request = new ResourceSpecifierRequest(specifier);
		ResourceResult result = ru.performRequest(request);
		
		DebugUtils.dump(result);
	}

	public static void main(String[] args) {
		(new ResourceTool()).run(args);
	}
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.