Skip to content

Commit d94e279

Browse files
author
Federico Fissore
committed
Showing post install script errors AFTER the installation is completed
1 parent a40415a commit d94e279

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

app/src/cc/arduino/contributions/libraries/ui/ContributedLibraryTableCell.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ private Component getUpdatedCellComponent(Object value, boolean isSelected, int
344344
String desc = "<html><body>";
345345

346346
// Library name...
347-
desc += format("<b>{0}</b> ", name);
347+
desc += format("<b>{0}</b>", name);
348348
if (installed != null && installed.isReadOnly()) {
349-
desc += "Built-In ";
349+
desc += " Built-In ";
350350
}
351351

352352
// ...author...

app/src/cc/arduino/contributions/packages/ui/ContributedPlatformTableCell.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,11 @@ private Component getUpdatedCellComponent(Object value, boolean isSelected, int
348348

349349
String desc = "<html><body>";
350350
desc += "<b>" + selected.getName() + "</b>";
351+
if (installed != null && installed.isReadOnly()) {
352+
desc += " Built-In ";
353+
}
354+
351355
String author = selected.getParentPackage().getMaintainer();
352-
String url = selected.getParentPackage().getWebsiteURL();
353356
if (author != null && !author.isEmpty()) {
354357
desc += " " + format("by <b>{0}</b>", author);
355358
}
@@ -364,6 +367,7 @@ private Component getUpdatedCellComponent(Object value, boolean isSelected, int
364367
}
365368
desc = desc.substring(0, desc.lastIndexOf(',')) + ".<br />";
366369

370+
String url = selected.getParentPackage().getWebsiteURL();
367371
if (url != null && !url.isEmpty()) {
368372
desc += " " + format("<a href=\"{0}\">More info</a>", url);
369373
}

app/src/cc/arduino/contributions/packages/ui/ContributionManagerUI.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import javax.swing.*;
4141
import java.awt.*;
4242
import java.util.Collection;
43+
import java.util.LinkedList;
44+
import java.util.List;
4345

4446
import static processing.app.I18n._;
4547

@@ -158,17 +160,21 @@ public void onInstallPressed(final ContributedPlatform platformToInstall, final
158160
installerThread = new Thread(new Runnable() {
159161
@Override
160162
public void run() {
163+
List<String> errors = new LinkedList<String>();
161164
try {
162165
setProgressVisible(true, _("Installing..."));
163-
installer.install(platformToInstall);
166+
errors.addAll(installer.install(platformToInstall));
164167
if (platformToRemove != null && !platformToRemove.isReadOnly()) {
165-
installer.remove(platformToRemove);
168+
errors.addAll(installer.remove(platformToRemove));
166169
}
167170
onIndexesUpdated();
168171
} catch (Exception e) {
169172
throw new RuntimeException(e);
170173
} finally {
171174
setProgressVisible(false, "");
175+
if (!errors.isEmpty()) {
176+
setErrorMessage(errors.get(0));
177+
}
172178
}
173179
}
174180
});

arduino-core/src/cc/arduino/contributions/packages/ContributionInstaller.java

+24-10
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ protected void onProgress(Progress progress) {
7979
};
8080
}
8181

82-
public void install(ContributedPlatform platform) throws Exception {
82+
public List<String> install(ContributedPlatform platform) throws Exception {
83+
List<String> errors = new LinkedList<String>();
8384
if (platform.isInstalled()) {
8485
throw new Exception("Platform is already installed!");
8586
}
@@ -117,7 +118,7 @@ public void install(ContributedPlatform platform) throws Exception {
117118
}
118119
} catch (InterruptedException e) {
119120
// Download interrupted... just exit
120-
return;
121+
return errors;
121122
}
122123

123124
ContributedPackage pack = platform.getParentPackage();
@@ -140,7 +141,11 @@ public void install(ContributedPlatform platform) throws Exception {
140141
destFolder.mkdirs();
141142
assert toolContrib.getDownloadedFile() != null;
142143
new ArchiveExtractor(BaseNoGui.getPlatform()).extract(toolContrib.getDownloadedFile(), destFolder, 1);
143-
executePostInstallScriptIfAny(destFolder);
144+
try {
145+
executePostInstallScriptIfAny(destFolder);
146+
} catch (IOException e) {
147+
errors.add(_("Error running post install script"));
148+
}
144149
toolContrib.setInstalled(true);
145150
toolContrib.setInstalledFolder(destFolder);
146151
progress.stepDone();
@@ -159,6 +164,8 @@ public void install(ContributedPlatform platform) throws Exception {
159164

160165
progress.setStatus(_("Installation completed!"));
161166
onProgress(progress);
167+
168+
return errors;
162169
}
163170

164171
private void executePostInstallScriptIfAny(File folder) throws IOException {
@@ -184,14 +191,15 @@ public boolean apply(File file) {
184191
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
185192
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
186193
Executor executor = new CollectStdOutStdErrExecutor(stdout, stderr);
187-
194+
executor.setWorkingDirectory(folder);
188195
executor.execute(new CommandLine(postInstallScript));
189196

190197
System.out.write(stdout.toByteArray());
191198
System.err.write(stderr.toByteArray());
192199
}
193200

194-
public void remove(ContributedPlatform platform) {
201+
public List<String> remove(ContributedPlatform platform) {
202+
List<String> errors = new LinkedList<String>();
195203
FileUtils.recursiveDelete(platform.getInstalledFolder());
196204
platform.setInstalled(false);
197205
platform.setInstalledFolder(null);
@@ -217,11 +225,14 @@ public void remove(ContributedPlatform platform) {
217225
// ignore
218226
}
219227
}
228+
229+
return errors;
220230
}
221231

222-
public void updateIndex() throws Exception {
223-
final MultiStepProgress progress = new MultiStepProgress(1);
224-
final String statusText = _("Downloading platforms index...");
232+
public List<String> updateIndex() throws Exception {
233+
List<String> errors = new LinkedList<String>();
234+
MultiStepProgress progress = new MultiStepProgress(1);
235+
String statusText = _("Downloading platforms index...");
225236

226237
URL url = new URL(PACKAGE_INDEX_URL);
227238
File outputFile = indexer.getIndexFile();
@@ -232,10 +243,13 @@ public void updateIndex() throws Exception {
232243
// TODO: Check downloaded index
233244

234245
// Replace old index with the updated one
235-
if (outputFile.exists())
246+
if (outputFile.exists()) {
236247
outputFile.delete();
237-
if (!tmpFile.renameTo(outputFile))
248+
}
249+
if (!tmpFile.renameTo(outputFile)) {
238250
throw new Exception("An error occurred while updating platforms index!");
251+
}
252+
return errors;
239253
}
240254

241255
protected void onProgress(Progress progress) {

0 commit comments

Comments
 (0)