You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2021/05/30 15:45:09 UTC
[maven-doxia] 03/03: [DOXIA-614] Support passing source reference
to Doxia instance
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
commit 497a4387007732ffe5c780451cbc3778c9e0b265
Author: Abel Salgado Romero <ab...@gmail.com>
AuthorDate: Mon Jun 29 19:51:37 2020 +0200
[DOXIA-614] Support passing source reference to Doxia instance
Closes #35
---
.../java/org/apache/maven/doxia/DefaultDoxia.java | 10 +++-
.../main/java/org/apache/maven/doxia/Doxia.java | 14 ++++++
.../org/apache/maven/doxia/DefaultDoxiaTest.java | 54 ++++++++++++++++++++++
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/DefaultDoxia.java b/doxia-core/src/main/java/org/apache/maven/doxia/DefaultDoxia.java
index f8583e7..dae7ec2 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/DefaultDoxia.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/DefaultDoxia.java
@@ -57,11 +57,19 @@ public class DefaultDoxia
public void parse( Reader source, String parserId, Sink sink )
throws ParserNotFoundException, ParseException
{
+ this.parse( source, parserId, sink, null );
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void parse( Reader source, String parserId, Sink sink, String reference )
+ throws ParserNotFoundException, ParseException
+ {
Parser parser = parserManager.getParser( parserId );
parser.enableLogging( new PlexusLoggerWrapper( getLogger() ) );
- parser.parse( source, sink );
+ parser.parse( source, sink, reference );
}
/** {@inheritDoc} */
diff --git a/doxia-core/src/main/java/org/apache/maven/doxia/Doxia.java b/doxia-core/src/main/java/org/apache/maven/doxia/Doxia.java
index 5741910..17d3920 100644
--- a/doxia-core/src/main/java/org/apache/maven/doxia/Doxia.java
+++ b/doxia-core/src/main/java/org/apache/maven/doxia/Doxia.java
@@ -51,6 +51,20 @@ public interface Doxia
throws ParserNotFoundException, ParseException;
/**
+ * Parses the given source model using a parser with given id,
+ * and emits Doxia events into the given sink.
+ *
+ * @param source not null reader that provides the source document
+ * @param parserId identifier for the parser to use
+ * @param sink a sink that consumes the Doxia events
+ * @param reference string containing the reference to the source (e.g. filename)
+ * @throws ParserNotFoundException if no parser could be found for the given id
+ * @throws ParseException if the model could not be parsed
+ */
+ void parse( Reader source, String parserId, Sink sink, String reference )
+ throws ParserNotFoundException, ParseException;
+
+ /**
* Return a parser for the given <code>parserId</code>.
*
* @param parserId identifier for the parser to use
diff --git a/doxia-core/src/test/java/org/apache/maven/doxia/DefaultDoxiaTest.java b/doxia-core/src/test/java/org/apache/maven/doxia/DefaultDoxiaTest.java
new file mode 100644
index 0000000..2075b7f
--- /dev/null
+++ b/doxia-core/src/test/java/org/apache/maven/doxia/DefaultDoxiaTest.java
@@ -0,0 +1,54 @@
+package org.apache.maven.doxia;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.doxia.parser.manager.ParserNotFoundException;
+import org.codehaus.plexus.PlexusTestCase;
+import org.junit.Test;
+
+public class DefaultDoxiaTest extends PlexusTestCase
+{
+
+ @Test
+ public void testCreatesDefaultDoxia()
+ {
+ final DefaultDoxia defaultDoxia = new DefaultDoxia();
+
+ assertNotNull( defaultDoxia );
+ }
+
+ @Test
+ public void testFailsWhenParserIdDoesNotExist() throws Exception
+ {
+ final String parserId = "a-parser";
+ final Doxia doxia = lookup( Doxia.class );
+
+ try
+ {
+ doxia.getParser( parserId );
+ fail( "Call should fail with ParserNotFoundException" );
+ }
+ catch ( ParserNotFoundException e )
+ {
+ assertEquals( "Cannot find parser with id = a-parser", e.getMessage() );
+ }
+ }
+
+}