View Javadoc

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.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      public String getScope()
44      {
45          return Artifact.SCOPE_RUNTIME;
46      }
47  
48      public VersionRange getVersionRange()
49      {
50          return VersionRange.createFromVersion( getVersion());
51      }
52  
53      public boolean isOptional()
54      {
55          return false;
56      }
57  
58      public ArtifactHandler getArtifactHandler()
59      {
60          return new DefaultArtifactHandler( getType() );
61      }
62  
63      /*
64       * TODO: Coppied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging...
65       */
66      public int compareTo( Object o )
67      {
68          Artifact a = (Artifact) o;
69  
70          /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */
71          int result;
72          if ( a.getGroupId() != null )
73          {
74              result = getGroupId().compareTo( a.getGroupId() );
75          }
76          else
77          {
78              result = ( getGroupId() == null ? 0 : -1 );
79          }
80          /* -- */
81  
82          if ( result == 0 )
83          {
84              result = getArtifactId().compareTo( a.getArtifactId() );
85              if ( result == 0 )
86              {
87                  result = getType().compareTo( a.getType() );
88                  if ( result == 0 )
89                  {
90                      if ( getClassifier() == null )
91                      {
92                          if ( a.getClassifier() != null )
93                          {
94                              result = 1;
95                          }
96                      }
97                      else
98                      {
99                          if ( a.getClassifier() != null )
100                         {
101                             result = getClassifier().compareTo( a.getClassifier() );
102                         }
103                         else
104                         {
105                             result = -1;
106                         }
107                     }
108                     if ( result == 0 )
109                     {
110                         // We don't consider the version range in the comparison, just the resolved version
111                         result = getVersion().compareTo( a.getVersion() );
112                     }
113                 }
114             }
115         }
116         return result;
117     }
118 
119     /*
120      * TODO: Coppied from org/apache/maven/artifact/DefaultArtifact.java; Consider merging...
121      */
122     public boolean equals( Object o )
123     {
124         if ( o == this )
125         {
126             return true;
127         }
128 
129         if ( !( o instanceof Artifact ) )
130         {
131             return false;
132         }
133 
134         Artifact a = (Artifact) o;
135 
136         /* -- We need to support groupId=null (it is missing in DefaultArtifact.java) */
137         if ( a.getGroupId() == null ? ( getGroupId() != null ) : a.getGroupId().equals( getGroupId() ) )
138         {
139             return false;
140         }
141         else if ( !a.getArtifactId().equals( getArtifactId() ) )
142         {
143             return false;
144         }
145         else if ( !a.getVersion().equals( getVersion() ) )
146         {
147             return false;
148         }
149         else if ( !a.getType().equals( getType() ) )
150         {
151             return false;
152         }
153         else if ( a.getClassifier() == null ? getClassifier() != null : !a.getClassifier().equals( getClassifier() ) )
154         {
155             return false;
156         }
157 
158         // We don't consider the version range in the comparison, just the resolved version
159 
160         return true;
161     }
162 }