Skip to content

Commit ca33777

Browse files
author
jantje
committed
#1145 arduino ide way and sloeber way are now swapping referen ced/ing
1 parent 1ee6a23 commit ca33777

File tree

1 file changed

+18
-42
lines changed

1 file changed

+18
-42
lines changed

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

+18-42
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.ArrayList;
1313
import java.util.Arrays;
1414
import java.util.Collections;
15-
import java.util.HashMap;
1615
import java.util.List;
1716
import java.util.Map;
1817
import java.util.Map.Entry;
@@ -58,14 +57,14 @@
5857
import io.sloeber.core.api.BoardDescriptor;
5958
import io.sloeber.core.api.CompileOptions;
6059
import io.sloeber.core.api.Defaults;
60+
import io.sloeber.core.api.PackageManager;
6161
import io.sloeber.core.api.Preferences;
6262
import io.sloeber.core.common.Common;
6363
import io.sloeber.core.common.ConfigurationPreferences;
6464
import io.sloeber.core.common.Const;
6565
import io.sloeber.core.managers.ArduinoPlatform;
6666
import io.sloeber.core.managers.InternalPackageManager;
6767
import io.sloeber.core.managers.Library;
68-
import io.sloeber.core.managers.Package;
6968
import io.sloeber.core.managers.Tool;
7069
import io.sloeber.core.managers.ToolDependency;
7170

@@ -644,8 +643,11 @@ private static boolean isLocalKey(String key) {
644643

645644
}
646645

647-
private static void addPlatformFileTools(ArduinoPlatform platform, IContributedEnvironment contribEnv,
646+
public static void addPlatformFileTools(ArduinoPlatform platform, IContributedEnvironment contribEnv,
648647
ICConfigurationDescription confDesc, boolean reportToolNotFound) {
648+
if(platform==null) {
649+
return;
650+
}
649651
if (platform.getToolsDependencies() == null) {
650652
return;
651653
}
@@ -680,48 +682,22 @@ private static void addDependentTools(Iterable<ToolDependency> tools, IContribut
680682
private static void setTheEnvironmentVariablesAddThePlatformInfo(BoardDescriptor boardDescriptor,
681683
IContributedEnvironment contribEnv, ICConfigurationDescription confDesc) {
682684

683-
String architecture = boardDescriptor.getArchitecture();
684-
HashMap<String, ToolDependency> allTools = new HashMap<>();
685-
for (ArduinoPlatform curPlatform : InternalPackageManager.getInstalledPlatforms()) {
686-
addPlatformFileTools(curPlatform, contribEnv, confDesc, false);
687-
if (architecture.equals(curPlatform.getArchitecture())) {
688-
Package pkg = curPlatform.getPackage();
689-
if (pkg != null) {
690-
if (curPlatform.getToolsDependencies() != null) {
691-
for (ToolDependency curDependency : curPlatform.getToolsDependencies()) {
692-
String name = curDependency.getName();
693-
ToolDependency previousDependency = allTools.get(name);
694-
if (previousDependency == null) {
695-
allTools.put(name, curDependency);
696-
} else {
697-
String prevVersion = previousDependency.getVersion().toLowerCase();
698-
String curVersion = curDependency.getVersion();
699-
if (Version.compare(curVersion, prevVersion) == 1) {
700-
allTools.put(name, curDependency);
701-
}
702-
}
703-
}
704-
}
705-
}
706-
}
707-
}
708-
addDependentTools(allTools.values(), contribEnv, confDesc, false);
685+
//update the gobal variables if needed
686+
PackageManager.updateGlobalEnvironmentVariables();
687+
File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile();
688+
File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile();
689+
ArduinoPlatform referencingPlatform = InternalPackageManager.getPlatform(referencingPlatformFile);
690+
ArduinoPlatform referencedPlatform = InternalPackageManager.getPlatform(referencedPlatformFile);
709691

710-
// overrule the Arduino IDE way of working and use the json refereced tools
711692
boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
712693
if (jsonBasedPlatformManagement) {
713-
File referencingPlatformFile = boardDescriptor.getReferencingPlatformFile();
714-
File referencedPlatformFile = boardDescriptor.getreferencedPlatformFile();
715-
// add the referenced platform before the real platform
716-
ArduinoPlatform referencedPlatform = InternalPackageManager.getPlatform(referencedPlatformFile);
717-
if (referencedPlatform != null) {
718-
addPlatformFileTools(referencedPlatform, contribEnv, confDesc, true);
719-
}
720-
// and the real platform
721-
ArduinoPlatform referencingPlatform = InternalPackageManager.getPlatform(referencingPlatformFile);
722-
if (referencingPlatform != null) {
723-
addPlatformFileTools(referencingPlatform, contribEnv, confDesc, false);
724-
}
694+
// overrule the Arduino IDE way of working and use the json refereced tools
695+
addPlatformFileTools(referencedPlatform, contribEnv, confDesc, true);
696+
addPlatformFileTools(referencingPlatform, contribEnv, confDesc, false);
697+
} else {
698+
//standard arduino IDE way
699+
addPlatformFileTools(referencingPlatform, contribEnv, confDesc, false);
700+
addPlatformFileTools(referencedPlatform, contribEnv, confDesc, true);
725701
}
726702
}
727703

0 commit comments

Comments
 (0)