Skip to content

Commit 823b14e

Browse files
committed
Merge branch 'trust_tp_arch_160' into release/2.6
2 parents 36cfd78 + e342938 commit 823b14e

File tree

2 files changed

+59
-49
lines changed

2 files changed

+59
-49
lines changed

launching/org.eclipse.rcptt.launching.ext/src/org/eclipse/rcptt/launching/ext/BundleStart.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public static BundleStart fromModelString(String str) {
141141
}
142142

143143
public static BundleStart fromBundle(BundleInfo info) {
144-
return new BundleStart(info.getStartLevel(), info.isMarkedAsStarted(),
144+
return internDefault(new BundleStart(info.getStartLevel(), info.isMarkedAsStarted(),
145145
info.getStartLevel() == BundleInfo.NO_LEVEL,
146-
!info.isMarkedAsStarted());
146+
!info.isMarkedAsStarted()));
147147
}
148148

149149
public final int level;
@@ -160,4 +160,7 @@ public static BundleStart fromQ7Headers(String q7sl, String q7as) {
160160
MoreObjects.firstNonNull(q7sl, DEF_STR),
161161
MoreObjects.firstNonNull(q7as, DEF_STR)));
162162
}
163+
private static BundleStart internDefault(BundleStart info) {
164+
return info.isDefault() ? DEFAULT : info;
165+
}
163166
}

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

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static java.lang.String.format;
1515
import static java.util.Arrays.stream;
1616
import static java.util.Collections.emptyList;
17+
import static java.util.function.Predicate.not;
1718
import static org.eclipse.core.runtime.IProgressMonitor.done;
1819
import static org.eclipse.rcptt.internal.launching.ext.Q7ExtLaunchingPlugin.PLUGIN_ID;
1920

@@ -110,6 +111,7 @@
110111
import org.osgi.framework.BundleException;
111112
import org.osgi.framework.Version;
112113

