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  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
34  
35  /**
36   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
37   * @version $Id$
38   */
39  public class CustomConfigurationMavenProjectStub
40      extends MavenProjectStub
41  {
42      private Build build;
43  
44      private List<ReportPlugin> reportPlugins = new ArrayList<>();
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<>();
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      /** {@inheritDoc} */
95      @Override
96      public void setBuild( Build build )
97      {
98          this.build = build;
99      }
100 
101     /** {@inheritDoc} */
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     /** {@inheritDoc} */
114     @Override
115     public List<ReportPlugin> getReportPlugins()
116     {
117         return reportPlugins;
118     }
119 
120 }