Skip to content

Commit 9eced1b

Browse files
committed
Do not use fragments without architecture name for arch detection #!60
1 parent 2ea910c commit 9eced1b

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/internal/target/TargetPlatformHelper.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import java.util.TreeMap;
5252
import java.util.TreeSet;
5353
import java.util.function.Consumer;
54+
import java.util.regex.Matcher;
55+
import java.util.regex.Pattern;
5456
import java.util.stream.Collectors;
5557
import java.util.stream.Stream;
5658

@@ -1085,37 +1087,24 @@ public OSArchitecture detectArchitecture(
10851087
}
10861088

10871089
String os = Platform.getOS();
1088-
Set<String> launcherLibraries = targetBundleIndex.keySet().stream().filter(name -> name.startsWith("org.eclipse.equinox.launcher") && name.contains(os)).collect(Collectors.toSet());
1089-
if (launcherLibraries.size() != 1) {
1090+
// Find org.eclipse.equinox.launcher.cocoa.macosx.aarch64
1091+
// Skip org.eclipse.equinox.launcher.cocoa.macosx
1092+
Pattern prefix = Pattern.compile(("org.eclipse.equinox.launcher.[\\w\\d]+."+os+".").replace(".", "\\."));
1093+
Set<String> launcherArchitectures = targetBundleIndex.keySet().stream().map(name -> removePrefix(name, prefix)).flatMap(Optional::stream).collect(Collectors.toSet());
1094+
if (launcherArchitectures.size() != 1) {
10901095
if (detectMsg != null) {
1091-
detectMsg.append("Multiple launcher libraries are found in target platform: " + Joiner.on(", ").join(launcherLibraries));
1096+
detectMsg.append("Multiple launcher architectures are found in target platform: " + Joiner.on(", ").join(launcherArchitectures));
10921097
}
10931098
return OSArchitecture.Unknown;
10941099
}
10951100

1096-
String name = launcherLibraries.iterator().next();
1097-
if (name.contains("aarch64")) {
1098-
if (detectMsg != null) {
1099-
detectMsg.append("aarch64 arch is selected because AUT uses " + name);
1100-
}
1101-
return OSArchitecture.aarch64;
1102-
} else if (name.contains("x86_64")) {
1103-
if (detectMsg != null) {
1104-
detectMsg.append("x86_64 arch is selected because AUT uses " + name);
1105-
}
1106-
return OSArchitecture.x86_64;
1107-
} else if (name.contains("x86")) {
1108-
if (detectMsg != null) {
1109-
detectMsg.append("x86 arch is selected because AUT uses " + name);
1110-
}
1111-
return OSArchitecture.x86;
1112-
}
1113-
1101+
String name = launcherArchitectures.iterator().next();
1102+
OSArchitecture result = OSArchitecture.valueOf(name);
11141103
if (detectMsg != null) {
1115-
detectMsg.append("Unrecognized launcher architecture: " + name);
1104+
detectMsg.append(result).append(" arch detected");
11161105
}
11171106

1118-
return OSArchitecture.Unknown;
1107+
return result;
11191108
}
11201109

11211110
private Map<String, BundleStart> getRunlevelsFromSimpleConfigurator() throws IOException {
@@ -1775,4 +1764,14 @@ private Model toModel(IPluginModelBase model) {
17751764
return new Model(model, BundleStart.fromBundle(bundle.getBundleInfo()));
17761765
}
17771766

1767+
private Optional<String> removePrefix(String input, Pattern prefix) {
1768+
Matcher matcher = prefix.matcher(input);
1769+
if (matcher.find()) {
1770+
if (matcher.start() == 0) {
1771+
return Optional.of(input.substring(matcher.end()));
1772+
}
1773+
}
1774+
return Optional.empty();
1775+
}
1776+
17781777
}

0 commit comments

Comments
 (0)