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 InvalidFormatMavenProjectStub
39      extends MavenProjectStub
40  {
41      private Build build;
42  
43      public InvalidFormatMavenProjectStub()
44      {
45          MavenXpp3Reader pomReader = new MavenXpp3Reader();
46          Model model = null;
47  
48          try
49          {
50              model = pomReader.read( new FileReader( new File(
51                  getBasedir() + "/src/test/resources/unit/invalid-format/invalid-format-plugin-config.xml" ) ) );
52              setModel( model );
53          }
54          catch ( Exception e )
55          {
56  
57          }
58  
59          setGroupId( model.getGroupId() );
60          setArtifactId( model.getArtifactId() );
61          setVersion( model.getVersion() );
62          setName( model.getName() );
63          setUrl( model.getUrl() );
64          setPackaging( model.getPackaging() );
65  
66          Scm scm = new Scm();
67          scm.setConnection( "scm:svn:http://svn.apache.org/maven/sample/trunk" );
68          setScm( scm );
69  
70          Build build = new Build();
71          build.setFinalName( model.getBuild().getFinalName() );
72          build.setDirectory( getBasedir() + "/target/test/unit/invalid-format/target" );
73          build.setSourceDirectory( getBasedir() + "/src/test/resources/unit/invalid-format" );
74          setBuild( build );
75  
76          String basedir = getBasedir().getAbsolutePath();
77          List compileSourceRoots = new ArrayList();
78          compileSourceRoots.add( basedir + "/src/test/resources/unit/invalid-format/invalid/format" );
79          setCompileSourceRoots( compileSourceRoots );
80  
81          Artifact artifact = new PmdPluginArtifactStub( getGroupId(), getArtifactId(), getVersion(), getPackaging() );
82          artifact.setArtifactHandler( new DefaultArtifactHandlerStub() );
83          setArtifact( artifact );
84  
85          setFile(new File(getBasedir().getAbsolutePath() + "/pom.xml"));
86  
87      }
88  
89      /** {@inheritDoc} */
90      public void setBuild( Build build )
91      {
92          this.build = build;
93      }
94  
95      /** {@inheritDoc} */
96      public Build getBuild()
97      {
98          return build;
99      }
100     
101 }