View Javadoc
1   package org.apache.maven.plugins.pmd.stubs;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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  
34  /**
35   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
36   * @version $Id$
37   */
38  public class CustomConfigurationMavenProjectStub
39      extends PmdProjectStub
40  {
41      private Build build;
42  
43      private List<ReportPlugin> reportPlugins = new ArrayList<>();
44  
45      public CustomConfigurationMavenProjectStub()
46      {
47          MavenXpp3Reader pomReader = new MavenXpp3Reader();
48          Model model = null;
49  
50          try
51          {
52              model =
53                  pomReader.read( new FileReader( new File( getBasedir()
54                      + "/src/test/resources/unit/custom-configuration/custom-configuration-plugin-config.xml" ) ) );
55              setModel( model );
56          }
57          catch ( Exception e )
58          {
59  
60          }
61  
62          setGroupId( model.getGroupId() );
63          setArtifactId( model.getArtifactId() );
64          setVersion( model.getVersion() );
65          setName( model.getName() );
66          setUrl( model.getUrl() );
67          setPackaging( model.getPackaging() );
68  
69          Scm scm = new Scm();
70          scm.setConnection( "scm:svn:http://svn.apache.org/maven/sample/trunk" );
71          setScm( scm );
72  
73          Build build = new Build();
74          build.setFinalName( model.getBuild().getFinalName() );
75          build.setDirectory( getBasedir() + "/target/test/unit/custom-configuration/target" );
76          build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/custom-configuration" );
77          setBuild( build );
78  
79          setReportPlugins( model.getReporting().getPlugins() );
80  
81          String basedir = getBasedir().getAbsolutePath();
82          List<String> compileSourceRoots = new ArrayList<>();
83          compileSourceRoots.add( basedir + "/src/test/resources/unit/custom-configuration/custom/configuration" );
84          setCompileSourceRoots( compileSourceRoots );
85  
86          Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
87          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
88          setArtifact( artifact );
89  
90          setFile( new File( getBasedir().getAbsolutePath() + "/pom.xml" ) );
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public void setBuild( Build build )
96      {
97          this.build = build;
98      }
99  
100     /** {@inheritDoc} */
101     @Override
102     public Build getBuild()
103     {
104         return build;
105     }
106 
107     public void setReportPlugins( List<ReportPlugin> plugins )
108     {
109         this.reportPlugins = plugins;
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public List<ReportPlugin> getReportPlugins()
115     {
116         return reportPlugins;
117     }
118 
119 }