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