Skip to content

Commit 2f92261

Browse files
committed
Merge branch '2.2.x'
Closes gh-20502
2 parents ad9e5be + e937b2e commit 2f92261

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public DependencyCustomizer ifAllResourcesPresent(String... paths) {
140140
protected boolean canAdd() {
141141
for (String path : paths) {
142142
try {
143-
return DependencyCustomizer.this.loader.getResource(path) != null;
143+
if (DependencyCustomizer.this.loader.getResource(path) == null) {
144+
return false;
145+
}
144146
}
145147
catch (Exception ex) {
146148
// swallow exception and continue

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -138,6 +138,48 @@ void allMissingClassesWithAllClassesMissingPerformsAdd() {
138138
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
139139
}
140140

141+
@Test
142+
void allResourcesPresentWithAllResourcesPresentPerformsAdd() {
143+
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/resource1.txt",
144+
"dependency-customizer-tests/resource2.txt").add("spring-boot-starter-logging");
145+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
146+
}
147+
148+
@Test
149+
void allResourcesPresentWithSomeResourcesPresentDoesNotPerformAdd() {
150+
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/resource1.txt",
151+
"dependency-customizer-tests/does-not-exist.txt").add("spring-boot-starter-logging");
152+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
153+
}
154+
155+
@Test
156+
void allResourcesPresentWithNoResourcesPresentDoesNotPerformAdd() {
157+
this.dependencyCustomizer.ifAllResourcesPresent("dependency-customizer-tests/does-not-exist",
158+
"dependency-customizer-tests/does-not-exist-either.txt").add("spring-boot-starter-logging");
159+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
160+
}
161+
162+
@Test
163+
void anyResourcesPresentWithAllResourcesPresentPerformsAdd() {
164+
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/resource1.txt",
165+
"dependency-customizer-tests/resource2.txt").add("spring-boot-starter-logging");
166+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
167+
}
168+
169+
@Test
170+
void anyResourcesPresentWithSomeResourcesPresentPerforms() {
171+
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/resource1.txt",
172+
"dependency-customizer-tests/does-not-exist.txt").add("spring-boot-starter-logging");
173+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).hasSize(1);
174+
}
175+
176+
@Test
177+
void anyResourcesPresentWithNoResourcesPresentDoesNotPerformAdd() {
178+
this.dependencyCustomizer.ifAnyResourcesPresent("dependency-customizer-tests/does-not-exist",
179+
"dependency-customizer-tests/does-not-exist-either.txt").add("spring-boot-starter-logging");
180+
assertThat(this.classNode.getAnnotations(new ClassNode(Grab.class))).isEmpty();
181+
}
182+
141183
private void assertGrabAnnotation(AnnotationNode annotationNode, String group, String module, String version,
142184
String classifier, String type, boolean transitive) {
143185
assertThat(getMemberValue(annotationNode, "group")).isEqualTo(group);

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

Whitespace-only changes.

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

Whitespace-only changes.

0 commit comments

Comments
 (0)