Skip to content

Commit f36f53d

Browse files
authored
Merge pull request #6913 from chrisrueger/effective-provenance-for-merged
Effective view: Show multiple provenances when merged properties are enabled
2 parents eaa4879 + a7a93ab commit f36f53d

File tree

2 files changed

+61
-15
lines changed

2 files changed

+61
-15
lines changed

bndtools.core/src/bndtools/editor/BndSourceEffectivePage.java

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import static aQute.bnd.osgi.Constants.MERGED_HEADERS;
55
import static bndtools.editor.completion.BndHover.lookupSyntax;
66
import static bndtools.editor.completion.BndHover.syntaxHoverText;
7+
import static java.util.stream.Collectors.collectingAndThen;
8+
import static java.util.stream.Collectors.mapping;
9+
import static java.util.stream.Collectors.toCollection;
710

811
import java.io.File;
912
import java.net.URI;
@@ -315,7 +318,15 @@ public void controlMoved(ControlEvent arg0) {}
315318

316319
private void open(Object element) {
317320
if (element instanceof PropertyRow prop) {
318-
String fpath = prop.provenance();
321+
List<String> fpaths = prop.provenances();
322+
323+
if (fpaths == null || fpaths.isEmpty()) {
324+
return;
325+
}
326+
327+
// we can only open one path
328+
String fpath = fpaths.get(0);
329+
319330
if (fpath == null || fpath.isBlank()) {
320331
return;
321332
}
@@ -493,7 +504,13 @@ private int[] createColumns(TableViewer tableViewer) {
493504
return syntax != null ? syntax.autoHelpUrl() : null;
494505
}), //
495506
new ColSpec("Value", -250, PropertyRow::value, PropertyRow::tooltip, null), //
496-
new ColSpec("Provenance", 150, (pr -> relativizeProvenancePath(pr.provenance())), null, null), //
507+
new ColSpec("Provenance", 150, (pr -> {
508+
return pr.provenances()
509+
.stream()
510+
.map(prov -> relativizeProvenancePath(prov))
511+
.collect(Collectors.joining(","));
512+
}),
513+
null, null), //
497514
new ColSpec("Errors", 150, (pr -> {
498515
List<String> errors = pr.errors();
499516
return errors.isEmpty() ? "" : errors.toString();
@@ -681,6 +698,24 @@ Object[] getTableData() {
681698
})
682699
.collect(Collectors.toCollection(LinkedHashSet::new));
683700

701+
Map<String, List<String>> stemProvenances = visible.stream()
702+
.collect(Collectors.groupingBy(k -> {
703+
String stem = BndEditModel.getStem(k.key());
704+
if (isInstruction(stem) || MERGED_HEADERS.contains(stem)) {
705+
return stem;
706+
}
707+
return k.key();
708+
}, mapping(k -> {
709+
String prov = k.getProvenance()
710+
.orElse(null);
711+
return prov;
712+
}, //
713+
// remove duplicates
714+
collectingAndThen(toCollection(LinkedHashSet::new),
715+
// convert back to List
716+
ArrayList::new
717+
))));
718+
684719
return stems.stream()
685720
.map(stem -> {
686721
Processor p = getProperties();
@@ -690,8 +725,10 @@ Object[] getTableData() {
690725
.toString()
691726
: p.get(stem);
692727

728+
List<String> provList = stemProvenances.get(stem);
729+
693730
String tooltip = BndEditModel.format(stem, value);
694-
return new PropertyRow(stem, value, null, tooltip,
731+
return new PropertyRow(stem, value, provList, tooltip,
695732
p.getErrors());
696733
})
697734
.toArray();
@@ -704,7 +741,7 @@ Object[] getTableData() {
704741
.orElse(null);
705742
Processor p = getProperties();
706743
String tooltip = BndEditModel.format(k.key(), expandedOrRawValue(k, p));
707-
return new PropertyRow(k.key(), expandedOrRawValue(k, p), provenance, tooltip,
744+
return new PropertyRow(k.key(), expandedOrRawValue(k, p), List.of(provenance), tooltip,
708745
p.getErrors());
709746
})
710747
.toArray();
@@ -756,9 +793,15 @@ public boolean useNativeToolTip(Object object) {
756793

757794
@Override
758795
public String getToolTipText(Object element) {
759-
if (spec.tooltip != null && element instanceof PropertyRow pkey) {
760-
return spec.tooltip.apply(pkey);
796+
if ("Provenance".equals(spec.title) && element instanceof PropertyRow prow) {
797+
return prow.provenances()
798+
.stream()
799+
.collect(Collectors.joining("\n"));
761800
}
801+
if (spec.tooltip != null && element instanceof PropertyRow prow) {
802+
return spec.tooltip.apply(prow);
803+
}
804+
762805
return null;
763806
}
764807

@@ -775,5 +818,6 @@ public TooltipInput getTooltipInfo(Object element) {
775818
/**
776819
* represents a row in the Effective view table.
777820
*/
778-
record PropertyRow(String title, String value, String provenance, String tooltip, List<String> errors) {}
821+
record PropertyRow(String title, String value, List<String> provenances, String tooltip,
822+
List<String> errors) {}
779823
}

bndtools.core/src/bndtools/editor/completion/BndHover.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.swt.graphics.Point;
2323
import org.eclipse.swt.widgets.Shell;
2424

25+
import aQute.bnd.build.model.BndEditModel;
2526
import aQute.bnd.help.Syntax;
2627
import aQute.bnd.osgi.Processor;
2728

@@ -100,6 +101,7 @@ static String wrap(String text, int width) {
100101
}
101102

102103
public static String syntaxHoverText(String key, Processor properties) {
104+
103105
Syntax syntax = lookupSyntax(key);
104106
StringBuilder sb = new StringBuilder();
105107

@@ -118,11 +120,14 @@ public static String syntaxHoverText(String key, Processor properties) {
118120
.toString()
119121
: properties.get(key);
120122

123+
121124
if (value != null && !value.isEmpty()) {
125+
String stem = BndEditModel.getStem(key);
126+
String formatted = BndEditModel.format(stem, value);
122127
sb.append("\n")
123128
.append(key)
124129
.append("=")
125-
.append(value);
130+
.append(formatted);
126131
}
127132

128133
List<String> errors = properties.getErrors();
@@ -132,16 +137,13 @@ public static String syntaxHoverText(String key, Processor properties) {
132137
sb.append(errors);
133138
}
134139

135-
String text = sb.toString();
136-
137-
if (text.length() > 30) {
138-
text = wrap(text, 30);
139-
}
140-
return text;
140+
return sb.toString();
141141
}
142142

143143
public static Syntax lookupSyntax(String key) {
144-
Syntax syntax = Syntax.HELP.get(key);
144+
145+
String stem = BndEditModel.getStem(key);
146+
Syntax syntax = Syntax.HELP.get(stem);
145147

146148
if (syntax == null) {
147149
if (!key.startsWith("-"))

0 commit comments

Comments
 (0)