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.source.stubs;
20  
21  import java.io.File;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  import org.apache.maven.model.Build;
26  import org.apache.maven.model.Model;
27  import org.apache.maven.model.Resource;
28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29  
30  import static org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
31  
32  /**
33   * @author Dennis Lundberg
34   */
35  public class Project009Stub extends MavenProjectStub {
36      private Build build;
37  
38      private List<Resource> resources;
39  
40      private List<Resource> testResources;
41  
42      public Project009Stub() {
43          Model model;
44  
45          try {
46              final File pomFile = new File(getBasedir(), "target/test-classes/unit/project-009/pom.xml");
47              model = readModelFromFile(pomFile);
48              setModel(model);
49              setFile(pomFile);
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              Build build = new Build();
59              build.setFinalName(getArtifactId() + "-" + getVersion());
60              build.setDirectory(getBasedir() + "/target/test/unit/project-009/target");
61              setBuild(build);
62  
63              String basedir = getBasedir().getAbsolutePath();
64              List<String> compileSourceRoots = new ArrayList<>();
65              compileSourceRoots.add(basedir + "/target/test-classes/unit/project-009/src/main/java");
66              setCompileSourceRoots(compileSourceRoots);
67  
68              List<String> testCompileSourceRoots = new ArrayList<>();
69              testCompileSourceRoots.add(basedir + "/target/test-classes/unit/project-009/src/test/java");
70              setTestCompileSourceRoots(testCompileSourceRoots);
71  
72              setResources(model.getBuild().getResources());
73              setTestResources(model.getBuild().getTestResources());
74  
75              SourcePluginArtifactStub artifact =
76                      new SourcePluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging(), null);
77              artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
78              artifact.setType("jar");
79              artifact.setBaseVersion("1.0-SNAPSHOT");
80              setArtifact(artifact);
81          } catch (Exception e) {
82              e.printStackTrace();
83          }
84      }
85  
86      public Build getBuild() {
87          return build;
88      }
89  
90      public void setBuild(Build build) {
91          this.build = build;
92      }
93  
94      public List<Resource> getResources() {
95          return resources;
96      }
97  
98      public void setResources(List<Resource> resources) {
99          this.resources = resources;
100     }
101 
102     public List<Resource> getTestResources() {
103         return testResources;
104     }
105 
106     public void setTestResources(List<Resource> testResources) {
107         this.testResources = testResources;
108     }
109 }