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