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