Search code examples
javareflectionparboiled

Pegdown Custom ParserPlugin binding failed


I'm stuck facing problems with pegdown v1.4.2 while trying to implement custom ParserPlugin to a library I'm writing (Maven project, JDK 8):

CustomPlugin:

public class CustomHeadersParserPlugin extends Parser implements BlockPluginParser {

public CustomHeadersParserPlugin() {super(HtmlMdProc.MDP_SETTINGS, HtmlMdProc.PROCESSING_TIME_LIMIT, DefaultParseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis) {
  super(options, maxParsingTimeInMillis, DefaultParseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider) {
  super(options, maxParsingTimeInMillis, parseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider, PegDownPlugins plugins) {
  super(options, maxParsingTimeInMillis, parseRunnerProvider, plugins);
}

//************* CUSTOM RULES ***************
...

Pegdown Usage:

public class HtmlMdProc {

public static final int MDP_SETTINGS = Extensions.HARDWRAPS | Extensions.AUTOLINKS | Extensions.TABLES | Extensions.FENCED_CODE_BLOCKS;
public static final long PROCESSING_TIME_LIMIT = 5000l;
...
public HtmlMdProc markdown() {
  PegDownPlugins pdp = PegDownPlugins.builder().withPlugin(CustomHeadersParserPlugin.class).build();
  PegDownProcessor mdp = new PegDownProcessor(MDP_SETTINGS, PROCESSING_TIME_LIMIT, pdp);
  RootNode rn = mdp.parseMarkdown(text.toCharArray());
  String result = new CustomMarkdownToHtmlSerializer().toHtml(rn);
    if (result != null)
      this.text = result;
    else
      logger.debug("Could not process markdown in {} seconds", PROCESSING_TIME_LIMIT / 1000);
  return this;
}

Test:

@Test
public void testmarkdownWithoutCode() {
  String before = "Simple new line\nTest\n\nTest\nVot";
  String expected = "<p>Simple new line<br />Test</p><p>Test<br />Vot</p>".replaceAll("\r", "");
  HtmlMdProc textProc = new HtmlMdProc(before);
  String result = textProc.markdown().text();
  assertEquals(expected, result);
}

Testing Exeption:

java.lang.RuntimeException: Error creating extended parser class: null
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.parboiled.transform.AsmUtils.createClassReader(AsmUtils.java:56)
  at org.parboiled.transform.ClassNodeInitializer.process(ClassNodeInitializer.java:62)
  at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:44)
  at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38)
  at org.parboiled.Parboiled.createParser(Parboiled.java:54)
  at org.pegdown.plugins.PegDownPlugins$Builder.withPlugin(PegDownPlugins.java:113)
  at com.myorg.html.services.HtmlMdProc.markdown(HtmlMdProc.java:317)
  at com.myorg.html.services.HtmlMdProcTest.testmarkdownWithoutCode(HtmlMdProcTest.java:262)
  1. Can I somehow bind my CustomHeadersParserPlugin avoiding spooky Reflections?
  2. If not, tell me how to setup maven-bundle-plugin in pom.xml to make it work with pegdown v 1.4.2.

I found Issue with discussion Here, but I'm too novice to deal alone with Maven plugins and Reflections.


Solution

  • The only solution is to wait for This Issue to be closed, until I thing there is no luck with Pegdown and Java 8.