View Javadoc
1   package org.apache.maven.plugin.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  import org.codehaus.plexus.util.IOUtil;
35  
36  /**
37   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
38   * @version $Id: DefaultConfigurationMavenProjectStub.html 975451 2015-12-13 21:06:46Z dennisl $
39   */
40  public class DefaultConfigurationMavenProjectStub
41      extends MavenProjectStub
42  {
43      private List<ReportPlugin> reportPlugins = new ArrayList<ReportPlugin>();
44  
45      private Build build;
46  
47      public DefaultConfigurationMavenProjectStub()
48      {
49          MavenXpp3Reader pomReader = new MavenXpp3Reader();
50          Model model = null;
51  
52          FileReader reader = null;
53          try
54          {
55              reader = new FileReader( new File( getBasedir() + "/src/test/resources/unit/default-configuration/default-configuration-plugin-config.xml" ) );
56              model = pomReader.read( reader );
57              setModel( model );
58          }
59          catch ( Exception e )
60          {
61  
62          }
63          finally
64          {
65              IOUtil.close( reader );
66          }
67  
68          setGroupId( model.getGroupId() );
69          setArtifactId( model.getArtifactId() );
70          setVersion( model.getVersion() );
71          setName( model.getName() );
72          setUrl( model.getUrl() );
73          setPackaging( model.getPackaging() );
74  
75          Scm scm = new Scm();
76          scm.setConnection( "scm:svn:http://svn.apache.org/maven/sample/trunk" );
77          setScm( scm );
78  
79          Build build = new Build();
80          build.setFinalName( model.getBuild()
81                                   .getFinalName() );
82          build.setDirectory( getBasedir() + "/target/test/unit/default-configuration/target" );
83          build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/default-configuration" );
84          setBuild( build );
85  
86          setReportPlugins( model.getReporting()
87                                 .getPlugins() );
88  
89          String basedir = getBasedir().getAbsolutePath();
90          List<String> compileSourceRoots = new ArrayList<String>();
91          compileSourceRoots.add( basedir + "/src/test/resources/unit/default-configuration/def/configuration" );
92          setCompileSourceRoots( compileSourceRoots );
93  
94          File file = new File( getBasedir().getAbsolutePath() + "/pom.xml" );
95          setFile( file );
96  
97          Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
98          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
99          setArtifact( artifact );
100 
101     }
102 
103     public void setReportPlugins( List<ReportPlugin> plugins )
104     {
105         this.reportPlugins = plugins;
106     }
107 
108     /** {@inheritDoc} */
109     @Override
110     public List<ReportPlugin> getReportPlugins()
111     {
112         return reportPlugins;
113     }
114 
115     /** {@inheritDoc} */
116     @Override
117     public void setBuild( Build build )
118     {
119         this.build = build;
120     }
121 
122     /** {@inheritDoc} */
123     @Override
124     public Build getBuild()
125     {
126         return build;
127     }
128 }