diff --git a/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchBuilder.java b/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchBuilder.java index b365e866a..ad1d850cb 100644 --- a/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchBuilder.java +++ b/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchBuilder.java @@ -224,7 +224,7 @@ public class SketchBuilder extends IncrementalProjectBuilder{ String[] codeFolderPackages = null; if (codeFolder != null && codeFolder.exists()){ String codeFolderClassPath = Utilities.contentsToClassPath(codeFolder.getLocation().toFile()); - for( String s : codeFolderClassPath.split(File.separator)){ + for( String s : codeFolderClassPath.split(File.pathSeparator)){ if (!s.isEmpty()){ libraryJarPathList.add(new Path(s).makeAbsolute()); } diff --git a/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchProject.java b/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchProject.java index 749b15f5d..4ddd1b388 100644 --- a/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchProject.java +++ b/editor/processing.plugin.core/src/processing/plugin/core/builder/SketchProject.java @@ -12,7 +12,6 @@ package processing.plugin.core.builder; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.HashSet; import java.util.Hashtable; import java.util.List; @@ -358,14 +357,17 @@ public class SketchProject implements IProjectNature { // this should include the build folder and the code folder, if it was necessary if(srcFolderPathList != null){ for( IPath p : srcFolderPathList){ - if (p!=null) entries.add(JavaCore.newSourceEntry(p.makeAbsolute())); + if (p!=null){ + System.out.println(p.toOSString()); + entries.add(JavaCore.newSourceEntry(p.makeAbsolute())); + } } } if(libraryJarPathList != null){ for(IPath p : libraryJarPathList){ - //System.out.println(p.toString()); if (p != null){ + System.out.println(p.toString()); entries.add( JavaCore.newLibraryEntry(p.makeAbsolute(), null, // no source @@ -494,56 +496,5 @@ public class SketchProject implements IProjectNature { public String getMainType() { return project.getName(); } - - /** - * Tries to export the sketch as an applet - * returns whether or not it was successful - */ - public boolean exportAsApplet() { - if (!wasLastBuildSuccessful) return false; - if (!project.isAccessible()) return false; - - IFile code = this.getMainFile(); - if (code == null) return false; - - IFolder exportFolder = getAppletFolder(true); // true nukes the folder if it exists - - // if the code folder has stuff, dump it to a jar - try{ - IFolder codeFolder = getCodeFolder(); - if(codeFolder != null){ - if(codeFolder.members().length > 0){ - for(IResource r : codeFolder.members()){ - - } - } - } - } catch (CoreException e) { - ProcessingLog.logError("Could not export. CoreException while getting code folder.", e); - return false; - } - -// 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); -// } - - return false; - } } \ No newline at end of file diff --git a/editor/processing.plugin.core/src/processing/plugin/core/builder/Utilities.java b/editor/processing.plugin.core/src/processing/plugin/core/builder/Utilities.java index 4aedd8c1b..66911ef86 100644 --- a/editor/processing.plugin.core/src/processing/plugin/core/builder/Utilities.java +++ b/editor/processing.plugin.core/src/processing/plugin/core/builder/Utilities.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; +import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -116,7 +117,8 @@ public class Utilities { //TODO Review this method and make sure that it is returning only paths directly to jars and zip files // It was returning empty paths which was breaking things. Needs to be reviewed. if (folder == null) return ""; - + if (!folder.isDirectory()) return ""; + StringBuffer abuffer = new StringBuffer(); String sep = System.getProperty("path.separator"); @@ -125,11 +127,10 @@ public class Utilities { // When getting the name of this folder, make sure it has a slash // after it, so that the names of sub-items can be added. - if (!path.endsWith(File.separator)) { - path += File.separator; - } + if (!path.endsWith(File.separator)) path += File.separator; String list[] = folder.list(); + for (int i = 0; i < list.length; i++) { // Skip . and ._ files. Prior to 0125p3, .jar files that had // OS X AppleDouble files associated would cause trouble. @@ -492,6 +493,31 @@ public class Utilities { //} return splits; } + + /** + * Splits a string into pieces, using any of the chars in the + * String 'delim' as separator characters. For instance, + * in addition to white space, you might want to treat commas + * as a separator. The delimeter characters won't appear in + * the returned String array. + *
+	   * i.e. splitTokens("a, b", " ,") -> { "a", "b" }
+	   * 
+ * To include all the whitespace possibilities, use the variable + * WHITESPACE, found in PConstants: + *
+	   * i.e. splitTokens("a   | b", WHITESPACE + "|");  ->  { "a", "b" }
+ */ + static public String[] splitTokens(String what, String delim) { + StringTokenizer toker = new StringTokenizer(what, delim); + String pieces[] = new String[toker.countTokens()]; + + int index = 0; + while (toker.hasMoreTokens()) { + pieces[index++] = toker.nextToken(); + } + return pieces; + } public static void deleteFolderContents(File folder) { if (folder == null) return; diff --git a/editor/processing.plugin.ui/META-INF/MANIFEST.MF b/editor/processing.plugin.ui/META-INF/MANIFEST.MF index 6708a0409..de51cf70f 100644 --- a/editor/processing.plugin.ui/META-INF/MANIFEST.MF +++ b/editor/processing.plugin.ui/META-INF/MANIFEST.MF @@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide;bundle-version="3.6.0", org.eclipse.jdt.core;bundle-version="3.6.0", org.eclipse.ui.navigator, - org.eclipse.ui.navigator.resources + org.eclipse.ui.navigator.resources, + org.eclipse.jdt.ui;bundle-version="3.6.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.ui.actions diff --git a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java index afdc1b658..1d8abdfc9 100644 --- a/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java +++ b/editor/processing.plugin.ui/src/processing/plugin/ui/wizards/ExportAsAppletWizard.java @@ -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 couldNotExport = new ArrayList(); 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; + } }