mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-16 11:21:18 +03:00
update AVR src
* java code not tested * Merge remote-tracking branch 'remotes/arduino/master' into esp8266 Conflicts: README.md app/src/processing/app/AbstractMonitor.java arduino-core/src/processing/app/Serial.java libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino libraries/WiFi/library.properties
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/jna.jar"/>
|
||||
<classpathentry kind="lib" path="lib/apple.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jmdns-3.4.1.jar"/>
|
||||
|
@ -31,8 +31,8 @@
|
||||
<property environment="env" />
|
||||
<property name="java_home" value="${env.JAVA_HOME}" />
|
||||
|
||||
<javac source="1.6"
|
||||
target="1.6"
|
||||
<javac source="1.8"
|
||||
target="1.8"
|
||||
encoding="UTF-8"
|
||||
includeAntRuntime="false"
|
||||
srcdir="src"
|
||||
|
@ -1 +0,0 @@
|
||||
https://github.com/twall/jna/blob/master/LICENSE
|
Binary file not shown.
107
arduino-core/src/cc/arduino/MyStreamPumper.java
Normal file
107
arduino-core/src/cc/arduino/MyStreamPumper.java
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino;
|
||||
|
||||
import processing.app.debug.MessageConsumer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* A version of StreamPumper from commons-exec that write to a MessageConsumer
|
||||
*/
|
||||
public class MyStreamPumper implements Runnable {
|
||||
|
||||
/**
|
||||
* the input stream to pump from
|
||||
*/
|
||||
private final BufferedReader reader;
|
||||
|
||||
/**
|
||||
* the output stream to pmp into
|
||||
*/
|
||||
private final MessageConsumer messageConsumer;
|
||||
|
||||
/**
|
||||
* was the end of the stream reached
|
||||
*/
|
||||
private boolean finished;
|
||||
|
||||
public MyStreamPumper(final InputStream is, final MessageConsumer messageConsumer) {
|
||||
this.reader = new BufferedReader(new InputStreamReader(is));
|
||||
this.messageConsumer = messageConsumer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies data from the input stream to the output stream. Terminates as
|
||||
* soon as the input stream is closed or an error occurs.
|
||||
*/
|
||||
public void run() {
|
||||
synchronized (this) {
|
||||
// Just in case this object is reused in the future
|
||||
finished = false;
|
||||
}
|
||||
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
messageConsumer.message(line + "\n");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing to do - happens quite often with watchdog
|
||||
} finally {
|
||||
synchronized (this) {
|
||||
finished = true;
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether the end of the stream has been reached.
|
||||
*
|
||||
* @return true is the stream has been exhausted.
|
||||
*/
|
||||
public synchronized boolean isFinished() {
|
||||
return finished;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method blocks until the stream pumper finishes.
|
||||
*
|
||||
* @see #isFinished()
|
||||
*/
|
||||
public synchronized void waitFor() throws InterruptedException {
|
||||
while (!isFinished()) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,9 +26,9 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.VersionHelper;
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
|
||||
import java.io.File;
|
@ -29,8 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DownloadableContributionBuiltInAtTheBottomComparator implements Comparator<DownloadableContribution> {
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class DownloadableContributionVersionComparator implements Comparator<DownloadableContribution> {
|
||||
|
@ -26,7 +26,8 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.FileHash;
|
||||
import cc.arduino.utils.Progress;
|
@ -77,12 +77,8 @@ public class GPGDetachedSignatureVerifier {
|
||||
|
||||
return pgpSignature.verify();
|
||||
} finally {
|
||||
if (signatureInputStream != null) {
|
||||
signatureInputStream.close();
|
||||
}
|
||||
if (signedFileInputStream != null) {
|
||||
signedFileInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(signatureInputStream);
|
||||
IOUtils.closeQuietly(signedFileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,9 +88,7 @@ public class GPGDetachedSignatureVerifier {
|
||||
keyIn = new BufferedInputStream(new FileInputStream(file));
|
||||
return readPublicKey(keyIn, keyId);
|
||||
} finally {
|
||||
if (keyIn != null) {
|
||||
keyIn.close();
|
||||
}
|
||||
IOUtils.closeQuietly(keyIn);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipUtils;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class GZippedJsonDownloader {
|
||||
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final URL url;
|
||||
private final URL gzippedUrl;
|
||||
|
||||
public GZippedJsonDownloader(DownloadableContributionsDownloader downloader, URL url, URL gzippedUrl) {
|
||||
this.downloader = downloader;
|
||||
this.url = url;
|
||||
this.gzippedUrl = gzippedUrl;
|
||||
}
|
||||
|
||||
public void download(File tmpFile, Progress progress, String statusText) throws Exception {
|
||||
try {
|
||||
new JsonDownloader(downloader, gzippedUrl).download(tmpFile, progress, statusText);
|
||||
File gzipTmpFile = new File(tmpFile.getParentFile(), GzipUtils.getCompressedFilename(tmpFile.getName()));
|
||||
tmpFile.renameTo(gzipTmpFile);
|
||||
decompress(gzipTmpFile, tmpFile);
|
||||
} catch (Exception e) {
|
||||
new JsonDownloader(downloader, url).download(tmpFile, progress, statusText);
|
||||
}
|
||||
}
|
||||
|
||||
private void decompress(File gzipTmpFile, File tmpFile) throws IOException {
|
||||
OutputStream os = null;
|
||||
GzipCompressorInputStream gzipIs = null;
|
||||
try {
|
||||
os = new FileOutputStream(tmpFile);
|
||||
gzipIs = new GzipCompressorInputStream(new FileInputStream(gzipTmpFile));
|
||||
final byte[] buffer = new byte[4096];
|
||||
int n = 0;
|
||||
while (-1 != (n = gzipIs.read(buffer))) {
|
||||
os.write(buffer, 0, n);
|
||||
}
|
||||
} finally {
|
||||
IOUtils.closeQuietly(os);
|
||||
IOUtils.closeQuietly(gzipIs);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import cc.arduino.utils.Progress;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
public class JsonDownloader {
|
||||
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final URL url;
|
||||
|
||||
public JsonDownloader(DownloadableContributionsDownloader downloader, URL url) {
|
||||
this.downloader = downloader;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public void download(File tmpFile, Progress progress, String statusText) throws Exception {
|
||||
try {
|
||||
downloader.download(url, tmpFile, progress, statusText);
|
||||
} catch (InterruptedException e) {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import processing.app.I18n;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions;
|
||||
|
||||
import com.github.zafarkhaja.semver.Version;
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class BuiltInPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class DownloadableContributionWithVersionPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
package cc.arduino.contributions.filters;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class InstalledPredicate implements Predicate<DownloadableContribution> {
|
||||
|
@ -26,9 +26,10 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import processing.app.I18n;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
public abstract class ContributedLibraryReference {
|
||||
|
@ -26,11 +26,19 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.libraries.filters.LibraryInstalledInsideCore;
|
||||
import cc.arduino.contributions.libraries.filters.TypePredicate;
|
||||
import cc.arduino.contributions.packages.ContributedPlatform;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.helpers.FileUtils;
|
||||
@ -43,6 +51,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -50,6 +59,7 @@ import static processing.app.I18n._;
|
||||
|
||||
public class LibrariesIndexer {
|
||||
|
||||
private final ContributionsIndexer contributionsIndexer;
|
||||
private LibrariesIndex index;
|
||||
private final LibraryList installedLibraries = new LibraryList();
|
||||
private final LibraryList installedLibrariesWithDuplicates = new LibraryList();
|
||||
@ -57,11 +67,13 @@ public class LibrariesIndexer {
|
||||
private final File indexFile;
|
||||
private final File stagingFolder;
|
||||
private File sketchbookLibrariesFolder;
|
||||
|
||||
private final List<String> badLibNotified = new ArrayList<String>();
|
||||
|
||||
public LibrariesIndexer(File preferencesFolder) {
|
||||
indexFile = new File(preferencesFolder, "library_index.json");
|
||||
stagingFolder = new File(preferencesFolder, "staging" + File.separator +
|
||||
"libraries");
|
||||
public LibrariesIndexer(File preferencesFolder, ContributionsIndexer contributionsIndexer) {
|
||||
this.contributionsIndexer = contributionsIndexer;
|
||||
this.indexFile = new File(preferencesFolder, "library_index.json");
|
||||
this.stagingFolder = new File(new File(preferencesFolder, "staging"), "libraries");
|
||||
}
|
||||
|
||||
public void parseIndex() throws IOException {
|
||||
@ -86,9 +98,7 @@ public class LibrariesIndexer {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (indexIn != null) {
|
||||
indexIn.close();
|
||||
}
|
||||
IOUtils.closeQuietly(indexIn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,12 +111,23 @@ public class LibrariesIndexer {
|
||||
// Clear all installed flags
|
||||
installedLibraries.clear();
|
||||
installedLibrariesWithDuplicates.clear();
|
||||
for (ContributedLibrary lib : index.getLibraries())
|
||||
for (ContributedLibrary lib : index.getLibraries()) {
|
||||
lib.setInstalled(false);
|
||||
}
|
||||
|
||||
// Rescan libraries
|
||||
for (File folder : librariesFolders)
|
||||
for (File folder : librariesFolders) {
|
||||
scanInstalledLibraries(folder, folder.equals(sketchbookLibrariesFolder));
|
||||
}
|
||||
|
||||
FluentIterable.from(installedLibraries).filter(new TypePredicate("Contributed")).filter(new LibraryInstalledInsideCore(contributionsIndexer)).transform(new Function<UserLibrary, Object>() {
|
||||
@Override
|
||||
public Object apply(UserLibrary userLibrary) {
|
||||
ContributedPlatform platform = contributionsIndexer.getPlatformByFolder(userLibrary.getInstalledFolder());
|
||||
userLibrary.setTypes(Arrays.asList(platform.getCategory()));
|
||||
return userLibrary;
|
||||
}
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private void scanInstalledLibraries(File folder, boolean isSketchbook) {
|
||||
@ -117,11 +138,18 @@ public class LibrariesIndexer {
|
||||
|
||||
for (File subfolder : list) {
|
||||
if (!BaseNoGui.isSanitaryName(subfolder.getName())) {
|
||||
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
|
||||
|
||||
// Detect whether the current folder name has already had a notification.
|
||||
if(!badLibNotified.contains(subfolder.getName())) {
|
||||
|
||||
badLibNotified.add(subfolder.getName());
|
||||
|
||||
String mess = I18n.format(_("The library \"{0}\" cannot be used.\n"
|
||||
+ "Library names must contain only basic letters and numbers.\n"
|
||||
+ "(ASCII only and no spaces, and it cannot start with a number)"),
|
||||
subfolder.getName());
|
||||
BaseNoGui.showMessage(_("Ignoring bad library name"), mess);
|
||||
BaseNoGui.showMessage(_("Ignoring bad library name"), mess);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -26,14 +26,16 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries;
|
||||
|
||||
import cc.arduino.contributions.packages.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.GZippedJsonDownloader;
|
||||
import cc.arduino.utils.ArchiveExtractor;
|
||||
import cc.arduino.utils.MultiStepProgress;
|
||||
import cc.arduino.utils.Progress;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -45,6 +47,7 @@ import static processing.app.I18n._;
|
||||
public class LibraryInstaller {
|
||||
|
||||
private static final String LIBRARY_INDEX_URL;
|
||||
private static final String LIBRARY_INDEX_URL_GZ;
|
||||
|
||||
static {
|
||||
String externalLibraryIndexUrl = System.getProperty("LIBRARY_INDEX_URL");
|
||||
@ -53,14 +56,17 @@ public class LibraryInstaller {
|
||||
} else {
|
||||
LIBRARY_INDEX_URL = "http://downloads.arduino.cc/libraries/library_index.json";
|
||||
}
|
||||
LIBRARY_INDEX_URL_GZ = "http://downloads.arduino.cc/libraries/library_index.json.gz";
|
||||
}
|
||||
|
||||
private final LibrariesIndexer indexer;
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final Platform platform;
|
||||
|
||||
public LibraryInstaller(LibrariesIndexer _indexer) {
|
||||
indexer = _indexer;
|
||||
File stagingFolder = _indexer.getStagingFolder();
|
||||
public LibraryInstaller(LibrariesIndexer indexer, Platform platform) {
|
||||
this.indexer = indexer;
|
||||
this.platform = platform;
|
||||
File stagingFolder = indexer.getStagingFolder();
|
||||
downloader = new DownloadableContributionsDownloader(stagingFolder) {
|
||||
@Override
|
||||
protected void onProgress(Progress progress) {
|
||||
@ -77,8 +83,8 @@ public class LibraryInstaller {
|
||||
File outputFile = indexer.getIndexFile();
|
||||
File tmpFile = new File(outputFile.getAbsolutePath() + ".tmp");
|
||||
try {
|
||||
downloader.download(url, tmpFile, progress,
|
||||
_("Downloading libraries index..."));
|
||||
GZippedJsonDownloader gZippedJsonDownloader = new GZippedJsonDownloader(downloader, new URL(LIBRARY_INDEX_URL), new URL(LIBRARY_INDEX_URL_GZ));
|
||||
gZippedJsonDownloader.download(tmpFile, progress, _("Downloading libraries index..."));
|
||||
} catch (InterruptedException e) {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
@ -91,8 +97,7 @@ public class LibraryInstaller {
|
||||
if (outputFile.exists())
|
||||
outputFile.delete();
|
||||
if (!tmpFile.renameTo(outputFile))
|
||||
throw new Exception(
|
||||
_("An error occurred while updating libraries index!"));
|
||||
throw new Exception(_("An error occurred while updating libraries index!"));
|
||||
|
||||
// Step 2: Rescan index
|
||||
rescanLibraryIndex(progress);
|
||||
@ -124,7 +129,7 @@ public class LibraryInstaller {
|
||||
File libsFolder = indexer.getSketchbookLibrariesFolder();
|
||||
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
|
||||
try {
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
} catch (Exception e) {
|
||||
if (tmpFolder.exists())
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.packages.ContributionsIndexer;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class LibraryInstalledInsideCore implements Predicate<ContributedLibrary> {
|
||||
|
||||
private final ContributionsIndexer indexer;
|
||||
|
||||
public LibraryInstalledInsideCore(ContributionsIndexer indexer) {
|
||||
this.indexer = indexer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary contributedLibrary) {
|
||||
return indexer.isFolderInsidePlatform(contributedLibrary.getInstalledFolder());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.libraries.filters;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
public class TypePredicate implements Predicate<ContributedLibrary> {
|
||||
|
||||
private final String type;
|
||||
|
||||
public TypePredicate(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(ContributedLibrary input) {
|
||||
return input.getTypes() != null && input.getTypes().contains(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return obj instanceof TypePredicate && ((TypePredicate) obj).type.equals(type);
|
||||
}
|
||||
|
||||
}
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
public interface ContributedBoard {
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
public abstract class ContributedHelp {
|
||||
|
@ -26,9 +26,8 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.VersionComparator;
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -80,16 +79,16 @@ public abstract class ContributedPackage {
|
||||
}
|
||||
res += "\n category : " + plat.getCategory();
|
||||
res += "\n architecture : " +
|
||||
plat.getArchitecture() + " " + plat.getParsedVersion() + "\n";
|
||||
plat.getArchitecture() + " " + plat.getParsedVersion() + "\n";
|
||||
if (plat.getToolsDependencies() != null)
|
||||
for (ContributedToolReference t : plat.getToolsDependencies()) {
|
||||
res += " tool dep : " + t.getName() + " " +
|
||||
t.getVersion() + "\n";
|
||||
t.getVersion() + "\n";
|
||||
}
|
||||
if (plat.getBoards() != null)
|
||||
for (ContributedBoard board : plat.getBoards())
|
||||
res += " board : " + board.getName() +
|
||||
"\n";
|
||||
"\n";
|
||||
}
|
||||
}
|
||||
if (getTools() != null) {
|
||||
|
@ -26,8 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
@ -26,15 +26,16 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
|
||||
public class ContributedTargetPackage implements TargetPackage {
|
||||
|
||||
private final String id;
|
||||
|
@ -26,14 +26,15 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.io.File;
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import processing.app.debug.LegacyTargetPlatform;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ContributedTargetPlatform extends LegacyTargetPlatform {
|
||||
|
||||
public ContributedTargetPlatform(String _name, File _folder,
|
||||
|
@ -26,9 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import processing.app.Platform;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -40,9 +42,9 @@ public abstract class ContributedTool {
|
||||
|
||||
public abstract List<HostDependentDownloadableContribution> getSystems();
|
||||
|
||||
public DownloadableContribution getDownloadableContribution() {
|
||||
public DownloadableContribution getDownloadableContribution(Platform platform) {
|
||||
for (HostDependentDownloadableContribution c : getSystems()) {
|
||||
if (c.isCompatible(BaseNoGui.getPlatform()))
|
||||
if (c.isCompatible(platform))
|
||||
return c;
|
||||
}
|
||||
return null;
|
||||
@ -50,11 +52,17 @@ public abstract class ContributedTool {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(null);
|
||||
}
|
||||
|
||||
public String toString(Platform platform) {
|
||||
String res;
|
||||
res = "Tool name : " + getName() + " " + getVersion() + "\n";
|
||||
for (HostDependentDownloadableContribution sys : getSystems()) {
|
||||
res += " sys";
|
||||
res += sys.isCompatible(BaseNoGui.getPlatform()) ? "*" : " ";
|
||||
if (platform != null) {
|
||||
res += sys.isCompatible(platform) ? "*" : " ";
|
||||
}
|
||||
res += " : " + sys + "\n";
|
||||
}
|
||||
return res;
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -40,6 +41,7 @@ public abstract class ContributedToolReference {
|
||||
|
||||
public ContributedTool resolve(Collection<ContributedPackage> packages) {
|
||||
for (ContributedPackage pack : packages) {
|
||||
assert pack.getTools() != null;
|
||||
for (ContributedTool tool : pack.getTools())
|
||||
if (tool.getName().equals(getName()) &&
|
||||
tool.getVersion().equals(getVersion()) &&
|
||||
@ -54,4 +56,4 @@ public abstract class ContributedToolReference {
|
||||
return "name=" + getName() + " version=" + getVersion() + " packager=" +
|
||||
getPackager();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionsDownloader;
|
||||
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
|
||||
import cc.arduino.filters.FileExecutablePredicate;
|
||||
import cc.arduino.utils.ArchiveExtractor;
|
||||
@ -35,13 +38,15 @@ import cc.arduino.utils.MultiStepProgress;
|
||||
import cc.arduino.utils.Progress;
|
||||
import com.google.common.collect.Collections2;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.tools.CollectStdOutStdErrExecutor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -56,8 +61,10 @@ public class ContributionInstaller {
|
||||
|
||||
private final ContributionsIndexer indexer;
|
||||
private final DownloadableContributionsDownloader downloader;
|
||||
private final Platform platform;
|
||||
|
||||
public ContributionInstaller(ContributionsIndexer contributionsIndexer) {
|
||||
public ContributionInstaller(ContributionsIndexer contributionsIndexer, Platform platform) {
|
||||
this.platform = platform;
|
||||
File stagingFolder = contributionsIndexer.getStagingFolder();
|
||||
indexer = contributionsIndexer;
|
||||
downloader = new DownloadableContributionsDownloader(stagingFolder) {
|
||||
@ -68,18 +75,18 @@ public class ContributionInstaller {
|
||||
};
|
||||
}
|
||||
|
||||
public List<String> install(ContributedPlatform platform) throws Exception {
|
||||
public List<String> install(ContributedPlatform contributedPlatform) throws Exception {
|
||||
List<String> errors = new LinkedList<String>();
|
||||
if (platform.isInstalled()) {
|
||||
if (contributedPlatform.isInstalled()) {
|
||||
throw new Exception("Platform is already installed!");
|
||||
}
|
||||
|
||||
// Do not download already installed tools
|
||||
List<ContributedTool> tools = new LinkedList<ContributedTool>(platform.getResolvedTools());
|
||||
List<ContributedTool> tools = new LinkedList<ContributedTool>(contributedPlatform.getResolvedTools());
|
||||
Iterator<ContributedTool> toolsIterator = tools.iterator();
|
||||
while (toolsIterator.hasNext()) {
|
||||
ContributedTool tool = toolsIterator.next();
|
||||
DownloadableContribution downloadable = tool.getDownloadableContribution();
|
||||
DownloadableContribution downloadable = tool.getDownloadableContribution(platform);
|
||||
if (downloadable == null) {
|
||||
throw new Exception(format(_("Tool {0} is not available for your operating system."), tool.getName()));
|
||||
}
|
||||
@ -94,7 +101,7 @@ public class ContributionInstaller {
|
||||
// Download all
|
||||
try {
|
||||
// Download platform
|
||||
downloader.download(platform, progress, _("Downloading boards definitions."));
|
||||
downloader.download(contributedPlatform, progress, _("Downloading boards definitions."));
|
||||
progress.stepDone();
|
||||
|
||||
// Download tools
|
||||
@ -102,7 +109,7 @@ public class ContributionInstaller {
|
||||
for (ContributedTool tool : tools) {
|
||||
String msg = format(_("Downloading tools ({0}/{1})."), i, tools.size());
|
||||
i++;
|
||||
downloader.download(tool.getDownloadableContribution(), progress, msg);
|
||||
downloader.download(tool.getDownloadableContribution(platform), progress, msg);
|
||||
progress.stepDone();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
@ -110,7 +117,7 @@ public class ContributionInstaller {
|
||||
return errors;
|
||||
}
|
||||
|
||||
ContributedPackage pack = platform.getParentPackage();
|
||||
ContributedPackage pack = contributedPlatform.getParentPackage();
|
||||
File packageFolder = new File(indexer.getPackagesFolder(), pack.getName());
|
||||
|
||||
// TODO: Extract to temporary folders and move to the final destination only
|
||||
@ -124,12 +131,12 @@ public class ContributionInstaller {
|
||||
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
|
||||
onProgress(progress);
|
||||
i++;
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution();
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
|
||||
|
||||
destFolder.mkdirs();
|
||||
assert toolContrib.getDownloadedFile() != null;
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||
new ArchiveExtractor(platform).extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||
try {
|
||||
executePostInstallScriptIfAny(destFolder);
|
||||
} catch (IOException e) {
|
||||
@ -143,12 +150,12 @@ public class ContributionInstaller {
|
||||
// Unpack platform on the correct location
|
||||
progress.setStatus(_("Installing boards..."));
|
||||
onProgress(progress);
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator + platform.getArchitecture());
|
||||
File destFolder = new File(platformFolder, platform.getParsedVersion());
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator + contributedPlatform.getArchitecture());
|
||||
File destFolder = new File(platformFolder, contributedPlatform.getParsedVersion());
|
||||
destFolder.mkdirs();
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(platform.getDownloadedFile(), destFolder, 1);
|
||||
platform.setInstalled(true);
|
||||
platform.setInstalledFolder(destFolder);
|
||||
new ArchiveExtractor(platform).extract(contributedPlatform.getDownloadedFile(), destFolder, 1);
|
||||
contributedPlatform.setInstalled(true);
|
||||
contributedPlatform.setInstalledFolder(destFolder);
|
||||
progress.stepDone();
|
||||
|
||||
progress.setStatus(_("Installation completed!"));
|
||||
@ -158,7 +165,7 @@ public class ContributionInstaller {
|
||||
}
|
||||
|
||||
private void executePostInstallScriptIfAny(File folder) throws IOException {
|
||||
Collection<File> postInstallScripts = Collections2.filter(BaseNoGui.getPlatform().postInstallScripts(folder), new FileExecutablePredicate());
|
||||
Collection<File> postInstallScripts = Collections2.filter(platform.postInstallScripts(folder), new FileExecutablePredicate());
|
||||
|
||||
if (postInstallScripts.isEmpty()) {
|
||||
String[] subfolders = folder.list(new OnlyDirs());
|
||||
@ -174,7 +181,8 @@ public class ContributionInstaller {
|
||||
|
||||
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
|
||||
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutStdErrExecutor(stdout, stderr);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(stdout, stderr));
|
||||
executor.setWorkingDirectory(folder);
|
||||
executor.setExitValues(null);
|
||||
int exitValue = executor.execute(new CommandLine(postInstallScript));
|
||||
@ -188,22 +196,22 @@ public class ContributionInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> remove(ContributedPlatform platform) {
|
||||
if (platform == null || platform.isReadOnly()) {
|
||||
public List<String> remove(ContributedPlatform contributedPlatform) {
|
||||
if (contributedPlatform == null || contributedPlatform.isReadOnly()) {
|
||||
return new LinkedList<String>();
|
||||
}
|
||||
List<String> errors = new LinkedList<String>();
|
||||
FileUtils.recursiveDelete(platform.getInstalledFolder());
|
||||
platform.setInstalled(false);
|
||||
platform.setInstalledFolder(null);
|
||||
FileUtils.recursiveDelete(contributedPlatform.getInstalledFolder());
|
||||
contributedPlatform.setInstalled(false);
|
||||
contributedPlatform.setInstalledFolder(null);
|
||||
|
||||
// Check if the tools are no longer needed
|
||||
for (ContributedTool tool : platform.getResolvedTools()) {
|
||||
for (ContributedTool tool : contributedPlatform.getResolvedTools()) {
|
||||
if (indexer.isContributedToolUsed(tool)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution();
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution(platform);
|
||||
File destFolder = toolContrib.getInstalledFolder();
|
||||
FileUtils.recursiveDelete(destFolder);
|
||||
toolContrib.setInstalled(false);
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
@ -83,7 +84,11 @@ public abstract class ContributionsIndex {
|
||||
return platforms.iterator().next();
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalled(String packageName, String platformArch) {
|
||||
public List<ContributedPlatform> getInstalledPlatforms() {
|
||||
return Lists.newLinkedList(Collections2.filter(getPlatforms(), new InstalledPredicate()));
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalledPlatform(String packageName, String platformArch) {
|
||||
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>(Collections2.filter(findPlatforms(packageName, platformArch), new InstalledPredicate()));
|
||||
Collections.sort(installedPlatforms, new DownloadableContributionBuiltInAtTheBottomComparator());
|
||||
|
||||
|
@ -26,8 +26,10 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import cc.arduino.contributions.DownloadableContributionBuiltInAtTheBottomComparator;
|
||||
import cc.arduino.contributions.GPGDetachedSignatureVerifier;
|
||||
import cc.arduino.contributions.SignatureVerificationFailedException;
|
||||
@ -37,14 +39,19 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.module.mrbean.MrBeanModule;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Multimaps;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.Platform;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
import java.io.File;
|
||||
@ -60,10 +67,12 @@ public class ContributionsIndexer {
|
||||
private final File packagesFolder;
|
||||
private final File stagingFolder;
|
||||
private final File preferencesFolder;
|
||||
private final Platform platform;
|
||||
private ContributionsIndex index;
|
||||
|
||||
public ContributionsIndexer(File preferencesFolder) {
|
||||
public ContributionsIndexer(File preferencesFolder, Platform platform) {
|
||||
this.preferencesFolder = preferencesFolder;
|
||||
this.platform = platform;
|
||||
packagesFolder = new File(preferencesFolder, "packages");
|
||||
stagingFolder = new File(preferencesFolder, "staging" + File.separator + "packages");
|
||||
}
|
||||
@ -83,13 +92,20 @@ public class ContributionsIndexer {
|
||||
}
|
||||
|
||||
List<ContributedPackage> packages = index.getPackages();
|
||||
Collection<ContributedPackage> packagesWithTools = Collections2.filter(packages, new Predicate<ContributedPackage>() {
|
||||
@Override
|
||||
public boolean apply(ContributedPackage input) {
|
||||
return input.getTools() != null;
|
||||
}
|
||||
});
|
||||
|
||||
for (ContributedPackage pack : packages) {
|
||||
for (ContributedPlatform platform : pack.getPlatforms()) {
|
||||
// Set a reference to parent packages
|
||||
platform.setParentPackage(pack);
|
||||
|
||||
// Resolve tools dependencies (works also as a check for file integrity)
|
||||
platform.resolveToolsDependencies(packages);
|
||||
platform.resolveToolsDependencies(packagesWithTools);
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,9 +184,7 @@ public class ContributionsIndexer {
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return mapper.readValue(inputStream, ContributionsIndex.class);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +277,7 @@ public class ContributionsIndexer {
|
||||
if (tool == null) {
|
||||
return;
|
||||
}
|
||||
DownloadableContribution contrib = tool.getDownloadableContribution();
|
||||
DownloadableContribution contrib = tool.getDownloadableContribution(platform);
|
||||
if (contrib == null) {
|
||||
System.err.println(tool + " seems to have no downloadable contributions for your operating system, but it is installed in\n" + installationFolder);
|
||||
return;
|
||||
@ -287,7 +301,7 @@ public class ContributionsIndexer {
|
||||
return index.toString();
|
||||
}
|
||||
|
||||
public List<TargetPackage> createTargetPackages() throws TargetPlatformException {
|
||||
public List<TargetPackage> createTargetPackages() {
|
||||
List<TargetPackage> packages = new ArrayList<TargetPackage>();
|
||||
|
||||
if (index == null) {
|
||||
@ -304,9 +318,13 @@ public class ContributionsIndexer {
|
||||
String arch = platform.getArchitecture();
|
||||
File folder = platform.getInstalledFolder();
|
||||
|
||||
TargetPlatform targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
|
||||
if (!targetPackage.hasPlatform(targetPlatform)) {
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
try {
|
||||
TargetPlatform targetPlatform = new ContributedTargetPlatform(arch, folder, targetPackage, index);
|
||||
if (!targetPackage.hasPlatform(targetPlatform)) {
|
||||
targetPackage.addPlatform(targetPlatform);
|
||||
}
|
||||
} catch (TargetPlatformException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,6 +332,15 @@ public class ContributionsIndexer {
|
||||
packages.add(targetPackage);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(packages, new Comparator<TargetPackage>() {
|
||||
@Override
|
||||
public int compare(TargetPackage p1, TargetPackage p2) {
|
||||
assert p1.getId() != null && p2.getId() != null;
|
||||
return p1.getId().toLowerCase().compareTo(p2.getId().toLowerCase());
|
||||
}
|
||||
});
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
@ -398,6 +425,29 @@ public class ContributionsIndexer {
|
||||
if (index == null) {
|
||||
return null;
|
||||
}
|
||||
return index.getInstalled(packageName, platformArch);
|
||||
return index.getInstalledPlatform(packageName, platformArch);
|
||||
}
|
||||
|
||||
public List<ContributedPlatform> getInstalledPlatforms() {
|
||||
if (index == null) {
|
||||
return new LinkedList<ContributedPlatform>();
|
||||
}
|
||||
return index.getInstalledPlatforms();
|
||||
}
|
||||
|
||||
public boolean isFolderInsidePlatform(final File folder) {
|
||||
return getPlatformByFolder(folder) != null;
|
||||
}
|
||||
|
||||
public ContributedPlatform getPlatformByFolder(final File folder) {
|
||||
com.google.common.base.Optional<ContributedPlatform> platformOptional = Iterables.tryFind(getInstalledPlatforms(), new Predicate<ContributedPlatform>() {
|
||||
@Override
|
||||
public boolean apply(ContributedPlatform contributedPlatform) {
|
||||
assert contributedPlatform.getInstalledFolder() != null;
|
||||
return FileUtils.isSubDirectory(contributedPlatform.getInstalledFolder(), folder);
|
||||
}
|
||||
});
|
||||
|
||||
return platformOptional.orNull();
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,10 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import cc.arduino.contributions.DownloadableContribution;
|
||||
import processing.app.Platform;
|
||||
|
||||
public abstract class HostDependentDownloadableContribution extends DownloadableContribution {
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.contributions.packages;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.files;
|
||||
|
||||
import processing.app.PreferencesData;
|
||||
|
@ -33,6 +33,7 @@ import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Discovery;
|
||||
import cc.arduino.packages.discoverers.network.BoardReachabilityFilter;
|
||||
import cc.arduino.packages.discoverers.network.NetworkChecker;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.zeroconf.jmdns.ArduinoDNSTaskStarter;
|
||||
@ -199,12 +200,6 @@ public class NetworkDiscovery implements Discovery, ServiceListener, cc.arduino.
|
||||
@Override
|
||||
public void inetAddressRemoved(InetAddress address) {
|
||||
JmDNS jmDNS = mappedJmDNSs.remove(address);
|
||||
if (jmDNS != null) {
|
||||
try {
|
||||
jmDNS.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(jmDNS);
|
||||
}
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class SerialDiscovery implements Discovery {
|
||||
|
||||
private Timer serialBoardsListerTimer;
|
||||
|
@ -41,8 +41,6 @@ import java.util.*;
|
||||
|
||||
public class SerialBoardsLister extends TimerTask {
|
||||
|
||||
private static final int MAX_TIME_AWAITING_FOR_PACKAGES = 5000;
|
||||
|
||||
private final SerialDiscovery serialDiscovery;
|
||||
|
||||
public SerialBoardsLister(SerialDiscovery serialDiscovery) {
|
||||
@ -55,13 +53,11 @@ public class SerialBoardsLister extends TimerTask {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int sleptFor = 0;
|
||||
while (BaseNoGui.packages == null && sleptFor <= MAX_TIME_AWAITING_FOR_PACKAGES) {
|
||||
while (BaseNoGui.packages == null) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
sleptFor += 1000;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
// noop
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.packages.ssh;
|
||||
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
|
@ -32,6 +32,7 @@ package cc.arduino.packages.ssh;
|
||||
import com.jcraft.jsch.Channel;
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
import com.jcraft.jsch.Session;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -61,12 +62,8 @@ public class SCP extends SSH {
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
IOUtils.closeQuietly(in);
|
||||
if (channel != null) {
|
||||
channel.disconnect();
|
||||
}
|
||||
@ -118,9 +115,7 @@ public class SCP extends SSH {
|
||||
buf[0] = 0;
|
||||
out.write(buf, 0, 1);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fis);
|
||||
}
|
||||
|
||||
ensureAcknowledged();
|
||||
|
@ -33,6 +33,7 @@ import com.jcraft.jsch.Channel;
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
import com.jcraft.jsch.JSchException;
|
||||
import com.jcraft.jsch.Session;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -70,12 +71,8 @@ public class SSH {
|
||||
return exitCode == 0;
|
||||
|
||||
} finally {
|
||||
if (stdout != null) {
|
||||
stdout.close();
|
||||
}
|
||||
if (stderr != null) {
|
||||
stderr.close();
|
||||
}
|
||||
IOUtils.closeQuietly(stdout);
|
||||
IOUtils.closeQuietly(stderr);
|
||||
if (channel != null) {
|
||||
channel.disconnect();
|
||||
}
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.packages.ssh;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.packages.ssh;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.packages.ssh;
|
||||
|
||||
import cc.arduino.packages.BoardPort;
|
||||
|
@ -26,23 +26,19 @@
|
||||
|
||||
package cc.arduino.packages.uploaders;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.Serial;
|
||||
import processing.app.SerialException;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import processing.app.*;
|
||||
import processing.app.debug.RunnerException;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.StringReplacer;
|
||||
import cc.arduino.packages.Uploader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
public class SerialUploader extends Uploader {
|
||||
|
||||
@ -110,16 +106,18 @@ public class SerialUploader extends Uploader {
|
||||
t = prefs.get("upload.wait_for_upload_port");
|
||||
boolean waitForUploadPort = (t != null) && t.equals("true");
|
||||
|
||||
String userSelectedUploadPort = prefs.getOrExcept("serial.port");
|
||||
String actualUploadPort = null;
|
||||
|
||||
if (doTouch) {
|
||||
String uploadPort = prefs.getOrExcept("serial.port");
|
||||
try {
|
||||
// Toggle 1200 bps on selected serial port to force board reset.
|
||||
List<String> before = Serial.list();
|
||||
if (before.contains(uploadPort)) {
|
||||
if (before.contains(userSelectedUploadPort)) {
|
||||
if (verbose)
|
||||
System.out.println(
|
||||
I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), uploadPort));
|
||||
Serial.touchForCDCReset(uploadPort);
|
||||
I18n.format(_("Forcing reset using 1200bps open/close on port {0}"), userSelectedUploadPort));
|
||||
Serial.touchForCDCReset(userSelectedUploadPort);
|
||||
}
|
||||
Thread.sleep(400);
|
||||
if (waitForUploadPort) {
|
||||
@ -127,34 +125,34 @@ public class SerialUploader extends Uploader {
|
||||
// otherwise assert DTR, which would cancel the WDT reset if
|
||||
// it happened within 250 ms. So we wait until the reset should
|
||||
// have already occured before we start scanning.
|
||||
uploadPort = waitForUploadPort(uploadPort, before);
|
||||
actualUploadPort = waitForUploadPort(userSelectedUploadPort, before);
|
||||
}
|
||||
} catch (SerialException e) {
|
||||
throw new RunnerException(e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RunnerException(e.getMessage());
|
||||
}
|
||||
prefs.put("serial.port", uploadPort);
|
||||
if (uploadPort.startsWith("/dev/"))
|
||||
prefs.put("serial.port.file", uploadPort.substring(5));
|
||||
else
|
||||
prefs.put("serial.port.file", uploadPort);
|
||||
if (actualUploadPort == null) {
|
||||
actualUploadPort = userSelectedUploadPort;
|
||||
}
|
||||
prefs.put("serial.port", actualUploadPort);
|
||||
if (actualUploadPort.startsWith("/dev/")) {
|
||||
prefs.put("serial.port.file", actualUploadPort.substring(5));
|
||||
} else {
|
||||
prefs.put("serial.port.file", actualUploadPort);
|
||||
}
|
||||
}
|
||||
|
||||
prefs.put("build.path", buildPath);
|
||||
prefs.put("build.project_name", className);
|
||||
if (verbose)
|
||||
if (verbose) {
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.verbose"));
|
||||
else
|
||||
} else {
|
||||
prefs.put("upload.verbose", prefs.getOrExcept("upload.params.quiet"));
|
||||
}
|
||||
|
||||
boolean uploadResult;
|
||||
try {
|
||||
// if (prefs.get("upload.disable_flushing") == null
|
||||
// || prefs.get("upload.disable_flushing").toLowerCase().equals("false")) {
|
||||
// flushSerialBuffer();
|
||||
// }
|
||||
|
||||
String pattern = prefs.getOrExcept("upload.pattern");
|
||||
String[] cmd = StringReplacer.formatAndSplit(pattern, prefs, true);
|
||||
uploadResult = executeUploadCommand(cmd);
|
||||
@ -164,9 +162,9 @@ public class SerialUploader extends Uploader {
|
||||
throw new RunnerException(e);
|
||||
}
|
||||
|
||||
try {
|
||||
if (uploadResult && doTouch) {
|
||||
String uploadPort = PreferencesData.get("serial.port");
|
||||
String finalUploadPort = null;
|
||||
if (uploadResult && doTouch) {
|
||||
try {
|
||||
if (waitForUploadPort) {
|
||||
// For Due/Leonardo wait until the bootloader serial port disconnects and the
|
||||
// sketch serial port reconnects (or timeout after a few seconds if the
|
||||
@ -176,15 +174,28 @@ public class SerialUploader extends Uploader {
|
||||
long started = System.currentTimeMillis();
|
||||
while (System.currentTimeMillis() - started < 2000) {
|
||||
List<String> portList = Serial.list();
|
||||
if (portList.contains(uploadPort))
|
||||
if (portList.contains(actualUploadPort)) {
|
||||
finalUploadPort = actualUploadPort;
|
||||
break;
|
||||
} else if (portList.contains(userSelectedUploadPort)) {
|
||||
finalUploadPort = userSelectedUploadPort;
|
||||
break;
|
||||
}
|
||||
Thread.sleep(250);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
// noop
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
// noop
|
||||
}
|
||||
|
||||
if (finalUploadPort == null) {
|
||||
finalUploadPort = actualUploadPort;
|
||||
}
|
||||
if (finalUploadPort == null) {
|
||||
finalUploadPort = userSelectedUploadPort;
|
||||
}
|
||||
BaseNoGui.selectSerialPort(finalUploadPort);
|
||||
return uploadResult;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils;
|
||||
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
||||
@ -35,6 +36,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
||||
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
|
||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
|
||||
@ -258,9 +260,7 @@ public class ArchiveExtractor {
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
|
||||
// Set folders timestamps
|
||||
@ -294,9 +294,7 @@ public class ArchiveExtractor {
|
||||
size -= length;
|
||||
}
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,11 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
@ -68,9 +71,7 @@ public class FileHash {
|
||||
}
|
||||
return algorithm + ":" + res;
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
IOUtils.closeQuietly(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils;
|
||||
|
||||
public class MultiStepProgress implements Progress {
|
||||
|
@ -26,6 +26,7 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils;
|
||||
|
||||
public interface Progress {
|
||||
|
@ -1,3 +1,32 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2015 Arduino LLC (http://www.arduino.cc/)
|
||||
*
|
||||
* Arduino is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* As a special exception, you may use this file as part of a free software
|
||||
* library without restriction. Specifically, if other files instantiate
|
||||
* templates or use macros or inline functions from this file, or you compile
|
||||
* this file and link it with other files to produce an executable, this
|
||||
* file does not by itself cause the resulting executable to be covered by
|
||||
* the GNU General Public License. This exception does not however
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
@ -26,18 +26,17 @@
|
||||
* invalidate any other reasons why the executable file might be covered by
|
||||
* the GNU General Public License.
|
||||
*/
|
||||
|
||||
package cc.arduino.utils.network;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import processing.app.PreferencesData;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.*;
|
||||
import java.util.Observable;
|
||||
|
||||
public class FileDownloader extends Observable {
|
||||
@ -121,29 +120,9 @@ public class FileDownloader extends Observable {
|
||||
|
||||
setStatus(Status.CONNECTING);
|
||||
|
||||
System.getProperties().remove("http.proxyHost");
|
||||
System.getProperties().remove("http.proxyPort");
|
||||
System.getProperties().remove("https.proxyHost");
|
||||
System.getProperties().remove("https.proxyPort");
|
||||
System.getProperties().remove("http.proxyUser");
|
||||
System.getProperties().remove("http.proxyPassword");
|
||||
Proxy proxy = ProxySelector.getDefault().select(downloadUrl.toURI()).get(0);
|
||||
|
||||
if (PreferencesData.has("proxy.http.server") && PreferencesData.get("proxy.http.server") != null && !PreferencesData.get("proxy.http.server").equals("")) {
|
||||
System.getProperties().put("http.proxyHost", PreferencesData.get("proxy.http.server"));
|
||||
System.getProperties().put("http.proxyPort", PreferencesData.get("proxy.http.port"));
|
||||
}
|
||||
if (PreferencesData.has("proxy.https.server") && PreferencesData.get("proxy.https.server") != null && !PreferencesData.get("proxy.https.server").equals("")) {
|
||||
System.getProperties().put("https.proxyHost", PreferencesData.get("proxy.https.server"));
|
||||
System.getProperties().put("https.proxyPort", PreferencesData.get("proxy.https.port"));
|
||||
}
|
||||
if (PreferencesData.has("proxy.user") && PreferencesData.get("proxy.user") != null && !PreferencesData.get("proxy.user").equals("")) {
|
||||
System.getProperties().put("http.proxyUser", PreferencesData.get("proxy.user"));
|
||||
System.getProperties().put("http.proxyPassword", PreferencesData.get("proxy.password"));
|
||||
System.getProperties().put("https.proxyUser", PreferencesData.get("proxy.user"));
|
||||
System.getProperties().put("https.proxyPassword", PreferencesData.get("proxy.password"));
|
||||
}
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection();
|
||||
HttpURLConnection connection = (HttpURLConnection) downloadUrl.openConnection(proxy);
|
||||
|
||||
if (downloadUrl.getUserInfo() != null) {
|
||||
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
|
||||
@ -159,10 +138,12 @@ public class FileDownloader extends Observable {
|
||||
int resp = connection.getResponseCode();
|
||||
|
||||
if (resp == HttpURLConnection.HTTP_MOVED_PERM || resp == HttpURLConnection.HTTP_MOVED_TEMP) {
|
||||
String newUrl = connection.getHeaderField("Location");
|
||||
URL newUrl = new URL(connection.getHeaderField("Location"));
|
||||
|
||||
proxy = ProxySelector.getDefault().select(newUrl.toURI()).get(0);
|
||||
|
||||
// open the new connnection again
|
||||
connection = (HttpURLConnection) new URL(newUrl).openConnection();
|
||||
connection = (HttpURLConnection) newUrl.openConnection(proxy);
|
||||
if (downloadUrl.getUserInfo() != null) {
|
||||
String auth = "Basic " + new String(new Base64().encode(downloadUrl.getUserInfo().getBytes()));
|
||||
connection.setRequestProperty("Authorization", auth);
|
||||
@ -176,7 +157,7 @@ public class FileDownloader extends Observable {
|
||||
}
|
||||
|
||||
if (resp < 200 || resp >= 300) {
|
||||
throw new IOException("Recevied invalid http status code from server: " + resp);
|
||||
throw new IOException("Received invalid http status code from server: " + resp);
|
||||
}
|
||||
|
||||
// Check for valid content length.
|
||||
@ -221,22 +202,10 @@ public class FileDownloader extends Observable {
|
||||
setError(e);
|
||||
|
||||
} finally {
|
||||
if (file != null) {
|
||||
try {
|
||||
file.close();
|
||||
} catch (Exception e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(file);
|
||||
|
||||
synchronized (this) {
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import cc.arduino.files.DeleteFilesOnShutdown;
|
||||
import cc.arduino.packages.DiscoveryManager;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||
import org.apache.commons.logging.impl.NoOpLog;
|
||||
import processing.app.debug.Compiler;
|
||||
@ -30,9 +31,9 @@ import static processing.app.I18n._;
|
||||
public class BaseNoGui {
|
||||
|
||||
/** Version string to be used for build */
|
||||
public static final int REVISION = 10605;
|
||||
public static final int REVISION = 10606;
|
||||
/** Extended version string displayed on GUI */
|
||||
public static final String VERSION_NAME = "1.6.5";
|
||||
public static final String VERSION_NAME = "1.6.6";
|
||||
public static final String VERSION_NAME_LONG;
|
||||
|
||||
static {
|
||||
@ -315,14 +316,15 @@ public class BaseNoGui {
|
||||
static public File getSketchbookLibrariesFolder() {
|
||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
||||
if (!libdir.exists()) {
|
||||
FileWriter freadme = null;
|
||||
try {
|
||||
libdir.mkdirs();
|
||||
File readme = new File(libdir, "readme.txt");
|
||||
FileWriter freadme = new FileWriter(readme);
|
||||
freadme = new FileWriter(new File(libdir, "readme.txt"));
|
||||
freadme.write(_("For information on installing libraries, see: " +
|
||||
"http://arduino.cc/en/Guide/Libraries\n"));
|
||||
freadme.close();
|
||||
"http://www.arduino.cc/en/Guide/Libraries\n"));
|
||||
} catch (Exception e) {
|
||||
} finally {
|
||||
IOUtils.closeQuietly(freadme);
|
||||
}
|
||||
}
|
||||
return libdir;
|
||||
@ -417,7 +419,7 @@ public class BaseNoGui {
|
||||
* within the header files at the top-level).
|
||||
*/
|
||||
static public String[] headerListFromIncludePath(File path) throws IOException {
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h"));
|
||||
String[] list = path.list(new OnlyFilesWithExtension(".h", ".hh", ".hpp"));
|
||||
if (list == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
@ -425,8 +427,9 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void init(String[] args) throws Exception {
|
||||
getPlatform().init();
|
||||
|
||||
CommandlineParser parser = new CommandlineParser(args);
|
||||
parser.parseArgumentsPhase1();
|
||||
|
||||
String sketchbookPath = getSketchbookPath();
|
||||
|
||||
// If no path is set, get the default sketchbook folder for this platform
|
||||
@ -436,13 +439,13 @@ public class BaseNoGui {
|
||||
else
|
||||
showError(_("No sketchbook"), _("Sketchbook path not defined"), null);
|
||||
}
|
||||
|
||||
|
||||
BaseNoGui.initPackages();
|
||||
|
||||
// Setup board-dependent variables.
|
||||
onBoardOrPortChange();
|
||||
|
||||
CommandlineParser parser = CommandlineParser.newCommandlineParser(args);
|
||||
|
||||
parser.parseArgumentsPhase2();
|
||||
|
||||
for (String path: parser.getFilenames()) {
|
||||
// Correctly resolve relative paths
|
||||
@ -570,6 +573,12 @@ public class BaseNoGui {
|
||||
System.exit(0);
|
||||
}
|
||||
else if (parser.isGetPrefMode()) {
|
||||
dumpPrefs(parser);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void dumpPrefs(CommandlineParser parser) {
|
||||
if (parser.getGetPref() != null) {
|
||||
String value = PreferencesData.get(parser.getGetPref(), null);
|
||||
if (value != null) {
|
||||
System.out.println(value);
|
||||
@ -577,6 +586,13 @@ public class BaseNoGui {
|
||||
} else {
|
||||
System.exit(4);
|
||||
}
|
||||
} else {
|
||||
System.out.println("#PREFDUMP#");
|
||||
PreferencesMap prefs = PreferencesData.getMap();
|
||||
for (Map.Entry<String, String> entry : prefs.entrySet()) {
|
||||
System.out.println(entry.getKey() + "=" + entry.getValue());
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -586,7 +602,7 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void initPackages() throws Exception {
|
||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder());
|
||||
indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder(), BaseNoGui.getPlatform());
|
||||
File indexFile = indexer.getIndexFile("package_index.json");
|
||||
File defaultPackageJsonFile = new File(getContentFile("dist"), "package_index.json");
|
||||
if (!indexFile.isFile() || (defaultPackageJsonFile.isFile() && defaultPackageJsonFile.lastModified() > indexFile.lastModified())) {
|
||||
@ -597,11 +613,8 @@ public class BaseNoGui {
|
||||
try {
|
||||
out = new FileOutputStream(indexFile);
|
||||
out.write("{ \"packages\" : [ ] }".getBytes());
|
||||
out.close();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -624,13 +637,13 @@ public class BaseNoGui {
|
||||
}
|
||||
indexer.syncWithFilesystem(getHardwareFolder());
|
||||
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
packages = new LinkedHashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
loadContributedHardware(indexer);
|
||||
loadHardware(getSketchbookHardwareFolder());
|
||||
createToolPreferences(indexer);
|
||||
|
||||
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder());
|
||||
librariesIndexer = new LibrariesIndexer(BaseNoGui.getSettingsFolder(), indexer);
|
||||
File librariesIndexFile = librariesIndexer.getIndexFile();
|
||||
if (!librariesIndexFile.isFile()) {
|
||||
File defaultLibraryJsonFile = new File(getContentFile("dist"), "library_index.json");
|
||||
@ -645,9 +658,7 @@ public class BaseNoGui {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -734,20 +745,47 @@ public class BaseNoGui {
|
||||
}
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
if (args.length == 0)
|
||||
if (args.length == 0) {
|
||||
showError(_("No parameters"), _("No command line parameters found"), null);
|
||||
}
|
||||
System.setProperty("java.net.useSystemProxies", "true");
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
|
||||
|
||||
initPlatform();
|
||||
|
||||
|
||||
getPlatform().init();
|
||||
|
||||
initPortableFolder();
|
||||
|
||||
initParameters(args);
|
||||
|
||||
|
||||
checkInstallationFolder();
|
||||
|
||||
init(args);
|
||||
}
|
||||
|
||||
public static void checkInstallationFolder() {
|
||||
if (isIDEInstalledIntoSettingsFolder()) {
|
||||
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your settings folder.\nPlease move the IDE to another folder."), 10);
|
||||
}
|
||||
if (isIDEInstalledIntoSketchbookFolder()) {
|
||||
showError(_("Incorrect IDE installation folder"), _("Your copy of the IDE is installed in a subfolder of your sketchbook.\nPlease move the IDE to another folder."), 10);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIDEInstalledIntoSketchbookFolder() {
|
||||
return PreferencesData.has("sketchbook.path") && FileUtils.isSubDirectory(new File(PreferencesData.get("sketchbook.path")), new File(PreferencesData.get("runtime.ide.path")));
|
||||
}
|
||||
|
||||
public static boolean isIDEInstalledIntoSettingsFolder() {
|
||||
try {
|
||||
return FileUtils.isSubDirectory(BaseNoGui.getPlatform().getSettingsFolder(), new File(PreferencesData.get("runtime.ide.path")));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static public void onBoardOrPortChange() {
|
||||
examplesFolder = getContentFile("examples");
|
||||
toolsFolder = getContentFile("tools");
|
||||
@ -788,7 +826,7 @@ public class BaseNoGui {
|
||||
populateImportToLibraryTable();
|
||||
}
|
||||
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) throws TargetPlatformException {
|
||||
static protected void loadContributedHardware(ContributionsIndexer indexer) {
|
||||
for (TargetPackage pack : indexer.createTargetPackages()) {
|
||||
packages.put(pack.getId(), pack);
|
||||
}
|
||||
@ -800,7 +838,7 @@ public class BaseNoGui {
|
||||
PreferencesData.removeAllKeysWithPrefix(prefix);
|
||||
|
||||
for (ContributedTool tool : indexer.getInstalledTools()) {
|
||||
File installedFolder = tool.getDownloadableContribution().getInstalledFolder();
|
||||
File installedFolder = tool.getDownloadableContribution(getPlatform()).getInstalledFolder();
|
||||
if (installedFolder != null) {
|
||||
PreferencesData.set(prefix + tool.getName() + ".path", installedFolder.getAbsolutePath());
|
||||
PreferencesData.set(prefix + tool.getName() + "-" + tool.getVersion() + ".path", installedFolder.getAbsolutePath());
|
||||
@ -956,14 +994,18 @@ public class BaseNoGui {
|
||||
if (!dir.exists()) return;
|
||||
|
||||
String files[] = dir.list();
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || files[i].equals("..")) continue;
|
||||
File dead = new File(dir, files[i]);
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String file : files) {
|
||||
if (file.equals(".") || file.equals("..")) continue;
|
||||
File dead = new File(dir, file);
|
||||
if (!dead.isDirectory()) {
|
||||
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
|
||||
if (!dead.delete()) {
|
||||
// temporarily disabled
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
System.err.println(I18n.format(_("Could not delete {0}"), dead));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -1068,10 +1110,11 @@ public class BaseNoGui {
|
||||
|
||||
public static void selectSerialPort(String port) {
|
||||
PreferencesData.set("serial.port", port);
|
||||
if (port.startsWith("/dev/"))
|
||||
PreferencesData.set("serial.port.file", port.substring(5));
|
||||
else
|
||||
PreferencesData.set("serial.port.file", port);
|
||||
String portFile = port;
|
||||
if (port.startsWith("/dev/")) {
|
||||
portFile = portFile.substring(5);
|
||||
}
|
||||
PreferencesData.set("serial.port.file", portFile);
|
||||
}
|
||||
|
||||
public static void setBuildFolder(File newBuildFolder) {
|
||||
|
@ -29,8 +29,12 @@ import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -38,42 +42,42 @@ import static processing.app.I18n._;
|
||||
/**
|
||||
* Used by Base for platform-specific tweaking, for instance finding the
|
||||
* sketchbook location using the Windows registry, or OS X event handling.
|
||||
*
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
*
|
||||
* <p/>
|
||||
* The methods in this implementation are used by default, and can be
|
||||
* overridden by a subclass, if loaded by Base.main().
|
||||
* <p/>
|
||||
* These methods throw vanilla-flavored Exceptions, so that error handling
|
||||
* occurs inside Base.
|
||||
*
|
||||
* There is currently no mechanism for adding new platforms, as the setup is
|
||||
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
||||
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
||||
* occurs inside Base.
|
||||
* <p/>
|
||||
* There is currently no mechanism for adding new platforms, as the setup is
|
||||
* not automated. We could use getProperty("os.arch") perhaps, but that's
|
||||
* debatable (could be upper/lowercase, have spaces, etc.. basically we don't
|
||||
* know if name is proper Java package syntax.)
|
||||
*/
|
||||
public class Platform {
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set the default L & F. While I enjoy the bounty of the sixteen possible
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* exception types that this UIManager method might throw, I feel that in
|
||||
* just this one particular case, I'm being spoiled by those engineers
|
||||
* at Sun, those Masters of the Abstractionverse. It leaves me feeling sad
|
||||
* and overweight. So instead, I'll pretend that I'm not offered eleven dozen
|
||||
* ways to report to the user exactly what went wrong, and I'll bundle them
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* all into a single catch-all "Exception". Because in the end, all I really
|
||||
* care about is whether things worked or not. And even then, I don't care.
|
||||
*
|
||||
*
|
||||
* @throws Exception Just like I said.
|
||||
*/
|
||||
public void setLookAndFeel() throws Exception {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void init() throws IOException {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// otherwise make a .processing directory int the user's home dir
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
@ -95,37 +99,46 @@ public class Platform {
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @return null if not overridden, which will cause a prompt to show instead.
|
||||
* @throws Exception
|
||||
*/
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void openURL(File folder, String url) throws Exception {
|
||||
if (!url.startsWith("file://./")) {
|
||||
openURL(url);
|
||||
return;
|
||||
}
|
||||
|
||||
url = url.replaceAll("file://./", folder.getCanonicalFile().toURI().toASCIIString());
|
||||
openURL(url);
|
||||
}
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
Runtime.getRuntime().exec(new String[] { launcher, url });
|
||||
Runtime.getRuntime().exec(new String[]{launcher, url});
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
return PreferencesData.get("launcher") != null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void openFolder(File file) throws Exception {
|
||||
String launcher = PreferencesData.get("launcher");
|
||||
if (launcher != null) {
|
||||
String folder = file.getAbsolutePath();
|
||||
Runtime.getRuntime().exec(new String[] { launcher, folder });
|
||||
Runtime.getRuntime().exec(new String[]{launcher, folder});
|
||||
} else {
|
||||
showLauncherWarning();
|
||||
}
|
||||
@ -184,14 +197,14 @@ public class Platform {
|
||||
return PConstants.platformNames[PConstants.OTHER];
|
||||
}
|
||||
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
protected void showLauncherWarning() {
|
||||
BaseNoGui.showWarning(_("No launcher available"),
|
||||
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
||||
null);
|
||||
BaseNoGui.showWarning(_("No launcher available"),
|
||||
_("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"),
|
||||
null);
|
||||
}
|
||||
|
||||
public List<BoardPort> filterPorts(List<BoardPort> ports, boolean aBoolean) {
|
||||
|
@ -1,23 +1,23 @@
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.helpers.PreferencesHelper;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
public class PreferencesData {
|
||||
|
||||
@ -50,14 +50,14 @@ public class PreferencesData {
|
||||
prefs.load(new File(BaseNoGui.getContentFile("lib"), PREFS_FILE));
|
||||
} catch (IOException e) {
|
||||
BaseNoGui.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = BaseNoGui.getHardwareFolder();
|
||||
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);
|
||||
|
||||
|
||||
// clone the hash table
|
||||
defaults = new PreferencesMap(prefs);
|
||||
|
||||
@ -67,10 +67,10 @@ public class PreferencesData {
|
||||
prefs.load(preferencesFile);
|
||||
} catch (IOException ex) {
|
||||
BaseNoGui.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,9 +124,7 @@ public class PreferencesData {
|
||||
|
||||
writer.flush();
|
||||
} finally {
|
||||
if (writer != null) {
|
||||
writer.close();
|
||||
}
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -198,8 +196,7 @@ public class PreferencesData {
|
||||
}
|
||||
|
||||
// get a copy of the Preferences
|
||||
static public PreferencesMap getMap()
|
||||
{
|
||||
static public PreferencesMap getMap() {
|
||||
return new PreferencesMap(prefs);
|
||||
}
|
||||
|
||||
@ -212,8 +209,7 @@ public class PreferencesData {
|
||||
|
||||
// Decide wether changed preferences will be saved. When value is
|
||||
// false, Preferences.save becomes a no-op.
|
||||
static public void setDoSave(boolean value)
|
||||
{
|
||||
static public void setDoSave(boolean value) {
|
||||
doSave = value;
|
||||
}
|
||||
|
||||
@ -226,4 +222,13 @@ public class PreferencesData {
|
||||
}
|
||||
return font;
|
||||
}
|
||||
|
||||
public static Collection<String> getCollection(String key) {
|
||||
return Arrays.asList(get(key, "").split(","));
|
||||
}
|
||||
|
||||
public static void setCollection(String key, Collection<String> values) {
|
||||
String value = Joiner.on(',').join(values);
|
||||
set(key, value);
|
||||
}
|
||||
}
|
||||
|
@ -22,16 +22,16 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import jssc.SerialPort;
|
||||
import jssc.SerialPortEvent;
|
||||
import jssc.SerialPortEventListener;
|
||||
import jssc.SerialPortException;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
|
||||
public class Serial implements SerialPortEventListener {
|
||||
@ -45,19 +45,14 @@ public class Serial implements SerialPortEventListener {
|
||||
// for the classloading problem.. because if code ran again,
|
||||
// the static class would have an object that could be closed
|
||||
|
||||
SerialPort port;
|
||||
|
||||
int rate;
|
||||
int parity;
|
||||
int databits;
|
||||
int stopbits;
|
||||
private SerialPort port;
|
||||
|
||||
public Serial() throws SerialException {
|
||||
this(PreferencesData.get("serial.port"),
|
||||
PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -66,7 +61,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(PreferencesData.get("serial.port"), irate,
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -74,7 +69,7 @@ public class Serial implements SerialPortEventListener {
|
||||
public Serial(String iname, int irate) throws SerialException {
|
||||
this(iname, irate, PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -83,7 +78,7 @@ public class Serial implements SerialPortEventListener {
|
||||
this(iname, PreferencesData.getInteger("serial.debug_rate"),
|
||||
PreferencesData.get("serial.parity").charAt(0),
|
||||
PreferencesData.getInteger("serial.databits"),
|
||||
new Float(PreferencesData.get("serial.stopbits")).floatValue(),
|
||||
Float.parseFloat(PreferencesData.get("serial.stopbits"))),
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableRTS") == null,
|
||||
BaseNoGui.getBoardPreferences().get("serial.disableDTR") == null);
|
||||
}
|
||||
@ -109,29 +104,28 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean setRTS, boolean setDTR) throws SerialException {
|
||||
private Serial(String iname, int irate, char iparity, int idatabits, float istopbits, boolean setRTS, boolean setDTR) throws SerialException {
|
||||
//if (port != null) port.close();
|
||||
//this.parent = parent;
|
||||
//parent.attach(this);
|
||||
|
||||
this.rate = irate;
|
||||
|
||||
parity = SerialPort.PARITY_NONE;
|
||||
int parity = SerialPort.PARITY_NONE;
|
||||
if (iparity == 'E') parity = SerialPort.PARITY_EVEN;
|
||||
if (iparity == 'O') parity = SerialPort.PARITY_ODD;
|
||||
|
||||
this.databits = idatabits;
|
||||
|
||||
stopbits = SerialPort.STOPBITS_1;
|
||||
int stopbits = SerialPort.STOPBITS_1;
|
||||
if (istopbits == 1.5f) stopbits = SerialPort.STOPBITS_1_5;
|
||||
if (istopbits == 2) stopbits = SerialPort.STOPBITS_2;
|
||||
|
||||
try {
|
||||
port = new SerialPort(iname);
|
||||
port.openPort();
|
||||
port.setParams(rate, databits, stopbits, parity, setRTS, setDTR);
|
||||
port.setParams(irate, idatabits, stopbits, parity, setRTS, setDTR);
|
||||
port.addEventListener(this);
|
||||
} catch (Exception e) {
|
||||
} catch (SerialPortException e) {
|
||||
if (e.getPortName().startsWith("/dev") && SerialPortException.TYPE_PERMISSION_DENIED.equals(e.getExceptionType())) {
|
||||
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission"), iname));
|
||||
}
|
||||
throw new SerialException(I18n.format(_("Error opening serial port ''{0}''."), iname), e);
|
||||
}
|
||||
|
||||
@ -176,9 +170,6 @@ public class Serial implements SerialPortEventListener {
|
||||
/**
|
||||
* This method is intented to be extended to receive messages
|
||||
* coming from serial port.
|
||||
*
|
||||
* @param chars
|
||||
* @param length
|
||||
*/
|
||||
protected void message(char[] chars, int length) {
|
||||
// Empty
|
||||
@ -197,7 +188,7 @@ public class Serial implements SerialPortEventListener {
|
||||
}
|
||||
|
||||
|
||||
public void write(byte bytes[]) {
|
||||
private void write(byte bytes[]) {
|
||||
try {
|
||||
port.writeBytes(bytes);
|
||||
} catch (SerialPortException e) {
|
||||
@ -213,7 +204,7 @@ public class Serial implements SerialPortEventListener {
|
||||
* (most often the case for networking and serial i/o) and
|
||||
* will only use the bottom 8 bits of each char in the string.
|
||||
* (Meaning that internally it uses String.getBytes)
|
||||
* <p/>
|
||||
* <p>
|
||||
* If you want to move Unicode data, you can first convert the
|
||||
* String to a byte stream in the representation of your choice
|
||||
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
|
||||
@ -247,92 +238,8 @@ public class Serial implements SerialPortEventListener {
|
||||
* General error reporting, all corraled here just in case
|
||||
* I think of something slightly more intelligent to do.
|
||||
*/
|
||||
static public void errorMessage(String where, Throwable e) {
|
||||
private static void errorMessage(String where, Throwable e) {
|
||||
System.err.println(I18n.format(_("Error inside Serial.{0}()"), where));
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
class SerialMenuListener implements ItemListener {
|
||||
//public SerialMenuListener() { }
|
||||
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
int count = serialMenu.getItemCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
((CheckboxMenuItem)serialMenu.getItem(i)).setState(false);
|
||||
}
|
||||
CheckboxMenuItem item = (CheckboxMenuItem)e.getSource();
|
||||
item.setState(true);
|
||||
String name = item.getLabel();
|
||||
//System.out.println(item.getLabel());
|
||||
PdeBase.properties.put("serial.port", name);
|
||||
//System.out.println("set to " + get("serial.port"));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
protected Vector buildPortList() {
|
||||
// get list of names for serial ports
|
||||
// have the default port checked (if present)
|
||||
Vector list = new Vector();
|
||||
|
||||
//SerialMenuListener listener = new SerialMenuListener();
|
||||
boolean problem = false;
|
||||
|
||||
// if this is failing, it may be because
|
||||
// lib/javax.comm.properties is missing.
|
||||
// java is weird about how it searches for java.comm.properties
|
||||
// so it tends to be very fragile. i.e. quotes in the CLASSPATH
|
||||
// environment variable will hose things.
|
||||
try {
|
||||
//System.out.println("building port list");
|
||||
Enumeration portList = CommPortIdentifier.getPortIdentifiers();
|
||||
while (portList.hasMoreElements()) {
|
||||
CommPortIdentifier portId =
|
||||
(CommPortIdentifier) portList.nextElement();
|
||||
//System.out.println(portId);
|
||||
|
||||
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
||||
//if (portId.getName().equals(port)) {
|
||||
String name = portId.getName();
|
||||
//CheckboxMenuItem mi =
|
||||
//new CheckboxMenuItem(name, name.equals(defaultName));
|
||||
|
||||
//mi.addItemListener(listener);
|
||||
//serialMenu.add(mi);
|
||||
list.addElement(name);
|
||||
}
|
||||
}
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
e.printStackTrace();
|
||||
problem = true;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("exception building serial menu");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//if (serialMenu.getItemCount() == 0) {
|
||||
//System.out.println("dimming serial menu");
|
||||
//serialMenu.setEnabled(false);
|
||||
//}
|
||||
|
||||
// only warn them if this is the first time
|
||||
if (problem && PdeBase.firstTime) {
|
||||
JOptionPane.showMessageDialog(this, //frame,
|
||||
"Serial port support not installed.\n" +
|
||||
"Check the readme for instructions\n" +
|
||||
"if you need to use the serial port. ",
|
||||
"Serial Port Warning",
|
||||
JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
@ -22,31 +22,37 @@
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
import processing.app.helpers.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
/**
|
||||
* Represents a single tab of a sketch.
|
||||
* Represents a single tab of a sketch.
|
||||
*/
|
||||
public class SketchCode {
|
||||
|
||||
/** Pretty name (no extension), not the full file name */
|
||||
private String prettyName;
|
||||
|
||||
/** File object for where this code is located */
|
||||
/**
|
||||
* File object for where this code is located
|
||||
*/
|
||||
private File file;
|
||||
|
||||
/** Text of the program text for this tab */
|
||||
/**
|
||||
* Text of the program text for this tab
|
||||
*/
|
||||
private String program;
|
||||
|
||||
private boolean modified;
|
||||
|
||||
/** where this code starts relative to the concat'd code */
|
||||
private int preprocOffset;
|
||||
/**
|
||||
* where this code starts relative to the concat'd code
|
||||
*/
|
||||
private int preprocOffset;
|
||||
|
||||
private Object metadata;
|
||||
|
||||
@ -62,8 +68,6 @@ public class SketchCode {
|
||||
this.file = file;
|
||||
this.metadata = metadata;
|
||||
|
||||
makePrettyName();
|
||||
|
||||
try {
|
||||
load();
|
||||
} catch (IOException e) {
|
||||
@ -73,28 +77,21 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
protected void makePrettyName() {
|
||||
prettyName = file.getName();
|
||||
int dot = prettyName.lastIndexOf('.');
|
||||
prettyName = prettyName.substring(0, dot);
|
||||
}
|
||||
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean fileExists() {
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean fileReadOnly() {
|
||||
return !file.canWrite();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean deleteFile(File tempBuildFolder) {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
@ -106,38 +103,42 @@ public class SketchCode {
|
||||
}
|
||||
});
|
||||
for (File compiledFile : compiledFiles) {
|
||||
compiledFile.delete();
|
||||
if (!compiledFile.delete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
protected boolean renameTo(File what) {
|
||||
boolean success = file.renameTo(what);
|
||||
if (success) {
|
||||
file = what;
|
||||
makePrettyName();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
protected void copyTo(File dest) throws IOException {
|
||||
BaseNoGui.saveFile(program, dest);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getFileName() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getPrettyName() {
|
||||
return prettyName;
|
||||
String prettyName = getFileName();
|
||||
int dot = prettyName.lastIndexOf('.');
|
||||
return prettyName.substring(0, dot);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getFileNameWithExtensionIfNotIno() {
|
||||
if (getFileName().endsWith(".ino")) {
|
||||
return getPrettyName();
|
||||
}
|
||||
return getFileName();
|
||||
}
|
||||
|
||||
public boolean isExtension(String... extensions) {
|
||||
return isExtension(Arrays.asList(extensions));
|
||||
}
|
||||
@ -145,23 +146,23 @@ public class SketchCode {
|
||||
public boolean isExtension(List<String> extensions) {
|
||||
return FileUtils.hasExtension(file, extensions);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String getProgram() {
|
||||
return program;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setProgram(String replacement) {
|
||||
program = replacement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int getLineCount() {
|
||||
return BaseNoGui.countLines(program);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setModified(boolean modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
@ -177,25 +178,21 @@ public class SketchCode {
|
||||
}
|
||||
|
||||
|
||||
public int getPreprocOffset() {
|
||||
return preprocOffset;
|
||||
}
|
||||
|
||||
|
||||
public void addPreprocOffset(int extra) {
|
||||
preprocOffset += extra;
|
||||
}
|
||||
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
|
||||
/**
|
||||
* Load this piece of code from a file.
|
||||
*/
|
||||
public void load() throws IOException {
|
||||
private void load() throws IOException {
|
||||
program = BaseNoGui.loadFile(file);
|
||||
|
||||
if (program == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
if (program.indexOf('\uFFFD') != -1) {
|
||||
System.err.println(
|
||||
I18n.format(
|
||||
@ -209,7 +206,7 @@ public class SketchCode {
|
||||
);
|
||||
System.err.println();
|
||||
}
|
||||
|
||||
|
||||
setModified(false);
|
||||
}
|
||||
|
||||
|
@ -1,17 +1,19 @@
|
||||
package processing.app;
|
||||
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class SketchData {
|
||||
|
||||
public static final List<String> SKETCH_EXTENSIONS = Arrays.asList("ino", "pde");
|
||||
public static final List<String> OTHER_ALLOWED_EXTENSIONS = Arrays.asList("c", "cpp", "h", "s");
|
||||
public static final List<String> EXTENSIONS = new LinkedList<String>(FluentIterable.from(SKETCH_EXTENSIONS).append(OTHER_ALLOWED_EXTENSIONS).toList());
|
||||
|
||||
/** main pde file for this sketch. */
|
||||
private File primaryFile;
|
||||
|
||||
@ -95,6 +97,9 @@ public class SketchData {
|
||||
|
||||
// get list of files in the sketch folder
|
||||
String list[] = folder.list();
|
||||
if (list == null) {
|
||||
throw new IOException("Unable to list files from " + folder);
|
||||
}
|
||||
|
||||
// reset these because load() may be called after an
|
||||
// external editor event. (fix for 0099)
|
||||
@ -102,8 +107,6 @@ public class SketchData {
|
||||
clearCodeDocs();
|
||||
// data.setCodeDocs(codeDocs);
|
||||
|
||||
List<String> extensions = getExtensions();
|
||||
|
||||
for (String filename : list) {
|
||||
// Ignoring the dot prefix files is especially important to avoid files
|
||||
// with the ._ prefix on Mac OS X. (You'll see this with Mac files on
|
||||
@ -116,7 +119,7 @@ public class SketchData {
|
||||
// figure out the name without any extension
|
||||
String base = filename;
|
||||
// now strip off the .pde and .java extensions
|
||||
for (String extension : extensions) {
|
||||
for (String extension : EXTENSIONS) {
|
||||
if (base.toLowerCase().endsWith("." + extension)) {
|
||||
base = base.substring(0, base.length() - (extension.length() + 1));
|
||||
|
||||
@ -170,13 +173,6 @@ public class SketchData {
|
||||
return "ino";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String[] array of proper extensions.
|
||||
*/
|
||||
public List<String> getExtensions() {
|
||||
return Arrays.asList("ino", "pde", "c", "cpp", "h");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a file object for the primary .pde of this sketch.
|
||||
*/
|
||||
|
@ -34,14 +34,16 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import cc.arduino.MyStreamPumper;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import cc.arduino.packages.Uploader;
|
||||
import cc.arduino.packages.UploaderFactory;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import org.apache.commons.exec.*;
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.I18n;
|
||||
import processing.app.PreferencesData;
|
||||
@ -100,12 +102,14 @@ public class Compiler implements MessageConsumer {
|
||||
compiler.cleanup(prefsChanged, tempBuildFolder);
|
||||
|
||||
if (prefsChanged) {
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
PrintWriter out = new PrintWriter(buildPrefsFile);
|
||||
out = new PrintWriter(buildPrefsFile);
|
||||
out.print(newBuildPrefs);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println(_("Could not write build preferences file"));
|
||||
} finally {
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,15 +135,12 @@ public class Compiler implements MessageConsumer {
|
||||
TargetPlatform target = BaseNoGui.getTargetPlatform();
|
||||
String board = PreferencesData.get("board");
|
||||
|
||||
if (noUploadPort)
|
||||
{
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), null, noUploadPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
BoardPort boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
BoardPort boardPort = null;
|
||||
if (!noUploadPort) {
|
||||
boardPort = BaseNoGui.getDiscoveryManager().find(PreferencesData.get("serial.port"));
|
||||
}
|
||||
|
||||
return new UploaderFactory().newUploader(target.getBoards().get(board), boardPort, noUploadPort);
|
||||
}
|
||||
|
||||
static public boolean upload(SketchData data, Uploader uploader, String buildPath, String suggestedClassName, boolean usingProgrammer, boolean noUploadPort, List<String> warningsAccumulator) throws Exception {
|
||||
@ -151,7 +152,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
if (uploader.requiresAuthorization() && !PreferencesData.has(uploader.getAuthorizationKey())) {
|
||||
BaseNoGui.showError(_("Authorization required"),
|
||||
_("No athorization data found"), null);
|
||||
_("No authorization data found"), null);
|
||||
}
|
||||
|
||||
boolean useNewWarningsAccumulator = false;
|
||||
@ -277,11 +278,13 @@ public class Compiler implements MessageConsumer {
|
||||
// used. Keep everything else, which might be reusable
|
||||
if (tempBuildFolder.exists()) {
|
||||
String files[] = tempBuildFolder.list();
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
|
||||
File deleteMe = new File(tempBuildFolder, file);
|
||||
if (!deleteMe.delete()) {
|
||||
System.err.println("Could not delete " + deleteMe);
|
||||
if (files != null) {
|
||||
for (String file : files) {
|
||||
if (file.endsWith(".c") || file.endsWith(".cpp") || file.endsWith(".s")) {
|
||||
File deleteMe = new File(tempBuildFolder, file);
|
||||
if (!deleteMe.delete()) {
|
||||
System.err.println("Could not delete " + deleteMe);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -399,26 +402,44 @@ public class Compiler implements MessageConsumer {
|
||||
System.err.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
runActions("hooks.sketch.prebuild", prefs);
|
||||
|
||||
// 1. compile the sketch (already in the buildPath)
|
||||
progressListener.progress(20);
|
||||
compileSketch(includeFolders);
|
||||
sketchIsCompiled = true;
|
||||
|
||||
runActions("hooks.sketch.postbuild", prefs);
|
||||
|
||||
runActions("hooks.libraries.prebuild", prefs);
|
||||
|
||||
// 2. compile the libraries, outputting .o files to: <buildPath>/<library>/
|
||||
// Doesn't really use configPreferences
|
||||
progressListener.progress(30);
|
||||
compileLibraries(includeFolders);
|
||||
|
||||
runActions("hooks.libraries.postbuild", prefs);
|
||||
|
||||
runActions("hooks.core.prebuild", prefs);
|
||||
|
||||
// 3. compile the core, outputting .o files to <buildPath> and then
|
||||
// collecting them into the core.a library file.
|
||||
progressListener.progress(40);
|
||||
compileCore();
|
||||
|
||||
runActions("hooks.core.postbuild", prefs);
|
||||
|
||||
runActions("hooks.linking.prelink", prefs);
|
||||
|
||||
// 4. link it all together into the .elf file
|
||||
progressListener.progress(50);
|
||||
compileLink();
|
||||
|
||||
runActions("hooks.linking.postlink", prefs);
|
||||
|
||||
runActions("hooks.objcopy.preobjcopy", prefs);
|
||||
|
||||
// 5. run objcopy to generate output files
|
||||
progressListener.progress(60);
|
||||
List<String> objcopyPatterns = new ArrayList<String>();
|
||||
@ -431,10 +452,16 @@ public class Compiler implements MessageConsumer {
|
||||
runRecipe(recipe);
|
||||
}
|
||||
|
||||
runActions("hooks.objcopy.postobjcopy", prefs);
|
||||
|
||||
// 7. save the hex file
|
||||
if (saveHex) {
|
||||
runActions("hooks.savehex.presavehex", prefs);
|
||||
|
||||
progressListener.progress(80);
|
||||
saveHex();
|
||||
|
||||
runActions("hooks.savehex.postsavehex", prefs);
|
||||
}
|
||||
|
||||
progressListener.progress(90);
|
||||
@ -557,6 +584,17 @@ public class Compiler implements MessageConsumer {
|
||||
p.put("build.variant.path", "");
|
||||
}
|
||||
|
||||
// Build Time
|
||||
Date d = new Date();
|
||||
GregorianCalendar cal = new GregorianCalendar();
|
||||
long current = d.getTime()/1000;
|
||||
long timezone = cal.get(cal.ZONE_OFFSET)/1000;
|
||||
long daylight = cal.get(cal.DST_OFFSET)/1000;
|
||||
p.put("extra.time.utc", Long.toString(current));
|
||||
p.put("extra.time.local", Long.toString(current + timezone + daylight));
|
||||
p.put("extra.time.zone", Long.toString(timezone));
|
||||
p.put("extra.time.dst", Long.toString(daylight));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
@ -617,6 +655,7 @@ public class Compiler implements MessageConsumer {
|
||||
|
||||
private boolean isAlreadyCompiled(File src, File obj, File dep, Map<String, String> prefs) {
|
||||
boolean ret=true;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
//System.out.println("\n isAlreadyCompiled: begin checks: " + obj.getPath());
|
||||
if (!obj.exists()) return false; // object file (.o) does not exist
|
||||
@ -625,7 +664,7 @@ public class Compiler implements MessageConsumer {
|
||||
long obj_modified = obj.lastModified();
|
||||
if (src_modified >= obj_modified) return false; // source modified since object compiled
|
||||
if (src_modified >= dep.lastModified()) return false; // src modified since dep compiled
|
||||
BufferedReader reader = new BufferedReader(new FileReader(dep.getPath()));
|
||||
reader = new BufferedReader(new FileReader(dep.getPath()));
|
||||
String line;
|
||||
boolean need_obj_parse = true;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
@ -669,9 +708,10 @@ public class Compiler implements MessageConsumer {
|
||||
//System.out.println(" isAlreadyCompiled: prerequisite ok");
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
} catch (Exception e) {
|
||||
return false; // any error reading dep file = recompile it
|
||||
} finally {
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
if (ret && verbose) {
|
||||
System.out.println(I18n.format(_("Using previously compiled file: {0}"), obj.getPath()));
|
||||
@ -703,37 +743,13 @@ public class Compiler implements MessageConsumer {
|
||||
}
|
||||
|
||||
DefaultExecutor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream os) throws IOException {
|
||||
|
||||
}
|
||||
executor.setStreamHandler(new PumpStreamHandler() {
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream is) throws IOException {
|
||||
forwardToMessage(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream is) throws IOException {
|
||||
forwardToMessage(is);
|
||||
}
|
||||
|
||||
private void forwardToMessage(InputStream is) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
message(line + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
protected Thread createPump(InputStream is, OutputStream os, boolean closeWhenExhausted) {
|
||||
final Thread result = new Thread(new MyStreamPumper(is, Compiler.this));
|
||||
result.setDaemon(true);
|
||||
return result;
|
||||
|
||||
}
|
||||
});
|
||||
@ -1149,6 +1165,7 @@ public class Compiler implements MessageConsumer {
|
||||
void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
|
||||
PreferencesMap dict = new PreferencesMap(prefs);
|
||||
dict.put("ide_version", "" + BaseNoGui.REVISION);
|
||||
dict.put("sketch_path", sketch.getFolder().getAbsolutePath());
|
||||
|
||||
String[] cmdArray;
|
||||
String cmd = prefs.getOrExcept(recipe);
|
||||
@ -1226,7 +1243,7 @@ public class Compiler implements MessageConsumer {
|
||||
StringBuffer bigCode = new StringBuffer();
|
||||
int bigCount = 0;
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("ino") || sc.isExtension("pde")) {
|
||||
if (sc.isExtension(SketchData.SKETCH_EXTENSIONS)) {
|
||||
sc.setPreprocOffset(bigCount);
|
||||
// These #line directives help the compiler report errors with
|
||||
// correct the filename and line number (issue 281 & 907)
|
||||
@ -1272,13 +1289,7 @@ public class Compiler implements MessageConsumer {
|
||||
ex.printStackTrace();
|
||||
throw new RunnerException(ex.toString());
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
|
||||
// grab the imports from the code just preproc'd
|
||||
@ -1303,7 +1314,7 @@ public class Compiler implements MessageConsumer {
|
||||
// 3. then loop over the code[] and save each .java file
|
||||
|
||||
for (SketchCode sc : sketch.getCodes()) {
|
||||
if (sc.isExtension("c") || sc.isExtension("cpp") || sc.isExtension("h")) {
|
||||
if (sc.isExtension(SketchData.OTHER_ALLOWED_EXTENSIONS)) {
|
||||
// no pre-processing services necessary for java files
|
||||
// just write the the contents of 'program' to a .java file
|
||||
// into the build directory. uses byte stream and reader/writer
|
||||
|
@ -58,7 +58,7 @@ public class LegacyTargetBoard implements TargetBoard {
|
||||
String board = containerPlatform.getId() + "_" + id;
|
||||
board = board.toUpperCase();
|
||||
prefs.put("build.board", board);
|
||||
System.out
|
||||
System.err
|
||||
.println(format(_("Board {0}:{1}:{2} doesn''t define a ''build.board'' preference. Auto-set to: {3}"),
|
||||
containerPlatform.getContainerPackage().getId(),
|
||||
containerPlatform.getId(), id, board));
|
||||
|
@ -51,7 +51,7 @@ public class LegacyTargetPackage implements TargetPackage {
|
||||
TargetPlatform platform = new LegacyTargetPlatform(arch, subFolder, this);
|
||||
platforms.put(arch, platform);
|
||||
} catch (TargetPlatformException e) {
|
||||
System.out.println(e.getMessage());
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,7 @@ import processing.app.debug.TargetPlatform;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@ -32,6 +29,8 @@ public class CommandlineParser {
|
||||
}
|
||||
}
|
||||
|
||||
private final String[] args;
|
||||
private final Map<String, ACTION> actions;
|
||||
private ACTION action = ACTION.GUI;
|
||||
private boolean doVerboseBuild = false;
|
||||
private boolean doVerboseUpload = false;
|
||||
@ -44,39 +43,32 @@ public class CommandlineParser {
|
||||
private String libraryToInstall;
|
||||
private List<String> filenames = new LinkedList<String>();
|
||||
|
||||
public static CommandlineParser newCommandlineParser(String[] args) {
|
||||
return new CommandlineParser(args);
|
||||
}
|
||||
public CommandlineParser(String[] args) {
|
||||
this.args = args;
|
||||
|
||||
private CommandlineParser(String[] args) {
|
||||
parseArguments(args);
|
||||
checkAction();
|
||||
}
|
||||
|
||||
private void parseArguments(String[] args) {
|
||||
// Map of possible actions and corresponding options
|
||||
final Map<String, ACTION> actions = new HashMap<String, ACTION>();
|
||||
actions = new HashMap<String, ACTION>();
|
||||
actions.put("--verify", ACTION.VERIFY);
|
||||
actions.put("--upload", ACTION.UPLOAD);
|
||||
actions.put("--get-pref", ACTION.GET_PREF);
|
||||
actions.put("--install-boards", ACTION.INSTALL_BOARD);
|
||||
actions.put("--install-library", ACTION.INSTALL_LIBRARY);
|
||||
}
|
||||
|
||||
// Check if any files were passed in on the command line
|
||||
public void parseArgumentsPhase1() {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
ACTION a = actions.get(args[i]);
|
||||
if (a != null) {
|
||||
if (action != ACTION.GUI && action != ACTION.NOOP) {
|
||||
String[] valid = actions.keySet().toArray(new String[0]);
|
||||
Set<String> strings = actions.keySet();
|
||||
String[] valid = strings.toArray(new String[strings.size()]);
|
||||
String mess = I18n.format(_("Can only pass one of: {0}"), PApplet.join(valid, ", "));
|
||||
BaseNoGui.showError(null, mess, 3);
|
||||
}
|
||||
if (a == ACTION.GET_PREF) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, I18n.format(_("Argument required for {0}"), a.value), 3);
|
||||
if (i < args.length) {
|
||||
getPref = args[i];
|
||||
}
|
||||
getPref = args[i];
|
||||
}
|
||||
if (a == ACTION.INSTALL_BOARD) {
|
||||
i++;
|
||||
@ -140,7 +132,6 @@ public class CommandlineParser {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
BaseNoGui.showError(null, _("Argument required for --board"), 3);
|
||||
processBoardArgument(args[i]);
|
||||
if (action == ACTION.GUI)
|
||||
action = ACTION.NOOP;
|
||||
continue;
|
||||
@ -201,6 +192,23 @@ public class CommandlineParser {
|
||||
|
||||
filenames.add(args[i]);
|
||||
}
|
||||
|
||||
checkAction();
|
||||
}
|
||||
|
||||
public void parseArgumentsPhase2() {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
if (args[i].equals("--board")) {
|
||||
i++;
|
||||
if (i >= args.length) {
|
||||
BaseNoGui.showError(null, _("Argument required for --board"), 3);
|
||||
}
|
||||
processBoardArgument(args[i]);
|
||||
if (action == ACTION.GUI) {
|
||||
action = ACTION.NOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAction() {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -49,12 +51,8 @@ public class FileUtils {
|
||||
fos.write(buf, 0, readBytes);
|
||||
}
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
if (fos != null) {
|
||||
fos.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fis);
|
||||
IOUtils.closeQuietly(fos);
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +169,15 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
public static boolean isSCCSOrHiddenFile(File file) {
|
||||
return file.isHidden() || file.getName().charAt(0) == '.' || (file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName()));
|
||||
return isSCCSFolder(file) || isHiddenFile(file);
|
||||
}
|
||||
|
||||
public static boolean isHiddenFile(File file) {
|
||||
return file.isHidden() || file.getName().charAt(0) == '.';
|
||||
}
|
||||
|
||||
public static boolean isSCCSFolder(File file) {
|
||||
return file.isDirectory() && SOURCE_CONTROL_FOLDERS.contains(file.getName());
|
||||
}
|
||||
|
||||
public static String readFileToString(File file) throws IOException {
|
||||
@ -185,13 +191,7 @@ public class FileUtils {
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
package processing.app.helpers;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
import processing.app.legacy.PApplet;
|
||||
|
||||
import java.io.*;
|
||||
@ -72,9 +73,7 @@ public class PreferencesMap extends LinkedHashMap<String, String> {
|
||||
fileInputStream = new FileInputStream(file);
|
||||
load(fileInputStream);
|
||||
} finally {
|
||||
if (fileInputStream != null) {
|
||||
fileInputStream.close();
|
||||
}
|
||||
IOUtils.closeQuietly(fileInputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package processing.app.legacy;
|
||||
|
||||
import org.apache.commons.compress.utils.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -272,13 +274,7 @@ public class PApplet {
|
||||
if (is != null) return loadStrings(is);
|
||||
return null;
|
||||
} finally {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(is);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,14 +308,7 @@ public class PApplet {
|
||||
e.printStackTrace();
|
||||
//throw new RuntimeException("Error inside loadStrings()");
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
//ignore
|
||||
}
|
||||
}
|
||||
|
||||
IOUtils.closeQuietly(reader);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -335,27 +324,25 @@ public class PApplet {
|
||||
outputStream = createOutput(file);
|
||||
saveStrings(outputStream, strings);
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
//noop
|
||||
}
|
||||
}
|
||||
IOUtils.closeQuietly(outputStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public void saveStrings(OutputStream output, String strings[]) {
|
||||
PrintWriter writer = createWriter(output);
|
||||
if (writer == null) {
|
||||
return;
|
||||
PrintWriter writer = null;
|
||||
try {
|
||||
writer = createWriter(output);
|
||||
if (writer == null) {
|
||||
return;
|
||||
}
|
||||
for (String string : strings) {
|
||||
writer.println(string);
|
||||
}
|
||||
writer.flush();
|
||||
} finally {
|
||||
IOUtils.closeQuietly(writer);
|
||||
}
|
||||
for (String string : strings) {
|
||||
writer.println(string);
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,11 +23,12 @@
|
||||
package processing.app.linux;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import processing.app.PreferencesData;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@ -124,7 +125,8 @@ public class Platform extends processing.app.Platform {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
assert packages != null;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial);
|
||||
|
@ -25,19 +25,23 @@ package processing.app.macosx;
|
||||
import cc.arduino.packages.BoardPort;
|
||||
import com.apple.eio.FileManager;
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@ -57,6 +61,8 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
|
||||
public void init() throws IOException {
|
||||
super.init();
|
||||
|
||||
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
||||
|
||||
discoverRealOsArch();
|
||||
@ -65,7 +71,8 @@ public class Platform extends processing.app.Platform {
|
||||
private void discoverRealOsArch() throws IOException {
|
||||
CommandLine uname = CommandLine.parse("uname -m");
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
CollectStdOutExecutor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
executor.execute(uname);
|
||||
osArch = StringUtils.trim(new String(baos.toByteArray()));
|
||||
}
|
||||
@ -94,45 +101,13 @@ public class Platform extends processing.app.Platform {
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
if (PApplet.javaVersion < 1.6f) {
|
||||
if (url.startsWith("http")) {
|
||||
// formerly com.apple.eio.FileManager.openURL(url);
|
||||
// but due to deprecation, instead loading dynamically
|
||||
try {
|
||||
Class<?> eieio = Class.forName("com.apple.eio.FileManager");
|
||||
Method openMethod =
|
||||
eieio.getMethod("openURL", new Class[] { String.class });
|
||||
openMethod.invoke(null, new Object[] { url });
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// Assume this is a file instead, and just open it.
|
||||
// Extension of http://dev.processing.org/bugs/show_bug.cgi?id=1010
|
||||
PApplet.open(url);
|
||||
}
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
if (url.startsWith("http") || url.startsWith("file:")) {
|
||||
desktop.browse(new URI(url));
|
||||
} else {
|
||||
try {
|
||||
Class<?> desktopClass = Class.forName("java.awt.Desktop");
|
||||
Method getMethod = desktopClass.getMethod("getDesktop");
|
||||
Object desktop = getMethod.invoke(null, new Object[] { });
|
||||
|
||||
// for Java 1.6, replacing with java.awt.Desktop.browse()
|
||||
// and java.awt.Desktop.open()
|
||||
if (url.startsWith("http")) { // browse to a location
|
||||
Method browseMethod =
|
||||
desktopClass.getMethod("browse", new Class[] { URI.class });
|
||||
browseMethod.invoke(desktop, new Object[] { new URI(url) });
|
||||
} else { // open a file
|
||||
Method openMethod =
|
||||
desktopClass.getMethod("open", new Class[] { File.class });
|
||||
openMethod.invoke(desktop, new Object[] { new File(url) });
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
desktop.open(new File(url));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean openFolderAvailable() {
|
||||
@ -152,13 +127,13 @@ public class Platform extends processing.app.Platform {
|
||||
// Some of these are supposedly constants in com.apple.eio.FileManager,
|
||||
// however they don't seem to link properly from Eclipse.
|
||||
|
||||
static final int kDocumentsFolderType =
|
||||
private static final int kDocumentsFolderType =
|
||||
('d' << 24) | ('o' << 16) | ('c' << 8) | 's';
|
||||
//static final int kPreferencesFolderType =
|
||||
// ('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
|
||||
static final int kDomainLibraryFolderType =
|
||||
private static final int kDomainLibraryFolderType =
|
||||
('d' << 24) | ('l' << 16) | ('i' << 8) | 'b';
|
||||
static final short kUserDomain = -32763;
|
||||
private static final short kUserDomain = -32763;
|
||||
|
||||
|
||||
// apple java extensions documentation
|
||||
@ -175,12 +150,12 @@ public class Platform extends processing.app.Platform {
|
||||
// /Versions/Current/Frameworks/CarbonCore.framework/Headers/
|
||||
|
||||
|
||||
protected String getLibraryFolder() throws FileNotFoundException {
|
||||
private String getLibraryFolder() throws FileNotFoundException {
|
||||
return FileManager.findFolder(kUserDomain, kDomainLibraryFolderType);
|
||||
}
|
||||
|
||||
|
||||
protected String getDocumentsFolder() throws FileNotFoundException {
|
||||
private String getDocumentsFolder() throws FileNotFoundException {
|
||||
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
|
||||
}
|
||||
|
||||
@ -193,7 +168,7 @@ public class Platform extends processing.app.Platform {
|
||||
public Map<String, Object> resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages, String devicesListOutput) {
|
||||
assert packages != null;
|
||||
if (devicesListOutput == null) {
|
||||
return super.resolveDeviceAttachedTo(serial, packages, devicesListOutput);
|
||||
return super.resolveDeviceAttachedTo(serial, packages, null);
|
||||
}
|
||||
|
||||
try {
|
||||
@ -212,7 +187,8 @@ public class Platform extends processing.app.Platform {
|
||||
@Override
|
||||
public String preListAllCandidateDevices() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
CommandLine toDevicePath = CommandLine.parse("/usr/sbin/system_profiler SPUSBDataType");
|
||||
|
@ -55,7 +55,7 @@ public class SystemProfilerParser {
|
||||
|
||||
if ((matcher = serialNumberRegex.matcher(line)).matches()) {
|
||||
device.put(SERIAL_NUMBER, matcher.group(1));
|
||||
if ((serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL))) {
|
||||
if (serial.startsWith(DEV_TTY_USBSERIAL) || serial.startsWith(DEV_CU_USBSERIAL)) {
|
||||
String devicePath = devicePrefix + matcher.group(1);
|
||||
device.put(DEVICE_PATH, devicePath);
|
||||
}
|
||||
@ -65,17 +65,24 @@ public class SystemProfilerParser {
|
||||
device.put(DEVICE_PATH, devicePath);
|
||||
} else if ((matcher = pidRegex.matcher(line)).matches()) {
|
||||
String pid = matcher.group(1);
|
||||
if (pid.indexOf(" ") > 0)
|
||||
if (pid.indexOf(" ") > 0) {
|
||||
pid = pid.substring(0, pid.indexOf(" ")); // Remove any text after the hex number
|
||||
}
|
||||
device.put(PID, pid);
|
||||
} else if ((matcher = vidRegex.matcher(line)).matches()) {
|
||||
String vid = matcher.group(1);
|
||||
if (vid.indexOf(" ") > 0)
|
||||
if (vid.indexOf(" ") > 0) {
|
||||
vid = vid.substring(0, vid.indexOf(" ")); // Remove any text after the hex number
|
||||
}
|
||||
device.put(VID, vid);
|
||||
} else if (line.equals("")) {
|
||||
if (device.containsKey(DEVICE_PATH) && device.get(DEVICE_PATH).equals(serial)) {
|
||||
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
|
||||
if (device.containsKey(DEVICE_PATH)) {
|
||||
String computedDevicePath = device.get(DEVICE_PATH);
|
||||
String computedDevicePathMinusChar = computedDevicePath.substring(0, computedDevicePath.length() - 1);
|
||||
String serialMinusChar = serial.substring(0, serial.length() - 1);
|
||||
if (computedDevicePath.equals(serial) || computedDevicePathMinusChar.equals(serialMinusChar)) {
|
||||
return (device.get(VID) + "_" + device.get(PID)).toUpperCase();
|
||||
}
|
||||
}
|
||||
device = new HashMap<String, String>();
|
||||
}
|
||||
|
@ -32,8 +32,6 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import cc.arduino.contributions.libraries.ContributedLibraryReference;
|
||||
|
||||
public class LegacyUserLibrary extends UserLibrary {
|
||||
|
||||
private String name;
|
||||
@ -45,6 +43,8 @@ public class LegacyUserLibrary extends UserLibrary {
|
||||
res.setInstalled(true);
|
||||
res.layout = LibraryLayout.FLAT;
|
||||
res.name = libFolder.getName();
|
||||
res.setTypes(Arrays.asList("Contributed"));
|
||||
res.setCategory("Uncategorized");
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -58,66 +58,6 @@ public class LegacyUserLibrary extends UserLibrary {
|
||||
return Arrays.asList("*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParagraph() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSentence() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWebsite() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "Uncategorized";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLicense() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMaintainer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChecksum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContributedLibraryReference> getRequires() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LegacyLibrary:" + name + "\n";
|
||||
|
@ -56,13 +56,13 @@ public class UserLibrary extends ContributedLibrary {
|
||||
private List<String> declaredTypes;
|
||||
|
||||
private static final List<String> MANDATORY_PROPERTIES = Arrays
|
||||
.asList(new String[]{"name", "version", "author", "maintainer",
|
||||
"sentence", "paragraph", "url"});
|
||||
.asList("name", "version", "author", "maintainer",
|
||||
"sentence", "paragraph", "url");
|
||||
|
||||
private static final List<String> CATEGORIES = Arrays.asList(new String[]{
|
||||
"Display", "Communication", "Signal Input/Output", "Sensors",
|
||||
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
||||
"Uncategorized"});
|
||||
private static final List<String> CATEGORIES = Arrays.asList(
|
||||
"Display", "Communication", "Signal Input/Output", "Sensors",
|
||||
"Device Control", "Timing", "Data Storage", "Data Processing", "Other",
|
||||
"Uncategorized");
|
||||
|
||||
public static UserLibrary create(File libFolder) throws IOException {
|
||||
// Parse metadata
|
||||
@ -83,8 +83,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
// "arch" folder no longer supported
|
||||
File archFolder = new File(libFolder, "arch");
|
||||
if (archFolder.isDirectory())
|
||||
throw new IOException("'arch' folder is no longer supported! See "
|
||||
+ "http://goo.gl/gfFJzU for more information");
|
||||
throw new IOException("'arch' folder is no longer supported! See http://goo.gl/gfFJzU for more information");
|
||||
|
||||
// Check mandatory properties
|
||||
for (String p : MANDATORY_PROPERTIES)
|
||||
@ -101,8 +100,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
|
||||
File utilFolder = new File(libFolder, "utility");
|
||||
if (utilFolder.exists() && utilFolder.isDirectory()) {
|
||||
throw new IOException(
|
||||
"Library can't use both 'src' and 'utility' folders.");
|
||||
throw new IOException("Library can't use both 'src' and 'utility' folders.");
|
||||
}
|
||||
} else {
|
||||
// Layout with source code on library's root and "utility" folders
|
||||
@ -110,11 +108,14 @@ public class UserLibrary extends ContributedLibrary {
|
||||
}
|
||||
|
||||
// Warn if root folder contains development leftovers
|
||||
for (File file : libFolder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
if (FileUtils.isSCCSOrHiddenFile(file)) {
|
||||
File[] files = libFolder.listFiles();
|
||||
if (files == null) {
|
||||
throw new IOException("Unable to list files of library in " + libFolder);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory() && FileUtils.isSCCSOrHiddenFile(file)) {
|
||||
if (!FileUtils.isSCCSFolder(file) && FileUtils.isHiddenFile(file)) {
|
||||
System.out.println("WARNING: Spurious " + file.getName() + " folder in '" + properties.get("name") + "' library");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -131,8 +132,7 @@ public class UserLibrary extends ContributedLibrary {
|
||||
if (category == null)
|
||||
category = "Uncategorized";
|
||||
if (!CATEGORIES.contains(category)) {
|
||||
System.out.println("WARNING: Category '" + category + "' in library " +
|
||||
properties.get("name") + " is not valid. Setting to 'Uncategorized'");
|
||||
System.out.println("WARNING: Category '" + category + "' in library " + properties.get("name") + " is not valid. Setting to 'Uncategorized'");
|
||||
category = "Uncategorized";
|
||||
}
|
||||
|
||||
|
@ -1,44 +0,0 @@
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Handy process executor, collecting stdout into a given OutputStream
|
||||
*/
|
||||
public class CollectStdOutExecutor extends DefaultExecutor {
|
||||
|
||||
public CollectStdOutExecutor(final OutputStream stdout) {
|
||||
this.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stdout.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package processing.app.tools;
|
||||
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.ExecuteStreamHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
/**
|
||||
* Handy process executor, collecting stdout and stderr into given OutputStreams
|
||||
*/
|
||||
public class CollectStdOutStdErrExecutor extends DefaultExecutor {
|
||||
|
||||
public CollectStdOutStdErrExecutor(final OutputStream stdout, final OutputStream stderr) {
|
||||
this.setStreamHandler(new ExecuteStreamHandler() {
|
||||
@Override
|
||||
public void setProcessInputStream(OutputStream outputStream) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessErrorStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stderr.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setProcessOutputStream(InputStream inputStream) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
int bytes = -1;
|
||||
while ((bytes = inputStream.read(buf)) != -1) {
|
||||
stdout.write(buf, 0, bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -1,335 +0,0 @@
|
||||
package processing.app.windows;
|
||||
|
||||
/*
|
||||
* Advapi32.java
|
||||
*
|
||||
* Created on 6. August 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
import com.sun.jna.*;
|
||||
import com.sun.jna.ptr.*;
|
||||
import com.sun.jna.win32.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Advapi32 extends StdCallLibrary {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, Options.UNICODE_OPTIONS);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountName(
|
||||
LPCTSTR lpSystemName,
|
||||
LPCTSTR lpAccountName,
|
||||
PSID Sid,
|
||||
LPDWORD cbSid,
|
||||
LPTSTR ReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountName(String lpSystemName, String lpAccountName,
|
||||
byte[] Sid, IntByReference cbSid, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountSid(
|
||||
LPCTSTR lpSystemName,
|
||||
PSID lpSid,
|
||||
LPTSTR lpName,
|
||||
LPDWORD cchName,
|
||||
LPTSTR lpReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountSid(String lpSystemName, byte[] Sid,
|
||||
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL ConvertSidToStringSid(
|
||||
PSID Sid,
|
||||
LPTSTR* StringSid
|
||||
);*/
|
||||
public boolean ConvertSidToStringSid(byte[] Sid, PointerByReference StringSid);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ConvertStringSidToSid(
|
||||
LPCTSTR StringSid,
|
||||
PSID* Sid
|
||||
);*/
|
||||
public boolean ConvertStringSidToSid(String StringSid, PointerByReference Sid);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenSCManager(
|
||||
LPCTSTR lpMachineName,
|
||||
LPCTSTR lpDatabaseName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI CloseServiceHandle(
|
||||
SC_HANDLE hSCObject
|
||||
);*/
|
||||
public boolean CloseServiceHandle(Pointer hSCObject);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwNumServiceArgs,
|
||||
LPCTSTR* lpServiceArgVectors
|
||||
);*/
|
||||
public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ControlService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwControl,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartServiceCtrlDispatcher(
|
||||
const SERVICE_TABLE_ENTRY* lpServiceTable
|
||||
);*/
|
||||
public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION lpHandlerProc
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
|
||||
|
||||
/*
|
||||
BOOL WINAPI SetServiceStatus(
|
||||
SERVICE_STATUS_HANDLE hServiceStatus,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI CreateService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
LPCTSTR lpDisplayName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwServiceType,
|
||||
DWORD dwStartType,
|
||||
DWORD dwErrorControl,
|
||||
LPCTSTR lpBinaryPathName,
|
||||
LPCTSTR lpLoadOrderGroup,
|
||||
LPDWORD lpdwTagId,
|
||||
LPCTSTR lpDependencies,
|
||||
LPCTSTR lpServiceStartName,
|
||||
LPCTSTR lpPassword
|
||||
);*/
|
||||
public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
|
||||
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
|
||||
String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
|
||||
String lpDependencies, String lpServiceStartName, String lpPassword);
|
||||
|
||||
/*
|
||||
BOOL WINAPI DeleteService(
|
||||
SC_HANDLE hService
|
||||
);*/
|
||||
public boolean DeleteService(Pointer hService);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ChangeServiceConfig2(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwInfoLevel,
|
||||
LPVOID lpInfo
|
||||
);*/
|
||||
public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegOpenKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD ulOptions,
|
||||
REGSAM samDesired,
|
||||
PHKEY phkResult
|
||||
);*/
|
||||
public int RegOpenKeyEx(int hKey, String lpSubKey, int ulOptions, int samDesired, IntByReference phkResult);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegQueryValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegQueryValueEx(int hKey, String lpValueName, IntByReference lpReserved, IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCloseKey(
|
||||
HKEY hKey
|
||||
);*/
|
||||
public int RegCloseKey(int hKey);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteValue(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName
|
||||
);*/
|
||||
public int RegDeleteValue(int hKey, String lpValueName);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegSetValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
DWORD Reserved,
|
||||
DWORD dwType,
|
||||
const BYTE* lpData,
|
||||
DWORD cbData
|
||||
);*/
|
||||
public int RegSetValueEx(int hKey, String lpValueName, int Reserved, int dwType, byte[] lpData, int cbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCreateKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD Reserved,
|
||||
LPTSTR lpClass,
|
||||
DWORD dwOptions,
|
||||
REGSAM samDesired,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
PHKEY phkResult,
|
||||
LPDWORD lpdwDisposition
|
||||
);*/
|
||||
public int RegCreateKeyEx(int hKey, String lpSubKey, int Reserved, String lpClass, int dwOptions,
|
||||
int samDesired, WINBASE.SECURITY_ATTRIBUTES lpSecurityAttributes, IntByReference phkResult,
|
||||
IntByReference lpdwDisposition);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteKey(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey
|
||||
);*/
|
||||
public int RegDeleteKey(int hKey, String name);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumKeyEx(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpName,
|
||||
LPDWORD lpcName,
|
||||
LPDWORD lpReserved,
|
||||
LPTSTR lpClass,
|
||||
LPDWORD lpcClass,
|
||||
PFILETIME lpftLastWriteTime
|
||||
);*/
|
||||
public int RegEnumKeyEx(int hKey, int dwIndex, char[] lpName, IntByReference lpcName, IntByReference reserved,
|
||||
char[] lpClass, IntByReference lpcClass, WINBASE.FILETIME lpftLastWriteTime);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumValue(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpValueName,
|
||||
LPDWORD lpcchValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI ServiceMain(
|
||||
DWORD dwArgc,
|
||||
LPTSTR* lpszArgv
|
||||
);*/
|
||||
public void callback(int dwArgc, Pointer lpszArgv);
|
||||
}
|
||||
|
||||
interface Handler extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI Handler(
|
||||
DWORD fdwControl
|
||||
);*/
|
||||
public void callback(int fdwControl);
|
||||
}
|
||||
|
||||
interface HandlerEx extends StdCallCallback {
|
||||
/*
|
||||
DWORD WINAPI HandlerEx(
|
||||
DWORD dwControl,
|
||||
DWORD dwEventType,
|
||||
LPVOID lpEventData,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public void callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_STATUS {
|
||||
DWORD dwServiceType;
|
||||
DWORD dwCurrentState;
|
||||
DWORD dwControlsAccepted;
|
||||
DWORD dwWin32ExitCode;
|
||||
DWORD dwServiceSpecificExitCode;
|
||||
DWORD dwCheckPoint;
|
||||
DWORD dwWaitHint;
|
||||
} SERVICE_STATUS,
|
||||
*LPSERVICE_STATUS;*/
|
||||
public static class SERVICE_STATUS extends Structure {
|
||||
public int dwServiceType;
|
||||
public int dwCurrentState;
|
||||
public int dwControlsAccepted;
|
||||
public int dwWin32ExitCode;
|
||||
public int dwServiceSpecificExitCode;
|
||||
public int dwCheckPoint;
|
||||
public int dwWaitHint;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_TABLE_ENTRY {
|
||||
LPTSTR lpServiceName;
|
||||
LPSERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
} SERVICE_TABLE_ENTRY,
|
||||
*LPSERVICE_TABLE_ENTRY;*/
|
||||
public static class SERVICE_TABLE_ENTRY extends Structure {
|
||||
public String lpServiceName;
|
||||
public SERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
}
|
||||
|
||||
public static class ChangeServiceConfig2Info extends Structure {
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_DESCRIPTION {
|
||||
LPTSTR lpDescription;
|
||||
} SERVICE_DESCRIPTION,
|
||||
*LPSERVICE_DESCRIPTION;*/
|
||||
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
|
||||
public String lpDescription;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Options.java
|
||||
*
|
||||
* Created on 8. August 2007, 17:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
import static com.sun.jna.Library.*;
|
||||
import com.sun.jna.win32.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Options {
|
||||
@SuppressWarnings("serial")
|
||||
Map<String, Object> UNICODE_OPTIONS = new HashMap<String, Object>() {
|
||||
{
|
||||
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||
}
|
||||
};
|
||||
}
|
@ -23,127 +23,54 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
import org.apache.commons.exec.Executor;
|
||||
import processing.app.PreferencesData;
|
||||
import org.apache.commons.exec.PumpStreamHandler;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.legacy.PApplet;
|
||||
import processing.app.legacy.PConstants;
|
||||
import processing.app.tools.CollectStdOutExecutor;
|
||||
import processing.app.windows.Registry.REGISTRY_ROOT_KEY;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
// http://developer.apple.com/documentation/QuickTime/Conceptual/QT7Win_Update_Guide/Chapter03/chapter_3_section_1.html
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\Apple Computer, Inc.\QuickTime\QTSysDir
|
||||
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\CurrentVersion -> 1.6 (String)
|
||||
// HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit\CurrentVersion\1.6\JavaHome -> c:\jdk-1.6.0_05
|
||||
|
||||
public class Platform extends processing.app.Platform {
|
||||
|
||||
static final String openCommand =
|
||||
System.getProperty("user.dir").replace('/', '\\') +
|
||||
"\\arduino.exe \"%1\"";
|
||||
static final String DOC = "Arduino.Document";
|
||||
private File settingsFolder;
|
||||
private File defaultSketchbookFolder;
|
||||
|
||||
public void init() throws IOException {
|
||||
super.init();
|
||||
|
||||
checkAssociations();
|
||||
checkQuickTime();
|
||||
checkPath();
|
||||
recoverSettingsFolderPath();
|
||||
recoverDefaultSketchbookFolder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Make sure that .pde files are associated with processing.exe.
|
||||
*/
|
||||
protected void checkAssociations() {
|
||||
try {
|
||||
String knownCommand =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open\\command", "");
|
||||
if (knownCommand == null) {
|
||||
if (PreferencesData.getBoolean("platform.auto_file_type_associations")) {
|
||||
setAssociations();
|
||||
}
|
||||
|
||||
} else if (!knownCommand.equals(openCommand)) {
|
||||
// If the value is set differently, just change the registry setting.
|
||||
if (PreferencesData.getBoolean("platform.auto_file_type_associations")) {
|
||||
setAssociations();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
private void recoverSettingsFolderPath() throws IOException {
|
||||
String path = getFolderPathFromRegistry("AppData");
|
||||
this.settingsFolder = new File(path, "Arduino15");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associate .pde files with this version of Processing.
|
||||
*/
|
||||
protected void setAssociations() throws UnsupportedEncodingException {
|
||||
if (Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
"", ".ino") &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
".ino", "", DOC) &&
|
||||
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT, "", DOC) &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT, DOC, "",
|
||||
"Arduino Source Code") &&
|
||||
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC, "shell") &&
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell", "open") &&
|
||||
Registry.createKey(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open", "command") &&
|
||||
Registry.setStringValue(REGISTRY_ROOT_KEY.CLASSES_ROOT,
|
||||
DOC + "\\shell\\open\\command", "",
|
||||
openCommand)) {
|
||||
// everything ok
|
||||
// hooray!
|
||||
|
||||
} else {
|
||||
PreferencesData.setBoolean("platform.auto_file_type_associations", false);
|
||||
}
|
||||
private void recoverDefaultSketchbookFolder() throws IOException {
|
||||
String path = getFolderPathFromRegistry("Personal");
|
||||
this.defaultSketchbookFolder = new File(path, "Arduino");
|
||||
}
|
||||
|
||||
private String getFolderPathFromRegistry(String folderType) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
/**
|
||||
* Find QuickTime for Java installation.
|
||||
*/
|
||||
protected void checkQuickTime() {
|
||||
try {
|
||||
String qtsystemPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.LOCAL_MACHINE,
|
||||
"Software\\Apple Computer, Inc.\\QuickTime",
|
||||
"QTSysDir");
|
||||
// Could show a warning message here if QT not installed, but that
|
||||
// would annoy people who don't want anything to do with QuickTime.
|
||||
if (qtsystemPath != null) {
|
||||
File qtjavaZip = new File(qtsystemPath, "QTJava.zip");
|
||||
if (qtjavaZip.exists()) {
|
||||
String qtjavaZipPath = qtjavaZip.getAbsolutePath();
|
||||
String cp = System.getProperty("java.class.path");
|
||||
System.setProperty("java.class.path",
|
||||
cp + File.pathSeparator + qtjavaZipPath);
|
||||
}
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
CommandLine toDevicePath = CommandLine.parse("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v \"" + folderType + "\"");
|
||||
executor.execute(toDevicePath);
|
||||
return new RegQueryParser(new String(baos.toByteArray())).getValueOfKey();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Remove extra quotes, slashes, and garbage from the Windows PATH.
|
||||
*/
|
||||
@ -178,54 +105,15 @@ public class Platform extends processing.app.Platform {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// looking for Documents and Settings/blah/Application Data/Processing
|
||||
public File getSettingsFolder() throws Exception {
|
||||
// HKEY_CURRENT_USER\Software\Microsoft
|
||||
// \Windows\CurrentVersion\Explorer\Shell Folders
|
||||
// Value Name: AppData
|
||||
// Value Type: REG_SZ
|
||||
// Value Data: path
|
||||
|
||||
String keyPath =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion" +
|
||||
"\\Explorer\\Shell Folders";
|
||||
String appDataPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "AppData");
|
||||
|
||||
File dataFolder = new File(appDataPath, "Arduino15");
|
||||
return dataFolder;
|
||||
public File getSettingsFolder() {
|
||||
return settingsFolder;
|
||||
}
|
||||
|
||||
|
||||
// looking for Documents and Settings/blah/My Documents/Processing
|
||||
// (though using a reg key since it's different on other platforms)
|
||||
public File getDefaultSketchbookFolder() throws Exception {
|
||||
|
||||
// http://support.microsoft.com/?kbid=221837&sd=RMVP
|
||||
// http://support.microsoft.com/kb/242557/en-us
|
||||
|
||||
// The path to the My Documents folder is stored in the following
|
||||
// registry key, where path is the complete path to your storage location
|
||||
|
||||
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
|
||||
// Value Name: Personal
|
||||
// Value Type: REG_SZ
|
||||
// Value Data: path
|
||||
|
||||
// in some instances, this may be overridden by a policy, in which case check:
|
||||
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
|
||||
|
||||
String keyPath =
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion" +
|
||||
"\\Explorer\\Shell Folders";
|
||||
String personalPath =
|
||||
Registry.getStringValue(REGISTRY_ROOT_KEY.CURRENT_USER, keyPath, "Personal");
|
||||
|
||||
return new File(personalPath, "Arduino");
|
||||
return defaultSketchbookFolder;
|
||||
}
|
||||
|
||||
|
||||
public void openURL(String url) throws Exception {
|
||||
// this is not guaranteed to work, because who knows if the
|
||||
// path will always be c:\progra~1 et al. also if the user has
|
||||
@ -242,7 +130,7 @@ public class Platform extends processing.app.Platform {
|
||||
// "Access is denied" in both cygwin and the "dos" prompt.
|
||||
//Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" +
|
||||
// referenceFile + ".html");
|
||||
if (url.startsWith("http")) {
|
||||
if (url.startsWith("http") || url.startsWith("file:")) {
|
||||
// open dos prompt, give it 'start' command, which will
|
||||
// open the url properly. start by itself won't work since
|
||||
// it appears to need cmd
|
||||
@ -307,7 +195,8 @@ public class Platform extends processing.app.Platform {
|
||||
@Override
|
||||
public String preListAllCandidateDevices() {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
Executor executor = new CollectStdOutExecutor(baos);
|
||||
Executor executor = new DefaultExecutor();
|
||||
executor.setStreamHandler(new PumpStreamHandler(baos, null));
|
||||
|
||||
try {
|
||||
String listComPorts = new File(System.getProperty("user.dir"), "hardware/tools/listComPorts.exe").getCanonicalPath();
|
||||
|
35
arduino-core/src/processing/app/windows/RegQueryParser.java
Normal file
35
arduino-core/src/processing/app/windows/RegQueryParser.java
Normal file
@ -0,0 +1,35 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RegQueryParser {
|
||||
|
||||
private String valueOfKey;
|
||||
|
||||
public RegQueryParser(String regQueryOutput) {
|
||||
parse(regQueryOutput);
|
||||
}
|
||||
|
||||
private void parse(String regQueryOutput) {
|
||||
List<String> rows = Arrays.asList(regQueryOutput.replace(" ", "\t").replace("\r", "\n").replace("\n\n", "\n").split("\n"));
|
||||
|
||||
String row = Iterables.find(rows, new Predicate<String>() {
|
||||
@Override
|
||||
public boolean apply(String input) {
|
||||
return input.startsWith("\t");
|
||||
}
|
||||
});
|
||||
|
||||
String[] cols = row.split("\t");
|
||||
assert cols.length == 4;
|
||||
this.valueOfKey = cols[3];
|
||||
}
|
||||
|
||||
public String getValueOfKey() {
|
||||
return valueOfKey;
|
||||
}
|
||||
}
|
@ -1,456 +0,0 @@
|
||||
package processing.app.windows;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Methods for accessing the Windows Registry. Only String and DWORD values supported at the moment.
|
||||
*/
|
||||
public class Registry {
|
||||
public static enum REGISTRY_ROOT_KEY{CLASSES_ROOT, CURRENT_USER, LOCAL_MACHINE, USERS};
|
||||
private final static HashMap<REGISTRY_ROOT_KEY, Integer> rootKeyMap = new HashMap<REGISTRY_ROOT_KEY, Integer>();
|
||||
|
||||
static {
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CLASSES_ROOT, WINREG.HKEY_CLASSES_ROOT);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CURRENT_USER, WINREG.HKEY_CURRENT_USER);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.LOCAL_MACHINE, WINREG.HKEY_LOCAL_MACHINE);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.USERS, WINREG.HKEY_USERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing.
|
||||
*
|
||||
* @param args arguments
|
||||
* @throws java.lang.Exception on error
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one of the root keys.
|
||||
*
|
||||
* @param key key type
|
||||
* @return root key
|
||||
*/
|
||||
private static int getRegistryRootKey(REGISTRY_ROOT_KEY key) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int handle = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
handle = pHandle.getValue();
|
||||
}
|
||||
return(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName name of the key
|
||||
* @param access access mode
|
||||
* @return handle to the key or 0
|
||||
*/
|
||||
private static int openKey(REGISTRY_ROOT_KEY rootKey, String subKeyName, int access) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int rootKeyHandle;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
rootKeyHandle = getRegistryRootKey(rootKey);
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyHandle, subKeyName, 0, access, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
return(pHandle.getValue());
|
||||
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to a Java String.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String
|
||||
*/
|
||||
private static String convertBufferToString(byte[] buf) throws UnsupportedEncodingException {
|
||||
return(new String(buf, 0, buf.length - 2, "UTF-16LE"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to an int.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @return int
|
||||
*/
|
||||
private static int convertBufferToInt(byte[] buf) {
|
||||
return(((int)(buf[0] & 0xff)) + (((int)(buf[1] & 0xff)) << 8) + (((int)(buf[2] & 0xff)) << 16) + (((int)(buf[3] & 0xff)) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String or null
|
||||
*/
|
||||
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
String ret = null;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToString(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an int value.
|
||||
*
|
||||
*
|
||||
* @return int or 0
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
*/
|
||||
public static int getIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
int ret = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToInt(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
boolean ret = true;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegDeleteValue(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean setStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, String value) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
// appears to be Java 1.6 syntax, removing [fry]
|
||||
//data = Arrays.copyOf(value.getBytes("UTF-16LE"), value.length() * 2 + 2);
|
||||
data = new byte[value.length() * 2 + 2];
|
||||
byte[] src = value.getBytes("UTF-16LE");
|
||||
System.arraycopy(src, 0, data, 0, src.length);
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_SZ, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an int value.
|
||||
*
|
||||
*
|
||||
* @return true on success
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
*/
|
||||
public static boolean setIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, int value) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for existence of a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true if exists
|
||||
*/
|
||||
public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) != WINERROR.ERROR_FILE_NOT_FOUND) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference hkResult, dwDisposition;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
hkResult = new IntByReference();
|
||||
dwDisposition = new IntByReference();
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegCreateKeyEx(handle, name, 0, null, WINNT.REG_OPTION_NON_VOLATILE, WINNT.KEY_READ, null,
|
||||
hkResult, dwDisposition) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
advapi32.RegCloseKey(hkResult.getValue());
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegDeleteKey(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sub keys of a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent key name
|
||||
* @return array with all sub key names
|
||||
*/
|
||||
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex;
|
||||
char[] lpName;
|
||||
IntByReference lpcName;
|
||||
WINBASE.FILETIME lpftLastWriteTime;
|
||||
TreeSet<String> subKeys = new TreeSet<String>();
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
lpName = new char[256];
|
||||
lpcName = new IntByReference(256);
|
||||
lpftLastWriteTime = new WINBASE.FILETIME();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
while(advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null,
|
||||
null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) {
|
||||
subKeys.add(new String(lpName, 0, lpcName.getValue()));
|
||||
lpcName.setValue(256);
|
||||
dwIndex++;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
|
||||
return(subKeys.toArray(new String[]{}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values under a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param key jey name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return TreeMap with name and value pairs
|
||||
*/
|
||||
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex, result = 0;
|
||||
char[] lpValueName;
|
||||
byte[] lpData;
|
||||
IntByReference lpcchValueName, lpType, lpcbData;
|
||||
String name;
|
||||
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, key, WINNT.KEY_READ);
|
||||
lpValueName = new char[16384];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
lpType = new IntByReference();
|
||||
lpData = new byte[1];
|
||||
lpcbData = new IntByReference();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
do {
|
||||
lpcbData.setValue(0);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_SUCCESS) {
|
||||
name = new String(lpValueName, 0, lpcchValueName.getValue());
|
||||
|
||||
switch(lpType.getValue()) {
|
||||
case WINNT.REG_SZ:
|
||||
values.put(name, convertBufferToString(lpData));
|
||||
break;
|
||||
case WINNT.REG_DWORD:
|
||||
values.put(name, convertBufferToInt(lpData));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dwIndex++;
|
||||
} while(result == WINERROR.ERROR_SUCCESS);
|
||||
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(values);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* WINBASE.java
|
||||
*
|
||||
* Created on 5. September 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINBASE {
|
||||
/*
|
||||
typedef struct _SECURITY_ATTRIBUTES {
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES,
|
||||
*PSECURITY_ATTRIBUTES,
|
||||
*LPSECURITY_ATTRIBUTES;*/
|
||||
public static class SECURITY_ATTRIBUTES extends Structure {
|
||||
public int nLength;
|
||||
public Pointer lpSecurityDescriptor;
|
||||
public boolean bInheritHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _FILETIME {
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;*/
|
||||
public static class FILETIME extends Structure {
|
||||
public int dwLowDateTime;
|
||||
public int dwHighDateTime;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* WINERROR.java
|
||||
*
|
||||
* Created on 7. August 2007, 08:09
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINERROR {
|
||||
public final static int ERROR_SUCCESS = 0;
|
||||
public final static int NO_ERROR = 0;
|
||||
public final static int ERROR_FILE_NOT_FOUND = 2;
|
||||
public final static int ERROR_MORE_DATA = 234;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* WINNT.java
|
||||
*
|
||||
* Created on 8. August 2007, 13:41
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINNT {
|
||||
public final static int DELETE = 0x00010000;
|
||||
public final static int READ_CONTROL = 0x00020000;
|
||||
public final static int WRITE_DAC = 0x00040000;
|
||||
public final static int WRITE_OWNER = 0x00080000;
|
||||
public final static int SYNCHRONIZE = 0x00100000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_READ = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_WRITE = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
|
||||
|
||||
public final static int STANDARD_RIGHTS_ALL = 0x001F0000;
|
||||
|
||||
public final static int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
|
||||
|
||||
public final static int GENERIC_EXECUTE = 0x20000000;
|
||||
|
||||
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
|
||||
public final static int KEY_QUERY_VALUE = 0x0001;
|
||||
public final static int KEY_SET_VALUE = 0x0002;
|
||||
public final static int KEY_CREATE_SUB_KEY = 0x0004;
|
||||
public final static int KEY_ENUMERATE_SUB_KEYS = 0x0008;
|
||||
public final static int KEY_NOTIFY = 0x0010;
|
||||
public final static int KEY_CREATE_LINK = 0x0020;
|
||||
|
||||
public final static int KEY_READ = ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE));
|
||||
public final static int KEY_WRITE = ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE));
|
||||
|
||||
public final static int REG_NONE = 0; // No value type
|
||||
public final static int REG_SZ = 1; // Unicode nul terminated string
|
||||
public final static int REG_EXPAND_SZ = 2; // Unicode nul terminated string
|
||||
// (with environment variable references)
|
||||
public final static int REG_BINARY = 3; // Free form binary
|
||||
public final static int REG_DWORD = 4; // 32-bit number
|
||||
public final static int REG_DWORD_LITTLE_ENDIAN = 4; // 32-bit number (same as REG_DWORD)
|
||||
public final static int REG_DWORD_BIG_ENDIAN = 5; // 32-bit number
|
||||
public final static int REG_LINK = 6; // Symbolic Link (unicode)
|
||||
public final static int REG_MULTI_SZ = 7; // Multiple Unicode strings
|
||||
public final static int REG_RESOURCE_LIST = 8; // Resource list in the resource map
|
||||
public final static int REG_FULL_RESOURCE_DESCRIPTOR = 9; // Resource list in the hardware description
|
||||
public final static int REG_RESOURCE_REQUIREMENTS_LIST = 10;
|
||||
|
||||
public final static int REG_OPTION_RESERVED = 0x00000000; // Parameter is reserved
|
||||
public final static int REG_OPTION_NON_VOLATILE = 0x00000000; // Key is preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_VOLATILE = 0x00000001; // Key is not preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_CREATE_LINK = 0x00000002; // Created key is a
|
||||
// symbolic link
|
||||
public final static int REG_OPTION_BACKUP_RESTORE = 0x00000004; // open for backup or restore
|
||||
// special access rules
|
||||
// privilege required
|
||||
public final static int REG_OPTION_OPEN_LINK = 0x00000008; // Open symbolic link
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* WINREG.java
|
||||
*
|
||||
* Created on 17. August 2007, 14:32
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package processing.app.windows;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINREG {
|
||||
public final static int HKEY_CLASSES_ROOT = 0x80000000;
|
||||
public final static int HKEY_CURRENT_USER = 0x80000001;
|
||||
public final static int HKEY_LOCAL_MACHINE = 0x80000002;
|
||||
public final static int HKEY_USERS = 0x80000003;
|
||||
}
|
Reference in New Issue
Block a user