mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
This commit is contained in:
parent
3788128385
commit
b65b576eb0
@ -34,6 +34,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import processing.app.BaseNoGui;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import cc.arduino.contributions.libraries.ContributedLibrary;
|
||||
import cc.arduino.contributions.libraries.LibrariesIndexer;
|
||||
@ -122,7 +123,7 @@ public class LibraryInstaller {
|
||||
File libsFolder = indexer.getSketchbookLibrariesFolder();
|
||||
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
|
||||
try {
|
||||
ArchiveExtractor.extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
} catch (Exception e) {
|
||||
if (tmpFolder.exists())
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
|
@ -139,7 +139,7 @@ public class ContributionInstaller {
|
||||
|
||||
destFolder.mkdirs();
|
||||
assert toolContrib.getDownloadedFile() != null;
|
||||
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||
executePostInstallScriptIfAny(destFolder);
|
||||
toolContrib.setInstalled(true);
|
||||
toolContrib.setInstalledFolder(destFolder);
|
||||
@ -152,7 +152,7 @@ public class ContributionInstaller {
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator + platform.getArchitecture());
|
||||
File destFolder = new File(platformFolder, platform.getVersion());
|
||||
destFolder.mkdirs();
|
||||
ArchiveExtractor.extract(platform.getDownloadedFile(), destFolder, 1);
|
||||
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(platform.getDownloadedFile(), destFolder, 1);
|
||||
platform.setInstalled(true);
|
||||
platform.setInstalledFolder(destFolder);
|
||||
progress.stepDone();
|
||||
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 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.os;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import cc.arduino.os.linux.LinuxFileNativeUtils;
|
||||
import cc.arduino.os.macos.MacOSFileNativeUtils;
|
||||
import cc.arduino.os.windows.WindowsFileNativeUtils;
|
||||
import processing.app.helpers.OSUtils;
|
||||
|
||||
public class FileNativeUtils {
|
||||
|
||||
/**
|
||||
* Change file access permissions (UNIX). If the underlying filesystem doesn't
|
||||
* support UNIX permission then the command is ignored.
|
||||
*
|
||||
* @param file
|
||||
* @param mode
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void chmod(File file, int mode) throws IOException {
|
||||
if (OSUtils.isLinux())
|
||||
LinuxFileNativeUtils.chmod(file, mode);
|
||||
if (OSUtils.isMacOS())
|
||||
MacOSFileNativeUtils.chmod(file, mode);
|
||||
if (OSUtils.isWindows())
|
||||
WindowsFileNativeUtils.chmod(file, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a hard link from <b>oldFile</b> to <b>newFile</b>. If the underlying
|
||||
* filesystem doesn't support hard links then the command is ignored.
|
||||
*
|
||||
* @param something
|
||||
* @param somewhere
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void link(File something, File somewhere) throws IOException {
|
||||
if (OSUtils.isLinux())
|
||||
LinuxFileNativeUtils.link(something, somewhere);
|
||||
if (OSUtils.isMacOS())
|
||||
MacOSFileNativeUtils.link(something, somewhere);
|
||||
if (OSUtils.isWindows())
|
||||
WindowsFileNativeUtils.link(something, somewhere);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a symlink link from <b>oldFile</b> to <b>newFile</b>. If the
|
||||
* underlying filesystem doesn't support symlinks then the command is ignored.
|
||||
*
|
||||
* @param something
|
||||
* @param somewhere
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void symlink(File something, File somewhere) throws IOException {
|
||||
if (OSUtils.isLinux())
|
||||
LinuxFileNativeUtils.symlink(something, somewhere);
|
||||
if (OSUtils.isMacOS())
|
||||
MacOSFileNativeUtils.symlink(something, somewhere);
|
||||
if (OSUtils.isWindows())
|
||||
WindowsFileNativeUtils.symlink(something, somewhere);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 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.os.linux;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
public interface LibCNative extends Library {
|
||||
|
||||
LibCNative libc = (LibCNative) Native.loadLibrary("c", LibCNative.class);
|
||||
|
||||
Pointer errno = NativeLibrary.getInstance("c").getGlobalVariableAddress("errno");
|
||||
|
||||
int chmod(String path, int mode);
|
||||
|
||||
int link(String something, String somewhere);
|
||||
|
||||
int symlink(String something, String somewhere);
|
||||
|
||||
String strerror(int errno);
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 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.os.linux;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class LinuxFileNativeUtils {
|
||||
|
||||
public static final LibCNative libc = LibCNative.libc;
|
||||
|
||||
public static void chmod(File file, int mode) throws IOException {
|
||||
int res = libc.chmod(file.getAbsolutePath(), mode);
|
||||
if (res == -1) {
|
||||
throw new IOException("Could not change file permission: " + strerror());
|
||||
}
|
||||
}
|
||||
|
||||
public static void link(File something, File somewhere) throws IOException {
|
||||
int res = libc.link(something.getAbsolutePath(), somewhere.getAbsolutePath());
|
||||
if (res == -1) {
|
||||
throw new IOException("Could not create hard link to " + somewhere + " from " + something + ": " + strerror());
|
||||
}
|
||||
}
|
||||
|
||||
public static void symlink(File something, File somewhere) throws IOException {
|
||||
int res = libc.symlink(something.getPath(), somewhere.getAbsolutePath());
|
||||
if (res == -1) {
|
||||
throw new IOException("Could not create symlink to " + somewhere + " from " + something + ": " + strerror());
|
||||
}
|
||||
}
|
||||
|
||||
private static String strerror() {
|
||||
return libc.strerror(LibCNative.errno.getInt(0));
|
||||
}
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 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.os.macos;
|
||||
|
||||
import cc.arduino.os.linux.LinuxFileNativeUtils;
|
||||
|
||||
public class MacOSFileNativeUtils extends LinuxFileNativeUtils {
|
||||
|
||||
// OSX and Linux shares the same POSIX API
|
||||
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* This file is part of Arduino.
|
||||
*
|
||||
* Copyright 2014 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.os.windows;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class WindowsFileNativeUtils {
|
||||
|
||||
public static void chmod(File file, int mode) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public static void link(File file, File link) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
public static void symlink(File file, File link) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,6 @@
|
||||
*/
|
||||
package cc.arduino.utils;
|
||||
|
||||
import cc.arduino.os.FileNativeUtils;
|
||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.ArchiveInputStream;
|
||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||
@ -37,6 +36,7 @@ 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 processing.app.I18n;
|
||||
import processing.app.Platform;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
@ -46,6 +46,13 @@ import static processing.app.I18n._;
|
||||
|
||||
public class ArchiveExtractor {
|
||||
|
||||
private final Platform platform;
|
||||
|
||||
public ArchiveExtractor(Platform platform) {
|
||||
assert platform != null;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract <b>source</b> into <b>destFolder</b>. <b>source</b> file archive
|
||||
* format is autodetected from file extension.
|
||||
@ -54,7 +61,7 @@ public class ArchiveExtractor {
|
||||
* @param destFolder
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void extract(File archiveFile, File destFolder) throws IOException {
|
||||
public void extract(File archiveFile, File destFolder) throws IOException, InterruptedException {
|
||||
extract(archiveFile, destFolder, 0);
|
||||
}
|
||||
|
||||
@ -68,12 +75,12 @@ public class ArchiveExtractor {
|
||||
* archived files
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void extract(File archiveFile, File destFolder, int stripPath) throws IOException {
|
||||
public void extract(File archiveFile, File destFolder, int stripPath) throws IOException, InterruptedException {
|
||||
extract(archiveFile, destFolder, stripPath, false);
|
||||
}
|
||||
|
||||
|
||||
public static void extract(File archiveFile, File destFolder, int stripPath, boolean overwrite) throws IOException {
|
||||
public void extract(File archiveFile, File destFolder, int stripPath, boolean overwrite) throws IOException, InterruptedException {
|
||||
|
||||
// Folders timestamps must be set at the end of archive extraction
|
||||
// (because creating a file in a folder alters the folder's timestamp)
|
||||
@ -233,7 +240,7 @@ public class ArchiveExtractor {
|
||||
|
||||
// Set file/folder permission
|
||||
if (mode != null && !isSymLink && outputFile.exists()) {
|
||||
FileNativeUtils.chmod(outputFile, mode);
|
||||
platform.chmod(outputFile, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,10 +248,10 @@ public class ArchiveExtractor {
|
||||
if (entry.getKey().exists() && overwrite) {
|
||||
entry.getKey().delete();
|
||||
}
|
||||
FileNativeUtils.link(entry.getValue(), entry.getKey());
|
||||
platform.link(entry.getValue(), entry.getKey());
|
||||
Integer mode = hardLinksMode.get(entry.getKey());
|
||||
if (mode != null) {
|
||||
FileNativeUtils.chmod(entry.getKey(), mode);
|
||||
platform.chmod(entry.getKey(), mode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +259,7 @@ public class ArchiveExtractor {
|
||||
if (entry.getKey().exists() && overwrite) {
|
||||
entry.getKey().delete();
|
||||
}
|
||||
FileNativeUtils.symlink(entry.getValue(), entry.getKey());
|
||||
platform.symlink(entry.getValue(), entry.getKey());
|
||||
entry.getKey().setLastModified(symLinksModifiedTimes.get(entry.getKey()));
|
||||
}
|
||||
|
||||
|
@ -582,7 +582,7 @@ public class BaseNoGui {
|
||||
if (!indexFile.isFile() || !(avrCoreFolder.exists() && avrCoreFolder.isDirectory())) {
|
||||
File distFile = findDefaultPackageFile();
|
||||
if (distFile != null) {
|
||||
ArchiveExtractor.extract(distFile, BaseNoGui.getSettingsFolder(), 0, true);
|
||||
new ArchiveExtractor(getPlatform()).extract(distFile, BaseNoGui.getSettingsFolder(), 0, true);
|
||||
} else if (!indexFile.isFile()) {
|
||||
// Otherwise create an empty packages index
|
||||
FileOutputStream out = null;
|
||||
|
@ -244,4 +244,19 @@ public class Platform {
|
||||
public String getOsArch() {
|
||||
return System.getProperty("os.arch");
|
||||
}
|
||||
|
||||
public void symlink(File something, File somewhere) throws IOException, InterruptedException {
|
||||
Process process = Runtime.getRuntime().exec(new String[]{"ln", "-s", something.getAbsolutePath(), somewhere.getAbsolutePath()}, null, null);
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
public void link(File something, File somewhere) throws IOException, InterruptedException {
|
||||
Process process = Runtime.getRuntime().exec(new String[]{"ln", something.getAbsolutePath(), somewhere.getAbsolutePath()}, null, null);
|
||||
process.waitFor();
|
||||
}
|
||||
|
||||
public void chmod(File file, int mode) throws IOException, InterruptedException {
|
||||
Process process = Runtime.getRuntime().exec(new String[]{"chmod", Integer.toOctalString(mode), file.getAbsolutePath()}, null, null);
|
||||
process.waitFor();
|
||||
}
|
||||
}
|
||||
|
@ -362,4 +362,13 @@ public class Platform extends processing.app.Platform {
|
||||
scripts.add(new File(folder, "post_install.bat"));
|
||||
return scripts;
|
||||
}
|
||||
|
||||
public void symlink(File something, File somewhere) throws IOException, InterruptedException {
|
||||
}
|
||||
|
||||
public void link(File something, File somewhere) throws IOException, InterruptedException {
|
||||
}
|
||||
|
||||
public void chmod(File file, int mode) throws IOException, InterruptedException {
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user