You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2007/06/02 22:55:30 UTC
svn commit: r543783 - in /maven/shared/trunk/maven-reporting-impl: ./
src/main/java/org/apache/maven/reporting/ src/test/ src/test/java/
src/test/java/org/ src/test/java/org/apache/
src/test/java/org/apache/maven/ src/test/java/org/apache/maven/reporting/
Author: jvanzyl
Date: Sat Jun 2 13:55:29 2007
New Revision: 543783
URL: http://svn.apache.org/viewvc?view=rev&rev=543783
Log:
MNG-2855 Fix quote handling in linkPatternedText seems broken
Submitted by: Herve Boutemy
Added:
maven/shared/trunk/maven-reporting-impl/src/test/
maven/shared/trunk/maven-reporting-impl/src/test/java/
maven/shared/trunk/maven-reporting-impl/src/test/java/org/
maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/
maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/
maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/
maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java (with props)
Modified:
maven/shared/trunk/maven-reporting-impl/pom.xml
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java
Modified: maven/shared/trunk/maven-reporting-impl/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/pom.xml?view=diff&rev=543783&r1=543782&r2=543783
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/pom.xml (original)
+++ maven/shared/trunk/maven-reporting-impl/pom.xml Sat Jun 2 13:55:29 2007
@@ -7,9 +7,9 @@
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
@@ -80,6 +80,12 @@
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>2.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>junit-addons</groupId>
+ <artifactId>junit-addons</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
</dependency>
</dependencies>
</project>
Modified: maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java?view=diff&rev=543783&r1=543782&r2=543783
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java (original)
+++ maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReport.java Sat Jun 2 13:55:29 2007
@@ -19,14 +19,11 @@
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.doxia.sink.SinkFactory;
import org.apache.maven.doxia.siterenderer.Renderer;
-import org.apache.maven.doxia.siterenderer.RendererException;
-import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import java.io.File;
-import java.io.IOException;
import java.util.Locale;
/**
@@ -42,8 +39,6 @@
private Sink sink;
private SinkFactory sinkFactory;
-
- private Locale locale = Locale.ENGLISH;
protected abstract Renderer getSiteRenderer();
Modified: maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java?view=diff&rev=543783&r1=543782&r2=543783
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java (original)
+++ maven/shared/trunk/maven-reporting-impl/src/main/java/org/apache/maven/reporting/AbstractMavenReportRenderer.java Sat Jun 2 13:55:29 2007
@@ -21,10 +21,10 @@
import org.apache.maven.doxia.sink.Sink;
import org.codehaus.plexus.util.StringUtils;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.List;
import java.util.Properties;
/**
@@ -350,7 +350,7 @@
}
else
{
- Map segments = applyPattern( text );
+ List segments = applyPattern( text );
if ( segments == null )
{
@@ -358,12 +358,10 @@
}
else
{
- for ( Iterator it = segments.entrySet().iterator(); it.hasNext(); )
+ for ( Iterator it = segments.iterator(); it.hasNext(); )
{
- Map.Entry entry = (Map.Entry) it.next();
-
- String name = (String) entry.getKey();
- String href = (String) entry.getValue();
+ String name = (String) it.next();
+ String href = (String) it.next();
if ( href == null )
{
@@ -512,7 +510,7 @@
* @param text a text with or without the pattern <code>{text, url}</code>
* @return a map of text/href
*/
- private static Map applyPattern( String text )
+ private static List applyPattern( String text )
{
if ( StringUtils.isEmpty( text ) )
{
@@ -521,7 +519,7 @@
// Map defined by key/value name/href
// If href == null, it means
- Map segments = new LinkedHashMap();
+ List segments = new ArrayList();
// TODO Special case http://jira.codehaus.org/browse/MEV-40
if ( text.indexOf( "${" ) != -1 )
@@ -530,11 +528,13 @@
int lastSemi = text.lastIndexOf( "}" );
if ( lastComma != -1 && lastSemi != -1 )
{
- segments.put( text.substring( lastComma + 1, lastSemi ).trim(), null );
+ segments.add( text.substring( lastComma + 1, lastSemi ).trim() );
+ segments.add( null );
}
else
{
- segments.put( text, null );
+ segments.add( text );
+ segments.add( null );
}
return segments;
@@ -554,6 +554,9 @@
if ( i + 1 < text.length() && text.charAt( i + 1 ) == '\'' )
{
i++;
+ segments.add( text.substring( lastOffset, i ) );
+ segments.add( null );
+ lastOffset = i + 1;
}
else
{
@@ -571,11 +574,12 @@
{
if ( i != 0 ) // handle { at first character
{
- segments.put( text.substring( lastOffset, i ), null );
+ segments.add( text.substring( lastOffset, i ) );
+ segments.add( null );
}
lastOffset = i + 1;
- braceStack++;
}
+ braceStack++;
}
break;
case '}':
@@ -590,12 +594,13 @@
int lastComma = subString.lastIndexOf( "," );
if ( lastComma != -1 )
{
- segments.put( subString.substring( 0, lastComma ).trim(),
- subString.substring( lastComma + 1 ).trim() );
+ segments.add( subString.substring( 0, lastComma ).trim() );
+ segments.add( subString.substring( lastComma + 1 ).trim() );
}
else
{
- segments.put( subString.substring( 0, lastComma ).trim(), null );
+ segments.add( subString.substring( 0, lastComma ).trim() );
+ segments.add( null );
}
}
}
@@ -611,7 +616,8 @@
if ( !StringUtils.isEmpty( text.substring( lastOffset, text.length() ) ) )
{
- segments.put( text.substring( lastOffset, text.length() ), null );
+ segments.add( text.substring( lastOffset, text.length() ) );
+ segments.add( null );
}
if ( braceStack != 0 )
@@ -619,7 +625,13 @@
throw new IllegalArgumentException( "Unmatched braces in the pattern." );
}
- return Collections.unmodifiableMap( segments );
+ if ( inQuote )
+ {
+ //throw new IllegalArgumentException( "Unmatched quote in the pattern." );
+ //TODO: warning...
+ }
+
+ return Collections.unmodifiableList( segments );
}
public abstract String getTitle();
Added: maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java?view=auto&rev=543783
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java (added)
+++ maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java Sat Jun 2 13:55:29 2007
@@ -0,0 +1,100 @@
+package org.apache.maven.reporting;
+
+/*
+ * Copyright 2001-2007 The Apache Software Foundation.
+ *
+ * Licensed 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 java.util.Iterator;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import junitx.util.PrivateAccessor;
+
+public class AbstractMavenReportRendererTest extends TestCase
+{
+ private static List applyPattern( String pattern ) throws Throwable
+ {
+ return (List) PrivateAccessor.invoke( AbstractMavenReportRenderer.class, "applyPattern",
+ new Class[] { String.class }, new Object[] { pattern } );
+ }
+
+ private static void checkPattern( String pattern, String[] expectedResult ) throws Throwable
+ {
+ List result = applyPattern( pattern );
+ Assert.assertEquals( "result size", expectedResult.length, result.size() );
+ int i = 0;
+ for ( Iterator it = result.iterator(); it.hasNext(); )
+ {
+ String name = (String) it.next();
+ String href = (String) it.next();
+ Assert.assertEquals( expectedResult[i], name );
+ Assert.assertEquals( expectedResult[i + 1], href );
+ i += 2;
+ }
+ }
+
+ private static void checkPatternIllegalArgument( String cause, String pattern ) throws Throwable
+ {
+ try
+ {
+ applyPattern( pattern );
+ Assert.fail( cause + " should throw an IllegalArgumentException" );
+ }
+ catch ( IllegalArgumentException iae )
+ {
+ // ok
+ }
+ }
+
+ public void testApplyPattern() throws Throwable
+ {
+ // the most simple test
+ checkPattern( "test {text,url}", new String[] { "test ", null, "text", "url" } );
+
+ // check that link content is trimmed, and no problem if 2 text values are the same
+ checkPattern( "test{ text , url }test", new String[] { "test", null, "text", "url", "test", null } );
+
+ // check brace stacking
+ checkPattern( "test{ {text} , url }", new String[] { "test", null, "{text}", "url" } );
+
+ // check quoting
+ checkPatternIllegalArgument( "unmatched brace", "{" );
+ checkPattern( "'{'", new String[] { "'{'", null } );
+ checkPattern( " ' { '.", new String[] { " ' { '.", null } );
+
+ // unmatched quote: the actual behavior is to ignore that they are unmatched
+ checkPattern( " '", new String[] { " '", null } );
+ // but shouldn't it be different and throw an IllegalArgumentException?
+ // checkPatternIllegalArgument( "unmatched quote", " ' " );
+ // checkPatternIllegalArgument( "unmatched quote", " '" );
+ // impact is too important to make the change for the moment
+
+ // check double quoting
+ checkPattern( " ''", new String[] { " '", null } );
+ checkPattern( " '' ", new String[] { " '", null } );
+ checkPattern( " '' ", new String[] { " '", null } );
+
+ // real world cases with quote
+ checkPattern( "project''s info", new String[] { "project'", null, "s info", null } );
+ checkPattern( "it''s a question of {chance, http://en.wikipedia.org/wiki/Chance}",
+ new String[] { "it'", null, "s a question of ", null, "chance", "http://en.wikipedia.org/wiki/Chance" } );
+
+ // throwing an IllegalArgumentException in case of unmatched quote would avoid the following:
+ checkPattern( "it's a question of {chance, http://en.wikipedia.org/wiki/Chance}",
+ new String[] { "it's a question of {chance, http://en.wikipedia.org/wiki/Chance}", null } );
+ }
+
+}
Propchange: maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-reporting-impl/src/test/java/org/apache/maven/reporting/AbstractMavenReportRendererTest.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"