View Javadoc
1   package org.eclipse.aether.internal.impl;
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.eclipse.aether.RepositorySystemSession;
23  import org.eclipse.aether.impl.VersionRangeResolver;
24  import org.eclipse.aether.resolution.VersionRangeRequest;
25  import org.eclipse.aether.resolution.VersionRangeResolutionException;
26  import org.eclipse.aether.resolution.VersionRangeResult;
27  import org.eclipse.aether.util.version.GenericVersionScheme;
28  import org.eclipse.aether.version.InvalidVersionSpecificationException;
29  import org.eclipse.aether.version.Version;
30  import org.eclipse.aether.version.VersionConstraint;
31  import org.eclipse.aether.version.VersionScheme;
32  
33  /**
34   */
35  public class StubVersionRangeResolver
36      implements VersionRangeResolver
37  {
38  
39      private final VersionScheme versionScheme = new GenericVersionScheme();
40  
41      public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request )
42          throws VersionRangeResolutionException
43      {
44          VersionRangeResult result = new VersionRangeResult( request );
45          try
46          {
47              VersionConstraint constraint = versionScheme.parseVersionConstraint( request.getArtifact().getVersion() );
48              result.setVersionConstraint( constraint );
49              if ( constraint.getRange() == null )
50              {
51                  result.addVersion( constraint.getVersion() );
52              }
53              else
54              {
55                  for ( int i = 1; i < 10; i++ )
56                  {
57                      Version ver = versionScheme.parseVersion( Integer.toString( i ) );
58                      if ( constraint.containsVersion( ver ) )
59                      {
60                          result.addVersion( ver );
61                          if ( !request.getRepositories().isEmpty() )
62                          {
63                              result.setRepository( ver, request.getRepositories().get( 0 ) );
64                          }
65                      }
66                  }
67              }
68          }
69          catch ( InvalidVersionSpecificationException e )
70          {
71              result.addException( e );
72              throw new VersionRangeResolutionException( result );
73          }
74  
75          return result;
76      }
77  
78  }