package org.apache.tools.ant.taskdefs.optional.perforce;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.oro.text.perl.Perl5Util;

import java.util.ArrayList;

/*
 * Created by IntelliJ IDEA.
 * User: mike
 * Date: Oct 16, 2002
 * Time: 10:30:02 AM
 * To change this template use Options | File Templates.
 */
class FStatP4OutputHandler extends P4HandlerAdapter
{
	P4Fstat parent;
	ArrayList existing = new ArrayList();
	ArrayList nonExisting = new ArrayList();
	static Perl5Util util = new Perl5Util();

	public FStatP4OutputHandler(P4Fstat parent) {
	    this.parent = parent;
	}

	public void process(String line) throws BuildException {

		//parent.log("row:" + line, Project.MSG_INFO);

		if (util.match("/^... clientFile (.+)$/", line)) {
			String f = util.group(1);
		    existing.add(f);
			//parent.log("File exists: " + f, Project.MSG_INFO);
			return;
		}

		if (util.match("/^(.+) - no such file/", line)) {
			String f = util.group(1);
			//parent.log("File does not exist: " + f, Project.MSG_INFO);
			nonExisting.add(f);
			return;
		}
	}

	public ArrayList getExisting()
	{
		return existing;
	}

	public ArrayList getNonExisting()
	{
		return nonExisting;
	}


}
