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