From 379769638d2d1897a753a1c5b9b2798f484d4de8 Mon Sep 17 00:00:00 2001 From: Johannes Utzig Date: Wed, 10 Apr 2013 16:03:04 +0200 Subject: [PATCH] allow encoding of file paths for gitblit --- .../plugin/changelog/ChangeLogReport.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/maven-changelog-plugin/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java b/maven-changelog-plugin/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java index aead601f30..cb27756722 100644 --- a/maven-changelog-plugin/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java +++ b/maven-changelog-plugin/src/main/java/org/apache/maven/plugin/changelog/ChangeLogReport.java @@ -59,6 +59,7 @@ import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.net.URLEncoder; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -229,6 +230,14 @@ public class ChangeLogReport @Parameter( property = "changelog.skip", defaultValue = "false" ) protected boolean skip; + /** + * Encodes slashes in file uri. Required for some repository browsers like gitblit + * + * @since 2.3 + */ + @Parameter( property = "encodeFileUri", defaultValue = "false") + protected boolean encodeFileUri; + /** * The Maven Project Object */ @@ -1473,18 +1482,31 @@ protected void generateLinks( String connection, String name, String revision, S { if ( !linkFile.equals( scmUrl ) ) { + String linkName = name; + if(encodeFileUri) + { + try + { + linkName = URLEncoder.encode(linkName, "UTF-8"); + } + catch (UnsupportedEncodingException e) + { + // UTF-8 is always supported + } + } + // Use the given URL to create links to the files if ( linkFile.indexOf( FILE_TOKEN ) > 0 ) { - linkFile = linkFile.replaceAll( FILE_TOKEN, name ); + linkFile = linkFile.replaceAll( FILE_TOKEN, linkName ); } else { // This is here so that we are backwards compatible with the // format used before the special token was introduced - linkFile = linkFile + name; + linkFile = linkFile + linkName; } // Use the given URL to create links to the files