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.artifact.resolver;
20  
21  import java.io.File;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import org.apache.maven.model.Model;
26  import org.apache.maven.model.Repository;
27  import org.apache.maven.repository.internal.MavenWorkspaceReader;
28  import org.eclipse.aether.artifact.Artifact;
29  import org.eclipse.aether.repository.WorkspaceRepository;
30  
31  public class TestMavenWorkspaceReader implements MavenWorkspaceReader {
32  
33      static final String REPO_LAYOUT = "test";
34  
35      static final String REPO_URL = "https://test/me";
36  
37      static final String REPO_ID = "custom";
38  
39      static final String GROUP_ID = "org.apache.maven";
40  
41      static final String ARTIFACT_ID = "this.is.a.test";
42  
43      static final String VERSION = "99.99";
44  
45      private static final WorkspaceRepository WORKSPACE_REPOSITORY = new WorkspaceRepository(REPO_LAYOUT);
46  
47      @Override
48      public WorkspaceRepository getRepository() {
49          return WORKSPACE_REPOSITORY;
50      }
51  
52      @Override
53      public File findArtifact(Artifact artifact) {
54          return null;
55      }
56  
57      @Override
58      public List<String> findVersions(Artifact artifact) {
59          return Collections.emptyList();
60      }
61  
62      @Override
63      public Model findModel(Artifact artifact) {
64          if (GROUP_ID.equals(artifact.getGroupId())
65                  && ARTIFACT_ID.equals(artifact.getArtifactId())
66                  && VERSION.equals(artifact.getVersion())) {
67              Model m = new Model();
68              m.setArtifactId(ARTIFACT_ID);
69              m.setGroupId(GROUP_ID);
70              m.setVersion(VERSION);
71              Repository repository = new Repository();
72              repository.setId(REPO_ID);
73              repository.setUrl(REPO_URL);
74              repository.setLayout(REPO_LAYOUT);
75              m.getRepositories().add(repository);
76              return m;
77          }
78          return null;
79      }
80  }