1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-14 11:29:26 +01:00

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.
This commit is contained in:
Matthijs Kooijman 2015-12-18 16:23:30 +01:00 committed by Martino Facchin
parent 959fba7865
commit 7a73d0b3db
2 changed files with 8 additions and 8 deletions

View File

@ -839,7 +839,7 @@ public class SketchController {
CompilerProgressListener progressListener = editor.status::progressUpdate; CompilerProgressListener progressListener = editor.status::progressUpdate;
boolean deleteTemp = false; boolean deleteTemp = false;
String pathToSketch = sketch.getMainFilePath(); File pathToSketch = sketch.getPrimaryFile().getFile();
if (sketch.isModified()) { if (sketch.isModified()) {
// If any files are modified, make a copy of the sketch with the changes // If any files are modified, make a copy of the sketch with the changes
// saved, so arduino-builder will see the modifications. // saved, so arduino-builder will see the modifications.
@ -852,11 +852,11 @@ public class SketchController {
} finally { } finally {
// Make sure we clean up any temporary sketch copy // Make sure we clean up any temporary sketch copy
if (deleteTemp) 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_"); File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_");
FileUtils.copy(sketch.getFolder(), tempFolder); FileUtils.copy(sketch.getFolder(), tempFolder);
@ -864,7 +864,7 @@ public class SketchController {
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes()); 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 { protected boolean exportApplet(boolean usingProgrammer) throws Exception {

View File

@ -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 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 Sketch sketch;
private final String buildPath; private final String buildPath;
private final boolean verbose; private final boolean verbose;
private RunnerException exception; private RunnerException exception;
public Compiler(Sketch data, String buildPath) { 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.pathToSketch = pathToSketch;
this.sketch = sketch; this.sketch = sketch;
this.buildPath = buildPath; this.buildPath = buildPath;
@ -249,7 +249,7 @@ public class Compiler implements MessageConsumer {
cmd.add("-verbose"); cmd.add("-verbose");
} }
cmd.add(pathToSketch); cmd.add(pathToSketch.getAbsolutePath());
if (verbose) { if (verbose) {
System.out.println(StringUtils.join(cmd, ' ')); System.out.println(StringUtils.join(cmd, ' '));