// Path: si.gos.transpiler.core/src/si/gos/transpiler/core/builder/TranspilerBuilder.java
// public class TranspilerBuilder extends IncrementalProjectBuilder {
// 
// 	public static final String ID = "si.gos.transpiler.builder.TranspilerBuilder";
// 	
// 	private Map<String, TranspileItem> cache;
// 	
// 	public TranspilerBuilder() {
// 		cache = new HashMap<String, TranspileItem>();
// 	}
// 	
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
// 	 *      java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
// 	 */
// 	protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor)
// 			throws CoreException {
// 		
// 		IProject project = getProject();
// 		
// 		if (project.hasNature(TranspilerNature.NATURE_ID) == false) {
// 			return null;
// 		}
// 		
// 		Launcher launcher = new Launcher(project);
// 		launcher.addResponseListener(new ConsoleResponseHandler());
// 		
// 		IResourceDelta delta = getDelta(project);
// 
// 		if (delta != null) {
// 			ResourceLocator locator = new ResourceLocator(project);
// 			searchAndTranspile(delta.getAffectedChildren(), locator, launcher);
// 			
// 			// refresh workspace
// 			project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
// 		}
// 		
// 		return null;
// 	}
// 	
// 	private void searchAndTranspile(IResourceDelta[] affectedChildren, ResourceLocator locator, Launcher launcher) {
// 		for (IResourceDelta affected : affectedChildren) {
// 			IPath path = affected.getProjectRelativePath();
// 			
// 			if (affected.getResource() instanceof IFile) {
// 				TranspileItem transpileItem = null;
// 				// TODO: Cache, see: https://stackoverflow.com/questions/22886012/get-the-instance-for-an-eclipse-builder
// //				String cacheKey = path.toString();
// //				if (cache.containsKey(cacheKey)) {
// //					transpileItem = cache.get(cacheKey);
// //				} else {
// 					transpileItem = locator.getTranspileItem(path);
// //					cache.put(cacheKey, transpileItem);
// //				}
// 
// 				if (transpileItem != null) {
// 					transpile(transpileItem, launcher);
// 				}
// 			}
// 
// 			searchAndTranspile(affected.getAffectedChildren(), locator, launcher);
// 		}
// 	}
// 
// 	private void transpile(TranspileItem transpileItem, Launcher launcher) {
// 		ConfiguredTranspiler ct = transpileItem.getConfiguredTranspiler();
// 		InstalledTranspiler itp = transpileItem.getInstalledTranspiler();
// 
// 		String source = transpileItem.getSource().toOSString();
// 		String dest = transpileItem.getDestination().toOSString();
// 		String path = itp.getPath().toString();
// 		
// 		Map<String, String> subs = new HashMap<String, String>();
// 		subs.put("source", source);
// 		subs.put("destination", dest);
// 
// 		CommandLine cmd = itp.getTranspiler().getCommand(path, ct.getOptions());
// 		cmd.setSubstitutionMap(subs);
// 
// //		System.out.println("Transpiler: " + ct.getInstalledTranspiler().getTranspiler().getName());
// //		System.out.println("From: " + source + ", To: " + dest);
// //		System.out.println("Cmd: " + cmd);
// 		
// 		try {
// 			launcher.launch(cmd);
// 		} catch (ExecuteException e) {
// 			e.printStackTrace();
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 	}
// 	
// 	public void updateCache(ResourceLocator locator) {
// 		IProject project = locator.getProject();
// 		for (String cacheKey : cache.keySet()) {
// 			IPath path = project.findMember(cacheKey).getProjectRelativePath();
// 			
// 			TranspileItem item = locator.getTranspileItem(path);
// 			if (item == null) {
// 				cache.remove(cacheKey);
// 			}
// 		}
// 	}
// 	
// }


import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import si.gos.transpiler.core.builder.TranspilerBuilder;
package si.gos.transpiler.core;



public class TranspilerNature implements IProjectNature {

	/**
	 * ID of this project nature
	 */
	public static final String NATURE_ID = "si.gos.transpiler.nature";

