package org.jtoc.ant;

import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.jtoc.convertor.ProjectConvertor;

public class ConvertTask extends MatchingTask{
	private File srcDir;
	private File destDir;

	public void setSrcDir(File srcDir) {
		this.srcDir = srcDir;
	}

	public void setDestDir(File destDir) {
		this.destDir = destDir;
	}

	private boolean rewrite = false;
	
	public void setRewrite(boolean rewrite) {
		this.rewrite = rewrite;
	}

	public boolean isRewrite() {
		return rewrite;
	}
	
	public void execute() throws BuildException {
		if (srcDir == null) {
			throw new BuildException("srcdir must be specified");
		}
		log("srcDir = " + srcDir, Project.MSG_DEBUG);

		if (destDir == null) {
			throw new BuildException("destdir must be specified");
		}
		log("destDir = " + destDir, Project.MSG_DEBUG);

		try {
			ProjectConvertor.convertProject(srcDir, destDir, rewrite);
		} catch (Exception e) {
			throw new BuildException(e);
		}

		srcDir = null;
		destDir = null;
		this.setRewrite(false);
	}
}

@@ -224,16 +224,76 @@
 tor;%0D%0A%0D%0A
+/**%0D%0A * The Ant task to convert project by using jtoc%0D%0A */%0D%0A
 public c
@@ -1020,24 +1020,179 @@
 MSG_DEBUG);%0D
+%0A%09%09%0D%0A%09%09if (destDir.getAbsolutePath().equals(srcDir.getAbsolutePath())) %7B%0D%0A%09%09%09throw new BuildException(%22The srcdir and destdir must not be the same%22);%0D%0A%09%09%7D%0D
 %0A%0D%0A%09%09try %7B%0D%0A

modify the ConvertTask so that it would not execute when the srcdir is the same with the destdir.