Skip to content

Commit 7a73d0b

Browse files
matthijskooijmanfacchinm
authored andcommitted
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 959fba7 commit 7a73d0b

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
@@ -839,7 +839,7 @@ private String build(String buildPath, boolean verbose, boolean save) throws Run
839839
CompilerProgressListener progressListener = editor.status::progressUpdate;
840840

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

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

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

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

870870
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
@@ -110,17 +110,17 @@ enum BuilderAction {
110110

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

113-
private final String pathToSketch;
113+
private final File pathToSketch;
114114
private final Sketch sketch;
115115
private final String buildPath;
116116
private final boolean verbose;
117117
private RunnerException exception;
118118

119119
public Compiler(Sketch data, String buildPath) {
120-
this(data.getMainFilePath(), data, buildPath);
120+
this(data.getPrimaryFile().getFile(), data, buildPath);
121121
}
122122

123-
public Compiler(String pathToSketch, Sketch sketch, String buildPath) {
123+
public Compiler(File pathToSketch, Sketch sketch, String buildPath) {
124124
this.pathToSketch = pathToSketch;
125125
this.sketch = sketch;
126126
this.buildPath = buildPath;
@@ -249,7 +249,7 @@ private void callArduinoBuilder(TargetBoard board, TargetPlatform platform, Targ
249249
cmd.add("-verbose");
250250
}
251251

252-
cmd.add(pathToSketch);
252+
cmd.add(pathToSketch.getAbsolutePath());
253253

254254
if (verbose) {
255255
System.out.println(StringUtils.join(cmd, ' '));

0 commit comments

Comments
 (0)