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