Skip to content

Commit 04635e7

Browse files
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.
1 parent cf7498b commit 04635e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

app/src/processing/app/SketchController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
840840
CompilerProgressListener progressListener = editor.status::progressUpdate;
841841

842842
boolean deleteTemp = false;
843-
String pathToSketch = sketch.getMainFilePath();
843+
File pathToSketch = sketch.getPrimaryFile().getFile();
844844
if (sketch.isModified()) {
845845
// If any files are modified, make a copy of the sketch with the changes
846846
// saved, so arduino-builder will see the modifications.
@@ -853,19 +853,19 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
853853
} finally {
854854
// Make sure we clean up any temporary sketch copy
855855
if (deleteTemp)
856-
FileUtils.recursiveDelete(new File(pathToSketch).getParentFile());
856+
FileUtils.recursiveDelete(pathToSketch.getParentFile());
857857
}
858858
}
859859

860-
private String saveSketchInTempFolder() throws IOException {
860+
private File saveSketchInTempFolder() throws IOException {
861861
File tempFolder = FileUtils.createTempFolder("arduino_modified_sketch_");
862862
FileUtils.copy(sketch.getFolder(), tempFolder);
863863

864864
for (SketchFile file : Stream.of(sketch.getFiles()).filter(SketchFile::isModified).collect(Collectors.toList())) {
865865
Files.write(Paths.get(tempFolder.getAbsolutePath(), file.getFileName()), file.getProgram().getBytes());
866866
}
867867

868-
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toString();
868+
return Paths.get(tempFolder.getAbsolutePath(), sketch.getPrimaryFile().getFileName()).toFile();
869869
}
870870

871871
protected boolean exportApplet(boolean usingProgrammer) throws Exception {

arduino-core/src/cc/arduino/Compiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ enum BuilderAction {
108108

109109
private static final Pattern ERROR_FORMAT = Pattern.compile("(.+\\.\\w+):(\\d+)(:\\d+)*:\\s*error:\\s*(.*)\\s*", Pattern.MULTILINE | Pattern.DOTALL);
110110

111-
private final String pathToSketch;
111+
private final File pathToSketch;
112112
private final Sketch sketch;
113113
private final String buildPath;
114114
private final boolean verbose;
115115
private RunnerException exception;
116116

117117
public Compiler(Sketch data, String buildPath) {
118-
this(data.getMainFilePath(), data, buildPath);
118+
this(data.getPrimaryFile().getFile(), data, buildPath);
119119
}
120120

121-
public Compiler(String pathToSketch, Sketch sketch, String buildPath) {
121+
public Compiler(File pathToSketch, Sketch sketch, String buildPath) {
122122
this.pathToSketch = pathToSketch;
123123
this.sketch = sketch;
124124
this.buildPath = buildPath;
@@ -241,7 +241,7 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
241241
commandLine.addArgument("-verbose", false);
242242
}
243243

244-
commandLine.addArgument("\"" + pathToSketch + "\"", false);
244+
commandLine.addArgument("\"" + pathToSketch.getAbsolutePath() + "\"", false);
245245

246246
if (verbose) {
247247
System.out.println(commandLine);

0 commit comments

Comments
 (0)