You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2016/05/22 20:34:30 UTC
svn commit: r1745090 - in /maven/doxia/doxia/trunk: ./
doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/
doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/
Author: rfscholte
Date: Sun May 22 20:34:30 2016
New Revision: 1745090
URL: http://svn.apache.org/viewvc?rev=1745090&view=rev
Log:
[DOXIA-522] Make snippet macro less permissive of issues
Use ignoreDownloadError, setting default to true for backwards compatibility
Simplified code from patch
Modified:
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/SnippetMacroTest.java
maven/doxia/doxia/trunk/pom.xml
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java?rev=1745090&r1=1745089&r2=1745090&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetMacro.java Sun May 22 20:34:30 2016
@@ -69,7 +69,7 @@ public class SnippetMacro
/**
* in case of Exception during snippet download error will ignored and empty content returned.
*/
- private boolean ignoreDownloadError;
+ private boolean ignoreDownloadError = true;
/**
* {@inheritDoc}
@@ -207,13 +207,18 @@ public class SnippetMacro
}
catch ( IOException e )
{
- getLog().debug( "IOException which reading " + url + ": " + e );
- result = new StringBuffer( "Error during retrieving content skip as ignoreDownloadError activated." );
+ if ( ignoreDownloadError )
+ {
+ getLog().debug( "IOException which reading " + url + ": " + e );
+ result =
+ new StringBuffer( "Error during retrieving content skip as ignoreDownloadError activated." );
+ }
+ else
+ {
+ throw e;
+ }
}
-
-
}
-
return result;
}
Modified: maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java?rev=1745090&r1=1745089&r2=1745090&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/main/java/org/apache/maven/doxia/macro/snippet/SnippetReader.java Sun May 22 20:34:30 2016
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
+import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.IOUtil;
/**
@@ -149,9 +150,12 @@ public class SnippetReader
{
boolean capture = false;
String line;
+ boolean foundStart = false;
+ boolean foundEnd = false;
+ boolean hasSnippetId = StringUtils.isNotEmpty( snippetId );
while ( ( line = reader.readLine() ) != null )
{
- if ( snippetId == null || "".equals( snippetId.trim() ) )
+ if ( !hasSnippetId )
{
lines.add( line );
}
@@ -160,9 +164,11 @@ public class SnippetReader
if ( isStart( snippetId, line ) )
{
capture = true;
+ foundStart = true;
}
else if ( isEnd( snippetId, line ) )
{
+ foundEnd = true;
break;
}
else if ( capture )
@@ -171,6 +177,15 @@ public class SnippetReader
}
}
}
+
+ if ( hasSnippetId && !foundStart )
+ {
+ throw new IOException( "Failed to find START of snippet " + snippetId + " in file at URL: " + source );
+ }
+ if ( hasSnippetId && !foundEnd )
+ {
+ throw new IOException( "Failed to find END of snippet " + snippetId + " in file at URL: " + source );
+ }
}
finally
{
Modified: maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/SnippetMacroTest.java
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/SnippetMacroTest.java?rev=1745090&r1=1745089&r2=1745090&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/SnippetMacroTest.java (original)
+++ maven/doxia/doxia/trunk/doxia-core/src/test/java/org/apache/maven/doxia/macro/snippet/SnippetMacroTest.java Sun May 22 20:34:30 2016
@@ -19,6 +19,11 @@ package org.apache.maven.doxia.macro.sni
* under the License.
*/
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
import org.apache.maven.doxia.macro.MacroExecutionException;
import org.apache.maven.doxia.macro.MacroRequest;
import org.apache.maven.doxia.sink.impl.SinkEventElement;
@@ -27,11 +32,6 @@ import org.codehaus.plexus.PlexusTestCas
import org.hamcrest.CoreMatchers;
import org.junit.Assert;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
/**
* Test snippet macro.
*
@@ -120,6 +120,21 @@ public class SnippetMacroTest
// no need to verify the absence of the first and second snippets if tests above were successful
Assert.assertThat( snippet, CoreMatchers.containsString( "Этот сниппет в формате Unicode (UTF-8)" ) );
+
+ // again
+ // Shouldn't work because no snippet called "first" exists, only "firstId"
+ macroParameters.put( "id", "first" );
+ macroParameters.put( "verbatim", "" );
+ macroParameters.put( "ignoreDownloadError", "false" );
+ try
+ {
+ executeSnippetMacro( macroParameters );
+ fail();
+ }
+ catch ( Exception e )
+ {
+ // good
+ }
}
public void testIgnoreDownloadError()
Modified: maven/doxia/doxia/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/pom.xml?rev=1745090&r1=1745089&r2=1745090&view=diff
==============================================================================
--- maven/doxia/doxia/trunk/pom.xml (original)
+++ maven/doxia/doxia/trunk/pom.xml Sun May 22 20:34:30 2016
@@ -41,7 +41,7 @@ under the License.
<contributors>
<contributor>
- <name>Valters Vingolds</name>
+ <name>James Agnew</name>
</contributor>
<contributor>
<name>Manuel Blechschmidt</name>
@@ -49,6 +49,9 @@ under the License.
<contributor>
<name>Masatake Iwasaki</name>
</contributor>
+ <contributor>
+ <name>Valters Vingolds</name>
+ </contributor>
</contributors>
<prerequisites>