name,
codeFolderPackages);
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = "Build folder disappeared or could not be written";
throw new RunnerException(msg);
}
// 2. run preproc on that code using the sugg class name
// to create a single .java file and write to buildpath
String primaryClassName = null;
try {
// if (i != 0) preproc will fail if a pde file is not
// java mode, since that's required
String className = preprocessor.write();
if (className == null) {
throw new RunnerException("Could not find main class");
// this situation might be perfectly fine,
// (i.e. if the file is empty)
//System.out.println("No class found in " + code[i].name);
//System.out.println("(any code in that file will be ignored)");
//System.out.println();
// } else {
// code[0].setPreprocName(className + ".cpp");
}
// store this for the compiler and the runtime
primaryClassName = className + ".cpp";
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = "Build folder disappeared or could not be written";
throw new RunnerException(msg);
} catch (RunnerException pe) {
// RunnerExceptions are caught here and re-thrown, so that they don't
// get lost in the more general "Exception" handler below.
throw pe;
} catch (Exception ex) {
// TODO better method for handling this?
System.err.println("Uncaught exception type:" + ex.getClass());
ex.printStackTrace();
throw new RunnerException(ex.toString());
}
// grab the imports from the code just preproc'd
importedLibraries = new ArrayList<File>();
for (String item : preprocessor.getExtraImports()) {
File libFolder = (File) Base.importToLibraryTable.get(item);
if (libFolder != null && !importedLibraries.contains(libFolder)) {
importedLibraries.add(libFolder);
classPath += Compiler.contentsToClassPath(libFolder);
libraryPath += File.pathSeparator + libFolder.getAbsolutePath();
}
}
/*
importedLibraries = new ArrayList<Library>(); //new Vector();
String imports[] = preprocessor.extraImports;
try {
LibraryManager libraryManager = new LibraryManager();
Collection libraries = libraryManager.getAll();
for (Iterator i = libraries.iterator(); i.hasNext(); ) {
Library library = (Library) i.next();
File[] headerFiles = library.getHeaderFiles();
for (int j = 0; j < headerFiles.length; j++)
for (int k = 0; k < imports.length; k++)
if (headerFiles[j].getName().equals(imports[k]) &&
!importedLibraries.contains(library)) {
importedLibraries.add(library); //.getFolder());
//System.out.println("Adding library " + library.getName());
}
}
} catch (IOException e) {
System.err.println("Error finding libraries:");
e.printStackTrace();
throw new RunnerException(e.getMessage());
}
*/
// 3. then loop over the code[] and save each .java file
for (SketchCode sc : code) {
// System.out.println(sc.getFileName());
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
// no pre-processing services necessary for java files
// just write the the contents of 'program' to a .java file
// into the build directory. uses byte stream and reader/writer
// shtuff so that unicode bunk is properly handled
String filename = sc.getFileName(); //code[i].name + ".java";
try {
Base.saveFile(sc.getProgram(), new File(buildPath, filename));
} catch (IOException e) {
e.printStackTrace();
throw new RunnerException("Problem moving " + filename +
" to the build folder");
}
// sc.setPreprocName(filename);
} else if (sc.isExtension("pde") || sc.isExtension("ino")) {