mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
working to enforce size() rules, move settings() around, remove exportApplet()
This commit is contained in:
@@ -199,7 +199,8 @@ public class Debugger implements VMEventListener {
|
||||
|
||||
log(Level.INFO, "building sketch: {0}", sketch.getName());
|
||||
//LineMapping.addLineNumbers(sketch); // annotate
|
||||
mainClassName = build.build(false);
|
||||
// mainClassName = build.build(false);
|
||||
mainClassName = build.build(true);
|
||||
//LineMapping.removeLineNumbers(sketch); // annotate
|
||||
log(Level.INFO, "class: {0}", mainClassName);
|
||||
|
||||
|
||||
@@ -251,6 +251,10 @@ public class JavaBuild {
|
||||
//String[] sizeParts =
|
||||
SizeInfo sizeInfo =
|
||||
preprocessor.initSketchSize(sketch.getMainProgram(), sizeWarning);
|
||||
if (sizeInfo == null) {
|
||||
// An error occurred while trying to pull out the size, so exit here
|
||||
return null;
|
||||
}
|
||||
//System.out.format("size() is '%s'%n", info[0]);
|
||||
|
||||
// Remove the size() statement (will be added back by writeFooter())
|
||||
@@ -748,344 +752,6 @@ public class JavaBuild {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
protected boolean exportApplet() throws SketchException, IOException {
|
||||
return exportApplet(new File(sketch.getFolder(), "applet"));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Handle export to applet.
|
||||
*/
|
||||
/*
|
||||
public boolean exportApplet(File appletFolder) throws SketchException, IOException {
|
||||
mode.prepareExportFolder(appletFolder);
|
||||
|
||||
srcFolder = sketch.makeTempFolder();
|
||||
binFolder = sketch.makeTempFolder();
|
||||
String foundName = build(srcFolder, binFolder, true);
|
||||
|
||||
// (already reported) error during export, exit this function
|
||||
if (foundName == null) return false;
|
||||
|
||||
// If name != exportSketchName, then that's weirdness
|
||||
// BUG unfortunately, that can also be a bug in the preproc :(
|
||||
if (!sketch.getName().equals(foundName)) {
|
||||
Base.showWarning("Error during export",
|
||||
"Sketch name is " + sketch.getName() + " but the\n" +
|
||||
"name found in the code was " + foundName + ".", null);
|
||||
return false;
|
||||
}
|
||||
|
||||
String[] sizeInfo =
|
||||
PdePreprocessor.parseSketchSize(sketch.getMainProgram(), false);
|
||||
int sketchWidth = PApplet.DEFAULT_WIDTH;
|
||||
int sketchHeight = PApplet.DEFAULT_HEIGHT;
|
||||
boolean openglApplet = false;
|
||||
boolean foundSize = false;
|
||||
if (sizeInfo != null) {
|
||||
try {
|
||||
if (sizeInfo[1] != null && sizeInfo[2] != null) {
|
||||
sketchWidth = Integer.parseInt(sizeInfo[1]);
|
||||
sketchHeight = Integer.parseInt(sizeInfo[2]);
|
||||
foundSize = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// parsing errors, whatever; ignored
|
||||
}
|
||||
|
||||
String sketchRenderer = sizeInfo[3];
|
||||
if (sketchRenderer != null) {
|
||||
if (sketchRenderer.equals("P2D") ||
|
||||
sketchRenderer.equals("P3D") ||
|
||||
sketchRenderer.equals("OPENGL")) {
|
||||
openglApplet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundSize) {
|
||||
final String message =
|
||||
"The size of this applet could not automatically be\n" +
|
||||
"determined from your code. You'll have to edit the\n" +
|
||||
"HTML file to set the size of the applet.\n" +
|
||||
"Use only numeric values (not variables) for the size()\n" +
|
||||
"command. See the size() reference for an explanation.";
|
||||
Base.showWarning("Could not find applet size", message, null);
|
||||
}
|
||||
|
||||
// // If the renderer is set to the built-in OpenGL library,
|
||||
// // then it's definitely an OpenGL applet.
|
||||
// if (sketchRenderer.equals("P3D") || sketchRenderer.equals("OPENGL")) {
|
||||
// openglApplet = true;
|
||||
// }
|
||||
|
||||
|
||||
// int wide = PApplet.DEFAULT_WIDTH;
|
||||
// int high = PApplet.DEFAULT_HEIGHT;
|
||||
// String renderer = "";
|
||||
//
|
||||
// String scrubbed = PdePreprocessor.scrubComments(sketch.getCode(0).getProgram());
|
||||
// String[] matches = PApplet.match(scrubbed, PdePreprocessor.SIZE_REGEX);
|
||||
//
|
||||
// if (matches != null) {
|
||||
// try {
|
||||
// wide = Integer.parseInt(matches[1]);
|
||||
// high = Integer.parseInt(matches[2]);
|
||||
//
|
||||
// // Adding back the trim() for 0136 to handle Bug #769
|
||||
// if (matches.length == 4) renderer = matches[3].trim();
|
||||
// // Actually, matches.length should always be 4...
|
||||
//
|
||||
// } catch (NumberFormatException e) {
|
||||
// // found a reference to size, but it didn't
|
||||
// // seem to contain numbers
|
||||
// final String message =
|
||||
// "The size of this applet could not automatically be\n" +
|
||||
// "determined from your code. You'll have to edit the\n" +
|
||||
// "HTML file to set the size of the applet.\n" +
|
||||
// "Use only numeric values (not variables) for the size()\n" +
|
||||
// "command. See the size() reference for an explanation.";
|
||||
//
|
||||
// Base.showWarning("Could not find applet size", message, null);
|
||||
// }
|
||||
// } // else no size() command found
|
||||
|
||||
// Grab the Javadoc-style description from the main code.
|
||||
String description = "";
|
||||
// If there are multiple closings, need to catch the first,
|
||||
// which is what the (.*?) will do for us.
|
||||
// http://code.google.com/p/processing/issues/detail?id=877
|
||||
String[] javadoc = PApplet.match(sketch.getCode(0).getProgram(), "/\\*{2,}(.*?)\\*+/");
|
||||
if (javadoc != null) {
|
||||
StringBuffer dbuffer = new StringBuffer();
|
||||
String found = javadoc[1];
|
||||
String[] pieces = PApplet.split(found, '\n');
|
||||
for (String line : pieces) {
|
||||
// if this line starts with * characters, remove 'em
|
||||
String[] m = PApplet.match(line, "^\\s*\\*+(.*)");
|
||||
dbuffer.append(m != null ? m[1] : line);
|
||||
// insert the new line into the html to help w/ line breaks
|
||||
dbuffer.append('\n');
|
||||
}
|
||||
description = dbuffer.toString();
|
||||
}
|
||||
|
||||
// Add links to all the code
|
||||
StringBuffer sources = new StringBuffer();
|
||||
//for (int i = 0; i < codeCount; i++) {
|
||||
for (SketchCode code : sketch.getCode()) {
|
||||
sources.append("<a href=\"" + code.getFileName() + "\">" +
|
||||
code.getPrettyName() + "</a> ");
|
||||
}
|
||||
|
||||
// Copy the source files to the target, since we like
|
||||
// to encourage people to share their code
|
||||
// for (int i = 0; i < codeCount; i++) {
|
||||
for (SketchCode code : sketch.getCode()) {
|
||||
try {
|
||||
File exportedSource = new File(appletFolder, code.getFileName());
|
||||
//Base.copyFile(code[i].getFile(), exportedSource);
|
||||
code.copyTo(exportedSource);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // ho hum, just move on...
|
||||
}
|
||||
}
|
||||
// move the .java file from the preproc there too
|
||||
String preprocFilename = sketch.getName() + ".java";
|
||||
File preprocFile = new File(srcFolder, preprocFilename);
|
||||
if (preprocFile.exists()) {
|
||||
preprocFile.renameTo(new File(appletFolder, preprocFilename));
|
||||
} else {
|
||||
System.err.println("Could not copy source file: " + preprocFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
// Use separate .jar files whenever a library or code folder is in use.
|
||||
boolean separateJar =
|
||||
Preferences.getBoolean("export.applet.separate_jar_files") ||
|
||||
sketch.hasCodeFolder() ||
|
||||
javaLibraryPath.length() != 0;
|
||||
|
||||
File skeletonFolder = mode.getContentFile("applet");
|
||||
|
||||
// Copy the loading gif to the applet
|
||||
String LOADING_IMAGE = "loading.gif";
|
||||
// Check if the user already has their own loader image
|
||||
File loadingImage = new File(sketch.getFolder(), LOADING_IMAGE);
|
||||
if (!loadingImage.exists()) {
|
||||
// File skeletonFolder = new File(Base.getContentFile("lib"), "export");
|
||||
loadingImage = new File(skeletonFolder, LOADING_IMAGE);
|
||||
}
|
||||
Base.copyFile(loadingImage, new File(appletFolder, LOADING_IMAGE));
|
||||
|
||||
// not a good idea after all
|
||||
// File deployFile = new File(skeletonFolder, "deployJava.js");
|
||||
// Base.copyFile(deployFile, new File(appletFolder, "deployJava.js"));
|
||||
|
||||
// Create new .jar file
|
||||
FileOutputStream zipOutputFile =
|
||||
new FileOutputStream(new File(appletFolder, sketch.getName() + ".jar"));
|
||||
ZipOutputStream zos = new ZipOutputStream(zipOutputFile);
|
||||
// ZipEntry entry;
|
||||
|
||||
StringBuffer archives = new StringBuffer();
|
||||
archives.append(sketch.getName() + ".jar");
|
||||
|
||||
// Add the manifest file
|
||||
addManifest(zos);
|
||||
|
||||
// File openglLibraryFolder =
|
||||
// new File(editor.getMode().getLibrariesFolder(), "opengl/library");
|
||||
// String openglLibraryPath = openglLibraryFolder.getAbsolutePath();
|
||||
// boolean openglApplet = false;
|
||||
|
||||
HashMap<String,Object> zipFileContents = new HashMap<String,Object>();
|
||||
|
||||
// add contents of 'library' folders
|
||||
for (Library library : importedLibraries) {
|
||||
// if (library.getPath().equals(openglLibraryPath)) {
|
||||
if (library.getName().equals("OpenGL")) {
|
||||
openglApplet = true;
|
||||
}
|
||||
for (File exportFile : library.getAppletExports()) {
|
||||
String exportName = exportFile.getName();
|
||||
if (!exportFile.exists()) {
|
||||
System.err.println("File " + exportFile.getAbsolutePath() + " does not exist");
|
||||
|
||||
} else if (exportFile.isDirectory()) {
|
||||
System.out.println("Ignoring sub-folder \"" + exportFile.getAbsolutePath() + "\"");
|
||||
|
||||
} else if (exportName.toLowerCase().endsWith(".zip") ||
|
||||
exportName.toLowerCase().endsWith(".jar")) {
|
||||
if (separateJar) {
|
||||
Base.copyFile(exportFile, new File(appletFolder, exportName));
|
||||
archives.append("," + exportName);
|
||||
} else {
|
||||
String path = exportFile.getAbsolutePath();
|
||||
packClassPathIntoZipFile(path, zos, zipFileContents);
|
||||
}
|
||||
|
||||
} else { // just copy the file over.. prolly a .dll or something
|
||||
Base.copyFile(exportFile, new File(appletFolder, exportName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy core.jar, or add its contents to the output .jar file
|
||||
File bagelJar = Base.isMacOS() ?
|
||||
Base.getContentFile("core.jar") :
|
||||
Base.getContentFile("lib/core.jar");
|
||||
if (separateJar) {
|
||||
Base.copyFile(bagelJar, new File(appletFolder, "core.jar"));
|
||||
archives.append(",core.jar");
|
||||
} else {
|
||||
String bagelJarPath = bagelJar.getAbsolutePath();
|
||||
packClassPathIntoZipFile(bagelJarPath, zos, zipFileContents);
|
||||
}
|
||||
|
||||
if (sketch.hasCodeFolder()) {
|
||||
File[] codeJarFiles = sketch.getCodeFolder().listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
if (name.charAt(0) == '.') return false;
|
||||
if (name.toLowerCase().endsWith(".jar")) return true;
|
||||
if (name.toLowerCase().endsWith(".zip")) return true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
for (File exportFile : codeJarFiles) {
|
||||
String name = exportFile.getName();
|
||||
Base.copyFile(exportFile, new File(appletFolder, name));
|
||||
archives.append("," + name);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the data folder to the output .jar file
|
||||
addDataFolder(zos);
|
||||
|
||||
// add the project's .class files to the jar
|
||||
// just grabs everything from the build directory
|
||||
// since there may be some inner classes
|
||||
// (add any .class files from the applet dir, then delete them)
|
||||
// TODO this needs to be recursive (for packages)
|
||||
addClasses(zos, binFolder);
|
||||
|
||||
// close up the jar file
|
||||
zos.flush();
|
||||
zos.close();
|
||||
|
||||
//
|
||||
|
||||
// convert the applet template
|
||||
// @@sketch@@, @@width@@, @@height@@, @@archive@@, @@source@@
|
||||
// and now @@description@@
|
||||
|
||||
File htmlOutputFile = new File(appletFolder, "index.html");
|
||||
// UTF-8 fixes http://dev.processing.org/bugs/show_bug.cgi?id=474
|
||||
PrintWriter htmlWriter = PApplet.createWriter(htmlOutputFile);
|
||||
|
||||
InputStream is = null;
|
||||
// if there is an applet.html file in the sketch folder, use that
|
||||
File customHtml = new File(sketch.getFolder(), "applet.html");
|
||||
if (customHtml.exists()) {
|
||||
is = new FileInputStream(customHtml);
|
||||
}
|
||||
// for (File libraryFolder : importedLibraries) {
|
||||
// System.out.println(libraryFolder + " " + libraryFolder.getAbsolutePath());
|
||||
// }
|
||||
if (is == null) {
|
||||
if (openglApplet) {
|
||||
is = mode.getContentStream("applet/template-opengl.html");
|
||||
} else {
|
||||
is = mode.getContentStream("applet/template.html");
|
||||
}
|
||||
}
|
||||
BufferedReader reader = PApplet.createReader(is);
|
||||
|
||||
String line = null;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.indexOf("@@") != -1) {
|
||||
StringBuffer sb = new StringBuffer(line);
|
||||
int index = 0;
|
||||
while ((index = sb.indexOf("@@sketch@@")) != -1) {
|
||||
sb.replace(index, index + "@@sketch@@".length(),
|
||||
sketch.getName());
|
||||
}
|
||||
while ((index = sb.indexOf("@@source@@")) != -1) {
|
||||
sb.replace(index, index + "@@source@@".length(),
|
||||
sources.toString());
|
||||
}
|
||||
while ((index = sb.indexOf("@@archive@@")) != -1) {
|
||||
sb.replace(index, index + "@@archive@@".length(),
|
||||
archives.toString());
|
||||
}
|
||||
while ((index = sb.indexOf("@@width@@")) != -1) {
|
||||
sb.replace(index, index + "@@width@@".length(),
|
||||
String.valueOf(sketchWidth));
|
||||
}
|
||||
while ((index = sb.indexOf("@@height@@")) != -1) {
|
||||
sb.replace(index, index + "@@height@@".length(),
|
||||
String.valueOf(sketchHeight));
|
||||
}
|
||||
while ((index = sb.indexOf("@@description@@")) != -1) {
|
||||
sb.replace(index, index + "@@description@@".length(),
|
||||
description);
|
||||
}
|
||||
line = sb.toString();
|
||||
}
|
||||
htmlWriter.println(line);
|
||||
}
|
||||
|
||||
reader.close();
|
||||
htmlWriter.flush();
|
||||
htmlWriter.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Export to application via GUI.
|
||||
*/
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JavaMode extends Mode {
|
||||
loadPreferences();
|
||||
loadIcons();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Needed by code completion panel. See {@link processing.mode.java.pdex.CompletionPanel}
|
||||
*/
|
||||
@@ -148,7 +148,8 @@ public class JavaMode extends Mode {
|
||||
public Runner handleLaunch(Sketch sketch, RunnerListener listener,
|
||||
final boolean present) throws SketchException {
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
// String appletClassName = build.build(false);
|
||||
String appletClassName = build.build(true);
|
||||
if (appletClassName != null) {
|
||||
final Runner runtime = new Runner(build, listener);
|
||||
new Thread(new Runnable() {
|
||||
@@ -177,7 +178,8 @@ public class JavaMode extends Mode {
|
||||
|
||||
// first try to build the unmodified code
|
||||
JavaBuild build = new JavaBuild(sketch);
|
||||
String appletClassName = build.build(false);
|
||||
// String appletClassName = build.build(false);
|
||||
String appletClassName = build.build(true);
|
||||
if (appletClassName == null) {
|
||||
// unmodified build failed, so fail
|
||||
return null;
|
||||
@@ -331,7 +333,7 @@ public class JavaMode extends Mode {
|
||||
static public final String prefImportSuggestEnabled = "pdex.importSuggestEnabled";
|
||||
|
||||
static volatile public boolean enableTweak = false;
|
||||
|
||||
|
||||
static public ImageIcon classIcon;
|
||||
static public ImageIcon fieldIcon;
|
||||
static public ImageIcon methodIcon;
|
||||
|
||||
@@ -167,9 +167,10 @@ public class PdePreprocessor {
|
||||
"(?:^|\\s|;)size\\s*\\(([^\\)]+)\\)\\s*\\;";
|
||||
static private final String FULL_SCREEN_CONTENTS_REGEX =
|
||||
"(?:^|\\s|;)fullScreen\\s*\\(([^\\)]+)\\)\\s*\\;";
|
||||
/** Test whether there's a void somewhere (the program has functions). */
|
||||
static private final String VOID_REGEX =
|
||||
"(?:^|\\s|;)void\\s";
|
||||
// /** Test whether there's a void somewhere (the program has functions). */
|
||||
// static private final String VOID_REGEX =
|
||||
// "(?:^|\\s|;)void\\s";
|
||||
/** Used to grab the start of setup() so we can mine it for size() */
|
||||
static private final String VOID_SETUP_REGEX =
|
||||
"(?:^|\\s|;)void\\ssetup\\s*\\(";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user