114+
import com.google.common.base.Joiner;
113115
import com.google.common.base.Objects;
114116
import com.google.common.base.Preconditions;
115117
import com.google.common.collect.HashMultimap;
@@ -517,6 +519,7 @@ public IStatus resolve(IProgressMonitor monitor) {
517519

518520
private void index() {
519521
stream(target.getBundles()).forEach(bundle -> targetBundleIndex.put(bundle.getBundleInfo().getSymbolicName(), bundle));
522+
targetBundleIndex.removeAll(null);
520523
}
521524

522525
private void resetIndex() {
@@ -1059,38 +1062,40 @@ public String getTemplateConfigLocation() {
10591062
public OSArchitecture detectArchitecture(
10601063
boolean preferCurrentVmArchitecture, StringBuilder detectMsg) {
10611064
checkResolved();
1065+
String architecture = target.getArch();
1066+
if (architecture != null) {
1067+
return OSArchitecture.valueOf(architecture);
1068+
}
1069+
10621070
String os = Platform.getOS();
1063-
TargetBundle[] bundles = target.getAllBundles();
1064-
for (TargetBundle b : bundles) {
1065-
BundleInfo info = b.getBundleInfo();
1066-
String name = info.getSymbolicName();
1067-
if (name != null && name.startsWith("org.eclipse.equinox.launcher")) {
1068-
if (!name.contains(os)) {
1069-
continue;
1070-
}
1071-
URI location = info.getLocation();
1072-
if (location == null || location.getPath() == null) {
1073-
continue;
1074-
}
1075-
1076-
if (name.contains("aarch64")) {
1077-
if (detectMsg != null) {
1078-
detectMsg.append("aarch64 arch is selected because AUT uses " + name);
1079-
}
1080-
return OSArchitecture.aarch64;
1081-
} else if (name.contains("x86_64")) {
1082-
if (detectMsg != null) {
1083-
detectMsg.append("x86_64 arch is selected because AUT uses " + name);
1084-
}
1085-
return OSArchitecture.x86_64;
1086-
} else if (name.contains("x86")) {
1087-
if (detectMsg != null) {
1088-
detectMsg.append("x86 arch is selected because AUT uses " + name);
1089-
}
1090-
return OSArchitecture.x86;
1091-
1092-
}
1071+
Set<String> launcherLibraries = targetBundleIndex.keySet().stream().filter(name -> name.startsWith("org.eclipse.equinox.launcher") && name.contains(os)).collect(Collectors.toSet());
1072+
if (launcherLibraries.size() != 1) {
1073+
if (detectMsg != null) {
1074+
detectMsg.append("Multiple launcher libraries are found in target platform: " + Joiner.on(", ").join(launcherLibraries));
10931075
}
1076+
return OSArchitecture.Unknown;
1077+
}
1078+
1079+
String name = launcherLibraries.iterator().next();
1080+
if (name.contains("aarch64")) {
1081+
if (detectMsg != null) {
1082+
detectMsg.append("aarch64 arch is selected because AUT uses " + name);
1083+
}
1084+
return OSArchitecture.aarch64;
1085+
} else if (name.contains("x86_64")) {
1086+
if (detectMsg != null) {
1087+
detectMsg.append("x86_64 arch is selected because AUT uses " + name);
1088+
}
1089+
return OSArchitecture.x86_64;
1090+
} else if (name.contains("x86")) {
1091+
if (detectMsg != null) {
1092+
detectMsg.append("x86 arch is selected because AUT uses " + name);
1093+
}
1094+
return OSArchitecture.x86;
1095+
}
1096+
1097+
if (detectMsg != null) {
1098+
detectMsg.append("Unrecognized launcher architecture: " + name);
10941099
}
10951100

10961101
return OSArchitecture.Unknown;
@@ -1239,8 +1244,7 @@ public String toString() {
12391244

12401245
@Override
12411246
public Map<String, org.eclipse.equinox.p2.metadata.Version> getVersions() throws CoreException {
1242-
if (!getStatus().isOK())
1243-
throw new CoreException(getStatus());
1247+
checkResolved();
12441248
return AUTInformation.getInformationMap(target);
12451249
}
12461250

@@ -1706,30 +1710,33 @@ private static void debug(String message) {
17061710
}
17071711
private void setStartLevels(SubMonitor monitor) throws IOException, BundleException {
17081712
Map<String, BundleStart> levelMap = getRunlevelsMap();
1709-
1710-
if (levelMap.isEmpty()) {
1711-
warning("No start levels are configured");
1712-
}
17131713
if (!target.isResolved()) {
17141714
throw new IllegalStateException("Target definition is unresolved");
17151715
}
1716-
1716+
17171717
TargetBundle[] bundles = target.getBundles();
17181718
monitor.beginTask("Setting bundle start levels", bundles.length);
17191719
for (TargetBundle bundle : bundles) {
1720-
monitor.subTask(bundle.getBundleInfo().getLocation().toString());
1721-
BundleStart bundleLevel = levelMap.getOrDefault(bundle.getBundleInfo().getSymbolicName(), BundleStart.DEFAULT);
1722-
bundleLevel = StartLevelSupport.getStartInfo(bundle.getBundleInfo().getManifest(), bundleLevel);
1720+
BundleInfo bundleInfo = bundle.getBundleInfo();
1721+
monitor.subTask(bundleInfo.getLocation().toString());
1722+
BundleStart bundleLevel = levelMap.getOrDefault(bundleInfo.getSymbolicName(), BundleStart.DEFAULT);
1723+
bundleLevel = StartLevelSupport.getStartInfo(bundleInfo.getManifest(), bundleLevel);
17231724
monitor.split(1);
1724-
if (bundleLevel != null) {
1725-
try {
1726-
bundle.getBundleInfo().setStartLevel(bundleLevel.level);
1727-
bundle.getBundleInfo().setMarkedAsStarted(bundleLevel.autoStart);
1728-
} catch (RuntimeException e) {
1729-
throw new IllegalStateException(format("Invalid run level descriptor for bundle %s : %s ", bundle.getBundleInfo().getSymbolicName(), bundleLevel), e);
1730-
}
1725+
if (bundleLevel.isDefault()) {
1726+
continue;
1727+
}
1728+
try {
1729+
bundleInfo.setStartLevel(bundleLevel.level);
1730+
bundleInfo.setMarkedAsStarted(bundleLevel.autoStart);
1731+
} catch (RuntimeException e) {
1732+
throw new IllegalStateException(format("Invalid run level descriptor for bundle %s : %s ", bundleInfo.getSymbolicName(), bundleLevel), e);
17311733
}
17321734
}
1735+
if (!stream(bundles).map(TargetBundle::getBundleInfo).map(BundleStart::fromBundle).anyMatch(not(BundleStart::isDefault))) {
1736+
// this happens only if target platform has no bundles from org.eclipse.rcptt.launching.ext.StartLevelSupport.predefined
1737+
warning("No start levels are configured");
1738+
}
1739+
17331740
}
17341741

17351742
private void warning(String message) {

0 commit comments

Comments
 (0)