1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.releaser.util.pom;
35
36 import java.io.FileInputStream;
37 import java.io.FileNotFoundException;
38 import java.io.IOException;
39 import java.io.InputStream;
40 import java.io.StringReader;
41 import java.util.ArrayList;
42 import java.util.List;
43
44 import javax.xml.bind.JAXBContext;
45 import javax.xml.bind.JAXBElement;
46 import javax.xml.bind.JAXBException;
47 import javax.xml.bind.Unmarshaller;
48
49 import org.xml.sax.InputSource;
50
51 import fr.paris.lutece.plugins.releaser.business.jaxb.maven.Model;
52 import fr.paris.lutece.plugins.releaser.business.Component;
53 import fr.paris.lutece.plugins.releaser.business.Dependency;
54 import fr.paris.lutece.plugins.releaser.business.Site;
55 import fr.paris.lutece.portal.service.util.AppLogService;
56
57
58
59
60
61 public class PomParser
62 {
63
64
65
66 private ArrayList<Dependency> _listDependencies = new ArrayList<Dependency>( );
67
68
69
70
71
72
73 public List<Dependency> getDependencies( )
74 {
75 return _listDependencies;
76 }
77
78
79
80
81
82
83
84
85
86 public void parse( Site site, String strPOM )
87 {
88 try
89 {
90 InputSource isPOM = new InputSource( new StringReader( strPOM ) );
91 Model model = unmarshal( Model.class, isPOM );
92
93 filledSite( site, model );
94
95 fr.paris.lutece.plugins.releaser.business.jaxb.maven.Model.Dependencies dependencies = model.getDependencies( );
96
97 if ( dependencies != null )
98 {
99 for ( fr.paris.lutece.plugins.releaser.business.jaxb.maven.Dependency jaxDependency : dependencies.getDependency( ) )
100 {
101 filledDependency( site, jaxDependency );
102
103 }
104 }
105 }
106 catch( JAXBException e )
107 {
108 AppLogService.error( e );
109 }
110 }
111
112
113
114
115
116
117
118
119
120 public void parse( Component component, String strPOM )
121 {
122
123 try
124 {
125 InputSource isPOM = new InputSource( new StringReader( strPOM ) );
126 Model model = unmarshal( Model.class, isPOM );
127 component.setArtifactId( model.getArtifactId( ) );
128 component.setGroupId( model.getGroupId( ) );
129 component.setCurrentVersion( model.getVersion( ) );
130 if ( model.getScm( ) != null )
131 {
132 component.setScmDeveloperConnection( model.getScm( ).getDeveloperConnection( ) );
133 component.setBranchReleaseVersion( model.getVersion( ) );
134
135 }
136
137 }
138 catch( JAXBException e )
139 {
140 AppLogService.error( e );
141 }
142
143 }
144
145
146
147
148
149
150
151
152
153 public void parse( Component component, InputStream inputStream )
154 {
155
156 try
157 {
158 Model model = PomUpdater.unmarshal( Model.class, inputStream );
159 component.setArtifactId( model.getArtifactId( ) );
160 component.setGroupId( model.getGroupId( ) );
161 component.setCurrentVersion( model.getVersion( ) );
162 if ( model.getScm( ) != null )
163 {
164 component.setScmDeveloperConnection( model.getScm( ).getDeveloperConnection( ) );
165
166 }
167
168 }
169 catch( JAXBException e )
170 {
171 AppLogService.error( e );
172 }
173 finally
174 {
175
176 try
177 {
178 inputStream.close( );
179 }
180 catch( IOException e )
181 {
182 AppLogService.error( e );
183 }
184 }
185
186 }
187
188
189
190
191
192
193
194
195
196 private void filledSite( Site site, Model model )
197 {
198 site.setArtifactId( model.getArtifactId( ) );
199 site.setGroupId( model.getGroupId( ) );
200 site.setVersion( model.getVersion( ) );
201 }
202
203
204
205
206
207
208
209
210
211 private void filledDependency( Site site, fr.paris.lutece.plugins.releaser.business.jaxb.maven.Dependency jaxDependency )
212 {
213 Dependencyins/releaser/business/Dependency.html#Dependency">Dependency dep = new Dependency( );
214 dep.setArtifactId( jaxDependency.getArtifactId( ) );
215 dep.setVersion( jaxDependency.getVersion( ) );
216 dep.setGroupId( jaxDependency.getGroupId( ) );
217 dep.setType( jaxDependency.getType( ) );
218
219 site.addCurrentDependency( dep );
220 }
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 public static <T> T unmarshal( Class<T> docClass, InputSource inputSource ) throws JAXBException
236 {
237 String packageName = docClass.getPackage( ).getName( );
238 JAXBContext jc = JAXBContext.newInstance( packageName );
239 Unmarshaller u = jc.createUnmarshaller( );
240 JAXBElement<T> doc = (JAXBElement<T>) u.unmarshal( inputSource );
241
242 return doc.getValue( );
243 }
244
245 }