Skip to content

Commit fe6718c

Browse files
author
Federico Fissore
committed
Removing previously installed platform on upgrade
1 parent b1e0249 commit fe6718c

File tree

7 files changed

+49
-35
lines changed

7 files changed

+49
-35
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
9898
installButton.addActionListener(new ActionListener() {
9999
@Override
100100
public void actionPerformed(ActionEvent e) {
101-
onInstall(editorValue.getSelected());
101+
onInstall(editorValue.getSelected(), editorValue.getInstalled());
102102
}
103103
});
104104

@@ -129,7 +129,7 @@ protected void onRemove(ContributedPlatform contributedPlatform) {
129129
// Empty
130130
}
131131

132-
protected void onInstall(ContributedPlatform contributedPlatform) {
132+
protected void onInstall(ContributedPlatform contributedPlatform, ContributedPlatform installed) {
133133
// Empty
134134
}
135135

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

+25-10
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
*/
2929
package cc.arduino.packages.contributions.ui;
3030

31-
import java.util.ArrayList;
32-
import java.util.List;
33-
3431
import cc.arduino.packages.contributions.ContributedPackage;
3532
import cc.arduino.packages.contributions.ContributedPlatform;
3633
import cc.arduino.packages.contributions.ContributionsIndex;
3734
import cc.arduino.ui.FilteredAbstractTableModel;
3835

36+
import java.util.ArrayList;
37+
import java.util.LinkedList;
38+
import java.util.List;
39+
40+
import static processing.app.I18n._;
41+
3942
@SuppressWarnings("serial")
4043
public class ContributionIndexTableModel extends FilteredAbstractTableModel {
4144

@@ -69,9 +72,21 @@ public void add(ContributedPlatform platform) {
6972
}
7073

7174
public ContributedPlatform getInstalled() {
72-
for (ContributedPlatform plat : releases)
73-
if (plat.isInstalled())
74-
return plat;
75+
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>();
76+
for (ContributedPlatform platform : releases) {
77+
if (platform.isInstalled()) {
78+
installedPlatforms.add(platform);
79+
}
80+
}
81+
82+
if (installedPlatforms.size() > 1) {
83+
throw new IllegalStateException(_("More than one platform is currently installed! Only one can be installed at any given time"));
84+
}
85+
86+
if (!installedPlatforms.isEmpty()) {
87+
return installedPlatforms.get(0);
88+
}
89+
7590
return null;
7691
}
7792

@@ -112,9 +127,9 @@ public void select(ContributedPlatform value) {
112127

113128
private List<ContributedPlatformReleases> contributions = new ArrayList<ContributedPlatformReleases>();
114129

115-
private String[] columnNames = { "Description" };
130+
private String[] columnNames = {"Description"};
116131

117-
private Class<?>[] columnTypes = { ContributedPlatform.class };
132+
private Class<?>[] columnTypes = {ContributedPlatform.class};
118133

119134
private ContributionsIndex index;
120135

@@ -141,11 +156,11 @@ public void updateIndexFilter(String category, String filters[]) {
141156
/**
142157
* Check if <b>string</b> contains all the substrings in <b>set</b>. The
143158
* compare is case insensitive.
144-
*
159+
*
145160
* @param string
146161
* @param set
147162
* @return <b>true<b> if all the strings in <b>set</b> are contained in
148-
* <b>string</b>.
163+
* <b>string</b>.
149164
*/
150165
private boolean stringContainsAll(String string, String set[]) {
151166
if (set == null)

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ protected InstallerTableCell createCellRenderer() {
6363
protected InstallerTableCell createCellEditor() {
6464
return new ContributedPlatformTableCell() {
6565
@Override
66-
protected void onInstall(ContributedPlatform selectedPlatform) {
67-
onInstallPressed(selectedPlatform);
66+
protected void onInstall(ContributedPlatform selectedPlatform, ContributedPlatform installed) {
67+
onInstallPressed(selectedPlatform, installed);
6868
}
6969

7070
@Override
@@ -146,13 +146,16 @@ public void run() {
146146
installerThread.start();
147147
}
148148

149-
public void onInstallPressed(final ContributedPlatform platform) {
149+
public void onInstallPressed(final ContributedPlatform platformToInstall, final ContributedPlatform platformToRemove) {
150150
installerThread = new Thread(new Runnable() {
151151
@Override
152152
public void run() {
153153
try {
154154
setProgressVisible(true);
155-
installer.install(platform);
155+
installer.install(platformToInstall);
156+
if (platformToRemove != null) {
157+
installer.remove(platformToRemove);
158+
}
156159
} catch (Exception e) {
157160
// TODO Show ERROR
158161
e.printStackTrace();

app/src/processing/app/Base.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ protected void onIndexesUpdated() throws Exception {
11231123
rebuildExamplesMenu(Editor.examplesMenu);
11241124
}
11251125

1126-
private void openInstallBoardDialog() {
1126+
private void openInstallBoardDialog() throws Exception {
11271127
// Create dialog for contribution manager
11281128
@SuppressWarnings("serial")
11291129
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
@@ -1139,14 +1139,9 @@ protected void onIndexesUpdated() throws Exception {
11391139
// Installer dialog is modal, waits here until closed
11401140

11411141
// Reload all boards (that may have been installed/updated/removed)
1142-
try {
1143-
BaseNoGui.initPackages();
1144-
rebuildBoardsMenu();
1145-
onBoardOrPortChange();
1146-
} catch (Exception e) {
1147-
// TODO Auto-generated catch block
1148-
e.printStackTrace();
1149-
}
1142+
BaseNoGui.initPackages();
1143+
rebuildBoardsMenu();
1144+
onBoardOrPortChange();
11501145
}
11511146

11521147
public void rebuildBoardsMenu() throws Exception {
@@ -1158,7 +1153,12 @@ public void rebuildBoardsMenu() throws Exception {
11581153
@SuppressWarnings("serial")
11591154
Action runInstaller = new AbstractAction("Install boards...") {
11601155
public void actionPerformed(ActionEvent actionevent) {
1161-
openInstallBoardDialog();
1156+
try {
1157+
openInstallBoardDialog();
1158+
} catch (Exception e) {
1159+
//TODO show error
1160+
e.printStackTrace();
1161+
}
11621162
}
11631163
};
11641164
boardMenu.add(new JMenuItem(runInstaller));

arduino-core/src/cc/arduino/libraries/contributions/LibrariesIndexer.java

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public LibrariesIndexer(File preferencesFolder) {
6666

6767
public void parseIndex() throws JsonParseException, IOException {
6868
parseIndex(indexFile);
69-
System.out.println(index);
7069

7170
index.fillCategories();
7271
// TODO: resolve libraries inner references

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ protected void onProgress(Progress progress) {
6060
}
6161

6262
public void install(ContributedPlatform platform) throws Exception {
63-
if (platform.isInstalled())
63+
if (platform.isInstalled()) {
6464
throw new Exception("Platform is already installed!");
65+
}
6566

6667
// Do not download already installed tools
6768
List<ContributedTool> tools = new LinkedList<ContributedTool>(platform.getResolvedTools());
@@ -111,13 +112,11 @@ public void install(ContributedPlatform platform) throws Exception {
111112
File toolsFolder = new File(packageFolder, "tools");
112113
int i = 1;
113114
for (ContributedTool tool : platform.getResolvedTools()) {
114-
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i,
115-
tools.size()));
115+
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
116116
onProgress(progress);
117117
i++;
118118
DownloadableContribution toolContrib = tool.getDownloadableContribution();
119-
File destFolder = new File(toolsFolder, tool.getName() + File.separator +
120-
tool.getVersion());
119+
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
121120

122121
destFolder.mkdirs();
123122
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
@@ -129,8 +128,7 @@ public void install(ContributedPlatform platform) throws Exception {
129128
// Unpack platform on the correct location
130129
progress.setStatus(_("Installing boards..."));
131130
onProgress(progress);
132-
File platformFolder = new File(packageFolder, "hardware" + File.separator +
133-
platform.getArchitecture());
131+
File platformFolder = new File(packageFolder, "hardware" + File.separator + platform.getArchitecture());
134132
File destFolder = new File(platformFolder, platform.getVersion());
135133
destFolder.mkdirs();
136134
ArchiveExtractor.extract(platform.getDownloadedFile(), destFolder, 1);

arduino-core/src/processing/app/BaseNoGui.java

-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ static public void initPackages() throws Exception {
612612
}
613613
indexer.parseIndex();
614614
indexer.syncWithFilesystem();
615-
System.out.println(indexer);
616615

617616
packages = new HashMap<String, TargetPackage>();
618617
loadHardware(getHardwareFolder());

0 commit comments

Comments
 (0)