package be.kuleuven.cs.distrinet.jlo.ant;

import java.io.File;

import be.kuleuven.cs.distrinet.jlo.build.JLoBuilder;
import be.kuleuven.cs.distrinet.jlo.model.language.JLoLanguageFactory;
import be.kuleuven.cs.distrinet.jnome.core.language.JavaLanguageFactory;

import org.apache.tools.ant.BuildException;

import be.kuleuven.cs.distrinet.chameleon.core.Config;
import be.kuleuven.cs.distrinet.chameleon.workspace.BootstrapProjectConfig;
import be.kuleuven.cs.distrinet.chameleon.workspace.ConfigException;
import be.kuleuven.cs.distrinet.chameleon.workspace.LanguageRepository;
import be.kuleuven.cs.distrinet.chameleon.workspace.Project;
import be.kuleuven.cs.distrinet.chameleon.workspace.Workspace;

public class AntCompileTask extends AbstractTask {

	@Override
	public void execute() throws BuildException {
		Config.setCaching(true);
		LanguageRepository repository = new LanguageRepository();
		Workspace workspace = new Workspace(repository);

		repository.add(new JavaLanguageFactory().create());
		repository.add(new JLoLanguageFactory().create());
		File configFile = getConfig();
		File root = configFile.getParentFile();
		BootstrapProjectConfig config = new BootstrapProjectConfig(root, workspace);
		try {
			Project project = config.project(configFile, null);
			// Attach the builder
			JLoBuilder builder = new JLoBuilder(project.views().get(0));
			// build!
			try {
				builder.buildAll(getDestDir(),null);
			} catch (be.kuleuven.cs.distrinet.chameleon.plugin.build.BuildException e) {
				throw new BuildException(e);
			}
		} catch (ConfigException e) {
			throw new BuildException(e);
		}
	}
	
	public void setDestDir(File output) {
		_output = output;
	}
	
	public File getDestDir() {
		return _output;
	}
	
	private File _output;

	/**
	 * args[0] should be the name of the config file.
	 * args[1] should be the name of the output directory.
	 * @param args
	 */
	public static void main(String[] args) {
		AntCompileTask task = new AntCompileTask();
		task.setConfig(new File(args[0]));
		task.setDestDir(new File(args[1]));
		task.execute();
	}
}

@@ -1424,16 +1424,58 @@
 ,null);%0A
+%09%09%09%09System.out.println(%22Done building.%22);%0A
 %09%09%09%7D cat

print when done building