1 package org.apache.maven.plugin.rar.stubs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.artifact.versioning.VersionRange;
24 import org.apache.maven.model.Model;
25 import org.apache.maven.model.Organization;
26 import org.apache.maven.project.MavenProject;
27 import org.codehaus.plexus.PlexusTestCase;
28
29 import java.io.File;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Set;
35
36
37
38
39 public class RarMavenProjectStub
40 extends MavenProject
41 {
42 private List attachedArtifacts;
43
44 public RarMavenProjectStub()
45 {
46 super( new Model() );
47
48 super.setGroupId( getGroupId() );
49 super.setArtifactId( getArtifactId() );
50 super.setVersion( getVersion() );
51 super.setDescription( "Test description" );
52
53 Organization org = new Organization();
54 org.setName( "organization" );
55 org.setUrl( "http://www.some.org" );
56
57 super.setOrganization( org );
58 super.setFile( getFile() );
59 super.setPluginArtifacts( Collections.EMPTY_SET );
60 super.setReportArtifacts( Collections.EMPTY_SET );
61 super.setExtensionArtifacts( Collections.EMPTY_SET );
62 super.setArtifact( getArtifact() );
63 super.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
64 super.setPluginArtifactRepositories( Collections.EMPTY_LIST );
65 super.setCollectedProjects( Collections.EMPTY_LIST );
66 super.setActiveProfiles( Collections.EMPTY_LIST );
67
68 super.addCompileSourceRoot( getBasedir() + "/src/test/resources/unit/basic-rar-test/src/main/java" );
69 super.addTestCompileSourceRoot( getBasedir() + "/src/test/resources/unit/basic-rar-test/src/test/java" );
70
71 super.setExecutionRoot( false );
72 }
73
74 public String getGroupId()
75 {
76 return "org.apache.maven.test";
77 }
78
79 public String getArtifactId()
80 {
81 return "maven-rar-test";
82 }
83
84 public String getVersion()
85 {
86 return "1.0-SNAPSHOT";
87 }
88
89 public File getFile()
90 {
91 return new File( getBasedir(), "src/test/resources/unit/basic-rar-test/plugin-config.xml" );
92 }
93
94 public File getBasedir()
95 {
96 return new File( PlexusTestCase.getBasedir() );
97 }
98
99 public Artifact getArtifact()
100 {
101 Artifact artifact = new RarArtifactStub();
102
103 artifact.setGroupId( getGroupId() );
104
105 artifact.setArtifactId( getArtifactId() );
106
107 artifact.setVersion( getVersion() );
108
109 return artifact;
110 }
111
112 public Set getArtifacts()
113 {
114 Set artifacts = new HashSet();
115
116 artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false ) );
117 artifacts.add( createArtifact( "org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false ) );
118
119 return artifacts;
120 }
121
122 public List getAttachedArtifacts()
123 {
124 if ( attachedArtifacts == null )
125 {
126 attachedArtifacts = new ArrayList();
127 }
128 return attachedArtifacts;
129 }
130
131 protected Artifact createArtifact( String groupId, String artifactId, String version, boolean optional )
132 {
133 Artifact artifact = new RarArtifactStub();
134
135 artifact.setGroupId( groupId );
136
137 artifact.setArtifactId( artifactId );
138
139 artifact.setVersion( version );
140
141 artifact.setOptional( optional );
142
143 artifact.setVersionRange( VersionRange.createFromVersion( "1.0" ) );
144
145 artifact.setFile(
146 new File( getBasedir() + "/src/test/remote-repo/" + artifact.getGroupId().replace( '.', '/' ) +
147 "/" + artifact.getArtifactId() + "/" + artifact.getVersion() +
148 "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + ".jar" ) );
149
150 artifact.setArtifactHandler( new ArtifactHandlerStub() );
151 return artifact;
152 }
153
154
155 }