1 package org.apache.maven.plugin.war.stub;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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.ArtifactVersion;
26 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
27 import org.apache.maven.artifact.versioning.VersionRange;
28 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
29
30 import java.util.ArrayList;
31
32 public abstract class AbstractArtifactStub
33 extends ArtifactStub
34 {
35 protected String basedir;
36
37 public AbstractArtifactStub( String _basedir )
38 {
39 basedir = _basedir;
40 }
41
42 public String getVersion()
43 {
44 return "0.0-Test";
45 }
46
47 public String getScope()
48 {
49 return Artifact.SCOPE_RUNTIME;
50 }
51
52 public VersionRange getVersionRange()
53 {
54 return VersionRange.createFromVersion( getVersion());
55 }
56
57 public boolean isOptional()
58 {
59 return false;
60 }
61
62 public ArtifactHandler getArtifactHandler()
63 {
64 return new DefaultArtifactHandler( getType() );
65 }
66
67 /*
68 * TODO: Coppied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging...
69 */
70 public int compareTo( Object o )
71 {
72 Artifact a = (Artifact) o;
73
74 /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */
75 int result;
76 if ( a.getGroupId() != null )
77 {
78 result = getGroupId().compareTo( a.getGroupId() );
79 }
80 else
81 {
82 result = ( getGroupId() == null ? 0 : -1 );
83 }
84 /* -- */
85
86 if ( result == 0 )
87 {
88 result = getArtifactId().compareTo( a.getArtifactId() );
89 if ( result == 0 )
90 {
91 result = getType().compareTo( a.getType() );
92 if ( result == 0 )
93 {
94 if ( getClassifier() == null )
95 {
96 if ( a.getClassifier() != null )
97 {
98 result = 1;
99 }
100 }
101 else
102 {
103 if ( a.getClassifier() != null )
104 {
105 result = getClassifier().compareTo( a.getClassifier() );
106 }
107 else
108 {
109 result = -1;
110 }
111 }
112 if ( result == 0 )
113 {
114 // We don't consider the version range in the comparison, just the resolved version
115 result = getVersion().compareTo( a.getVersion() );
116 }
117 }
118 }
119 }
120 return result;
121 }
122
123 /*
124 * TODO: Coppied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging...
125 */
126 public boolean equals( Object o )
127 {
128 if ( o == this )
129 {
130 return true;
131 }
132
133 if ( !( o instanceof Artifact ) )
134 {
135 return false;
136 }
137
138 Artifact a = (Artifact) o;
139
140 /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */
141 if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) )
142 {
143 return false;
144 }
145 else if ( !a.getArtifactId().equals( getArtifactId() ) )
146 {
147 return false;
148 }
149 else if ( !a.getVersion().equals( getVersion() ) )
150 {
151 return false;
152 }
153 else if ( !a.getType().equals( getType() ) )
154 {
155 return false;
156 }
157 else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) )
158 {
159 return false;
160 }
161
162 // We don't consider the version range in the comparison, just the resolved version
163
164 return true;
165 }
166 }