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 2020/08/20 08:49:11 UTC
[maven-doxia] branch
DOXIA-614/support-source-reference-in-doxia-parser updated: [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 DOXIA-614/support-source-reference-in-doxia-parser
in repository https://gitbox.apache.org/repos/asf/maven-doxia.git
The following commit(s) were added to refs/heads/DOXIA-614/support-source-reference-in-doxia-parser by this push:
new 91e6f5b [DOXIA-614] Support passing source reference to Doxia instance
91e6f5b is described below
commit 91e6f5bcf3708a8fe2ecdd4708f33a1cba13b16f
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
---
.../java/org/apache/maven/doxia/DefaultDoxia.java | 10 +++-
.../main/java/org/apache/maven/doxia/Doxia.java | 33 ++++++++-----
.../org/apache/maven/doxia/DefaultDoxiaTest.java | 54 ++++++++++++++++++++++
3 files changed, 85 insertions(+), 12 deletions(-)
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 837bdc2..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
@@ -41,24 +41,35 @@ public interface Doxia
* 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.
- * You could use <code>newReader</code> methods from {@link org.codehaus.plexus.util.ReaderFactory}.
- * @param parserId Identifier for the parser to use.
- * @param sink A sink that consumes the Doxia events.
- * @throws org.apache.maven.doxia.parser.manager.ParserNotFoundException
- * if no parser could be found for the given id.
- * @throws org.apache.maven.doxia.parser.ParseException if the model could not be parsed.
+ * @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
+ * @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 )
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.
- * @return the parser defining by parserId.
- * @throws org.apache.maven.doxia.parser.manager.ParserNotFoundException
- * if no parser could be found for the given id.
+ * @param parserId identifier for the parser to use
+ * @return the parser identified by parserId
+ * @throws ParserNotFoundException if no parser could be found for the given id
*/
Parser getParser( String parserId )
throws ParserNotFoundException;
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() );
+ }
+ }
+
+}