mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
move utility functions out of Base and into Util
This commit is contained in:
@@ -32,6 +32,7 @@ import processing.app.Preferences;
|
||||
import processing.app.RunnerListener;
|
||||
import processing.app.Sketch;
|
||||
import processing.app.SketchException;
|
||||
import processing.app.Util;
|
||||
import processing.app.contrib.ModeContribution;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.runner.Runner;
|
||||
@@ -208,7 +209,7 @@ public class Commander implements RunnerListener {
|
||||
outputFolder = new File(outputPath);
|
||||
if (outputFolder.exists()) {
|
||||
if (force) {
|
||||
Base.removeDir(outputFolder);
|
||||
Util.removeDir(outputFolder);
|
||||
} else {
|
||||
complainAndQuit("The output folder already exists. " +
|
||||
"Use --force to remove it.", false);
|
||||
|
||||
@@ -46,8 +46,8 @@ public class Compiler {
|
||||
importSuggestions.put("Frame", "java.awt.Frame");
|
||||
importSuggestions.put("Iterator", "java.util.Iterator");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Compile with ECJ. See http://j.mp/8paifz for documentation.
|
||||
*
|
||||
@@ -74,7 +74,7 @@ public class Compiler {
|
||||
};
|
||||
//PApplet.println(baseCommand);
|
||||
|
||||
String[] sourceFiles = Base.listFiles(build.getSrcFolder(), false, ".java");
|
||||
String[] sourceFiles = Util.listFiles(build.getSrcFolder(), false, ".java");
|
||||
String[] command = PApplet.concat(baseCommand, sourceFiles);
|
||||
//PApplet.println(command);
|
||||
|
||||
@@ -96,13 +96,13 @@ public class Compiler {
|
||||
PrintWriter writer = new PrintWriter(internalWriter);
|
||||
|
||||
//result = com.sun.tools.javac.Main.compile(command, writer);
|
||||
|
||||
|
||||
PrintWriter outWriter = new PrintWriter(System.out);
|
||||
|
||||
|
||||
// Version that's not dynamically loaded
|
||||
//CompilationProgress progress = null;
|
||||
//success = BatchCompiler.compile(command, outWriter, writer, progress);
|
||||
|
||||
|
||||
// Version that *is* dynamically loaded. First gets the mode class loader
|
||||
// so that it can grab the compiler JAR files from it.
|
||||
ClassLoader loader = build.mode.getClassLoader();
|
||||
@@ -114,13 +114,13 @@ public class Compiler {
|
||||
Class<?>[] compileArgs =
|
||||
new Class<?>[] { String[].class, PrintWriter.class, PrintWriter.class, progressClass };
|
||||
Method compileMethod = batchClass.getMethod("compile", compileArgs);
|
||||
success = (Boolean)
|
||||
success = (Boolean)
|
||||
compileMethod.invoke(null, new Object[] { command, outWriter, writer, null });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SketchException("Unknown error inside the compiler.");
|
||||
}
|
||||
|
||||
|
||||
// Close out the stream for good measure
|
||||
writer.flush();
|
||||
writer.close();
|
||||
@@ -207,7 +207,7 @@ public class Compiler {
|
||||
} else {
|
||||
exception.setMessage("Cannot find a class or type " +
|
||||
"named \u201C" + what + "\u201D");
|
||||
|
||||
|
||||
String suggestion = importSuggestions.get(what);
|
||||
if (suggestion != null) {
|
||||
System.err.println("You may need to add \"import " + suggestion + ";\" to the top of your sketch.");
|
||||
|
||||
@@ -36,8 +36,8 @@ import javax.swing.JPanel;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
import processing.app.Base;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.Util;
|
||||
import processing.mode.java.pdex.ErrorCheckerService;
|
||||
import processing.mode.java.pdex.ErrorMarker;
|
||||
import processing.mode.java.pdex.Problem;
|
||||
@@ -165,7 +165,7 @@ public class ErrorColumn extends JPanel {
|
||||
int totalLines = 0, currentTab = editor.getSketch()
|
||||
.getCurrentCodeIndex();
|
||||
try {
|
||||
totalLines = Base.countLines(sc.getDocument()
|
||||
totalLines = Util.countLines(sc.getDocument()
|
||||
.getText(0, sc.getDocument().getLength())) + 1;
|
||||
} catch (BadLocationException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -221,12 +221,12 @@ public class JavaBuild {
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
String codeFolderClassPath =
|
||||
Base.contentsToClassPath(codeFolder);
|
||||
Util.contentsToClassPath(codeFolder);
|
||||
// append the jar files in the code folder to the class path
|
||||
classPath += File.pathSeparator + codeFolderClassPath;
|
||||
// get list of packages found in those jars
|
||||
codeFolderPackages =
|
||||
Base.packageListFromClassPath(codeFolderClassPath);
|
||||
Util.packageListFromClassPath(codeFolderClassPath);
|
||||
|
||||
} else {
|
||||
javaLibraryPath = "";
|
||||
@@ -520,7 +520,7 @@ public class JavaBuild {
|
||||
}
|
||||
File packageFolder = new File(srcFolder, packageMatch[0].replace('.', '/'));
|
||||
packageFolder.mkdirs();
|
||||
Base.saveFile(javaCode, new File(packageFolder, filename));
|
||||
Util.saveFile(javaCode, new File(packageFolder, filename));
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
@@ -897,7 +897,7 @@ public class JavaBuild {
|
||||
|
||||
File macosFolder = new File(contentsFolder, "MacOS");
|
||||
macosFolder.mkdirs();
|
||||
Base.copyFile(new File(contentsOrig, "MacOS/Processing"),
|
||||
Util.copyFile(new File(contentsOrig, "MacOS/Processing"),
|
||||
new File(contentsFolder, "MacOS/" + sketch.getName()));
|
||||
|
||||
File pkgInfo = new File(contentsFolder, "PkgInfo");
|
||||
@@ -908,14 +908,14 @@ public class JavaBuild {
|
||||
|
||||
// Use faster(?) native copy here (also to do sym links)
|
||||
if (embedJava) {
|
||||
Base.copyDirNative(new File(contentsOrig, "PlugIns"),
|
||||
Util.copyDirNative(new File(contentsOrig, "PlugIns"),
|
||||
new File(contentsFolder, "PlugIns"));
|
||||
}
|
||||
|
||||
File resourcesFolder = new File(contentsFolder, "Resources");
|
||||
Base.copyDir(new File(contentsOrig, "Resources/en.lproj"),
|
||||
Util.copyDir(new File(contentsOrig, "Resources/en.lproj"),
|
||||
new File(resourcesFolder, "en.lproj"));
|
||||
Base.copyFile(mode.getContentFile("application/sketch.icns"),
|
||||
Util.copyFile(mode.getContentFile("application/sketch.icns"),
|
||||
new File(resourcesFolder, "sketch.icns"));
|
||||
|
||||
/*
|
||||
@@ -944,12 +944,12 @@ public class JavaBuild {
|
||||
*/
|
||||
} else if (exportPlatform == PConstants.LINUX) {
|
||||
if (embedJava) {
|
||||
Base.copyDirNative(Base.getJavaHome(), new File(destFolder, "java"));
|
||||
Util.copyDirNative(Base.getJavaHome(), new File(destFolder, "java"));
|
||||
}
|
||||
|
||||
} else if (exportPlatform == PConstants.WINDOWS) {
|
||||
if (embedJava) {
|
||||
Base.copyDir(Base.getJavaHome(), new File(destFolder, "java"));
|
||||
Util.copyDir(Base.getJavaHome(), new File(destFolder, "java"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1022,15 +1022,15 @@ public class JavaBuild {
|
||||
// 'data' folder next to 'lib'.
|
||||
if (sketch.hasDataFolder()) {
|
||||
if (exportPlatform == PConstants.MACOSX) {
|
||||
Base.copyDir(sketch.getDataFolder(), new File(jarFolder, "data"));
|
||||
Util.copyDir(sketch.getDataFolder(), new File(jarFolder, "data"));
|
||||
} else {
|
||||
Base.copyDir(sketch.getDataFolder(), new File(destFolder, "data"));
|
||||
Util.copyDir(sketch.getDataFolder(), new File(destFolder, "data"));
|
||||
}
|
||||
}
|
||||
|
||||
// add the contents of the code folder to the jar
|
||||
if (sketch.hasCodeFolder()) {
|
||||
String includes = Base.contentsToClassPath(sketch.getCodeFolder());
|
||||
String includes = Util.contentsToClassPath(sketch.getCodeFolder());
|
||||
// Use tokens to get rid of extra blanks, which causes huge exports
|
||||
String[] codeList = PApplet.splitTokens(includes, File.pathSeparator);
|
||||
for (int i = 0; i < codeList.length; i++) {
|
||||
@@ -1038,7 +1038,7 @@ public class JavaBuild {
|
||||
codeList[i].toLowerCase().endsWith(".zip")) {
|
||||
File exportFile = new File(codeList[i]);
|
||||
String exportFilename = exportFile.getName();
|
||||
Base.copyFile(exportFile, new File(jarFolder, exportFilename));
|
||||
Util.copyFile(exportFile, new File(jarFolder, exportFilename));
|
||||
jarListVector.add(exportFilename);
|
||||
} else {
|
||||
// cp += codeList[i] + File.pathSeparator;
|
||||
@@ -1064,17 +1064,17 @@ public class JavaBuild {
|
||||
"a big fat lie and does not exist.");
|
||||
|
||||
} else if (exportFile.isDirectory()) {
|
||||
Base.copyDir(exportFile, new File(jarFolder, exportName));
|
||||
Util.copyDir(exportFile, new File(jarFolder, exportName));
|
||||
|
||||
} else if (exportName.toLowerCase().endsWith(".zip") ||
|
||||
exportName.toLowerCase().endsWith(".jar")) {
|
||||
Base.copyFile(exportFile, new File(jarFolder, exportName));
|
||||
Util.copyFile(exportFile, new File(jarFolder, exportName));
|
||||
jarListVector.add(exportName);
|
||||
|
||||
} else {
|
||||
// Starting with 2.0a2 put extra export files (DLLs, plugins folder,
|
||||
// anything else for libraries) inside lib or Contents/Resources/Java
|
||||
Base.copyFile(exportFile, new File(jarFolder, exportName));
|
||||
Util.copyFile(exportFile, new File(jarFolder, exportName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1306,7 +1306,7 @@ public class JavaBuild {
|
||||
String preprocFilename = sketch.getName() + ".java";
|
||||
File preprocFile = new File(srcFolder, preprocFilename);
|
||||
if (preprocFile.exists()) {
|
||||
Base.copyFile(preprocFile, new File(sourceFolder, preprocFilename));
|
||||
Util.copyFile(preprocFile, new File(sourceFolder, preprocFilename));
|
||||
} else {
|
||||
System.err.println("Could not copy source file: " + preprocFile.getAbsolutePath());
|
||||
}
|
||||
@@ -1422,7 +1422,7 @@ public class JavaBuild {
|
||||
|
||||
protected void addDataFolder(ZipOutputStream zos) throws IOException {
|
||||
if (sketch.hasDataFolder()) {
|
||||
String[] dataFiles = Base.listFiles(sketch.getDataFolder(), false);
|
||||
String[] dataFiles = Util.listFiles(sketch.getDataFolder(), false);
|
||||
int offset = sketch.getFolder().getAbsolutePath().length() + 1;
|
||||
for (String path : dataFiles) {
|
||||
if (Base.isWindows()) {
|
||||
|
||||
@@ -1285,7 +1285,7 @@ public class JavaEditor extends Editor {
|
||||
StringList list = lib.getImports(); // ask the library for its imports
|
||||
if (list == null) {
|
||||
// Default to old behavior and load each package in the primary jar
|
||||
list = Base.packageListFromClassPath(lib.getJarPath());
|
||||
list = Util.packageListFromClassPath(lib.getJarPath());
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -109,6 +109,7 @@ import org.jsoup.select.Elements;
|
||||
import processing.app.Base;
|
||||
import processing.app.Library;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.Util;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.ui.Toolkit;
|
||||
import processing.mode.java.JavaEditor;
|
||||
@@ -304,8 +305,9 @@ public class ASTGenerator {
|
||||
protected void loadJars() {
|
||||
factory = new ClassPathFactory();
|
||||
|
||||
StringBuilder tehPath = new StringBuilder(System
|
||||
.getProperty("java.class.path"));
|
||||
StringBuilder tehPath =
|
||||
new StringBuilder(System.getProperty("java.class.path"));
|
||||
|
||||
// Starting with JDK 1.7, no longer using Apple's Java, so
|
||||
// rt.jar has the same path on all OSes
|
||||
tehPath.append(File.pathSeparatorChar
|
||||
@@ -837,7 +839,7 @@ public class ASTGenerator {
|
||||
if (codeIndex > 0)
|
||||
for (int i = 0; i < codeIndex; i++) {
|
||||
SketchCode sc = editor.getSketch().getCode(i);
|
||||
int len = Base.countLines(sc.getProgram()) + 1;
|
||||
int len = Util.countLines(sc.getProgram()) + 1;
|
||||
lineNumber += len;
|
||||
}
|
||||
|
||||
@@ -1636,7 +1638,7 @@ public class ASTGenerator {
|
||||
if (codeIndex > 0) {
|
||||
for (int i = 0; i < codeIndex; i++) {
|
||||
SketchCode sc = editor.getSketch().getCode(i);
|
||||
int len = Base.countLines(sc.getProgram()) + 1;
|
||||
int len = Util.countLines(sc.getProgram()) + 1;
|
||||
pdeLineNumber += len;
|
||||
}
|
||||
}
|
||||
@@ -2386,7 +2388,7 @@ public class ASTGenerator {
|
||||
if (codeIndex > 0)
|
||||
for (int i = 0; i < codeIndex; i++) {
|
||||
SketchCode sc = editor.getSketch().getCode(i);
|
||||
int len = Base.countLines(sc.getProgram()) + 1;
|
||||
int len = Util.countLines(sc.getProgram()) + 1;
|
||||
javaLineNumber += len;
|
||||
}
|
||||
return javaLineNumber;
|
||||
@@ -3327,8 +3329,7 @@ public class ASTGenerator {
|
||||
File codeFolder = editor.getSketch().getCodeFolder();
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
ClassPath cp = factory.createFromPath(Base
|
||||
.contentsToClassPath(codeFolder));
|
||||
ClassPath cp = factory.createFromPath(Util.contentsToClassPath(codeFolder));
|
||||
resources = cp.findResources("", regf);
|
||||
for (String res : resources) {
|
||||
candidates.add(res);
|
||||
@@ -3393,8 +3394,8 @@ public class ASTGenerator {
|
||||
File codeFolder = editor.getSketch().getCodeFolder();
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
ClassPath cp = factory.createFromPath(Base
|
||||
.contentsToClassPath(codeFolder));
|
||||
ClassPath cp =
|
||||
factory.createFromPath(Util.contentsToClassPath(codeFolder));
|
||||
resources = cp.findResources("", regf);
|
||||
for (String res : resources) {
|
||||
candidates.add(res);
|
||||
|
||||
@@ -52,6 +52,7 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
|
||||
import processing.app.Base;
|
||||
import processing.app.Library;
|
||||
import processing.app.SketchCode;
|
||||
import processing.app.Util;
|
||||
import processing.app.syntax.SyntaxDocument;
|
||||
import processing.app.ui.Editor;
|
||||
import processing.app.ui.EditorStatus;
|
||||
@@ -875,7 +876,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
String codeFolderClassPath = Base.contentsToClassPath(codeFolder);
|
||||
String codeFolderClassPath = Util.contentsToClassPath(codeFolder);
|
||||
codeFolderChecked = true;
|
||||
// huh? doesn't this mean .length() == 0? [fry]
|
||||
if (codeFolderClassPath.equalsIgnoreCase("")) {
|
||||
@@ -1098,10 +1099,9 @@ public class ErrorCheckerService implements Runnable {
|
||||
if (sc.isExtension("pde")) {
|
||||
int len = 0;
|
||||
if (editor.getSketch().getCurrentCode().equals(sc)) {
|
||||
len = Base.countLines(sc.getDocument().getText(0,
|
||||
sc.getDocument().getLength())) + 1;
|
||||
len = Util.countLines(sc.getDocument().getText(0, sc.getDocument().getLength())) + 1;
|
||||
} else {
|
||||
len = Base.countLines(sc.getProgram()) + 1;
|
||||
len = Util.countLines(sc.getProgram()) + 1;
|
||||
}
|
||||
|
||||
// log("x,len, CI: " + x + "," + len + ","
|
||||
@@ -1185,10 +1185,9 @@ public class ErrorCheckerService implements Runnable {
|
||||
if (sc.isExtension("pde")) {
|
||||
int len = 0;
|
||||
if (editor.getSketch().getCurrentCode().equals(sc)) {
|
||||
len = Base.countLines(sc.getDocument().getText(0,
|
||||
sc.getDocument().getLength())) + 1;
|
||||
len = Util.countLines(sc.getDocument().getText(0, sc.getDocument().getLength())) + 1;
|
||||
} else {
|
||||
len = Base.countLines(sc.getProgram()) + 1;
|
||||
len = Util.countLines(sc.getProgram()) + 1;
|
||||
}
|
||||
|
||||
// log("x,len, CI: " + x + "," + len + ","
|
||||
@@ -1240,7 +1239,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
int jLineNum = programImports.size() + 1;
|
||||
for (int i = 0; i < tab; i++) {
|
||||
SketchCode sc = editor.getSketch().getCode(i);
|
||||
int len = Base.countLines(sc.getProgram()) + 1;
|
||||
int len = Util.countLines(sc.getProgram()) + 1;
|
||||
jLineNum += len;
|
||||
}
|
||||
return jLineNum;
|
||||
@@ -1466,7 +1465,7 @@ public class ErrorCheckerService implements Runnable {
|
||||
// exception all the time would cause the editor to shut down over
|
||||
// trivial/recoverable quirks. It's the least bad option. [fry]
|
||||
final Document doc = editor.getTextArea().getDocument();
|
||||
final int lineCount = Base.countLines(doc.getText(0, doc.getLength()));
|
||||
final int lineCount = Util.countLines(doc.getText(0, doc.getLength()));
|
||||
if (p.getLineNumber() < lineCount && p.getLineNumber() >= 0) {
|
||||
editor.getTextArea().scrollTo(p.getLineNumber(), 0);
|
||||
}
|
||||
@@ -1581,8 +1580,8 @@ public class ErrorCheckerService implements Runnable {
|
||||
// log(" - "
|
||||
// + Base.countLines(tabSource.substring(0, idx)) + " tab "
|
||||
// + tabNumber);
|
||||
programImports.add(new ImportStatement(piece, tabNumber, Base
|
||||
.countLines(tabSource.substring(0, idx))));
|
||||
int lineCount = Util.countLines(tabSource.substring(0, idx));
|
||||
programImports.add(new ImportStatement(piece, tabNumber, lineCount));
|
||||
// Remove the import from the main program
|
||||
// Substitute with white spaces
|
||||
String whiteSpace = "";
|
||||
|
||||
Reference in New Issue
Block a user