View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugins.pmd.stubs;
20  
21  import java.io.File;
22  import java.io.FileReader;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.model.Build;
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.Scm;
30  import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
31  
32  /**
33   * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
34   * @version $Id$
35   */
36  public class InvalidFormatMavenProjectStub extends PmdProjectStub {
37      private Build build;
38  
39      public InvalidFormatMavenProjectStub() {
40          MavenXpp3Reader pomReader = new MavenXpp3Reader();
41          Model model = null;
42  
43          try {
44              model = pomReader.read(new FileReader(new File(
45                      getBasedir() + "/src/test/resources/unit/invalid-format/invalid-format-plugin-config.xml")));
46              setModel(model);
47          } catch (Exception e) {
48  
49          }
50  
51          setGroupId(model.getGroupId());
52          setArtifactId(model.getArtifactId());
53          setVersion(model.getVersion());
54          setName(model.getName());
55          setUrl(model.getUrl());
56          setPackaging(model.getPackaging());
57  
58          Scm scm = new Scm();
59          scm.setConnection("scm:svn:http://svn.apache.org/maven/sample/trunk");
60          setScm(scm);
61  
62          Build build = new Build();
63          build.setFinalName(model.getBuild().getFinalName());
64          build.setDirectory(getBasedir() + "/target/test/unit/invalid-format/target");
65          build.setSourceDirectory(getBasedir() + "/src/test/resources/unit/invalid-format");
66          setBuild(build);
67  
68          String basedir = getBasedir().getAbsolutePath();
69          List<String> compileSourceRoots = new ArrayList<>();
70          compileSourceRoots.add(basedir + "/src/test/resources/unit/invalid-format/invalid/format");
71          setCompileSourceRoots(compileSourceRoots);
72  
73          Artifact artifact = new PmdPluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging());
74          artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
75          setArtifact(artifact);
76  
77          setFile(new File(getBasedir().getAbsolutePath() + "/pom.xml"));
78      }
79  
80      /** {@inheritDoc} */
81      @Override
82      public void setBuild(Build build) {
83          this.build = build;
84      }
85  
86      /** {@inheritDoc} */
87      @Override
88      public Build getBuild() {
89          return build;
90      }
91  }