Skip to content

Commit

Permalink
Remove missing OSGi capabilities (#80 improves #74)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Feb 13, 2023
2 parents e78a22e + a0fecb8 commit e693a33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions solstice/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.

## [Unreleased]
### Fixed
- Missing OSGi capabilities are now handled the same as missing bundles and packages. ([#80](https://github.com/equodev/equo-ide/pull/80) fixes [#74](https://github.com/equodev/equo-ide/issues/74))

## [0.14.0] - 2023-02-12
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public Map<String, String> atomosHeaders(SolsticeManifest manifest) {
setHeader(atomos, Constants.IMPORT_PACKAGE, manifest.pkgImports);
setHeader(atomos, Constants.EXPORT_PACKAGE, manifest.pkgExports);
setHeader(atomos, Constants.REQUIRE_BUNDLE, manifest.requiredBundles);
// TODO: Atomos will work better if we finish https://github.com/equodev/equo-ide/issues/74
// setHeader(atomos, Constants.REQUIRE_CAPABILITY, manifest.TODO);
return atomos;
}

Expand Down
18 changes: 10 additions & 8 deletions solstice/src/main/java/dev/equo/solstice/Solstice.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void warnAndModifyManifestsToFix() {
bySymbolicName.forEach(
(symbolicName, manifests) -> {
if (manifests.size() > 1) {
logger.warn("Multiple bundles with same symbolic name: " + symbolicName);
logger.warn("Multiple bundles with the same symbolic name: " + symbolicName);
for (SolsticeManifest manifest : manifests) {
logger.warn(" - " + manifest.getJarUrl());
}
Expand Down Expand Up @@ -240,25 +240,30 @@ public void warnAndModifyManifestsToFix() {
if (missing.startsWith("org.xml.") || missing.startsWith("org.w3c.")) {
return;
}
logger.warn("Missing imported package " + missing + " imported by " + neededBy);
logger.warn("Missing imported package " + missing + " needed by " + neededBy);
});
for (var bundle : bundles) {
bundle.removeFromRequiredBundles(missingBundles.keySet());
bundle.removeFromPkgImports(missingPackages.keySet());
}

// warn about missing requirements. TODO: remove missing requirements and set them in Atomos
// warn about missing requirements
var allCapabilities = new Capability.SupersetSet();
for (var bundle : bundles) {
allCapabilities.addAll(bundle.capProvides);
}
var missingCapability = new TreeSet<Capability>();
for (var bundle : bundles) {
for (var cap : bundle.capRequires) {
if (!allCapabilities.containsAnySupersetOf(cap)) {
logger.warn("Missing capability " + cap + " required by " + bundle);
logger.warn("Missing required capability " + cap + " needed by " + bundle);
missingCapability.add(cap);
}
}
}
for (var bundle : bundles) {
bundle.removeRequiredCapabilities(missingCapability);
}
}

private boolean pkgExportIsNotDuplicate(
Expand Down Expand Up @@ -373,9 +378,7 @@ public void start(SolsticeManifest manifest) {
while ((cap = missingCap(manifest)) != null) {
var bundles = unactivatedBundlesForCap(cap);
if (bundles.isEmpty()) {
logger.warn("{} requires missing capability {}", manifest, cap);
caps.add(cap);
// throw new IllegalArgumentException(manifest + " requires missing capability " + cap);
throw new IllegalArgumentException(manifest + " requires missing capability " + cap);
} else {
for (var bundle : bundles) {
start(bundle);
Expand Down Expand Up @@ -409,7 +412,6 @@ private Capability missingCap(SolsticeManifest manifest) {
}

private List<SolsticeManifest> unactivatedBundlesForCap(Capability targetCap) {
var target = targetCap.toString();
Object bundlesForCap = null;
for (var bundle : bundles) {
if (bundle.isFragment() || activatingBundles.contains(bundle)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.Function;
Expand Down Expand Up @@ -161,6 +162,11 @@ static Map.Entry<String, String> parseSingleFilter(String filter) {
return Map.entry(key, value);
}

void removeRequiredCapabilities(Set<Capability> missingCapabilities) {
// TODO: Atomos will work better if we finish https://github.com/equodev/equo-ide/issues/74
capRequires.removeAll(missingCapabilities);
}

private List<Capability> parseCapability(
String header, BiConsumer<CapabilityParsed, ArrayList<Capability>> parser) {
var parsed = parseAndStripCapability(header);
Expand Down

0 comments on commit e693a33

Please sign in to comment.