Browse Source

Fix behaviour of DependencyCustomizer ifAllResourcesPresent

Previously, DependencyCustomizer's ifAllResourcesPresent method
would return a customizer that added modules if any of the resources
were present. This commit corrects this behaviours so that modules are
only added if all resources are present.

Fixes gh-20418
pull/20912/head
Andy Wilkinson 6 years ago
parent
commit
f251772e17
  1. 3
      spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java
  2. 44
      spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java
  3. 0
      spring-boot-project/spring-boot-cli/src/test/resources/dependency-customizer-tests/resource1.txt
  4. 0
      spring-boot-project/spring-boot-cli/src/test/resources/dependency-customizer-tests/resource2.txt

3
spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyCustomizer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -144,7 +144,6 @@ public class DependencyCustomizer { @@ -144,7 +144,6 @@ public class DependencyCustomizer {
if (DependencyCustomizer.this.loader.getResource(path) == null) {
return false;
}
return true;
}
catch (Exception ex) {
// swallow exception and continue

44
spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/DependencyCustomizerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -138,6 +138,48 @@ public class DependencyCustomizerTests { @@ -138,6 +138,48 @@ public class DependencyCustomizerTests {
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void allResourcesPresentWithAllResourcesPresentPerformsAdd() {
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/resource1.txt",
"dependency-customizer-tests/resource2.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void allResourcesPresentWithSomeResourcesPresentDoesNotPerformAdd() {
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/resource1.txt",
"dependency-customizer-tests/does-not-exist.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
@Test
public void allResourcesPresentWithNoResourcesPresentDoesNotPerformAdd() {
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/does-not-exist",
"dependency-customizer-tests/does-not-exist-either.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
@Test
public void anyResourcesPresentWithAllResourcesPresentPerformsAdd() {
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/resource1.txt",
"dependency-customizer-tests/resource2.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void anyResourcesPresentWithSomeResourcesPresentPerforms() {
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/resource1.txt",
"dependency-customizer-tests/does-not-exist.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
}
@Test
public void anyResourcesPresentWithNoResourcesPresentDoesNotPerformAdd() {
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/does-not-exist",
"dependency-customizer-tests/does-not-exist-either.txt").add("spring-boot-starter-logging");
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
}
private void assertGrabAnnotation(AnnotationNode annotationNode, String group, String module, String version,
String classifier, String type, boolean transitive) {
assertThat(getMemberValue(annotationNode, "group")).isEqualTo(group);

0
spring-boot-project/spring-boot-cli/src/test/resources/dependency-customizer-tests/resource1.txt

0
spring-boot-project/spring-boot-cli/src/test/resources/dependency-customizer-tests/resource2.txt

Loading…
Cancel
Save