1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.plugin.resources.remote.stub;
20  
21  import java.io.File;
22  import java.util.HashSet;
23  import java.util.LinkedList;
24  import java.util.Properties;
25  
26  import org.apache.maven.artifact.Artifact;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.model.Profile;
29  import org.apache.maven.project.MavenProject;
30  import org.codehaus.plexus.PlexusTestCase;
31  import org.codehaus.plexus.util.FileUtils;
32  
33  
34  
35  
36  public class MavenProjectBasicStub extends MavenProject {
37      protected String identifier;
38  
39      protected String testRootDir;
40  
41      protected Properties properties;
42  
43      protected String description;
44  
45      protected ModelStub modelStub;
46  
47      protected File file;
48  
49      protected ArtifactStub artifact;
50  
51      public MavenProjectBasicStub(String id) throws Exception {
52          
53          super(new ModelStub());
54  
55          modelStub = (ModelStub) getModel();
56          properties = new Properties();
57          artifact = new ArtifactStub();
58          identifier = id;
59  
60          
61          testRootDir = PlexusTestCase.getBasedir() + "/target/test-classes/unit/test-dir/" + identifier;
62  
63          if (!FileUtils.fileExists(testRootDir)) {
64              FileUtils.mkdir(testRootDir);
65          }
66  
67          artifact.populate(this);
68  
69          
70          
71          initializeParentFields();
72      }
73  
74      @Override
75      public String getName() {
76          return "Test Project " + identifier;
77      }
78  
79      @Override
80      public void setDescription(String desc) {
81          description = desc;
82      }
83  
84      @Override
85      public String getDescription() {
86          if (description == null) {
87              return "this is a test project";
88          } else {
89              return description;
90          }
91      }
92  
93      @Override
94      public File getBasedir() {
95          
96          
97          return new File(testRootDir);
98      }
99  
100     @Override
101     public Artifact getArtifact() {
102         return artifact;
103     }
104 
105     @Override
106     public String getGroupId() {
107         return "org.apache.maven.plugin.test";
108     }
109 
110     @Override
111     public String getArtifactId() {
112         return "maven-resource-plugin-test#" + identifier;
113     }
114 
115     @Override
116     public String getPackaging() {
117         return "ejb";
118     }
119 
120     @Override
121     public String getVersion() {
122         return identifier;
123     }
124 
125     public void addProperty(String key, String value) {
126         properties.put(key, value);
127     }
128 
129     @Override
130     public Properties getProperties() {
131         return properties;
132     }
133 
134     
135     private void initializeParentFields() {
136         
137         super.setFile(new File(getBasedir(), "pom.xml"));
138         super.setDependencyArtifacts(new HashSet<Artifact>());
139         super.setArtifacts(new HashSet<Artifact>());
140         super.setReportArtifacts(new HashSet<Artifact>());
141         super.setExtensionArtifacts(new HashSet<Artifact>());
142         super.setRemoteArtifactRepositories(new LinkedList<ArtifactRepository>());
143         super.setPluginArtifactRepositories(new LinkedList<ArtifactRepository>());
144         super.setCollectedProjects(new LinkedList<MavenProject>());
145         super.setActiveProfiles(new LinkedList<Profile>());
146         super.setOriginalModel(null);
147         super.setExecutionProject(this);
148         super.setArtifact(artifact);
149     }
150 }