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 DefaultConfigurationMavenProjectStub
40      extends MavenProjectStub
41  {
42      private List<ReportPlugin> reportPlugins = new ArrayList<>();
43  
44      private Build build;
45  
46      public DefaultConfigurationMavenProjectStub()
47      {
48          MavenXpp3Reader pomReader = new MavenXpp3Reader();
49          Model model = null;
50  
51          try ( FileReader reader = new FileReader( new File( getBasedir()
52              + "/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" ) ) )
53          {
54              model = pomReader.read( reader );
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()
75                                   .getFinalName() );
76          build.setDirectory( getBasedir() + "/target/test/unit/default-configuration/target" );
77          build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/default-configuration" );
78          setBuild( build );
79  
80          setReportPlugins( model.getReporting()
81                                 .getPlugins() );
82  
83          String basedir = getBasedir().getAbsolutePath();
84          List<String> compileSourceRoots = new ArrayList<>();
85          compileSourceRoots.add( basedir + "/src/test/resources/unit/default-configuration/def/configuration" );
86          setCompileSourceRoots( compileSourceRoots );
87  
88          File file = new File( getBasedir().getAbsolutePath() + "/pom.xml" );
89          setFile( file );
90  
91          Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
92          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
93          setArtifact( artifact );
94  
95      }
96  
97      public void setReportPlugins( List<ReportPlugin> plugins )
98      {
99          this.reportPlugins = plugins;
100     }
101 
102     /** {@inheritDoc} */
103     @Override
104     public List<ReportPlugin> getReportPlugins()
105     {
106         return reportPlugins;
107     }
108 
109     /** {@inheritDoc} */
110     @Override
111     public void setBuild( Build build )
112     {
113         this.build = build;
114     }
115 
116     /** {@inheritDoc} */
117     @Override
118     public Build getBuild()
119     {
120         return build;
121     }
122 }