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.FileInputStream;
23  import java.io.InputStream;
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 extends PmdProjectStub {
38      private Build build;
39  
40      public InvalidFormatMavenProjectStub() {
41          MavenXpp3Reader pomReader = new MavenXpp3Reader();
42          Model model = null;
43  
44          try (InputStream is = new FileInputStream(
45                  new File(getBasedir() + "/src/test/resources/unit/invalid-format/invalid-format-plugin-config.xml"))) {
46              model = pomReader.read(is);
47              setModel(model);
48          } catch (Exception e) {
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  }