Skip to content

Commit 2cbd959

Browse files
author
jantje
committed
#1167 tested in windows
This fix creates and works with a sloeber variant of boards.txt and platfrom.txt. This way the original files are not touched. This works with previously installed released versions. Nightly gives issues with some boards due to double workarounds. Removing and installing again does the trick The first line in the sloeber variants is used to identify the "workaround version" to enable updates on the fly NOTE: this change also copies the package json file to the platform but is not yet using it. Still need to think how to get this to work safely
1 parent 2823581 commit 2cbd959

File tree

9 files changed

+182
-85
lines changed

9 files changed

+182
-85
lines changed

io.sloeber.core/src/io/sloeber/core/api/PackageManager.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static private void loadJson(String url, boolean forceDownload) {
682682
static private void loadPackage(File jsonFile) {
683683
try (Reader reader = new FileReader(jsonFile)) {
684684
PackageIndex index = new Gson().fromJson(reader, PackageIndex.class);
685-
index.setOwners(null);
685+
index.setOwners();
686686
index.setJsonFile(jsonFile);
687687
packageIndices.add(index);
688688
} catch (Exception e) {
@@ -887,7 +887,7 @@ public static void updateGlobalEnvironmentVariables() {
887887
for (ArduinoPlatform curPlatform : InternalPackageManager.getInstalledPlatforms()) {
888888

889889

890-
Package pkg = curPlatform.getPackage();
890+
Package pkg = curPlatform.getParent();
891891
if (pkg != null) {
892892
if (Const.ARDUINO.equalsIgnoreCase(pkg.getMaintainer())) {
893893
Helpers.addPlatformFileTools(curPlatform, contribEnv, confDesc, false );

io.sloeber.core/src/io/sloeber/core/managers/ArduinoPlatform.java

+14-14
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ public class ArduinoPlatform {
3636
private List<Board> boards;
3737
private List<ToolDependency> toolsDependencies;
3838

39-
private Package pkg;
39+
private Package myParent;
4040

4141
private static final String ID_SEPERATOR = "-"; //$NON-NLS-1$
4242

43-
void setOwner(Package pkg) {
44-
this.pkg = pkg;
45-
for (Board board : this.boards) {
43+
void setParent(Package parent) {
44+
myParent = parent;
45+
for (Board board : boards) {
4646
board.setOwners(this);
4747
}
4848
if (this.toolsDependencies != null) {
49-
for (ToolDependency toolDep : this.toolsDependencies) {
49+
for (ToolDependency toolDep : toolsDependencies) {
5050
toolDep.setOwner(this);
5151
}
5252
}
5353
}
5454

55-
public Package getPackage() {
56-
return this.pkg;
55+
public Package getParent() {
56+
return this.myParent;
5757
}
5858

5959
public String getName() {
@@ -119,7 +119,7 @@ public File getPlatformFile() {
119119
}
120120

121121
public IPath getInstallPath() {
122-
IPath stPath = ConfigurationPreferences.getInstallationPathPackages().append(this.pkg.getName())
122+
IPath stPath = ConfigurationPreferences.getInstallationPathPackages().append(this.myParent.getName())
123123
.append(Const.ARDUINO_HARDWARE_FOLDER_NAME).append(this.architecture).append(this.version);
124124
return stPath;
125125
}
@@ -167,7 +167,7 @@ public int hashCode() {
167167
final int prime = 31;
168168
int result = 1;
169169
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
170-
result = prime * result + ((this.pkg == null) ? 0 : this.pkg.hashCode());
170+
result = prime * result + ((this.myParent == null) ? 0 : this.myParent.hashCode());
171171
result = prime * result + ((this.version == null) ? 0 : this.version.hashCode());
172172
return result;
173173
}
@@ -186,10 +186,10 @@ public boolean equals(Object obj) {
186186
return false;
187187
} else if (!this.name.equals(other.name))
188188
return false;
189-
if (this.pkg == null) {
190-
if (other.pkg != null)
189+
if (this.myParent == null) {
190+
if (other.myParent != null)
191191
return false;
192-
} else if (!this.pkg.equals(other.pkg))
192+
} else if (!this.myParent.equals(other.myParent))
193193
return false;
194194
if (this.version == null) {
195195
if (other.version != null)
@@ -211,11 +211,11 @@ public List<String> getBoardNames() {
211211
public String getID() {
212212
String ID=new String();
213213

214-
if (pkg==null) {
214+
if (myParent==null) {
215215
ID=getInstallPath().toOSString();
216216
}
217217
else {
218-
ID=pkg.getName();
218+
ID=myParent.getName();
219219
}
220220
ID=ID+ID_SEPERATOR+name+ID_SEPERATOR+architecture;
221221

io.sloeber.core/src/io/sloeber/core/managers/InternalPackageManager.java

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import java.io.IOException;
1818
import java.io.InputStream;
1919
import java.net.URL;
20+
import java.nio.file.Files;
21+
import java.nio.file.StandardCopyOption;
2022
import java.util.ArrayList;
2123
import java.util.Arrays;
2224
import java.util.HashMap;
@@ -123,13 +125,24 @@ public static void startup_Pluging(IProgressMonitor monitor) {
123125
static public IStatus downloadAndInstall(ArduinoPlatform platform, boolean forceDownload,
124126
IProgressMonitor monitor) {
125127

128+
126129
MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platform.getName()); //$NON-NLS-1$
127130
mstatus.addErrors(downloadAndInstall(platform.getUrl(), platform.getArchiveFileName(),
128131
platform.getInstallPath(), forceDownload, monitor));
129132
if (!mstatus.isOK()) {
130133
// no use going on installing tools if the boards failed installing
131134
return mstatus;
132135
}
136+
File packageFile=platform.getParent().getParent().getJsonFile();
137+
File copyToFile=platform.getInstallPath().append( packageFile.getName()).toFile();
138+
try {
139+
Files.copy(packageFile.toPath(),
140+
copyToFile.toPath(),
141+
StandardCopyOption.REPLACE_EXISTING);
142+
} catch (IOException e) {
143+
// TODO Auto-generated catch block
144+
e.printStackTrace();
145+
}
133146

134147
if (platform.getToolsDependencies() != null) {
135148
for (ToolDependency tool : platform.getToolsDependencies()) {

io.sloeber.core/src/io/sloeber/core/managers/Package.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,22 @@ public class Package implements Comparable<Package> {
2525
private Help help;
2626
private List<ArduinoPlatform> platforms;
2727
private List<Tool> tools;
28+
private PackageIndex myParent=null;
2829

29-
void setOwner(InternalPackageManager manager) {
30+
public PackageIndex getParent() {
31+
return myParent;
32+
}
33+
34+
void setParent(PackageIndex parent) {
35+
myParent=parent;
3036
// it happened that the list contained a null so I remove null platforms
3137
this.platforms.remove(null);
3238
for (ArduinoPlatform platform : this.platforms) {
33-
platform.setOwner(this);
39+
platform.setParent(this);
3440
}
3541
if (this.tools != null) {
3642
for (Tool tool : this.tools) {
37-
tool.setOwner(this);
43+
tool.setParent(this);
3844
}
3945
}
4046
}

io.sloeber.core/src/io/sloeber/core/managers/PackageIndex.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public Package getPackage(String packageName) {
3535
return null;
3636
}
3737

38-
public void setOwners(InternalPackageManager manager) {
38+
public void setOwners() {
3939
for (Package pkg : this.packages) {
40-
pkg.setOwner(manager);
40+
pkg.setParent(this);
4141
}
4242
}
4343

io.sloeber.core/src/io/sloeber/core/managers/Tool.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Tool {
2828

2929
private transient Package pkg;
3030

31-
public void setOwner(Package pkg) {
31+
public void setParent(Package pkg) {
3232
this.pkg = pkg;
3333
for (ToolSystem system : this.systems) {
3434
system.setOwner(this);

io.sloeber.core/src/io/sloeber/core/managers/ToolDependency.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public String getVersion() {
4141
}
4242

4343
public Tool getTool() {
44-
Package pkg = this.platform.getPackage();
44+
Package pkg = this.platform.getParent();
4545
if (!pkg.getName().equals(this.packager)) {
4646
pkg = InternalPackageManager.getPackage(this.packager);
4747
}

0 commit comments

Comments
 (0)