From 7a73d0b3dbead5e596252b1771bfcfaf74bf42fa Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Fri, 18 Dec 2015 16:23:30 +0100 Subject: [PATCH] Change `Compiler.pathToSketch` from String to File Keeping filenames as File objects for as long as possible is generally a good idea and this removes a dependency on `Sketch.getMainFilePath()`, so it can be removed later. --- app/src/processing/app/SketchController.java | 8 ++++---- arduino-core/src/cc/arduino/Compiler.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/processing/app/SketchController.java b/app/src/processing/app/SketchController.java index cee9b34dd..2b817646b 100644 --- a/app/src/processing/app/SketchController.java +++ b/app/src/processing/app/SketchController.java @@ -839,7 +839,7 @@ public class SketchController { CompilerProgressListener progressListener = editor.status::progressUpdate; boolean deleteTemp = false; - String pathToSketch = sketch.getMainFilePath(); + File pathToSketch = sketch.getPrimaryFile().getFile(); if (sketch.isModified()) { // If any files are modified, make a copy of the sketch with the changes // saved, so arduino-builder will see the modifications. @@ -852,11 +852,11 @@ public class SketchController { } finally { // Make sure we clean up any temporary sketch copy if (deleteTemp) - FileUtils.recursiveDelete(new File(pathToSketch).getParentFile()); + FileUtils.recursiveDelete(pathToSketch.getParentFile()); } } - private String saveSketchInTempFolder() throws IOException { + private File saveSketchInTempFolder() throws IOException { File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_"); FileUtils.copy(sketch.getFolder(), tempFolder); @@ -864,7 +864,7 @@ public class SketchController { Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes()); } - return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toString(); + return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toFile(); } protected boolean exportApplet(boolean usingProgrammer) throws Exception { diff --git a/arduino-core/src/cc/arduino/Compiler.java b/arduino-core/src/cc/arduino/Compiler.java index 440f0f6bf..20cd55785 100644 --- a/arduino-core/src/cc/arduino/Compiler.java +++ b/arduino-core/src/cc/arduino/Compiler.java @@ -110,17 +110,17 @@ public class Compiler implements MessageConsumer { private static final Pattern ERROR_FORMAT = Pattern.compile("(.+\\.\\w+):(\\d+)(:\\d+)*:\\s*error:\\s*(.*)\\s*", Pattern.MULTILINE | Pattern.DOTALL); - private final String pathToSketch; + private final File pathToSketch; private final Sketch sketch; private final String buildPath; private final boolean verbose; private RunnerException exception; public Compiler(Sketch data, String buildPath) { - this(data.getMainFilePath(), data, buildPath); + this(data.getPrimaryFile().getFile(), data, buildPath); } - public Compiler(String pathToSketch, Sketch sketch, String buildPath) { + public Compiler(File pathToSketch, Sketch sketch, String buildPath) { this.pathToSketch = pathToSketch; this.sketch = sketch; this.buildPath = buildPath; @@ -249,7 +249,7 @@ public class Compiler implements MessageConsumer { cmd.add("-verbose"); } - cmd.add(pathToSketch); + cmd.add(pathToSketch.getAbsolutePath()); if (verbose) { System.out.println(StringUtils.join(cmd, ' '));