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/07/09 13:31:55 UTC
[maven-doxia] 02/06: [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
commit 8f574e4314f2318b824df702e7781f037afdfeab
Author: Abel Salgado Romero <ab...@gmail.com>
AuthorDate: Sun Jun 28 19:37:58 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 | 16 +++++++
.../org/apache/maven/doxia/DefaultDoxiaTest.java | 54 ++++++++++++++++++++++
3 files changed, 79 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 837bdc2..5896684 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
@@ -53,6 +53,22 @@ 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.
+ * 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.
+ * @param reference A string containing the reference to the source of the input string (e.g. filename).
+ * @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.
+ */
+ 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() );
+ }
+ }
+
+}