View Javadoc
1   /*
2    * Copyright 2013-2020 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.cloud.contract.maven.verifier.stubrunner;
18  
19  import javax.inject.Inject;
20  import javax.inject.Named;
21  import javax.inject.Singleton;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.apache.maven.project.MavenProject;
26  import org.eclipse.aether.RepositorySystem;
27  import org.eclipse.aether.RepositorySystemSession;
28  import shaded.org.apache.maven.settings.Settings;
29  
30  import org.springframework.cloud.contract.stubrunner.AetherStubDownloader;
31  import org.springframework.cloud.contract.stubrunner.StubDownloader;
32  import org.springframework.cloud.contract.stubrunner.StubDownloaderBuilder;
33  import org.springframework.cloud.contract.stubrunner.StubRunnerOptions;
34  import org.springframework.core.io.Resource;
35  import org.springframework.core.io.ResourceLoader;
36  
37  /**
38   * Builds {@link StubDownloaderBuilder} for a Maven project.
39   *
40   * @author Mariusz Smykula
41   * @author EddĂș MelĂ©ndez
42   */
43  @Named
44  @Singleton
45  public class AetherStubDownloaderFactory {
46  
47  	private static final Log log = LogFactory.getLog(AetherStubDownloaderFactory.class);
48  
49  	private final MavenProject project;
50  
51  	private final RepositorySystem repoSystem;
52  
53  	private final Settings settings;
54  
55  	@Inject
56  	public AetherStubDownloaderFactory(RepositorySystem repoSystem, MavenProject project, Settings settings) {
57  		this.repoSystem = repoSystem;
58  		this.project = project;
59  		this.settings = settings;
60  	}
61  
62  	public StubDownloaderBuilder build(final RepositorySystemSession repoSession) {
63  		return new StubDownloaderBuilder() {
64  			@Override
65  			public StubDownloader build(StubRunnerOptions stubRunnerOptions) {
66  				log.info("Will download contracts using current build's Maven repository setup");
67  				return new AetherStubDownloader(AetherStubDownloaderFactory.this.repoSystem,
68  						AetherStubDownloaderFactory.this.project.getRemoteProjectRepositories(), repoSession,
69  						AetherStubDownloaderFactory.this.settings);
70  			}
71  
72  			@Override
73  			public Resource resolve(String location, ResourceLoader resourceLoader) {
74  				return null;
75  			}
76  		};
77  	}
78  
79  }