1 package org.apache.maven.plugin.war.stub;
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.handler.ArtifactHandler;
24 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
25 import org.apache.maven.artifact.versioning.VersionRange;
26 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
27
28 public abstract class AbstractArtifactStub
29 extends ArtifactStub
30 {
31 protected String basedir;
32
33 public AbstractArtifactStub( String _basedir )
34 {
35 basedir = _basedir;
36 }
37
38 public String getVersion()
39 {
40 return "0.0-Test";
41 }
42
43 @Override
44 public String getBaseVersion()
45 {
46 return getVersion();
47 }
48
49 public String getScope()
50 {
51 return Artifact.SCOPE_RUNTIME;
52 }
53
54 public VersionRange getVersionRange()
55 {
56 return VersionRange.createFromVersion( getVersion());
57 }
58
59 public boolean isOptional()
60 {
61 return false;
62 }
63
64 public ArtifactHandler getArtifactHandler()
65 {
66 return new DefaultArtifactHandler( getType() );
67 }
68
69
70
71
72 public int compareTo( Object o )
73 {
74 Artifact a = (Artifact) o;
75
76
77 int result;
78 if ( a.getGroupId() != null )
79 {
80 result = getGroupId().compareTo( a.getGroupId() );
81 }
82 else
83 {
84 result = ( getGroupId() == null ? 0 : -1 );
85 }
86
87
88 if ( result == 0 )
89 {
90 result = getArtifactId().compareTo( a.getArtifactId() );
91 if ( result == 0 )
92 {
93 result = getType().compareTo( a.getType() );
94 if ( result == 0 )
95 {
96 if ( getClassifier() == null )
97 {
98 if ( a.getClassifier() != null )
99 {
100 result = 1;
101 }
102 }
103 else
104 {
105 if ( a.getClassifier() != null )
106 {
107 result = getClassifier().compareTo( a.getClassifier() );
108 }
109 else
110 {
111 result = -1;
112 }
113 }
114 if ( result == 0 )
115 {
116
117 result = getVersion().compareTo( a.getVersion() );
118 }
119 }
120 }
121 }
122 return result;
123 }
124
125
126
127
128 public boolean equals( Object o )
129 {
130 if ( o == this )
131 {
132 return true;
133 }
134
135 if ( !( o instanceof Artifact ) )
136 {
137 return false;
138 }
139
140 Artifact a = (Artifact) o;
141
142
143 if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) )
144 {
145 return false;
146 }
147 else if ( !a.getArtifactId().equals( getArtifactId() ) )
148 {
149 return false;
150 }
151 else if ( !a.getVersion().equals( getVersion() ) )
152 {
153 return false;
154 }
155 else if ( !a.getType().equals( getType() ) )
156 {
157 return false;
158 }
159 else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) )
160 {
161 return false;
162 }
163
164
165
166 return true;
167 }
168 }