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