1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

Cores manager:

added post install script support
absolute path symlinks are converted to relative to the local folder and a warning is printed
This commit is contained in:
Federico Fissore
2015-03-19 12:24:19 +01:00
parent 639824e516
commit fc4179f1f7
6 changed files with 265 additions and 1 deletions

View File

@ -31,10 +31,20 @@ package cc.arduino.contributions.packages;
import cc.arduino.utils.ArchiveExtractor;
import cc.arduino.utils.MultiStepProgress;
import cc.arduino.utils.Progress;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.Executor;
import processing.app.BaseNoGui;
import processing.app.helpers.FileUtils;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.tools.CollectStdOutStdErrExecutor;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -131,6 +141,7 @@ public class ContributionInstaller {
destFolder.mkdirs();
assert toolContrib.getDownloadedFile() != null;
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
executePostInstallScriptIfAny(destFolder);
toolContrib.setInstalled(true);
toolContrib.setInstalledFolder(destFolder);
progress.stepDone();
@ -151,6 +162,36 @@ public class ContributionInstaller {
onProgress(progress);
}
private void executePostInstallScriptIfAny(File folder) throws IOException {
Collection<File> postInstallScripts = Collections2.filter(BaseNoGui.getPlatform().postInstallScripts(folder), new Predicate<File>() {
@Override
public boolean apply(File file) {
return file.isFile() && file.exists() && file.canRead() && file.canExecute();
}
});
if (postInstallScripts.isEmpty()) {
String[] subfolders = folder.list(new OnlyDirs());
if (subfolders.length > 1) {
return;
}
executePostInstallScriptIfAny(new File(folder, subfolders[0]));
return;
}
File postInstallScript = postInstallScripts.iterator().next();
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
Executor executor = new CollectStdOutStdErrExecutor(stdout, stderr);
executor.execute(new CommandLine(postInstallScript));
System.out.write(stdout.toByteArray());
System.err.write(stderr.toByteArray());
}
public void remove(ContributedPlatform platform) {
FileUtils.recursiveDelete(platform.getInstalledFolder());
platform.setInstalled(false);

View File

@ -36,11 +36,14 @@ 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 processing.app.I18n;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import static processing.app.I18n._;
public class ArchiveExtractor {
/**
@ -183,7 +186,9 @@ public class ArchiveExtractor {
// Symbolic links are referenced with relative paths
outputLinkFile = new File(linkName);
if (outputLinkFile.isAbsolute()) {
throw new IOException("Invalid archive: it contains a symbolic link with absolute path '" + outputLinkFile + "'");
System.err.println(I18n.format(_("Warning: file {0} links to an absolute path {1}, changing it to {2}"), outputFile, outputLinkFile, new File(outputLinkFile.getName())));
System.err.println();
outputLinkFile = new File(outputLinkFile.getName());
}
}

View File

@ -229,4 +229,11 @@ public class Platform {
Process process = Runtime.getRuntime().exec(new String[]{"chmod", "600", prefsFile.getAbsolutePath()}, null, null);
process.waitFor();
}
public List<File> postInstallScripts(File folder) {
List<File> scripts = new LinkedList<File>();
scripts.add(new File(folder, "install_script.sh"));
scripts.add(new File(folder, "post_install.sh"));
return scripts;
}
}

View File

@ -38,6 +38,8 @@ 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;
@ -354,4 +356,10 @@ public class Platform extends processing.app.Platform {
public void fixPrefsFilePermissions(File prefsFile) throws IOException {
//noop
}
public List<File> postInstallScripts(File folder) {
List<File> scripts = new LinkedList<File>();
scripts.add(new File(folder, "post_install.bat"));
return scripts;
}
}