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