diff --git a/.gitignore b/.gitignore index 2b8dedab5a..61a24192b6 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,8 @@ pom-model-classic.xml project-dependencies.xml project-units.xml requirements.txt -.DS_Store \ No newline at end of file +.DS_Store + +## Test cache files +tycho-core/http/ +tycho-core/https/ \ No newline at end of file diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/target/TargetPlatformFilterEvaluator.java b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/target/TargetPlatformFilterEvaluator.java index aeb107b822..c072aff2ca 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/target/TargetPlatformFilterEvaluator.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/resolver/target/TargetPlatformFilterEvaluator.java @@ -80,15 +80,18 @@ private void applyFilter(TargetPlatformFilter filter, Collection targetPlatformUnits) { ParsedCapabilityPattern scopePattern = parsePattern(filter.getScopePattern(), null); - // TODO implement debug logging + filterLogger.beginEvaluation(filter); for (Iterator unitIterator = targetPlatformUnits.iterator(); unitIterator.hasNext();) { IInstallableUnit unit = unitIterator.next(); if (matches(unit, scopePattern)) { unitIterator.remove(); + filterLogger.unitRemoved(unit); } } + + filterLogger.endEvaluation(); } private void applyRestrictionFilter(TargetPlatformFilter filter, Collection targetPlatformUnits) { @@ -254,11 +257,13 @@ private class FilterLogger { TargetPlatformFilter currentFilter; int unitsKept; int unitsRemoved; + List removedUnits; public void beginEvaluation(TargetPlatformFilter filter) { currentFilter = filter; unitsKept = 0; unitsRemoved = 0; + removedUnits = new ArrayList<>(); } public void unitKept(IInstallableUnit unit) { @@ -267,15 +272,58 @@ public void unitKept(IInstallableUnit unit) { public void unitRemoved(IInstallableUnit unit) { ++unitsRemoved; + removedUnits.add(unit); } public void endEvaluation() { - if (unitsRemoved > 0 && unitsKept == 0) { - logger.warn("Removed all units from the target platform matching {" - + currentFilter.getScopePattern().printMembers() - + "} because none of the units passed the restriction filter {" - + currentFilter.getActionPattern().printMembers() + "}"); + if (currentFilter.getAction() == TargetPlatformFilter.FilterAction.REMOVE_ALL) { + // For REMOVE_ALL filters + if (unitsRemoved == 0) { + logger.info("Filter {" + currentFilter.getScopePattern().printMembers() + + "} did not match any units"); + } else { + logger.info("Removed " + unitsRemoved + " unit(s) matching {" + + currentFilter.getScopePattern().printMembers() + "}: " + + formatRemovedUnits()); + } + } else { + // For RESTRICT filters + if (unitsRemoved > 0 && unitsKept == 0) { + logger.warn("Removed all units from the target platform matching {" + + currentFilter.getScopePattern().printMembers() + + "} because none of the units passed the restriction filter {" + + currentFilter.getActionPattern().printMembers() + "}"); + } else if (unitsRemoved == 0 && unitsKept == 0) { + logger.info("Filter {" + currentFilter.getScopePattern().printMembers() + + "} did not match any units"); + } else if (unitsRemoved > 0) { + logger.info("Removed " + unitsRemoved + " unit(s) matching {" + + currentFilter.getScopePattern().printMembers() + + "} that did not pass restriction filter {" + + currentFilter.getActionPattern().printMembers() + "}: " + + formatRemovedUnits()); + } + } + } + + private String formatRemovedUnits() { + // Limit the number of units shown in the log to avoid overly long messages + int maxUnitsToShow = 10; + StringBuilder sb = new StringBuilder(); + int count = 0; + for (IInstallableUnit unit : removedUnits) { + if (count > 0) { + sb.append(", "); + } + if (count < maxUnitsToShow) { + sb.append(unit.getId()).append("_").append(unit.getVersion()); + } else { + sb.append("... and ").append(removedUnits.size() - maxUnitsToShow).append(" more"); + break; + } + count++; } + return sb.toString(); } } } diff --git a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFilterEvaluatorTest.java b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFilterEvaluatorTest.java index 8cbe8e7e40..1c282f474f 100644 --- a/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFilterEvaluatorTest.java +++ b/tycho-core/src/test/java/org/eclipse/tycho/p2resolver/TargetPlatformFilterEvaluatorTest.java @@ -217,6 +217,59 @@ public void testNonParsableVersionRange() throws Exception { subject.filterUnits(workUnits); } + @Test + public void testRemoveAllLogsFilteredUnits() throws Exception { + TargetPlatformFilter removeAllFilter = removeAllFilter(ALL_MULTIVERSION_BUNDLES); + subject = newEvaluator(removeAllFilter); + + subject.filterUnits(workUnits); + + // Verify that the removal was logged + logVerifier.expectInfo(allOf(containsString("Removed 2 unit(s)"), + containsString("trf.bundle.multiversion"))); + } + + @Test + public void testRemoveAllLogsWhenNoUnitsMatched() throws Exception { + CapabilityPattern nonExistentPattern = patternWithVersion(CapabilityType.OSGI_BUNDLE, + "non.existent.bundle", null); + subject = newEvaluator(removeAllFilter(nonExistentPattern)); + + subject.filterUnits(workUnits); + + // Verify that a message was logged indicating no matches + logVerifier.expectInfo(allOf(containsString("did not match any units"), + containsString("non.existent.bundle"))); + } + + @Test + public void testRestrictLogsFilteredUnits() throws Exception { + TargetPlatformFilter versionFilter = restrictionFilter(ALL_MULTIVERSION_BUNDLES, + patternWithVersion(null, null, "1.0")); + subject = newEvaluator(versionFilter); + + subject.filterUnits(workUnits); + + // Verify that the removal was logged + logVerifier.expectInfo(allOf(containsString("Removed 1 unit(s)"), + containsString("trf.bundle.multiversion"))); + } + + @Test + public void testRestrictLogsWhenNoUnitsMatched() throws Exception { + CapabilityPattern nonExistentPattern = patternWithVersion(CapabilityType.OSGI_BUNDLE, + "non.existent.bundle", null); + TargetPlatformFilter versionFilter = restrictionFilter(nonExistentPattern, + patternWithVersion(null, null, "1.0")); + subject = newEvaluator(versionFilter); + + subject.filterUnits(workUnits); + + // Verify that a message was logged indicating no matches + logVerifier.expectInfo(allOf(containsString("did not match any units"), + containsString("non.existent.bundle"))); + } + private Collection removedUnits() { HashSet result = new HashSet<>(); for (IInstallableUnit unit : baselineUnits) {