Fix the build process to handle code folder entries correctly. Also, some updates for exporting.

This commit is contained in:
lonnen
2010-09-23 18:57:21 +00:00
parent d76aa79f03
commit 616e60a069
5 changed files with 130 additions and 61 deletions

View File

@@ -13,15 +13,28 @@ package processing.plugin.ui.wizards;
//import java.util.Iterator;
//import org.eclipse.core.resources.IProject;
//import org.eclipse.core.resources.IResource;
import java.io.File;
import java.util.ArrayList;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.ui.jarpackager.JarPackageData;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import processing.plugin.core.ProcessingLog;
import processing.plugin.core.builder.SketchProject;
import processing.plugin.core.builder.Utilities;
import processing.plugin.ui.ProcessingPlugin;
/**
@@ -75,7 +88,7 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
ArrayList<String> couldNotExport = new ArrayList<String>();
for(SketchProject sp : page.getSelectedProjects()){
// System.out.println(sp.getProject().getName());
if (!sp.exportAsApplet()) couldNotExport.add(sp.getProject().getName());
if (!exportAsApplet(sp)) couldNotExport.add(sp.getProject().getName());
}
if (couldNotExport.size() > 0)
@@ -83,5 +96,83 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
return true;
}
/**
* Tries to export the sketch as an applet
* returns whether or not it was successful
*/
public boolean exportAsApplet(SketchProject sp) {
if (!sp.wasLastBuildSuccessful()) return false;
if (!sp.getProject().isAccessible()) return false;
IFile code = sp.getMainFile();
if (code == null) return false;
// true to nuke the folder contents, if they exist
IFolder exportFolder = sp.getAppletFolder(true);
// if the code folder has stuff, move it to the applet folder
IFolder codeFolder = sp.getCodeFolder();
if(codeFolder != null){
try{
String includes = Utilities.contentsToClassPath(codeFolder.getFullPath().toFile());
String[] codeList = Utilities.splitTokens(includes,File.separator);
for (String path : codeList){
System.out.println("Found file: " + path + ".");
if (path.toLowerCase().endsWith(".jar") ||
path.toLowerCase().endsWith(".zip")) {
IFile exportFile = codeFolder.getFile(new Path(path));
if (exportFile.isAccessible()){
exportFile.copy(exportFolder.getFullPath(), true, null);
System.out.println("Copied the file to " + exportFolder.getFullPath().toString() + " .");
}
}
}
} catch (CoreException e) {
ProcessingLog.logError("Could not export. CoreException while packaging the code folder.", e);
return false;
}
}
////
// Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// JarPackageData codePackageData = new JarPackageData();
// codePackageData.setJarLocation(sp.getAppletFolder().getFullPath().append(sp.getProject().getName() + ".jar"));
// codePackageData.setSaveManifest(true);
// description.setManifestMainClass(mainType);
// description.setElements(filestoExport);
// IJarExportRunnable runnable= description.createJarExportRunnable(parentShell);
// try {
// new ProgressMonitorDialog(parentShell).run(true,true, runnable);
// } catch (InvocationTargetException e) {
// // An error has occurred while executing the operation
// } catch (InterruptedException e) {
// // operation has been canceled.
// }
// int wide = this.getWidth();
// int high = this.getHeight();
//
// String codeContents = Utilities.readFile(code);
//
// String description ="";
// String[] javadoc = Utilities.match(codeContents, "/\\*{2,}(.*)\\*+/");
// if (javadoc != null){
// StringBuffer dbuffer = new StringBuffer();
// String[] pieces = Utilities.split(javadoc[1], '\n');
// for (String line : pieces){
// // if this line starts with * characters, remove em
// String[] m = Utilities.match(line, "^\\s*\\*+(.*)");
// dbuffer.append(m != null ? m[1] : line);
// dbuffer.append('\n');
// }
// description = dbuffer.toString();
// ProcessingLog.logInfo(description);
// }
//DEBUG
ProcessingLog.logError("Could not export " + sp.getProject().getName() + " because the exporter is not finished.", null);
return false;
}
}