mirror of
https://github.com/processing/processing4.git
synced 2026-02-26 08:44:39 +01:00
More exporter stuff
This commit is contained in:
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Processing Plugin User Interface Elements
|
||||
Bundle-SymbolicName: processing.plugin.ui;singleton:=true
|
||||
Bundle-Version: 0.2.3.0
|
||||
Bundle-Version: 0.2.3.1
|
||||
Bundle-Activator: processing.plugin.ui.ProcessingPlugin
|
||||
Bundle-Vendor: Processing.org
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
|
||||
@@ -70,7 +70,6 @@
|
||||
</extension>
|
||||
<extension point="org.eclipse.debug.ui.launchShortcuts">
|
||||
<shortcut
|
||||
category="Processing"
|
||||
class="processing.plugin.ui.launching.RunSketchAsAppletShortcut"
|
||||
description="Runs the Sketch as an applet, equivalent to the PDE run button."
|
||||
icon="Resources/16x16_icon.gif"
|
||||
@@ -177,4 +176,22 @@
|
||||
</filterExpression>
|
||||
</commonFilter>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
categoryId="org.eclipse.debug.ui.category.run"
|
||||
description="Run a Processing sketch as an applet"
|
||||
id="processing.plugin.ui.launchApplet"
|
||||
name="Processing Sketch Launch (Applet)">
|
||||
<!-- the above command needs a defaultHandler before it is functional -->
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.bindings">
|
||||
<key
|
||||
commandId="processing.plugin.ui.launchApplet"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
|
||||
sequence="M1+R">
|
||||
</key>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
||||
@@ -92,7 +92,7 @@ public class ExportAsAppletSelectProjectsWizardPage extends WizardPage {
|
||||
public SketchProject getProject(){ return sp; }
|
||||
|
||||
public String getAdditionalMessage(){
|
||||
return (sp.wasLastBuildSuccessful()) ? "" : "Warning: there were errors on the last build.";
|
||||
return (sp.wasLastBuildSuccessful()) ? "" : "Warning: last build unsuccessful. May not export.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,9 +14,13 @@ package processing.plugin.ui.wizards;
|
||||
//import org.eclipse.core.resources.IProject;
|
||||
//import org.eclipse.core.resources.IResource;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
@@ -89,10 +93,10 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
}
|
||||
|
||||
public boolean performFinish() {
|
||||
// return SketchProject.forProject(page.getProject()).exportAsApplet();
|
||||
//return SketchProject.forProject(page.getProject()).exportAsApplet();
|
||||
ArrayList<String> couldNotExport = new ArrayList<String>();
|
||||
for(SketchProject sp : page.getSelectedProjects()){
|
||||
// System.out.println(sp.getProject().getName());
|
||||
//System.out.println(sp.getProject().getName());
|
||||
if (!exportAsApplet(sp)) couldNotExport.add(sp.getProject().getName());
|
||||
}
|
||||
|
||||
@@ -111,14 +115,27 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
*/
|
||||
public boolean exportAsApplet(SketchProject sp) {
|
||||
if (sp == null) return false;
|
||||
if (!sp.wasLastBuildSuccessful()) return false;
|
||||
if (!sp.getProject().isAccessible()) return false;
|
||||
|
||||
|
||||
try{
|
||||
sp.fullBuild(null);
|
||||
} catch (CoreException e){
|
||||
ProcessingLog.logError(e);
|
||||
return false;
|
||||
}
|
||||
if (!sp.wasLastBuildSuccessful()){
|
||||
ProcessingLog.logError("Could not export " + sp.getProject().getName() +
|
||||
". There were erros building the project.", null);
|
||||
return false;
|
||||
}
|
||||
|
||||
IFile code = sp.getMainFile();
|
||||
if (code == null) return false;
|
||||
String codeContents = ProcessingUtilities.readFile(code);
|
||||
|
||||
IFolder exportFolder = sp.getAppletFolder(true); // true to nuke the folder contents, if they exist
|
||||
|
||||
HashMap<String,Object> zipFileContents = new HashMap<String,Object>();
|
||||
|
||||
// Get size and renderer info from the project
|
||||
int wide = sp.getWidth();
|
||||
@@ -138,25 +155,38 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
dbuffer.append('\n');
|
||||
}
|
||||
description = dbuffer.toString();
|
||||
System.out.println(description);
|
||||
//System.out.println(description);
|
||||
}
|
||||
|
||||
//Copy the source files to the target, since we like to encourage people to share their code
|
||||
// Copy the source files to the target, since we like to encourage people to share their code
|
||||
// Get links for each copied code file
|
||||
StringBuffer sources = new StringBuffer();
|
||||
try{
|
||||
for(IResource r : sp.getProject().members()){
|
||||
if(!(r instanceof IFile)) continue;
|
||||
if(r.getName().startsWith(".")) continue;
|
||||
if("pde".equalsIgnoreCase(r.getFileExtension())){
|
||||
r.copy(exportFolder.getFullPath().append(r.getName()), true, null);
|
||||
System.out.println("Copied the source file " + r.getName()
|
||||
+ " to " + exportFolder.getFullPath().toString());
|
||||
try{
|
||||
r.copy(exportFolder.getFullPath().append(r.getName()), true, null);
|
||||
sources.append("<a href=\"" + r.getName() + "\">" +
|
||||
r.getName().subSequence(0, r.getName().lastIndexOf(".")-1)
|
||||
+ "</a> ");
|
||||
} catch (CoreException e) {
|
||||
ProcessingLog.logError("Sketch source files could not be included in export of "
|
||||
+ sp.getProject().getName() +". Trying to continue export anyway.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CoreException e){
|
||||
ProcessingLog.logError("Sketch source files could not be included in export of "
|
||||
+ sp.getProject().getName() +". Trying to continue export anyway. ", e);
|
||||
ProcessingLog.logError(e); // problem getting members
|
||||
}
|
||||
|
||||
// Use separate jarfiles
|
||||
boolean separateJar = true;
|
||||
// = Preferences.getBoolean("export.applet.separate_jar_files)||
|
||||
// codeFolder.exists() ||
|
||||
// (libraryPath.length() != 0);
|
||||
|
||||
// Copy the loading gif to the applet
|
||||
String LOADING_IMAGE = "loading.gif";
|
||||
IFile loadingImage = sp.getProject().getFile(LOADING_IMAGE); // user can specify their own loader
|
||||
@@ -168,7 +198,7 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
try {
|
||||
File exportResourcesFolder = new File(ProcessingCore.getProcessingCore().getPluginResourceFolder().getCanonicalPath(), "export");
|
||||
File loadingImageCoreResource = new File(exportResourcesFolder, LOADING_IMAGE);
|
||||
ProcessingUtilities.copyFile(loadingImageCoreResource, new File(exportFolder.getFullPath().toString(), LOADING_IMAGE));
|
||||
ProcessingUtilities.copyFile(loadingImageCoreResource, new File(exportFolder.getLocation().toFile(), LOADING_IMAGE));
|
||||
} catch (Exception ex) {
|
||||
// This is not expected, and should be reported, because we are about to bail
|
||||
ProcessingLog.logError("Could not access the Processing Plug-in Core resources. " +
|
||||
@@ -177,6 +207,22 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
}
|
||||
}
|
||||
|
||||
// Create new .jar file
|
||||
FileOutputStream zipOutputFile;
|
||||
try {
|
||||
zipOutputFile = new FileOutputStream(new File(exportFolder.getLocation().toFile(), sp.getProject().getName() + ".jar"));
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
ProcessingLog.logError(" ",fnfe);
|
||||
return false;
|
||||
}
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
ZipEntry entry;
|
||||
|
||||
StringBuffer archives = new StringBuffer();
|
||||
archives.append(sp.getProject().getName() + ".jar");
|
||||
|
||||
//addmanifest(zos);
|
||||
|
||||
// add the contents of the code folder to the jar
|
||||
IFolder codeFolder = sp.getCodeFolder();
|
||||
if (codeFolder != null){
|
||||
@@ -197,44 +243,47 @@ public class ExportAsAppletWizard extends Wizard implements IExportWizard {
|
||||
}
|
||||
|
||||
// snag the opengl library path so we can test for it later
|
||||
File openglLibraryFolder = new File(ProcessingCore.getProcessingCore().getCoreLibsFolder(), "opengl/library");
|
||||
String openglLibraryPath = openglLibraryFolder.getAbsolutePath();
|
||||
File openglLibrary = new File(ProcessingCore.getProcessingCore().getCoreLibsFolder(), "opengl/library/opengl.jar");
|
||||
String openglLibraryPath = openglLibrary.getAbsolutePath();
|
||||
boolean openglApplet = false;
|
||||
|
||||
// add the library jar files to the folder and detect if opengl is in use
|
||||
ArrayList<IPath> sketchLibraryImportPaths = sp.getLibraryPaths();
|
||||
if(sketchLibraryImportPaths != null){
|
||||
for(IPath path : sketchLibraryImportPaths){
|
||||
File libraryFolder = new File(path.toOSString());
|
||||
if (path.toOSString().equalsIgnoreCase(openglLibraryPath)) openglApplet=true;
|
||||
File exportSettings = new File(libraryFolder, "export.txt");
|
||||
HashMap<String,String> exportTable = ProcessingUtilities.readSettings(exportSettings);
|
||||
String appletList = (String) exportTable.get("applet");
|
||||
String exportList[] = null;
|
||||
if(appletList != null){
|
||||
exportList = ProcessingUtilities.splitTokens(appletList, ", ");
|
||||
} else {
|
||||
exportList = libraryFolder.list();
|
||||
}
|
||||
for (String s : exportList){
|
||||
if (s.equals(".") || s.equals("..")) continue;
|
||||
|
||||
s = ProcessingUtilities.trim(s);
|
||||
if (s.equals("")) continue;
|
||||
|
||||
File exportFile = new File( libraryFolder, s);
|
||||
if(!exportFile.exists()) {
|
||||
ProcessingLog.logError("Export File " + s + " does not exist.", null);
|
||||
} else if (exportFile.isDirectory()) {
|
||||
ProcessingLog.logInfo("Ignoring sub-folder \"" + s + "\"");
|
||||
} else if ( exportFile.getName().toLowerCase().endsWith(".zip") ||
|
||||
exportFile.getName().toLowerCase().endsWith(".jar")){
|
||||
// the PDE checks for separate jar boolean, but if we're here we have
|
||||
// met the conditions that require it
|
||||
// File exportFile = new File(codeFolder, s);
|
||||
}
|
||||
|
||||
}
|
||||
if (path.toOSString().equals(openglLibraryPath)) openglApplet = true;
|
||||
|
||||
|
||||
// File libraryFolder = new File(path.toOSString());
|
||||
// if (path.toOSString().equalsIgnoreCase(openglLibraryPath)) openglApplet=true;
|
||||
// File exportSettings = new File(libraryFolder, "export.txt");
|
||||
// HashMap<String,String> exportTable = ProcessingUtilities.readSettings(exportSettings);
|
||||
// String appletList = (String) exportTable.get("applet");
|
||||
// String exportList[] = null;
|
||||
// if(appletList != null){
|
||||
// exportList = ProcessingUtilities.splitTokens(appletList, ", ");
|
||||
// } else {
|
||||
// exportList = libraryFolder.list();
|
||||
// }
|
||||
// for (String s : exportList){
|
||||
// if (s.equals(".") || s.equals("..")) continue;
|
||||
//
|
||||
// s = ProcessingUtilities.trim(s);
|
||||
// if (s.equals("")) continue;
|
||||
//
|
||||
// File exportFile = new File( libraryFolder, s);
|
||||
// if(!exportFile.exists()) {
|
||||
// ProcessingLog.logError("Export File " + s + " does not exist.", null);
|
||||
// } else if (exportFile.isDirectory()) {
|
||||
// ProcessingLog.logInfo("Ignoring sub-folder \"" + s + "\"");
|
||||
// } else if ( exportFile.getName().toLowerCase().endsWith(".zip") ||
|
||||
// exportFile.getName().toLowerCase().endsWith(".jar")){
|
||||
// // the PDE checks for separate jar boolean, but if we're here we have
|
||||
// // met the conditions that require it
|
||||
//// File exportFile = new File(codeFolder, s);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user