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 java.io.File;
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.apache.maven.model.Build;
30 import org.apache.maven.model.Model;
31 import org.apache.maven.model.Reporting;
32 import org.apache.maven.model.Resource;
33 import org.apache.maven.model.building.ModelBuildingRequest;
34
35
36
37
38
39
40 @Named
41 @Singleton
42 public class DefaultModelPathTranslator implements ModelPathTranslator {
43
44 @Inject
45 private PathTranslator pathTranslator;
46
47 public DefaultModelPathTranslator setPathTranslator(PathTranslator pathTranslator) {
48 this.pathTranslator = pathTranslator;
49 return this;
50 }
51
52 @Override
53 public void alignToBaseDirectory(Model model, File basedir, ModelBuildingRequest request) {
54 if (model == null || basedir == null) {
55 return;
56 }
57
58 Build build = model.getBuild();
59
60 if (build != null) {
61 build.setDirectory(alignToBaseDirectory(build.getDirectory(), basedir));
62
63 build.setSourceDirectory(alignToBaseDirectory(build.getSourceDirectory(), basedir));
64
65 build.setTestSourceDirectory(alignToBaseDirectory(build.getTestSourceDirectory(), basedir));
66
67 build.setScriptSourceDirectory(alignToBaseDirectory(build.getScriptSourceDirectory(), basedir));
68
69 for (Resource resource : build.getResources()) {
70 resource.setDirectory(alignToBaseDirectory(resource.getDirectory(), basedir));
71 }
72
73 for (Resource resource : build.getTestResources()) {
74 resource.setDirectory(alignToBaseDirectory(resource.getDirectory(), basedir));
75 }
76
77 if (build.getFilters() != null) {
78 List<String> filters = new ArrayList<>(build.getFilters().size());
79 for (String filter : build.getFilters()) {
80 filters.add(alignToBaseDirectory(filter, basedir));
81 }
82 build.setFilters(filters);
83 }
84
85 build.setOutputDirectory(alignToBaseDirectory(build.getOutputDirectory(), basedir));
86
87 build.setTestOutputDirectory(alignToBaseDirectory(build.getTestOutputDirectory(), basedir));
88 }
89
90 Reporting reporting = model.getReporting();
91
92 if (reporting != null) {
93 reporting.setOutputDirectory(alignToBaseDirectory(reporting.getOutputDirectory(), basedir));
94 }
95 }
96
97 private String alignToBaseDirectory(String path, File basedir) {
98 return pathTranslator.alignToBaseDirectory(path, basedir);
99 }
100 }