1 | |
package org.apache.maven.model.converter; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.model.Build; |
23 | |
import org.apache.maven.model.CiManagement; |
24 | |
import org.apache.maven.model.Contributor; |
25 | |
import org.apache.maven.model.Dependency; |
26 | |
import org.apache.maven.model.DeploymentRepository; |
27 | |
import org.apache.maven.model.Developer; |
28 | |
import org.apache.maven.model.DistributionManagement; |
29 | |
import org.apache.maven.model.IssueManagement; |
30 | |
import org.apache.maven.model.License; |
31 | |
import org.apache.maven.model.MailingList; |
32 | |
import org.apache.maven.model.Model; |
33 | |
import org.apache.maven.model.Notifier; |
34 | |
import org.apache.maven.model.Organization; |
35 | |
import org.apache.maven.model.Plugin; |
36 | |
import org.apache.maven.model.ReportPlugin; |
37 | |
import org.apache.maven.model.Reporting; |
38 | |
import org.apache.maven.model.Resource; |
39 | |
import org.apache.maven.model.Scm; |
40 | |
import org.apache.maven.model.Site; |
41 | |
import org.apache.maven.model.v3_0_0.UnitTest; |
42 | |
import org.codehaus.plexus.util.StringUtils; |
43 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
44 | |
|
45 | |
import java.util.ArrayList; |
46 | |
import java.util.HashMap; |
47 | |
import java.util.Iterator; |
48 | |
import java.util.List; |
49 | |
import java.util.Map; |
50 | |
import java.util.Properties; |
51 | |
import java.util.regex.Matcher; |
52 | |
import java.util.regex.Pattern; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public class PomV3ToV4Translator |
59 | |
implements ModelConverter |
60 | |
{ |
61 | 8 | private transient List discoveredPlugins = new ArrayList(); |
62 | |
|
63 | |
private List warnings; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 8 | private Map model3ReportPlugins = new HashMap(); |
71 | |
|
72 | |
public PomV3ToV4Translator() |
73 | 8 | { |
74 | |
|
75 | |
|
76 | 8 | model3ReportPlugins.put( "maven-cobertura-plugin", "maven-plugins" ); |
77 | 8 | model3ReportPlugins.put( "maven-findbugs-plugin", "maven-plugins" ); |
78 | 8 | model3ReportPlugins.put( "maven-javancss-plugin", "maven-plugins" ); |
79 | 8 | } |
80 | |
|
81 | |
public Model translate( org.apache.maven.model.v3_0_0.Model v3Model ) |
82 | |
throws PomTranslationException |
83 | |
{ |
84 | 10 | warnings = new ArrayList(); |
85 | |
|
86 | |
try |
87 | |
{ |
88 | 10 | String groupId = format( v3Model.getGroupId() ); |
89 | 10 | String artifactId = format( v3Model.getArtifactId() ); |
90 | |
|
91 | 10 | String id = v3Model.getId(); |
92 | |
|
93 | 10 | if ( StringUtils.isNotEmpty( id ) ) |
94 | |
{ |
95 | 0 | if ( StringUtils.isEmpty( groupId ) ) |
96 | |
{ |
97 | 0 | int plusIdx = id.indexOf( "+" ); |
98 | 0 | if ( plusIdx > -1 ) |
99 | |
{ |
100 | 0 | groupId = id.substring( 0, plusIdx ); |
101 | |
} |
102 | |
else |
103 | |
{ |
104 | 0 | groupId = id; |
105 | |
} |
106 | |
} |
107 | |
|
108 | 0 | if ( StringUtils.isEmpty( artifactId ) ) |
109 | |
{ |
110 | 0 | artifactId = format( id ); |
111 | |
} |
112 | |
} |
113 | |
|
114 | 10 | String version = format( v3Model.getCurrentVersion() ); |
115 | |
|
116 | 10 | if ( version == null ) |
117 | |
{ |
118 | 10 | version = format( v3Model.getVersion() ); |
119 | |
} |
120 | |
|
121 | 10 | PomKey pomKey = new PomKey( groupId, artifactId, version ); |
122 | |
|
123 | 10 | Properties properties = v3Model.getProperties(); |
124 | |
|
125 | 10 | warnOfUnsupportedMainModelElements( v3Model ); |
126 | |
|
127 | 10 | Model model = new Model(); |
128 | 10 | model.setArtifactId( artifactId ); |
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | 10 | model.setDependencies( translateDependencies( v3Model.getDependencies() ) ); |
134 | |
|
135 | 10 | model.setBuild( translateBuild( v3Model.getBuild() ) ); |
136 | 10 | model.setCiManagement( translateCiManagementInfo( v3Model.getBuild() ) ); |
137 | 10 | model.setContributors( translateContributors( v3Model.getContributors() ) ); |
138 | |
|
139 | 10 | model.setDescription( v3Model.getDescription() ); |
140 | 10 | model.setDevelopers( translateDevelopers( v3Model.getDevelopers() ) ); |
141 | |
|
142 | 10 | model.setDistributionManagement( translateDistributionManagement( pomKey, v3Model ) ); |
143 | |
|
144 | 10 | model.setGroupId( groupId ); |
145 | 10 | model.setInceptionYear( v3Model.getInceptionYear() ); |
146 | 10 | model.setIssueManagement( translateIssueManagement( v3Model ) ); |
147 | |
|
148 | 10 | model.setLicenses( translateLicenses( v3Model.getLicenses() ) ); |
149 | 10 | model.setMailingLists( translateMailingLists( v3Model.getMailingLists() ) ); |
150 | 10 | model.setModelVersion( "4.0.0" ); |
151 | 10 | model.setName( v3Model.getName() ); |
152 | 10 | model.setOrganization( translateOrganization( v3Model.getOrganization() ) ); |
153 | 10 | model.setPackaging( "jar" ); |
154 | |
|
155 | 10 | model.setReporting( translateReports( v3Model.getReports() ) ); |
156 | 10 | model.setScm( translateScm( v3Model ) ); |
157 | 10 | model.setUrl( v3Model.getUrl() ); |
158 | |
|
159 | 10 | model.setProperties( properties ); |
160 | |
|
161 | 10 | model.setVersion( version ); |
162 | |
|
163 | 10 | return model; |
164 | |
} |
165 | |
finally |
166 | |
{ |
167 | 10 | this.discoveredPlugins.clear(); |
168 | |
} |
169 | |
} |
170 | |
|
171 | |
private String format( String source ) |
172 | |
{ |
173 | 62 | return source == null ? null : source.replace( '+', '-' ); |
174 | |
} |
175 | |
|
176 | |
private CiManagement translateCiManagementInfo( org.apache.maven.model.v3_0_0.Build v3Build ) |
177 | |
{ |
178 | 10 | CiManagement ciMgmt = null; |
179 | |
|
180 | 10 | if ( v3Build != null ) |
181 | |
{ |
182 | 9 | String nagEmailAddress = v3Build.getNagEmailAddress(); |
183 | |
|
184 | 9 | if ( StringUtils.isNotEmpty( nagEmailAddress ) ) |
185 | |
{ |
186 | 0 | Notifier notifier = new Notifier(); |
187 | |
|
188 | 0 | notifier.setType( "mail" ); |
189 | 0 | notifier.addConfiguration( "address", nagEmailAddress ); |
190 | |
|
191 | 0 | ciMgmt = new CiManagement(); |
192 | 0 | ciMgmt.addNotifier( notifier ); |
193 | |
} |
194 | |
} |
195 | |
|
196 | 10 | return ciMgmt; |
197 | |
} |
198 | |
|
199 | |
private void warnOfUnsupportedMainModelElements( org.apache.maven.model.v3_0_0.Model v3Model ) |
200 | |
{ |
201 | 10 | if ( StringUtils.isNotEmpty( v3Model.getExtend() ) ) |
202 | |
{ |
203 | 0 | warnings.add( "Ignoring non-portable parent declaration: " + v3Model.getExtend() ); |
204 | |
} |
205 | |
|
206 | 10 | if ( StringUtils.isNotEmpty( v3Model.getGumpRepositoryId() ) ) |
207 | |
{ |
208 | 0 | warnings.add( "Ignoring gump repository id: \'" + v3Model.getGumpRepositoryId() |
209 | |
+ "\'. This is not supported in v4 POMs." ); |
210 | |
} |
211 | |
|
212 | 10 | if ( notEmpty( v3Model.getVersions() ) ) |
213 | |
{ |
214 | 0 | warnings.add( "Ignoring <versions/> section. This is not supported in v4 POMs." ); |
215 | |
} |
216 | |
|
217 | 10 | if ( notEmpty( v3Model.getBranches() ) ) |
218 | |
{ |
219 | 0 | warnings.add( "Ignoring <branches/> section. This is not supported in v4 POMs." ); |
220 | |
} |
221 | |
|
222 | 10 | Properties v3ModelProperties = v3Model.getProperties(); |
223 | |
|
224 | 10 | if ( StringUtils.isNotEmpty( v3Model.getPackage() ) ) |
225 | |
{ |
226 | 0 | warnings.add( "Ignoring <package/>. It is not supported in v4 POMs." ); |
227 | |
} |
228 | |
|
229 | 10 | if ( notEmpty( v3Model.getPackageGroups() ) ) |
230 | |
{ |
231 | 0 | warnings.add( "Ignoring <packageGroups/> section. It is not supported in v4 POMs." ); |
232 | |
} |
233 | |
|
234 | 10 | if ( StringUtils.isNotEmpty( v3Model.getLogo() ) ) |
235 | |
{ |
236 | 0 | warnings.add( "Ignoring <logo/> for project. It is not supported in v4 POMs." ); |
237 | |
} |
238 | |
|
239 | 10 | if ( StringUtils.isNotEmpty( v3Model.getShortDescription() ) ) |
240 | |
{ |
241 | 0 | warnings.add( "Ignoring <shortDescription/>. It is not supported in v4 POMs." ); |
242 | |
} |
243 | 10 | } |
244 | |
|
245 | |
private Scm translateScm( org.apache.maven.model.v3_0_0.Model v3Model ) |
246 | |
{ |
247 | 10 | Scm scm = null; |
248 | |
|
249 | 10 | org.apache.maven.model.v3_0_0.Repository repo = v3Model.getRepository(); |
250 | 10 | if ( repo != null ) |
251 | |
{ |
252 | 0 | scm = new Scm(); |
253 | 0 | scm.setConnection( repo.getConnection() ); |
254 | 0 | scm.setDeveloperConnection( repo.getDeveloperConnection() ); |
255 | 0 | scm.setUrl( repo.getUrl() ); |
256 | |
} |
257 | |
|
258 | 10 | return scm; |
259 | |
} |
260 | |
|
261 | |
private Reporting translateReports( List v3Reports ) |
262 | |
{ |
263 | 10 | Reporting reports = null; |
264 | 10 | if ( v3Reports != null && !v3Reports.isEmpty() ) |
265 | |
{ |
266 | 0 | reports = new Reporting(); |
267 | 0 | for ( Iterator it = v3Reports.iterator(); it.hasNext(); ) |
268 | |
{ |
269 | 0 | String reportName = (String) it.next(); |
270 | |
|
271 | 0 | Pattern pluginNamePattern = Pattern.compile( "maven-(.+)-plugin" ); |
272 | 0 | Matcher matcher = pluginNamePattern.matcher( reportName ); |
273 | |
|
274 | 0 | if ( !matcher.matches() ) |
275 | |
{ |
276 | 0 | warnings.add( |
277 | |
"Non-standard report: \'" + reportName + "\'. Skipping this one." ); |
278 | |
} |
279 | |
else |
280 | |
{ |
281 | 0 | ReportPlugin reportPlugin = new ReportPlugin(); |
282 | |
|
283 | 0 | reportPlugin.setGroupId( findReportPluginGroupId( reportName ) ); |
284 | |
|
285 | 0 | reportPlugin.setArtifactId( reportName ); |
286 | |
|
287 | 0 | StringBuffer info = new StringBuffer(); |
288 | |
|
289 | 0 | info.append( "Using some derived information for report: \'" ).append( reportName ).append( "\'.\n" ) |
290 | |
.append( "\to groupId: \'" ).append( reportPlugin.getGroupId() ).append( "\'\n" ) |
291 | |
.append( "\to artifactId: \'" ).append( reportName ).append( "\'\n" ) |
292 | |
.append( "\to goal: \'report\'\n" ) |
293 | |
.append( "\n" ) |
294 | |
.append( "These values were extracted using the v3 report naming convention, but may be wrong." ); |
295 | |
|
296 | 0 | warnings.add( info.toString() ); |
297 | |
|
298 | 0 | reports.addPlugin( reportPlugin ); |
299 | |
} |
300 | |
} |
301 | |
} |
302 | |
|
303 | 10 | return reports; |
304 | |
} |
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
private String findReportPluginGroupId( String artifactId ) |
313 | |
{ |
314 | 0 | String groupId = (String) model3ReportPlugins.get( artifactId ); |
315 | 0 | if ( groupId == null ) |
316 | |
{ |
317 | 0 | groupId = "org.apache.maven.plugins"; |
318 | |
} |
319 | 0 | return groupId; |
320 | |
} |
321 | |
|
322 | |
private Organization translateOrganization( org.apache.maven.model.v3_0_0.Organization v3Organization ) |
323 | |
{ |
324 | 10 | Organization organization = null; |
325 | |
|
326 | 10 | if ( v3Organization != null ) |
327 | |
{ |
328 | 0 | organization = new Organization(); |
329 | |
|
330 | 0 | organization.setName( v3Organization.getName() ); |
331 | 0 | organization.setUrl( v3Organization.getUrl() ); |
332 | |
|
333 | 0 | if ( StringUtils.isNotEmpty( v3Organization.getLogo() ) ) |
334 | |
{ |
335 | 0 | warnings.add( "Ignoring <organization><logo/></organization>. It is not supported in v4 POMs." ); |
336 | |
} |
337 | |
} |
338 | |
|
339 | 10 | return organization; |
340 | |
} |
341 | |
|
342 | |
private List translateMailingLists( List v3MailingLists ) |
343 | |
{ |
344 | 10 | List mailingLists = new ArrayList(); |
345 | |
|
346 | 10 | if ( notEmpty( v3MailingLists ) ) |
347 | |
{ |
348 | 0 | for ( Iterator it = v3MailingLists.iterator(); it.hasNext(); ) |
349 | |
{ |
350 | 0 | org.apache.maven.model.v3_0_0.MailingList v3List = (org.apache.maven.model.v3_0_0.MailingList) it |
351 | |
.next(); |
352 | 0 | MailingList list = new MailingList(); |
353 | 0 | list.setArchive( v3List.getArchive() ); |
354 | 0 | list.setName( v3List.getName() ); |
355 | 0 | list.setSubscribe( v3List.getSubscribe() ); |
356 | 0 | list.setUnsubscribe( v3List.getUnsubscribe() ); |
357 | |
|
358 | 0 | mailingLists.add( list ); |
359 | |
} |
360 | |
} |
361 | |
|
362 | 10 | return mailingLists; |
363 | |
} |
364 | |
|
365 | |
private List translateLicenses( List v3Licenses ) |
366 | |
{ |
367 | 10 | List licenses = new ArrayList(); |
368 | |
|
369 | 10 | if ( notEmpty( v3Licenses ) ) |
370 | |
{ |
371 | 0 | for ( Iterator it = v3Licenses.iterator(); it.hasNext(); ) |
372 | |
{ |
373 | 0 | org.apache.maven.model.v3_0_0.License v3License = (org.apache.maven.model.v3_0_0.License) it.next(); |
374 | 0 | License license = new License(); |
375 | 0 | license.setComments( v3License.getComments() ); |
376 | 0 | license.setDistribution( v3License.getDistribution() ); |
377 | 0 | license.setName( v3License.getName() ); |
378 | 0 | license.setUrl( v3License.getUrl() ); |
379 | |
|
380 | 0 | licenses.add( license ); |
381 | |
} |
382 | |
} |
383 | |
|
384 | 10 | return licenses; |
385 | |
} |
386 | |
|
387 | |
private IssueManagement translateIssueManagement( org.apache.maven.model.v3_0_0.Model v3Model ) |
388 | |
{ |
389 | 10 | IssueManagement issueMgmt = null; |
390 | |
|
391 | 10 | String issueTrackingUrl = v3Model.getIssueTrackingUrl(); |
392 | 10 | if ( StringUtils.isNotEmpty( issueTrackingUrl ) ) |
393 | |
{ |
394 | 0 | issueMgmt = new IssueManagement(); |
395 | 0 | issueMgmt.setUrl( issueTrackingUrl ); |
396 | |
} |
397 | |
|
398 | 10 | return issueMgmt; |
399 | |
} |
400 | |
|
401 | |
private DistributionManagement translateDistributionManagement( PomKey pomKey, |
402 | |
org.apache.maven.model.v3_0_0.Model v3Model ) |
403 | |
throws PomTranslationException |
404 | |
{ |
405 | 10 | DistributionManagement distributionManagement = new DistributionManagement(); |
406 | |
|
407 | 10 | Site site = null; |
408 | |
|
409 | 10 | String siteAddress = v3Model.getSiteAddress(); |
410 | |
|
411 | 10 | String siteDirectory = v3Model.getSiteDirectory(); |
412 | |
|
413 | 10 | if ( StringUtils.isEmpty( siteAddress ) ) |
414 | |
{ |
415 | 10 | if ( !StringUtils.isEmpty( siteDirectory ) ) |
416 | |
{ |
417 | 0 | site = new Site(); |
418 | |
|
419 | 0 | site.setId( "default" ); |
420 | |
|
421 | 0 | site.setName( "Default Site" ); |
422 | |
|
423 | 0 | site.setUrl( "file://" + siteDirectory ); |
424 | |
} |
425 | |
} |
426 | |
else |
427 | |
{ |
428 | 0 | if ( StringUtils.isEmpty( siteDirectory ) ) |
429 | |
{ |
430 | 0 | throw new PomTranslationException( pomKey.groupId(), pomKey.artifactId(), pomKey.version(), |
431 | |
"Missing 'siteDirectory': Both siteAddress and siteDirectory must be set at the same time." ); |
432 | |
} |
433 | |
|
434 | 0 | site = new Site(); |
435 | |
|
436 | 0 | site.setId( "default" ); |
437 | |
|
438 | 0 | site.setName( "Default Site" ); |
439 | |
|
440 | 0 | StringBuffer url = new StringBuffer( "scp://" ); |
441 | 0 | url.append( siteAddress ); |
442 | 0 | if ( !siteAddress.endsWith( "/" ) && !siteDirectory.startsWith( "/" ) ) |
443 | |
{ |
444 | 0 | url.append( "/" ); |
445 | |
} |
446 | 0 | url.append( siteDirectory ); |
447 | 0 | site.setUrl( url.toString() ); |
448 | |
} |
449 | |
|
450 | 10 | distributionManagement.setSite( site ); |
451 | |
|
452 | 10 | String distributionSite = v3Model.getDistributionSite(); |
453 | |
|
454 | 10 | String distributionDirectory = v3Model.getDistributionDirectory(); |
455 | |
|
456 | 10 | DeploymentRepository repository = null; |
457 | |
|
458 | 10 | if ( StringUtils.isEmpty( distributionSite ) ) |
459 | |
{ |
460 | 10 | if ( !StringUtils.isEmpty( distributionDirectory ) ) |
461 | |
{ |
462 | 0 | repository = new DeploymentRepository(); |
463 | |
|
464 | 0 | repository.setId( "default" ); |
465 | |
|
466 | 0 | repository.setName( "Default Repository" ); |
467 | |
|
468 | 0 | repository.setUrl( "file://" + distributionDirectory ); |
469 | |
|
470 | |
|
471 | |
} |
472 | |
} |
473 | |
else |
474 | |
{ |
475 | 0 | if ( StringUtils.isEmpty( distributionDirectory ) ) |
476 | |
{ |
477 | 0 | throw new PomTranslationException( pomKey.groupId(), pomKey.artifactId(), pomKey.version(), |
478 | |
"Missing 'distributionDirectory': must be set is 'distributionSite' is set." ); |
479 | |
} |
480 | |
|
481 | 0 | repository = new DeploymentRepository(); |
482 | |
|
483 | 0 | repository.setId( "default" ); |
484 | |
|
485 | 0 | repository.setName( "Default Repository" ); |
486 | |
|
487 | 0 | repository.setUrl( distributionSite + "/" + distributionDirectory ); |
488 | |
} |
489 | |
|
490 | 10 | distributionManagement.setRepository( repository ); |
491 | |
|
492 | 10 | distributionManagement.setStatus( "converted" ); |
493 | |
|
494 | 10 | if ( site == null && repository == null ) |
495 | |
{ |
496 | 10 | return null; |
497 | |
} |
498 | |
|
499 | 0 | return distributionManagement; |
500 | |
} |
501 | |
|
502 | |
private List translateDevelopers( List v3Developers ) |
503 | |
{ |
504 | 10 | List developers = new ArrayList(); |
505 | |
|
506 | 10 | if ( notEmpty( v3Developers ) ) |
507 | |
{ |
508 | 0 | for ( Iterator it = v3Developers.iterator(); it.hasNext(); ) |
509 | |
{ |
510 | 0 | org.apache.maven.model.v3_0_0.Developer v3Developer = (org.apache.maven.model.v3_0_0.Developer) it |
511 | |
.next(); |
512 | |
|
513 | 0 | Developer developer = new Developer(); |
514 | |
|
515 | 0 | developer.setEmail( v3Developer.getEmail() ); |
516 | 0 | developer.setId( v3Developer.getId() ); |
517 | 0 | developer.setName( v3Developer.getName() ); |
518 | 0 | developer.setOrganization( v3Developer.getOrganization() ); |
519 | 0 | developer.setRoles( v3Developer.getRoles() ); |
520 | 0 | developer.setTimezone( v3Developer.getTimezone() ); |
521 | 0 | developer.setUrl( v3Developer.getUrl() ); |
522 | |
|
523 | 0 | developers.add( developer ); |
524 | |
} |
525 | |
} |
526 | |
|
527 | 10 | return developers; |
528 | |
} |
529 | |
|
530 | |
private List translateDependencies( List v3Deps ) |
531 | |
{ |
532 | 10 | List deps = new ArrayList(); |
533 | |
|
534 | 10 | if ( notEmpty( v3Deps ) ) |
535 | |
{ |
536 | 8 | boolean isJunitPresent = false; |
537 | |
|
538 | 8 | for ( Iterator it = v3Deps.iterator(); it.hasNext(); ) |
539 | |
{ |
540 | 10 | org.apache.maven.model.v3_0_0.Dependency v3Dep = (org.apache.maven.model.v3_0_0.Dependency) it.next(); |
541 | |
|
542 | 10 | String groupId = format( v3Dep.getGroupId() ); |
543 | 10 | String artifactId = format( v3Dep.getArtifactId() ); |
544 | |
|
545 | 10 | String id = v3Dep.getId(); |
546 | |
|
547 | 10 | if ( StringUtils.isNotEmpty( id ) ) |
548 | |
{ |
549 | 0 | if ( StringUtils.isEmpty( groupId ) ) |
550 | |
{ |
551 | 0 | int plusIdx = id.indexOf( "+" ); |
552 | |
|
553 | 0 | if ( plusIdx > -1 ) |
554 | |
{ |
555 | 0 | groupId = id.substring( 0, plusIdx ); |
556 | |
} |
557 | |
else |
558 | |
{ |
559 | 0 | groupId = id; |
560 | |
} |
561 | |
} |
562 | |
|
563 | 0 | if ( StringUtils.isEmpty( artifactId ) ) |
564 | |
{ |
565 | 0 | artifactId = format( id ); |
566 | |
} |
567 | |
} |
568 | |
|
569 | 10 | if ( "junit".equals( groupId ) && "junit".equals( artifactId ) ) |
570 | |
{ |
571 | 0 | isJunitPresent = true; |
572 | |
} |
573 | |
|
574 | 10 | String type = v3Dep.getType(); |
575 | 10 | if ( "plugin".equals( type ) ) |
576 | |
{ |
577 | 2 | if ( "maven".equals( groupId ) ) |
578 | |
{ |
579 | 1 | groupId = "org.apache.maven.plugins"; |
580 | |
} |
581 | |
|
582 | 2 | Plugin plugin = new Plugin(); |
583 | 2 | plugin.setGroupId( groupId ); |
584 | 2 | plugin.setArtifactId( artifactId ); |
585 | 2 | plugin.setVersion( format( v3Dep.getVersion() ) ); |
586 | |
|
587 | 2 | Xpp3Dom config = new Xpp3Dom( "configuration" ); |
588 | |
|
589 | 2 | Properties props = v3Dep.getProperties(); |
590 | |
|
591 | 2 | if ( !props.isEmpty() ) |
592 | |
{ |
593 | 0 | for ( Iterator propertyIterator = props.keySet().iterator(); propertyIterator.hasNext(); ) |
594 | |
{ |
595 | 0 | String key = (String) propertyIterator.next(); |
596 | 0 | String value = props.getProperty( key ); |
597 | |
|
598 | 0 | Xpp3Dom child = new Xpp3Dom( key ); |
599 | 0 | child.setValue( value ); |
600 | |
|
601 | 0 | config.addChild( child ); |
602 | |
} |
603 | |
|
604 | 0 | plugin.setConfiguration( config ); |
605 | |
} |
606 | |
|
607 | 2 | this.discoveredPlugins.add( plugin ); |
608 | |
} |
609 | |
else |
610 | |
{ |
611 | 8 | Dependency dep = new Dependency(); |
612 | |
|
613 | 8 | dep.setGroupId( groupId ); |
614 | 8 | dep.setArtifactId( artifactId ); |
615 | 8 | dep.setVersion( v3Dep.getVersion() ); |
616 | 8 | dep.setType( v3Dep.getType() ); |
617 | |
|
618 | 8 | String scope = v3Dep.getProperty( "scope" ); |
619 | 8 | if ( StringUtils.isNotEmpty( scope ) ) |
620 | |
{ |
621 | 1 | dep.setScope( scope ); |
622 | |
} |
623 | |
|
624 | 8 | String optional = v3Dep.getProperty( "optional" ); |
625 | 8 | if ( StringUtils.isNotEmpty( optional ) ) |
626 | |
{ |
627 | 4 | dep.setOptional( Boolean.valueOf( optional ).booleanValue() ); |
628 | |
} |
629 | |
|
630 | 8 | deps.add( dep ); |
631 | |
} |
632 | |
} |
633 | |
|
634 | 8 | if ( !isJunitPresent ) |
635 | |
{ |
636 | 8 | Dependency junitDep = new Dependency(); |
637 | 8 | junitDep.setGroupId( "junit" ); |
638 | 8 | junitDep.setArtifactId( "junit" ); |
639 | 8 | junitDep.setVersion( "3.8.2" ); |
640 | 8 | junitDep.setScope( "test" ); |
641 | 8 | deps.add( junitDep ); |
642 | |
} |
643 | |
} |
644 | |
|
645 | 10 | return deps; |
646 | |
} |
647 | |
|
648 | |
private List translateContributors( List v3Contributors ) |
649 | |
{ |
650 | 10 | List contributors = new ArrayList(); |
651 | |
|
652 | 10 | if ( notEmpty( v3Contributors ) ) |
653 | |
{ |
654 | 0 | for ( Iterator it = v3Contributors.iterator(); it.hasNext(); ) |
655 | |
{ |
656 | 0 | org.apache.maven.model.v3_0_0.Contributor v3Contributor = (org.apache.maven.model.v3_0_0.Contributor) it |
657 | |
.next(); |
658 | |
|
659 | 0 | Contributor contributor = new Contributor(); |
660 | |
|
661 | 0 | contributor.setEmail( v3Contributor.getEmail() ); |
662 | 0 | contributor.setName( v3Contributor.getName() ); |
663 | 0 | contributor.setOrganization( v3Contributor.getOrganization() ); |
664 | 0 | contributor.setRoles( v3Contributor.getRoles() ); |
665 | 0 | contributor.setTimezone( v3Contributor.getTimezone() ); |
666 | 0 | contributor.setUrl( v3Contributor.getUrl() ); |
667 | |
|
668 | 0 | contributors.add( contributor ); |
669 | |
} |
670 | |
} |
671 | |
|
672 | 10 | return contributors; |
673 | |
} |
674 | |
|
675 | |
private Build translateBuild( org.apache.maven.model.v3_0_0.Build v3Build ) |
676 | |
{ |
677 | 10 | Build build = null; |
678 | 10 | if ( v3Build != null ) |
679 | |
{ |
680 | 9 | build = new Build(); |
681 | |
|
682 | 9 | warnOfUnsupportedBuildElements( v3Build ); |
683 | |
|
684 | 9 | build.setSourceDirectory( v3Build.getSourceDirectory() ); |
685 | 9 | build.setTestSourceDirectory( v3Build.getUnitTestSourceDirectory() ); |
686 | |
|
687 | 9 | build.setResources( translateResources( v3Build.getResources() ) ); |
688 | |
|
689 | 9 | UnitTest unitTest = v3Build.getUnitTest(); |
690 | 9 | if ( unitTest != null ) |
691 | |
{ |
692 | 9 | build.setTestResources( translateResources( unitTest.getResources() ) ); |
693 | |
|
694 | 9 | List testIncludes = unitTest.getIncludes(); |
695 | |
|
696 | 9 | List testExcludes = new ArrayList( unitTest.getExcludes() ); |
697 | |
|
698 | 9 | if ( notEmpty( testIncludes ) || notEmpty( testExcludes ) ) |
699 | |
{ |
700 | 0 | Plugin plugin = new Plugin(); |
701 | 0 | plugin.setGroupId( "org.apache.maven.plugins" ); |
702 | 0 | plugin.setArtifactId( "maven-surefire-plugin" ); |
703 | |
|
704 | 0 | Xpp3Dom config = new Xpp3Dom( "configuration" ); |
705 | |
|
706 | 0 | if ( notEmpty( testIncludes ) ) |
707 | |
{ |
708 | 0 | Xpp3Dom includes = new Xpp3Dom( "includes" ); |
709 | 0 | for ( Iterator it = testIncludes.iterator(); it.hasNext(); ) |
710 | |
{ |
711 | 0 | String includePattern = (String) it.next(); |
712 | 0 | Xpp3Dom include = new Xpp3Dom( "include" ); |
713 | 0 | include.setValue( includePattern ); |
714 | |
|
715 | 0 | includes.addChild( include ); |
716 | |
} |
717 | |
|
718 | 0 | config.addChild( includes ); |
719 | |
} |
720 | |
|
721 | 0 | if ( notEmpty( testExcludes ) ) |
722 | |
{ |
723 | 0 | Xpp3Dom excludes = new Xpp3Dom( "excludes" ); |
724 | 0 | for ( Iterator it = testExcludes.iterator(); it.hasNext(); ) |
725 | |
{ |
726 | 0 | String excludePattern = (String) it.next(); |
727 | 0 | Xpp3Dom exclude = new Xpp3Dom( "exclude" ); |
728 | 0 | exclude.setValue( excludePattern ); |
729 | |
|
730 | 0 | excludes.addChild( exclude ); |
731 | |
} |
732 | |
|
733 | 0 | config.addChild( excludes ); |
734 | |
} |
735 | |
|
736 | 0 | if ( config.getChildCount() > 0 ) |
737 | |
{ |
738 | 0 | plugin.setConfiguration( config ); |
739 | |
} |
740 | |
|
741 | 0 | build.addPlugin( plugin ); |
742 | |
} |
743 | |
} |
744 | |
} |
745 | |
|
746 | 10 | if ( !this.discoveredPlugins.isEmpty() ) |
747 | |
{ |
748 | 2 | if ( build == null ) |
749 | |
{ |
750 | 0 | build = new Build(); |
751 | |
} |
752 | |
|
753 | 2 | for ( Iterator it = this.discoveredPlugins.iterator(); it.hasNext(); ) |
754 | |
{ |
755 | 2 | Plugin plugin = (Plugin) it.next(); |
756 | |
|
757 | 2 | build.addPlugin( plugin ); |
758 | |
} |
759 | |
} |
760 | |
|
761 | 10 | return build; |
762 | |
} |
763 | |
|
764 | |
private void warnOfUnsupportedBuildElements( org.apache.maven.model.v3_0_0.Build v3Build ) |
765 | |
{ |
766 | 9 | if ( notEmpty( v3Build.getSourceModifications() ) ) |
767 | |
{ |
768 | 0 | warnings.add( "Ignoring <sourceModifications/> section. It is not supported in v4 POMs." ); |
769 | |
} |
770 | |
|
771 | 9 | if ( StringUtils.isNotEmpty( v3Build.getAspectSourceDirectory() ) ) |
772 | |
{ |
773 | 0 | warnings.add( "Ignoring <aspectSourceDirectory/>. It is not supported in v4 POMs." ); |
774 | |
} |
775 | |
|
776 | 9 | if ( StringUtils.isNotEmpty( v3Build.getIntegrationUnitTestSourceDirectory() ) ) |
777 | |
{ |
778 | 0 | warnings.add( "Ignoring <integrationUnitTestSourceDirectory/>. It is not supported in v4 POMs." ); |
779 | |
} |
780 | 9 | } |
781 | |
|
782 | |
private List translateResources( List v3Resources ) |
783 | |
{ |
784 | 18 | List resources = new ArrayList(); |
785 | |
|
786 | 18 | if ( notEmpty( v3Resources ) ) |
787 | |
{ |
788 | 1 | for ( Iterator it = v3Resources.iterator(); it.hasNext(); ) |
789 | |
{ |
790 | 1 | org.apache.maven.model.v3_0_0.Resource v3Resource = (org.apache.maven.model.v3_0_0.Resource) it.next(); |
791 | 1 | Resource resource = new Resource(); |
792 | |
|
793 | 1 | if ( v3Resource.getDirectory() == null ) |
794 | |
{ |
795 | 1 | resource.setDirectory( "." ); |
796 | |
} |
797 | |
else |
798 | |
{ |
799 | 0 | resource.setDirectory( v3Resource.getDirectory() ); |
800 | |
} |
801 | |
|
802 | 1 | List excludes = new ArrayList( v3Resource.getExcludes() ); |
803 | |
|
804 | 1 | resource.setExcludes( excludes ); |
805 | |
|
806 | 1 | resource.setIncludes( v3Resource.getIncludes() ); |
807 | 1 | resource.setTargetPath( v3Resource.getTargetPath() ); |
808 | |
|
809 | 1 | resources.add( resource ); |
810 | |
} |
811 | |
} |
812 | |
|
813 | 18 | return resources; |
814 | |
} |
815 | |
|
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
|
830 | |
|
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
private boolean notEmpty( List test ) |
836 | |
{ |
837 | 125 | return test != null && !test.isEmpty(); |
838 | |
} |
839 | |
|
840 | |
public void validateV4Basics( Model model, String groupId, String artifactId, String version, String packaging ) |
841 | |
{ |
842 | 1 | if ( StringUtils.isEmpty( model.getModelVersion() ) ) |
843 | |
{ |
844 | 0 | model.setModelVersion( "4.0.0" ); |
845 | |
} |
846 | |
|
847 | 1 | if ( StringUtils.isEmpty( model.getGroupId() ) ) |
848 | |
{ |
849 | 1 | warnings.add( "Setting groupId on model using artifact information." ); |
850 | 1 | model.setGroupId( groupId ); |
851 | |
} |
852 | |
|
853 | 1 | if ( StringUtils.isEmpty( model.getArtifactId() ) ) |
854 | |
{ |
855 | 1 | warnings.add( "Setting artifactId on model using artifact information." ); |
856 | 1 | model.setArtifactId( artifactId ); |
857 | |
} |
858 | |
|
859 | 1 | if ( StringUtils.isEmpty( model.getVersion() ) ) |
860 | |
{ |
861 | 1 | warnings.add( "Setting version on model using artifact information." ); |
862 | 1 | model.setVersion( version ); |
863 | |
} |
864 | |
|
865 | 1 | if ( StringUtils.isEmpty( model.getPackaging() ) ) |
866 | |
{ |
867 | 0 | warnings.add( "Setting packaging on model using artifact type information." ); |
868 | 0 | model.setPackaging( packaging ); |
869 | |
} |
870 | 1 | } |
871 | |
|
872 | |
public List getWarnings() |
873 | |
{ |
874 | 0 | return warnings; |
875 | |
} |
876 | |
|
877 | |
private static class PomKey |
878 | |
{ |
879 | |
private final String groupId; |
880 | |
|
881 | |
private final String artifactId; |
882 | |
|
883 | |
private final String version; |
884 | |
|
885 | |
PomKey( String groupId, String artifactId, String version ) |
886 | 10 | { |
887 | 10 | this.groupId = groupId; |
888 | 10 | this.artifactId = artifactId; |
889 | 10 | this.version = version; |
890 | 10 | } |
891 | |
|
892 | |
public String groupId() |
893 | |
{ |
894 | 0 | return groupId; |
895 | |
} |
896 | |
|
897 | |
public String artifactId() |
898 | |
{ |
899 | 0 | return artifactId; |
900 | |
} |
901 | |
|
902 | |
public String version() |
903 | |
{ |
904 | 0 | return version; |
905 | |
} |
906 | |
} |
907 | |
|
908 | |
} |