// Path: src/com/microchip/mplab/nbide/embedded/arduino/utils/DeletingFileVisitor.java
// public class DeletingFileVisitor extends SimpleFileVisitor<Path> {
// 
//     @Override
//     public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//         Files.delete(file);
//         return FileVisitResult.CONTINUE;
//     }
// 
//     @Override
//     public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
//         Files.delete(dir);
//         return FileVisitResult.CONTINUE;
//     }
//     
// }
// 
// Path: src/com/microchip/mplab/nbide/embedded/arduino/importer/NativeProcessRunner.java
// public static final int NO_ERROR_CODE = 0;


import com.microchip.mplab.nbide.embedded.api.LanguageTool;
import com.microchip.mplab.nbide.embedded.arduino.utils.DeletingFileVisitor;
import static com.microchip.mplab.nbide.embedded.arduino.importer.NativeProcessRunner.NO_ERROR_CODE;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import static java.nio.file.FileVisitResult.CONTINUE;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
    }

    public ArduinoConfig getArduinoPathResolver() {
        return arduinoConfig;
    }

    public GCCToolFinder getToolFinder() {
        return toolFinder;
    }

    public void preprocess(BoardConfiguration boardConfiguration, Path inoFilePath) {
        Path tempDirPath = null;
        try {
            tempDirPath = Files.createTempDirectory("preprocess");
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        preprocess(boardConfiguration, inoFilePath, tempDirPath);
    }
    
    public void preprocess(BoardConfiguration boardConfiguration, Path inoFilePath, Path preprocessDirPath) {
        try {
            this.preprocessDirPath = preprocessDirPath;
            if ( !Files.exists(preprocessDirPath) ) {
                Files.createDirectories(preprocessDirPath);
            }
            
            // Run Arduino-Builder
            int errorCode = runArduinoBuilder(boardConfiguration, inoFilePath);

// Path: src/com/microchip/mplab/nbide/embedded/arduino/utils/DeletingFileVisitor.java
// public class DeletingFileVisitor extends SimpleFileVisitor<Path> {
// 
//     @Override
//     public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
//         Files.delete(file);
//         return FileVisitResult.CONTINUE;
//     }
// 
//     @Override
//     public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
//         Files.delete(dir);
//         return FileVisitResult.CONTINUE;
//     }
//     
// }
// 
// Path: src/com/microchip/mplab/nbide/embedded/arduino/importer/NativeProcessRunner.java
// public static final int NO_ERROR_CODE = 0;


// Path: src/com/microchip/mplab/nbide/embedded/arduino/importer/ArduinoBuilderRunner.java
import com.microchip.mplab.nbide.embedded.api.LanguageTool;
import com.microchip.mplab.nbide.embedded.arduino.utils.DeletingFileVisitor;
import static com.microchip.mplab.nbide.embedded.arduino.importer.NativeProcessRunner.NO_ERROR_CODE;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import static java.nio.file.FileVisitResult.CONTINUE;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import jdk.nashorn.api.scripting.ScriptObjectMirror;

    }

    public ArduinoConfig getArduinoPathResolver() {
        return arduinoConfig;
    }

    public GCCToolFinder getToolFinder() {
        return toolFinder;
    }

    public void preprocess(BoardConfiguration boardConfiguration, Path inoFilePath) {
        Path tempDirPath = null;
        try {
            tempDirPath = Files.createTempDirectory("preprocess");
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        preprocess(boardConfiguration, inoFilePath, tempDirPath);
    }
    
    public void preprocess(BoardConfiguration boardConfiguration, Path inoFilePath, Path preprocessDirPath) {
        try {
            this.preprocessDirPath = preprocessDirPath;
            if ( !Files.exists(preprocessDirPath) ) {
                Files.createDirectories(preprocessDirPath);
            }
            
            // Run Arduino-Builder
            int errorCode = runArduinoBuilder(boardConfiguration, inoFilePath);

            if (errorCode == NO_ERROR_CODE) {