26
26
import static processing .app .I18n ._ ;
27
27
28
28
import java .io .*;
29
+ import java .nio .file .Files ;
30
+ import java .nio .file .Path ;
31
+ import java .nio .file .Paths ;
29
32
import java .util .*;
33
+ import java .util .stream .Stream ;
30
34
31
35
import cc .arduino .MyStreamPumper ;
32
36
import cc .arduino .packages .BoardPort ;
33
37
import cc .arduino .packages .Uploader ;
34
38
import cc .arduino .packages .UploaderFactory ;
35
39
36
40
import cc .arduino .packages .uploaders .MergeSketchWithBooloader ;
41
+ import cc .arduino .utils .Pair ;
37
42
import org .apache .commons .compress .utils .IOUtils ;
38
43
import org .apache .commons .exec .*;
39
44
import processing .app .BaseNoGui ;
@@ -57,6 +62,7 @@ public class Compiler implements MessageConsumer {
57
62
* used for the last build.
58
63
*/
59
64
static final public String BUILD_PREFS_FILE = "buildprefs.txt" ;
65
+ private static final int ADDITIONAL_FILES_COPY_MAX_DEPTH = 5 ;
60
66
61
67
private SketchData sketch ;
62
68
private PreferencesMap prefs ;
@@ -1384,29 +1390,38 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
1384
1390
}
1385
1391
}
1386
1392
1387
- // 3. then loop over the code[] and save each .java file
1393
+ copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure ( sketch , buildPath );
1388
1394
1395
+ // 3. then loop over the code[] and save each .java file
1389
1396
for (SketchCode sc : sketch .getCodes ()) {
1390
- if (sc .isExtension (SketchData .OTHER_ALLOWED_EXTENSIONS )) {
1391
- // no pre-processing services necessary for java files
1392
- // just write the the contents of 'program' to a .java file
1393
- // into the build directory. uses byte stream and reader/writer
1394
- // shtuff so that unicode bunk is properly handled
1395
- String filename = sc .getFileName (); //code[i].name + ".java";
1396
- try {
1397
- BaseNoGui .saveFile (sc .getProgram (), new File (buildPath , filename ));
1398
- } catch (IOException e ) {
1399
- e .printStackTrace ();
1400
- throw new RunnerException (I18n .format (_ ("Problem moving {0} to the build folder" ), filename ));
1401
- }
1402
-
1403
- } else if (sc .isExtension ("ino" ) || sc .isExtension ("pde" )) {
1397
+ if (sc .isExtension ("ino" ) || sc .isExtension ("pde" )) {
1404
1398
// The compiler and runner will need this to have a proper offset
1405
1399
sc .addPreprocOffset (headerOffset );
1406
1400
}
1407
1401
}
1408
1402
}
1409
1403
1404
+ private void copyAdditionalFilesToBuildFolderSavingOriginalFolderStructure (SketchData sketch , String buildPath ) throws RunnerException {
1405
+ Path sketchPath = Paths .get (sketch .getFolder ().getAbsolutePath ());
1406
+ Stream <Path > otherFilesStream ;
1407
+ try {
1408
+ otherFilesStream = Files .find (sketchPath , ADDITIONAL_FILES_COPY_MAX_DEPTH , (path , attribs ) -> !attribs .isDirectory () && FileUtils .hasExtension (path .toFile (), SketchData .OTHER_ALLOWED_EXTENSIONS ));
1409
+ } catch (IOException e ) {
1410
+ throw new RunnerException (e );
1411
+ }
1412
+ otherFilesStream .map ((path ) -> new Pair <>(path , Paths .get (buildPath , sketchPath .relativize (path ).toString ())))
1413
+ .filter ((pair ) -> !Files .exists (pair .value ))
1414
+ .forEach ((pair ) -> {
1415
+ try {
1416
+ Files .createDirectories (pair .value .getParent ());
1417
+ Files .copy (pair .key , pair .value );
1418
+ } catch (IOException e ) {
1419
+ e .printStackTrace ();
1420
+ throw new RuntimeException (I18n .format (_ ("Problem moving {0} to the build folder" ), sketchPath .relativize (pair .key ).toString ()));
1421
+ }
1422
+ });
1423
+ }
1424
+
1410
1425
1411
1426
/**
1412
1427
* List of library folders.
0 commit comments