1 package org.apache.maven.model.path;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.model.Build;
27 import org.apache.maven.model.Model;
28 import org.apache.maven.model.Reporting;
29 import org.apache.maven.model.Resource;
30 import org.apache.maven.model.building.ModelBuildingRequest;
31 import org.codehaus.plexus.component.annotations.Component;
32 import org.codehaus.plexus.component.annotations.Requirement;
33
34
35
36
37
38
39 @Component( role = ModelPathTranslator.class )
40 public class DefaultModelPathTranslator
41 implements ModelPathTranslator
42 {
43
44 @Requirement
45 private PathTranslator pathTranslator;
46
47 public DefaultModelPathTranslator setPathTranslator( PathTranslator pathTranslator )
48 {
49 this.pathTranslator = pathTranslator;
50 return this;
51 }
52
53 public void alignToBaseDirectory( Model model, File basedir, ModelBuildingRequest request )
54 {
55 if ( model == null || basedir == null )
56 {
57 return;
58 }
59
60 Build build = model.getBuild();
61
62 if ( build != null )
63 {
64 build.setDirectory( alignToBaseDirectory( build.getDirectory(), basedir ) );
65
66 build.setSourceDirectory( alignToBaseDirectory( build.getSourceDirectory(), basedir ) );
67
68 build.setTestSourceDirectory( alignToBaseDirectory( build.getTestSourceDirectory(), basedir ) );
69
70 build.setScriptSourceDirectory( alignToBaseDirectory( build.getScriptSourceDirectory(), basedir ) );
71
72 for ( Resource resource : build.getResources() )
73 {
74 resource.setDirectory( alignToBaseDirectory( resource.getDirectory(), basedir ) );
75 }
76
77 for ( Resource resource : build.getTestResources() )
78 {
79 resource.setDirectory( alignToBaseDirectory( resource.getDirectory(), basedir ) );
80 }
81
82 if ( build.getFilters() != null )
83 {
84 List<String> filters = new ArrayList<String>( build.getFilters().size() );
85 for ( String filter : build.getFilters() )
86 {
87 filters.add( alignToBaseDirectory( filter, basedir ) );
88 }
89 build.setFilters( filters );
90 }
91
92 build.setOutputDirectory( alignToBaseDirectory( build.getOutputDirectory(), basedir ) );
93
94 build.setTestOutputDirectory( alignToBaseDirectory( build.getTestOutputDirectory(), basedir ) );
95 }
96
97 Reporting reporting = model.getReporting();
98
99 if ( reporting != null )
100 {
101 reporting.setOutputDirectory( alignToBaseDirectory( reporting.getOutputDirectory(), basedir ) );
102 }
103 }
104
105 private String alignToBaseDirectory( String path, File basedir )
106 {
107 return pathTranslator.alignToBaseDirectory( path, basedir );
108 }
109
110 }