	private IProject project;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.resources.IProjectNature#configure()
	 */
	public void configure() throws CoreException {
		IProjectDescription desc = project.getDescription();
		ICommand[] commands = desc.getBuildSpec();

		for (int i = 0; i < commands.length; ++i) {
// Path: si.gos.transpiler.core/src/si/gos/transpiler/core/builder/TranspilerBuilder.java
// public class TranspilerBuilder extends IncrementalProjectBuilder {
// 
// 	public static final String ID = "si.gos.transpiler.builder.TranspilerBuilder";
// 	
// 	private Map<String, TranspileItem> cache;
// 	
// 	public TranspilerBuilder() {
// 		cache = new HashMap<String, TranspileItem>();
// 	}
// 	
// 	/*
// 	 * (non-Javadoc)
// 	 * 
// 	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
// 	 *      java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
// 	 */
// 	protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor)
// 			throws CoreException {
// 		
// 		IProject project = getProject();
// 		
// 		if (project.hasNature(TranspilerNature.NATURE_ID) == false) {
// 			return null;
// 		}
// 		
// 		Launcher launcher = new Launcher(project);
// 		launcher.addResponseListener(new ConsoleResponseHandler());
// 		
// 		IResourceDelta delta = getDelta(project);
// 
// 		if (delta != null) {
// 			ResourceLocator locator = new ResourceLocator(project);
// 			searchAndTranspile(delta.getAffectedChildren(), locator, launcher);
// 			
// 			// refresh workspace
// 			project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
// 		}
// 		
// 		return null;
// 	}
// 	
// 	private void searchAndTranspile(IResourceDelta[] affectedChildren, ResourceLocator locator, Launcher launcher) {
// 		for (IResourceDelta affected : affectedChildren) {
// 			IPath path = affected.getProjectRelativePath();
// 			
// 			if (affected.getResource() instanceof IFile) {
// 				TranspileItem transpileItem = null;
// 				// TODO: Cache, see: https://stackoverflow.com/questions/22886012/get-the-instance-for-an-eclipse-builder
// //				String cacheKey = path.toString();
// //				if (cache.containsKey(cacheKey)) {
// //					transpileItem = cache.get(cacheKey);
// //				} else {
// 					transpileItem = locator.getTranspileItem(path);
// //					cache.put(cacheKey, transpileItem);
// //				}
// 
// 				if (transpileItem != null) {
// 					transpile(transpileItem, launcher);
// 				}
// 			}
// 
// 			searchAndTranspile(affected.getAffectedChildren(), locator, launcher);
// 		}
// 	}
// 
// 	private void transpile(TranspileItem transpileItem, Launcher launcher) {
// 		ConfiguredTranspiler ct = transpileItem.getConfiguredTranspiler();
// 		InstalledTranspiler itp = transpileItem.getInstalledTranspiler();
// 
// 		String source = transpileItem.getSource().toOSString();
// 		String dest = transpileItem.getDestination().toOSString();
// 		String path = itp.getPath().toString();
// 		
// 		Map<String, String> subs = new HashMap<String, String>();
// 		subs.put("source", source);
// 		subs.put("destination", dest);
// 
// 		CommandLine cmd = itp.getTranspiler().getCommand(path, ct.getOptions());
// 		cmd.setSubstitutionMap(subs);
// 
// //		System.out.println("Transpiler: " + ct.getInstalledTranspiler().getTranspiler().getName());
// //		System.out.println("From: " + source + ", To: " + dest);
// //		System.out.println("Cmd: " + cmd);
// 		
// 		try {
// 			launcher.launch(cmd);
// 		} catch (ExecuteException e) {
// 			e.printStackTrace();
// 		} catch (IOException e) {
// 			e.printStackTrace();
// 		} catch (InterruptedException e) {
// 			e.printStackTrace();
// 		}
// 	}
// 	
// 	public void updateCache(ResourceLocator locator) {
// 		IProject project = locator.getProject();
// 		for (String cacheKey : cache.keySet()) {
// 			IPath path = project.findMember(cacheKey).getProjectRelativePath();
// 			
// 			TranspileItem item = locator.getTranspileItem(path);
// 			if (item == null) {
// 				cache.remove(cacheKey);
// 			}
// 		}
// 	}
// 	
// }


// Path: si.gos.transpiler.core/src/si/gos/transpiler/core/TranspilerNature.java
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import si.gos.transpiler.core.builder.TranspilerBuilder;

package si.gos.transpiler.core;



public class TranspilerNature implements IProjectNature {

	/**
	 * ID of this project nature
	 */
	public static final String NATURE_ID = "si.gos.transpiler.nature";

	private IProject project;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.resources.IProjectNature#configure()
	 */
	public void configure() throws CoreException {
		IProjectDescription desc = project.getDescription();
		ICommand[] commands = desc.getBuildSpec();

		for (int i = 0; i < commands.length; ++i) {
			if (commands[i].getBuilderName().equals(TranspilerBuilder.ID)) {