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  
33  /**
34   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
35   * @version $Id$
36   */
37  public class InvalidFormatMavenProjectStub
38      extends PmdProjectStub
39  {
40      private Build build;
41  
42      public InvalidFormatMavenProjectStub()
43      {
44          MavenXpp3Reader pomReader = new MavenXpp3Reader();
45          Model model = null;
46  
47          try
48          {
49              model =
50                  pomReader.read( new FileReader( new File( getBasedir()
51                      + "/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<String> 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      @Override
91      public void setBuild( Build build )
92      {
93          this.build = build;
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public Build getBuild()
99      {
100         return build;
101     }
102 
103 }