Skip to content

Commit

Permalink
getInfo did not properly fixup values from other processor in getInfo
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <[email protected]>

Signed-off-by: Peter Kriens <[email protected]>
  • Loading branch information
pkriens committed Jan 26, 2024
1 parent 2ab9741 commit d297939
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 26 deletions.
32 changes: 25 additions & 7 deletions biz.aQute.bndlib.tests/test/test/ProcessorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,33 @@

public class ProcessorTest {

@Test
public void testFixup() throws IOException {
try (Processor p = new Processor()) {
p.setProperty("-fixupmessages.eclipserefactor",
"Unused Import-Package instructions: \\[org.eclipse.jdt.internal.corext.refactoring.*\\]");
p.warning(
"bndtools.core.test.launch: Unused Import-Package instructions: [org.eclipse.jdt.internal.corext.refactoring.*]");
assertThat(p.getWarnings()).isEmpty();

}
}

@Test
public void testFixupMerge() throws IOException {
Processor p = new Processor();
p.setProperty("-fixupmessages.foo", "foo");
p.setProperty("-fixupmessages.bar", "bar");
p.error("foo");
p.error("bar");
assertTrue(p.check());
p.close();
try (Processor p = new Processor()) {
p.setProperty("-fixupmessages.foo", "foo");
p.setProperty("-fixupmessages.bar", "bar");
p.error("foo");
p.error("bar");
assertTrue(p.check());

try (Processor p2 = new Processor()) {
p2.getInfo(p);
assertTrue(p2.check());
}

}
}

@Test
Expand Down
53 changes: 34 additions & 19 deletions biz.aQute.bndlib/src/aQute/bnd/osgi/MessageReporter.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package aQute.bnd.osgi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

Expand Down Expand Up @@ -102,9 +104,9 @@ public int compareTo(Message o) {
return Integer.compare(sequence, o.sequence);
}

void fixup(Instructions fixupInstrs, List<String> errors, List<String> warnings) {
Message fixup(Instructions fixupInstrs, boolean failok) {

boolean error = this.error;
boolean error = failok ? false : this.error;

Instruction matcher = fixupInstrs.finder(message);
String type = error ? Constants.FIXUPMESSAGES_IS_ERROR : Constants.FIXUPMESSAGES_IS_WARNING;
Expand Down Expand Up @@ -140,12 +142,13 @@ void fixup(Instructions fixupInstrs, List<String> errors, List<String> warnings)
}
}
}
if (message != null) {
if (error)
errors.add(message);
else
warnings.add(message);
}
if (message == null)
return null;

if (error == this.error && message.equals(this.message))
return this;

return new Message(sequence, message, error);
}

}
Expand All @@ -155,16 +158,12 @@ class Cache {
final List<String> warnings = new ArrayList<>();

Cache() {
boolean failOk = processor().isFailOk();
Instructions fixupInstrs = new Instructions();
Parameters fixup = processor().getMergedParameters(Constants.FIXUPMESSAGES);
fixup.forEach((k, v) -> fixupInstrs.put(Instruction.legacy(k), v));

messages.values()
.stream()
.sorted()
fixup(messages.values()).stream()
.forEach(m -> {
m.fixup(fixupInstrs, failOk ? warnings : errors, warnings);
if (m.error)
errors.add(m.message);
else
warnings.add(m.message);
});
}
}
Expand Down Expand Up @@ -240,15 +239,31 @@ void getInfo(Reporter from, String prefix) {
}

ConcurrentHashMap<String, Message> older = other.clear();
older.values()
other.fixup(older.values())
.stream()
.sorted()
.map(m -> new Message(counter.getAndIncrement(), m, actualPrefix))
.forEach(m -> {
putMessage(m.message, m);
});
}

/*
*
*/
private List<Message> fixup(Collection<Message> older) {
boolean failOk = processor().isFailOk();
Instructions fixupInstrs = new Instructions();
Parameters fixup = processor().getMergedParameters(Constants.FIXUPMESSAGES);
fixup.forEach((k, v) -> fixupInstrs.put(Instruction.legacy(k), v));

return older.stream()
.sorted()
.map(m -> m.fixup(fixupInstrs, failOk))
.filter(Objects::nonNull)
.toList();

}

/*
* for backward compatible reporters
*/
Expand Down

0 comments on commit d297939

Please sign in to comment.