1 package org.apache.maven.plugin.pmd.stubs;
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.io.FileReader;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.model.Build;
29 import org.apache.maven.model.Model;
30 import org.apache.maven.model.ReportPlugin;
31 import org.apache.maven.model.Scm;
32 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
33 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
34
35
36
37
38
39 public class CustomConfigurationMavenProjectStub
40 extends MavenProjectStub
41 {
42 private Build build;
43
44 private List<ReportPlugin> reportPlugins = new ArrayList<ReportPlugin>();
45
46 public CustomConfigurationMavenProjectStub()
47 {
48 MavenXpp3Reader pomReader = new MavenXpp3Reader();
49 Model model = null;
50
51 try
52 {
53 model =
54 pomReader.read( new FileReader( new File( getBasedir()
55 + "/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" ) ) );
56 setModel( model );
57 }
58 catch ( Exception e )
59 {
60
61 }
62
63 setGroupId( model.getGroupId() );
64 setArtifactId( model.getArtifactId() );
65 setVersion( model.getVersion() );
66 setName( model.getName() );
67 setUrl( model.getUrl() );
68 setPackaging( model.getPackaging() );
69
70 Scm scm = new Scm();
71 scm.setConnection( "scm:svn:http://svn.apache.org/maven/sample/trunk" );
72 setScm( scm );
73
74 Build build = new Build();
75 build.setFinalName( model.getBuild().getFinalName() );
76 build.setDirectory( getBasedir() + "/target/test/unit/custom-configuration/target" );
77 build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/custom-configuration" );
78 setBuild( build );
79
80 setReportPlugins( model.getReporting().getPlugins() );
81
82 String basedir = getBasedir().getAbsolutePath();
83 List<String> compileSourceRoots = new ArrayList<String>();
84 compileSourceRoots.add( basedir + "/src/test/resources/unit/custom-configuration/custom/configuration" );
85 setCompileSourceRoots( compileSourceRoots );
86
87 Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
88 artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
89 setArtifact( artifact );
90
91 setFile( new File( getBasedir().getAbsolutePath() + "/pom.xml" ) );
92 }
93
94
95 @Override
96 public void setBuild( Build build )
97 {
98 this.build = build;
99 }
100
101
102 @Override
103 public Build getBuild()
104 {
105 return build;
106 }
107
108 public void setReportPlugins( List<ReportPlugin> plugins )
109 {
110 this.reportPlugins = plugins;
111 }
112
113
114 @Override
115 public List<ReportPlugin> getReportPlugins()
116 {
117 return reportPlugins;
118 }
119
120 }