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