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 <a href="mailto:oching@exist.com">Maria Odea Ching</a>
34   */
35  public class Project007Stub extends MavenProjectStub {
36      private Build build;
37  
38      private List<Resource> resources;
39  
40      private List<Resource> testResources;
41  
42      public Project007Stub() {
43          Model model;
44          try {
45              model = readModelFromFile(new File(getBasedir(), "target/test-classes/unit/project-007/pom.xml"));
46              setModel(model);
47  
48              setGroupId(model.getGroupId());
49              setArtifactId(model.getArtifactId());
50              setVersion(model.getVersion());
51              setName(model.getName());
52              setUrl(model.getUrl());
53              setPackaging(model.getPackaging());
54  
55              Build build = new Build();
56              build.setFinalName(getArtifactId() + "-" + getVersion());
57              build.setDirectory(getBasedir() + "/target/test/unit/project-007/target");
58              setBuild(build);
59  
60              String basedir = getBasedir().getAbsolutePath();
61              List<String> compileSourceRoots = new ArrayList<>();
62              compileSourceRoots.add(basedir + "/target/test-classes/unit/project-007/src/main/java");
63              setCompileSourceRoots(compileSourceRoots);
64  
65              List<String> testCompileSourceRoots = new ArrayList<>();
66              testCompileSourceRoots.add(basedir + "/target/test-classes/unit/project-007/src/test/java");
67              setTestCompileSourceRoots(testCompileSourceRoots);
68  
69              setResources(model.getBuild().getResources());
70              setTestResources(model.getBuild().getTestResources());
71  
72              SourcePluginArtifactStub artifact =
73                      new SourcePluginArtifactStub(getGroupId(), getArtifactId(), getVersion(), getPackaging(), null);
74              artifact.setArtifactHandler(new DefaultArtifactHandlerStub());
75              artifact.setType("jar");
76              artifact.setBaseVersion("1.0-SNAPSHOT");
77              setArtifact(artifact);
78  
79          } catch (Exception e) {
80              e.printStackTrace();
81          }
82      }
83  
84      public Build getBuild() {
85          return build;
86      }
87  
88      public void setBuild(Build build) {
89          this.build = build;
90      }
91  
92      public List<Resource> getResources() {
93          return resources;
94      }
95  
96      public void setResources(List<Resource> resources) {
97          this.resources = resources;
98      }
99  
100     public List<Resource> getTestResources() {
101         return testResources;
102     }
103 
104     public void setTestResources(List<Resource> testResources) {
105         this.testResources = testResources;
106     }
107 }