Skip to content

Commit bde330b

Browse files
jjelliottDave Syer
authored andcommitted
Add support for artifacts without version numbers
1 parent 0149a0e commit bde330b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

launcher/src/main/java/org/springframework/boot/loader/thin/PathResolver.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,18 @@ public Resource getPom(Archive archive) {
140140
throw new IllegalStateException("Cannot locate archive", e);
141141
}
142142
String pattern = "META-INF/maven/**"
143-
+ (artifactId == null ? "" : "/" + artifactId) + "/pom.xml";
143+
+ (artifactId == null || artifactId.length() == 0 ? ""
144+
: "/" + artifactId)
145+
+ "/pom.xml";
144146
Resource resource = findResource(archive, pattern);
145147
if (resource != null) {
146148
return resource;
147149
}
148150
// Spring Boot fat jar
149151
pattern = "BOOT-INF/classes/META-INF/maven/**"
150-
+ (artifactId == null ? "" : "/" + artifactId) + "/pom.xml";
152+
+ (artifactId == null || artifactId.length() == 0 ? ""
153+
: "/" + artifactId)
154+
+ "/pom.xml";
151155
resource = findResource(archive, pattern);
152156
if (resource != null) {
153157
return resource;
@@ -399,6 +403,7 @@ private String extractArtifactId(Archive archive) throws MalformedURLException {
399403
path = path.substring(0, path.length() - 2);
400404
}
401405
path = StringUtils.getFilename(path);
406+
path = path.replace(".jar", "");
402407
path = path.split("-[0-9]")[0];
403408
return path;
404409
}

launcher/src/test/java/org/springframework/boot/loader/thin/PathResolverTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,12 @@ public void pomWithMavenArchiveBootInf() throws Exception {
135135
"BOOT-INF/classes/META-INF/maven/org.springframework.boot/spring-boot-cli/pom.xml");
136136
}
137137

138+
@Test
139+
public void pomWithUnversionedJar() throws Exception {
140+
Resource resource = resolver.getPom(
141+
new ExplodedArchive(new File("src/test/resources/apps/fake.jar")));
142+
assertThat(resource.getURL().toString())
143+
.endsWith("META-INF/maven/com.example/fake/pom.xml");
144+
}
145+
138146
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>simple</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>simple</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
</project>

0 commit comments

Comments
 (0)