Skip to content

Commit f137a05

Browse files
Injects Maven's repositorySystem to Aether downloader
without this change with the latest version of Maven, it is removing entries from the classpath so Aether related classes are not seen at runtime with this change we're passing the RepositorySystem to Aether that contains all classes fixes gh-2362 Signed-off-by: Marcin Grzejszczak <[email protected]>
1 parent 48e9ba7 commit f137a05

File tree

8 files changed

+22
-232
lines changed

8 files changed

+22
-232
lines changed

spring-cloud-contract-stub-runner/src/main/java/org/springframework/cloud/contract/stubrunner/AetherStubDownloader.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public class AetherStubDownloader implements StubDownloader {
7070
// Preloading class for the shutdown hook not to throw ClassNotFound
7171
private static final Class CLAZZ = TemporaryFileStorage.class;
7272

73+
// In order to allow to pass the injected values from Maven
74+
private static RepositorySystem repositorySystemFromMaven;
75+
7376
private final List<RemoteRepository> remoteRepos;
7477

7578
private final RepositorySystem repositorySystem;
@@ -105,7 +108,7 @@ public AetherStubDownloader(StubRunnerOptions stubRunnerOptions) {
105108
throw new UnsupportedOperationException(
106109
"You can't use Aether downloader when you use classpath to find stubs");
107110
}
108-
this.repositorySystem = AetherFactories.repositorySystemOr(null);
111+
this.repositorySystem = AetherFactories.repositorySystemOr(repositorySystemFromMaven);
109112
this.workOffline = stubRunnerOptions.stubsMode == StubRunnerProperties.StubsMode.LOCAL;
110113
this.session = newSession(this.repositorySystem, this.workOffline);
111114
registerShutdownHook();
@@ -278,4 +281,13 @@ private void registerShutdownHook() {
278281
new Thread(() -> TemporaryFileStorage.cleanup(AetherStubDownloader.this.deleteStubsAfterTest)));
279282
}
280283

284+
/**
285+
* Use this if you're in Maven and have the {@link RepositorySystem} injected to you
286+
* through the {@code Component} annotation.
287+
* @param fromMaven system injected to you by Maven
288+
*/
289+
public static void setRepositorySystemFromMaven(RepositorySystem fromMaven) {
290+
repositorySystemFromMaven = fromMaven;
291+
}
292+
281293
}

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/main/java/org/springframework/cloud/contract/maven/verifier/GenerateTestsMojo.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
import org.apache.maven.plugin.MojoExecution;
2929
import org.apache.maven.plugin.MojoExecutionException;
3030
import org.apache.maven.plugin.MojoFailureException;
31+
import org.apache.maven.plugins.annotations.Component;
3132
import org.apache.maven.plugins.annotations.LifecyclePhase;
3233
import org.apache.maven.plugins.annotations.Mojo;
3334
import org.apache.maven.plugins.annotations.Parameter;
3435
import org.apache.maven.plugins.annotations.ResolutionScope;
3536
import org.apache.maven.project.MavenProject;
37+
import org.eclipse.aether.RepositorySystem;
3638
import org.eclipse.aether.RepositorySystemSession;
3739

3840
import org.springframework.cloud.contract.spec.ContractVerifierException;
41+
import org.springframework.cloud.contract.stubrunner.AetherStubDownloader;
3942
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
4043
import org.springframework.cloud.contract.verifier.TestGenerator;
4144
import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties;
@@ -53,6 +56,11 @@
5356
requiresDependencyResolution = ResolutionScope.TEST)
5457
public class GenerateTestsMojo extends AbstractMojo {
5558

59+
@Component
60+
private RepositorySystem repositorySystem;
61+
62+
// Required for the case where there is no configuration (check the basic project for
63+
// tests)
5664
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
5765
private RepositorySystemSession repoSession;
5866

@@ -263,6 +271,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
263271
final ContractVerifierConfigProperties config = new ContractVerifierConfigProperties();
264272
config.setFailOnInProgress(this.failOnInProgress);
265273
// download contracts, unzip them and pass as output directory
274+
AetherStubDownloader.setRepositorySystemFromMaven(repositorySystem);
266275
File contractsDirectory = new MavenContractsDownloader(this.project, this.contractDependency,
267276
this.contractsPath, this.contractsRepositoryUrl, this.contractsMode, getLog(),
268277
this.contractsRepositoryUsername, this.contractsRepositoryPassword, this.contractsRepositoryProxyHost,

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/generated-test-resources/contracts/org/springframework/cloud/contract/verifier/tests/Messaging.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/ContractVerifierTest.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/generated-test-sources/contracts/org/springframework/cloud/contract/verifier/tests/Messaging.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Messaging.groovy

Lines changed: 0 additions & 29 deletions
This file was deleted.

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/Sample.groovy

Lines changed: 0 additions & 32 deletions
This file was deleted.

spring-cloud-contract-tools/spring-cloud-contract-maven-plugin/src/test/projects/basic/${project.build.directory}/stubs/META-INF/org.springframework.cloud.verifier.sample/sample-project/0.1/contracts/WithList.groovy

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)