1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.path;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24
25 import org.apache.maven.model.DistributionManagement;
26 import org.apache.maven.model.Model;
27 import org.apache.maven.model.Scm;
28 import org.apache.maven.model.Site;
29 import org.apache.maven.model.building.ModelBuildingRequest;
30
31
32
33
34
35
36
37 @Named
38 @Singleton
39 public class DefaultModelUrlNormalizer implements ModelUrlNormalizer {
40
41 @Inject
42 private UrlNormalizer urlNormalizer;
43
44 public DefaultModelUrlNormalizer setUrlNormalizer(UrlNormalizer urlNormalizer) {
45 this.urlNormalizer = urlNormalizer;
46 return this;
47 }
48
49 @Override
50 public void normalize(Model model, ModelBuildingRequest request) {
51 if (model == null) {
52 return;
53 }
54
55 model.setUrl(normalize(model.getUrl()));
56
57 Scm scm = model.getScm();
58 if (scm != null) {
59 scm.setUrl(normalize(scm.getUrl()));
60 scm.setConnection(normalize(scm.getConnection()));
61 scm.setDeveloperConnection(normalize(scm.getDeveloperConnection()));
62 }
63
64 DistributionManagement dist = model.getDistributionManagement();
65 if (dist != null) {
66 Site site = dist.getSite();
67 if (site != null) {
68 site.setUrl(normalize(site.getUrl()));
69 }
70 }
71 }
72
73 private String normalize(String url) {
74 return urlNormalizer.normalize(url);
75 }
76 }