Skip to content

Commit 9074a4b

Browse files
Introduce constants for file extensions
This prevents duplicating these lists in multiple places. As a side-effect, .S files are now handled in sketches as well (instead of just in libraries), fixing arduino#1616.
1 parent 806f0fe commit 9074a4b

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

Diff for: app/src/processing/app/Base.java

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ public class Base {
6767
/** Set true if this a proper release rather than a numbered revision. */
6868
static public boolean RELEASE = false;
6969

70+
// These should remain lowercase, they are matched against lowercased strings
71+
public static final String[] SOURCE_EXTENSIONS = {"s", "c", "cpp"};
72+
public static final String[] HEADER_EXTENSIONS = {"h"};
73+
public static final String[] SKETCH_EXTENSIONS = {"ino", "pde"};
74+
7075
static Map<Integer, String> platformNames = new HashMap<Integer, String>();
7176
static {
7277
platformNames.put(PConstants.WINDOWS, "windows");

Diff for: app/src/processing/app/Sketch.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
13081308
StringBuffer bigCode = new StringBuffer();
13091309
int bigCount = 0;
13101310
for (SketchCode sc : code) {
1311-
if (sc.isExtension("ino") || sc.isExtension("pde")) {
1311+
if (sc.isExtension(Base.SKETCH_EXTENSIONS)) {
13121312
sc.setPreprocOffset(bigCount);
13131313
// These #line directives help the compiler report errors with
13141314
// correct the filename and line number (issue 281 & 907)
@@ -1368,7 +1368,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
13681368
// 3. then loop over the code[] and save each .java file
13691369

13701370
for (SketchCode sc : code) {
1371-
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
1371+
if (sc.isExtension(Base.SOURCE_EXTENSIONS) || sc.isExtension(Base.HEADER_EXTENSIONS)) {
13721372
// no pre-processing services necessary for java files
13731373
// just write the the contents of 'program' to a .java file
13741374
// into the build directory. uses byte stream and reader/writer
@@ -1382,7 +1382,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
13821382
}
13831383
// sc.setPreprocName(filename);
13841384

1385-
} else if (sc.isExtension("ino") || sc.isExtension("pde")) {
1385+
} else if (sc.isExtension(Base.SKETCH_EXTENSIONS)) {
13861386
// The compiler and runner will need this to have a proper offset
13871387
sc.addPreprocOffset(headerOffset);
13881388
}
@@ -1818,20 +1818,22 @@ public boolean validExtension(String what) {
18181818
* Returns the default extension for this editor setup.
18191819
*/
18201820
public String getDefaultExtension() {
1821-
return "ino";
1821+
return Base.SKETCH_EXTENSIONS[0];
18221822
}
18231823

1824-
static private List<String> hiddenExtensions = Arrays.asList("ino", "pde");
1825-
18261824
public List<String> getHiddenExtensions() {
1827-
return hiddenExtensions;
1825+
return Arrays.asList(Base.SKETCH_EXTENSIONS);
18281826
}
18291827

18301828
/**
18311829
* Returns a String[] array of proper extensions.
18321830
*/
18331831
public List<String> getExtensions() {
1834-
return Arrays.asList("ino", "pde", "c", "cpp", "h");
1832+
List<String> res = new ArrayList<String>();
1833+
res.addAll(Arrays.asList(Base.SKETCH_EXTENSIONS));
1834+
res.addAll(Arrays.asList(Base.SOURCE_EXTENSIONS));
1835+
res.addAll(Arrays.asList(Base.HEADER_EXTENSIONS));
1836+
return res;
18351837
}
18361838

18371839

Diff for: app/src/processing/app/debug/Compiler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
240240
private List<File> compileFiles(File outputPath, File sourcePath,
241241
boolean recurse, List<File> includeFolders)
242242
throws RunnerException {
243-
List<File> sourceFiles = FileUtils.listFiles(sourcePath, recurse, "s", "c", "cpp");
243+
List<File> sourceFiles = FileUtils.listFiles(sourcePath, recurse, Base.SOURCE_EXTENSIONS);
244244
return compileFiles(outputPath, sourcePath, sourceFiles, includeFolders);
245245

246246
}

0 commit comments

Comments
 (0)