Skip to content

Commit bcabf13

Browse files
committed
testjars.<beanName>**.class is not repackaged
Closes gh-76
1 parent 4cd9e90 commit bcabf13

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/ScanningClasspathEntry.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ class ScanningClasspathEntry implements ClasspathEntry {
5757
this.renameResource = (name) -> {
5858
String prefix = baseDir + "/";
5959
int index = name.lastIndexOf(prefix);
60-
return (index > -1) ? name.substring(index + prefix.length()) : name;
60+
// .class files stay in the same package (otherwise invalid), but resources
61+
// are relative to baseDir
62+
int length = (name.endsWith(".class") ? 0 : prefix.length());
63+
return (index > -1) ? name.substring(index + length) : name;
6164
};
6265
}
6366

spring-boot-testjars/src/test/java/org/springframework/experimental/boot/server/exec/CommonsExecWebServerFactoryBeanTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
2626
import java.util.List;
27+
import java.util.Optional;
2728

2829
import org.junit.jupiter.api.Test;
2930

@@ -155,6 +156,19 @@ void classpathWhenYamlDefaults() throws Exception {
155156
});
156157
}
157158

159+
// gh-76
160+
@Test
161+
void classpathWhenJavaDefaults() throws Exception {
162+
CommonsExecWebServerFactoryBean factory = CommonsExecWebServerFactoryBean.builder();
163+
factory.setBeanName("javaDefaults");
164+
factory.classpath((cp) -> {
165+
List<ClasspathEntry> classpath = cp.getClasspath();
166+
Optional<String> javaDefaultsEntry = classpath.stream().map(ClasspathEntry::resolve).flatMap(List::stream)
167+
.filter((path) -> new File(path, "testjars/javaDefaults/Main.class").exists()).findFirst();
168+
assertThat(javaDefaultsEntry.isPresent()).isTrue();
169+
});
170+
}
171+
158172
@Test
159173
void setAdditionalBeanClassNamesWhenSingleName() {
160174
String envName = "testjars.additionalBeanClassNames";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2012-2023 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 testjars.javaDefaults;
18+
19+
public class Main {
20+
21+
}

0 commit comments

Comments
 (0)