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