1 package org.apache.maven.changes;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 /**
21 * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
22 *
23 * @version $Id: IssueFinder.java 434563 2006-08-24 23:32:54Z ltheussl $
24 */
25 public class IssueFinder
26 {
27 /**
28 * @param trackerURL the issue tracker URL (this is supposed to be the
29 * value of <issueTrackingUrl> found in the POM.
30 * @param issue the issue reference
31 * @param template the template string. Allowed template patterns are
32 * <code>%URL%</code> and <code>%ISSUE%</code>. They will be
33 * replaced by the base tracker URL extracted from trackerURL and
34 * by the issue reference.
35 * @return The URL of the issue.
36 */
37 public static String getIssueURL( String trackerURL, String issue,
38 String template )
39 {
40
41 String baseURL;
42 int pos = trackerURL.lastIndexOf( "/" );
43 if ( pos > 0 )
44 {
45 baseURL = trackerURL.substring( 0, pos );
46 }
47 else
48 {
49 throw new RuntimeException( "Failed to extract tracker URL from ["
50 + trackerURL + "]" );
51 }
52
53
54 String issueURL = replace( template, "%URL%", baseURL );
55 issueURL = replace( issueURL, "%ISSUE%", issue );
56
57 return issueURL;
58 }
59
60 /**
61 * @param original the original template
62 * @param oldPattern the pattern to replace
63 * @param newPattern the new pattern
64 * @return the modified template string with patterns applied
65 */
66 public static final String replace( String original, String oldPattern,
67 String newPattern )
68 {
69 int index, oldIndex;
70 StringBuffer buffer = new StringBuffer();
71
72 if ( ( index = original.indexOf( oldPattern ) ) != -1 )
73 {
74 oldIndex = 0;
75 while ( ( index = original.indexOf( oldPattern, oldIndex ) ) != -1 )
76 {
77 buffer.append( original.substring( oldIndex, index ) );
78 buffer.append( newPattern);
79 oldIndex = index + oldPattern.length();
80 }
81 buffer.append( original.substring( oldIndex ) );
82 original = buffer.toString();
83 }
84 return original;
85 }
86
87 }