@@ -96,6 +96,8 @@ public class Sketch {
96
96
* List of library folders.
97
97
*/
98
98
private ArrayList <File > importedLibraries ;
99
+ private ArrayList <String > importedDuplicateHeaders ;
100
+ private ArrayList <LinkedList <File >> importedDuplicateLibraries ;
99
101
100
102
/**
101
103
* path is location of the main .pde file, because this is also
@@ -1436,14 +1438,20 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
1436
1438
// grab the imports from the code just preproc'd
1437
1439
1438
1440
importedLibraries = new ArrayList <File >();
1441
+ importedDuplicateHeaders = new ArrayList <String >();
1442
+ importedDuplicateLibraries = new ArrayList <LinkedList <File >>();
1439
1443
1440
1444
for (String item : preprocessor .getExtraImports ()) {
1441
- File libFolder = (File ) Base .importToLibraryTable .get (item );
1442
-
1443
- if (libFolder != null && !importedLibraries .contains (libFolder )) {
1444
- importedLibraries .add (libFolder );
1445
- //classPath += Compiler.contentsToClassPath(libFolder);
1446
- libraryPath += File .pathSeparator + libFolder .getAbsolutePath ();
1445
+ LinkedList <File > liblist = Base .importToLibraryTable .get (item );
1446
+ if (liblist != null ) {
1447
+ File libFolder = liblist .peekFirst ();
1448
+ if (libFolder != null && !importedLibraries .contains (libFolder )) {
1449
+ importedLibraries .add (libFolder );
1450
+ if (liblist .size () > 1 ) {
1451
+ importedDuplicateHeaders .add (item );
1452
+ importedDuplicateLibraries .add (liblist );
1453
+ }
1454
+ }
1447
1455
}
1448
1456
}
1449
1457
@@ -1582,14 +1590,38 @@ public String build(String buildPath, boolean verbose)
1582
1590
// compile the program. errors will happen as a RunnerException
1583
1591
// that will bubble up to whomever called build().
1584
1592
Compiler compiler = new Compiler ();
1585
- if (compiler .compile (this , buildPath , primaryClassName , verbose )) {
1586
- size (buildPath , primaryClassName );
1587
- return primaryClassName ;
1593
+ try {
1594
+ if (compiler .compile (this , buildPath , primaryClassName , verbose )) {
1595
+ size (buildPath , primaryClassName );
1596
+ return primaryClassName ;
1597
+ }
1598
+ } catch (RunnerException e ) {
1599
+ // when the compile fails, take this opportunity to show
1600
+ // any helpful info possible before throwing the exception
1601
+ adviseDuplicateLibraries ();
1602
+ throw e ;
1588
1603
}
1589
1604
return null ;
1590
1605
}
1591
1606
1592
1607
1608
+ public void adviseDuplicateLibraries () {
1609
+ for (int i =0 ; i < importedDuplicateHeaders .size (); i ++) {
1610
+ System .out .println (I18n .format (_ ("Multiple libraries were found for \" {0}\" " ),
1611
+ importedDuplicateHeaders .get (i )));
1612
+ boolean first = true ;
1613
+ for (File libFolder : importedDuplicateLibraries .get (i )) {
1614
+ if (first ) {
1615
+ System .out .println (I18n .format (_ (" Used: {0}" ), libFolder .getPath ()));
1616
+ first = false ;
1617
+ } else {
1618
+ System .out .println (I18n .format (_ (" Not Used: {0}" ), libFolder .getPath ()));
1619
+ }
1620
+ }
1621
+ }
1622
+ }
1623
+
1624
+
1593
1625
protected boolean exportApplet (boolean usingProgrammer ) throws Exception {
1594
1626
return exportApplet (tempBuildFolder .getAbsolutePath (), usingProgrammer );
1595
1627
}
0 commit comments