use of processing.data.StringList in project processing by processing.
the class PreprocessingService method buildCodeFolderImports.
private static List<ImportStatement> buildCodeFolderImports(Sketch sketch) {
if (sketch.hasCodeFolder()) {
File codeFolder = sketch.getCodeFolder();
String codeFolderClassPath = Util.contentsToClassPath(codeFolder);
StringList codeFolderPackages = Util.packageListFromClassPath(codeFolderClassPath);
return StreamSupport.stream(codeFolderPackages.spliterator(), false).map(ImportStatement::wholePackage).collect(Collectors.toList());
}
return Collections.emptyList();
}
use of processing.data.StringList in project processing by processing.
the class JavaEditor method handleImportLibrary.
/**
* Add import statements to the current tab for all of packages inside
* the specified jar file.
*/
public void handleImportLibrary(String libraryName) {
// make sure the user didn't hide the sketch folder
sketch.ensureExistence();
//if (current.flavor == PDE) {
if (mode.isDefaultExtension(sketch.getCurrentCode())) {
sketch.setCurrentCode(0);
}
Library lib = mode.findLibraryByName(libraryName);
if (lib == null) {
statusError("Unable to locate library: " + libraryName);
return;
}
// could also scan the text in the file to see if each import
// statement is already in there, but if the user has the import
// commented out, then this will be a problem.
// ask the library for its imports
StringList list = lib.getImports();
if (list == null) {
// Default to old behavior and load each package in the primary jar
list = Util.packageListFromClassPath(lib.getJarPath());
}
StringBuilder sb = new StringBuilder();
// for (int i = 0; i < list.length; i++) {
for (String item : list) {
sb.append("import ");
// sb.append(list[i]);
sb.append(item);
sb.append(".*;\n");
}
sb.append('\n');
sb.append(getText());
setText(sb.toString());
// scroll to start
setSelection(0, 0);
sketch.setModified(true);
}
use of processing.data.StringList in project processing by processing.
the class InstallCommander method run.
public void run() {
try {
Editor editor = base.getActiveEditor();
final String primary = "Install processing-java for all users?";
final String secondary = "This will install the processing-java program, which is capable " + "of building and running Java Mode sketches from the command line. " + "Click “Yes” to install it for all users (an administrator password " + "is required), or “No” to place the program in your home directory. " + "If you rename or move Processing.app, " + "you'll need to reinstall the tool.";
int result = JOptionPane.showConfirmDialog(editor, "<html> " + "<head> <style type=\"text/css\">" + "b { font: 13pt \"Lucida Grande\" }" + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px; width: 300px }" + "</style> </head>" + "<b>" + primary + "</b>" + "<p>" + secondary + "</p>", "Commander", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.CANCEL_OPTION) {
return;
}
File file = File.createTempFile("processing", "commander");
PrintWriter writer = PApplet.createWriter(file);
writer.print("#!/bin/sh\n\n");
writer.print("# Prevents processing-java from stealing focus, see:\n" + "# https://github.com/processing/processing/issues/3996.\n" + "OPTION_FOR_HEADLESS_RUN=\"\"\n" + "for ARG in \"$@\"\n" + "do\n" + " if [ \"$ARG\" = \"--build\" ]; then\n" + " OPTION_FOR_HEADLESS_RUN=\"-Djava.awt.headless=true\"\n" + " fi\n" + "done\n\n");
String javaRoot = Platform.getContentFile(".").getCanonicalPath();
StringList jarList = new StringList();
addJarList(jarList, new File(javaRoot));
addJarList(jarList, new File(javaRoot, "core/library"));
addJarList(jarList, new File(javaRoot, "modes/java/mode"));
String classPath = jarList.join(":").replaceAll(javaRoot + "\\/?", "");
writer.println("cd \"" + javaRoot + "\" && " + Platform.getJavaPath().replaceAll(" ", "\\\\ ") + " -Djna.nosys=true" + " $OPTION_FOR_HEADLESS_RUN" + " -cp \"" + classPath + "\"" + " processing.mode.java.Commander \"$@\"");
writer.flush();
writer.close();
file.setExecutable(true);
String sourcePath = file.getAbsolutePath();
if (result == JOptionPane.YES_OPTION) {
// Moving to /usr/local/bin instead of /usr/bin for compatibility
// with OS X 10.11 and its "System Integrity Protection"
// https://github.com/processing/processing/issues/3497
String targetPath = "/usr/local/bin/processing-java";
// Remove the old version in case it exists
// https://github.com/processing/processing/issues/3786
String oldPath = "/usr/bin/processing-java";
String shellScript = "/bin/rm -f " + oldPath + " && /bin/mkdir -p /usr/local/bin" + " && /bin/mv " + sourcePath + " " + targetPath;
String appleScript = "do shell script \"" + shellScript + "\" with administrator privileges";
PApplet.exec(new String[] { "osascript", "-e", appleScript });
} else if (result == JOptionPane.NO_OPTION) {
File targetFile = new File(System.getProperty("user.home"), "processing-java");
String targetPath = targetFile.getAbsolutePath();
if (targetFile.exists()) {
Messages.showWarning("File Already Exists", "The processing-java program already exists at:\n" + targetPath + "\n" + "Please remove it and try again.");
} else {
PApplet.exec(new String[] { "mv", sourcePath, targetPath });
}
}
editor.statusNotice("Finished.");
} catch (IOException e) {
Messages.showWarning("Error while installing", "An error occurred and the tool was not installed.", e);
}
}
use of processing.data.StringList in project processing by processing.
the class ExamplesContribution method isCompatible.
/**
* Function to determine whether or not the example present in the
* exampleLocation directory is compatible with the current mode.
* @return true if compatible with the Mode of the currently active editor
*/
public static boolean isCompatible(Mode mode, StringDict props) {
String currentIdentifier = mode.getIdentifier();
StringList compatibleList = parseModeList(props);
if (compatibleList.size() == 0) {
if (mode.requireExampleCompatibility()) {
// for p5js (and maybe Python), examples must specify that they work
return false;
}
// if no Mode specified, assume compatible everywhere
return true;
}
return compatibleList.hasValue(currentIdentifier);
}
use of processing.data.StringList in project processing by processing.
the class AvailableContribution method writePropertiesFile.
/**
* We overwrite those fields that aren't proper in the properties file with
* the curated version from the Processing site. This ensures that things have
* been cleaned up (for instance, that the "sentence" is really a sentence)
* and that bad data from the contrib's .properties file doesn't break the
* manager. However, it also ensures that valid fields in the properties file
* aren't overwritten, since the properties file may be more recent than the
* contributions.txt file.
*/
public boolean writePropertiesFile(File propFile) {
try {
StringDict properties = Util.readSettings(propFile);
String name = properties.get("name");
if (name == null || name.isEmpty()) {
name = getName();
}
String category;
StringList categoryList = parseCategories(properties);
if (categoryList.size() == 1 && categoryList.get(0).equals(UNKNOWN_CATEGORY)) {
category = getCategoryStr();
} else {
category = categoryList.join(",");
}
StringList importsList = parseImports(properties);
String authors = properties.get(AUTHORS_PROPERTY);
// }
if (authors == null || authors.isEmpty()) {
authors = getAuthorList();
}
String url = properties.get("url");
if (url == null || url.isEmpty()) {
url = getUrl();
}
String sentence = properties.get("sentence");
if (sentence == null || sentence.isEmpty()) {
sentence = getSentence();
}
String paragraph = properties.get("paragraph");
if (paragraph == null || paragraph.isEmpty()) {
paragraph = getParagraph();
}
int version;
try {
version = Integer.parseInt(properties.get("version"));
} catch (NumberFormatException e) {
version = getVersion();
System.err.println("The version number for “" + name + "” is not a number.");
System.err.println("Please contact the author to fix it according to the guidelines.");
}
String prettyVersion = properties.get("prettyVersion");
if (prettyVersion != null && prettyVersion.isEmpty()) {
prettyVersion = null;
}
String compatibleContribsList = null;
if (getType() == ContributionType.EXAMPLES) {
compatibleContribsList = properties.get(MODES_PROPERTY);
}
long lastUpdated;
try {
lastUpdated = Long.parseLong(properties.get("lastUpdated"));
} catch (NumberFormatException nfe) {
lastUpdated = getLastUpdated();
// Better comment these out till all contribs have a lastUpdated
// System.err.println("The last updated date for the “" + name
// + "” contribution is not set properly.");
// System.err
// .println("Please contact the author to fix it according to the guidelines.");
}
int minRev;
try {
minRev = Integer.parseInt(properties.get("minRevision"));
} catch (NumberFormatException e) {
minRev = getMinRevision();
// System.err.println("The minimum compatible revision for the “" + name
// + "” contribution is not set properly. Assuming minimum revision 0.");
}
int maxRev;
try {
maxRev = Integer.parseInt(properties.get("maxRevision"));
} catch (NumberFormatException e) {
maxRev = getMaxRevision();
// System.err.println("The maximum compatible revision for the “" + name
// + "” contribution is not set properly. Assuming maximum revision INF.");
}
if (propFile.delete() && propFile.createNewFile() && propFile.setWritable(true)) {
PrintWriter writer = PApplet.createWriter(propFile);
writer.println("name=" + name);
writer.println("category=" + category);
writer.println(AUTHORS_PROPERTY + "=" + authors);
writer.println("url=" + url);
writer.println("sentence=" + sentence);
writer.println("paragraph=" + paragraph);
writer.println("version=" + version);
if (prettyVersion != null) {
writer.println("prettyVersion=" + prettyVersion);
}
writer.println("lastUpdated=" + lastUpdated);
writer.println("minRevision=" + minRev);
writer.println("maxRevision=" + maxRev);
if ((getType() == ContributionType.LIBRARY || getType() == ContributionType.MODE) && importsList != null) {
writer.println("imports=" + importsList.join(","));
}
if (getType() == ContributionType.EXAMPLES) {
if (compatibleContribsList != null) {
writer.println(MODES_PROPERTY + "=" + compatibleContribsList);
}
}
writer.flush();
writer.close();
}
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return false;
}
Aggregations