1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.codehaus.mojo.scmchangelog.scm.svn;
25
26 import org.codehaus.mojo.scmchangelog.AbstractBufferedConsumer;
27 import org.codehaus.mojo.scmchangelog.tags.Tag;
28 import org.codehaus.mojo.scmchangelog.scm.svn.xml.CommitDocument.Commit;
29 import org.codehaus.mojo.scmchangelog.scm.svn.xml.EntryDocument.Entry;
30 import org.codehaus.mojo.scmchangelog.scm.svn.xml.ListDocument.List;
31 import org.codehaus.mojo.scmchangelog.scm.svn.xml.ListsDocument;
32 import org.codehaus.mojo.scmchangelog.scm.svn.xml.ListsDocument.Factory;
33
34 import org.apache.xmlbeans.XmlException;
35
36
37 import java.io.IOException;
38 import java.io.StringReader;
39
40 import java.util.ArrayList;
41 import java.util.Collections;
42 import java.util.Iterator;
43 import java.util.regex.Matcher;
44 import java.util.regex.Pattern;
45
46
47
48
49
50
51
52 public class SvnListConsumer
53 extends AbstractBufferedConsumer
54 {
55
56
57
58
59 private java.util.List elements = new ArrayList();
60
61
62
63
64
65 private Pattern filter;
66
67
68
69
70
71 public SvnListConsumer ( Pattern filter )
72 {
73 this.filter = filter;
74 }
75
76
77
78
79
80
81 public java.util.List analyse()
82 {
83 getLogger().debug( "Receiving this line " + getOutput() );
84
85 try
86 {
87 ListsDocument doc = Factory.parse( new StringReader( getOutput() ) );
88
89 for ( int i = 0; i < doc.getLists().getListArray().length; i++ )
90 {
91 List list = doc.getLists().getListArray()[i];
92
93 for ( int j = 0; j < list.getEntryArray().length; j++ )
94 {
95 Entry entry = list.getEntryArray()[j];
96 getLogger().debug( entry.getName() );
97 if ( isTagAccepted( entry.getName() ) )
98 {
99 getLogger().debug( "Creating new Tag" );
100 Tag tag = new Tag( entry.getName() );
101 Commit commit = entry.getCommit();
102 tag.setDate( commit.getDate().getTime() );
103 tag.setEndRevision( commit.getRevision().toString() );
104 tag.setAuthor( commit.getAuthor() );
105 elements.add( tag );
106 }
107 }
108 }
109 Collections.sort( elements );
110 Tag oldTag = new Tag( "" );
111 oldTag.setEndRevision( "0" );
112 Iterator iter = elements.iterator();
113 while ( iter.hasNext() )
114 {
115 Tag tag = ( Tag ) iter.next();
116 tag.setStartRevision( oldTag.getEndRevision() );
117 oldTag = tag;
118 }
119 return this.elements;
120 }
121 catch ( XmlException ex )
122 {
123 getLogger().error( getOutput(), ex );
124 throw new RuntimeException( ex );
125 }
126 catch ( IOException ioe )
127 {
128 getLogger().error( getOutput(), ioe );
129 throw new RuntimeException( ioe );
130 }
131 }
132
133
134
135
136
137
138 protected boolean isTagAccepted( String title )
139 {
140 if ( "tags".equalsIgnoreCase( title ) )
141 {
142 return false;
143 }
144 if ( filter != null )
145 {
146 Matcher matcher = filter.matcher( title );
147 getLogger().debug( "Filtering " + title + " against " + filter.pattern()
148 + " : " + matcher.matches() );
149 return matcher.matches();
150 }
151 return true;
152 }
153 }