Skip to content

Commit 52b1c8b

Browse files
committed
Add ThinJarLauncher to spring-boot-loader
1 parent 43a1309 commit 52b1c8b

File tree

8 files changed

+797
-14
lines changed

8 files changed

+797
-14
lines changed

Diff for: spring-boot-tools/spring-boot-aether/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
</properties>
2020
<dependencies>
2121
<!-- Compile -->
22-
<dependency>
23-
<groupId>org.springframework.boot</groupId>
24-
<artifactId>spring-boot-loader-tools</artifactId>
25-
</dependency>
2622
<dependency>
2723
<groupId>org.springframework</groupId>
2824
<artifactId>spring-core</artifactId>

Diff for: spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/MainClassFinder.java

+3
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@
4646
* search.
4747
*
4848
* @author Phillip Webb
49+
*
50+
* @deprecated in favour of MainClassFinder in spring-boot-loader
4951
*/
52+
@Deprecated
5053
public abstract class MainClassFinder {
5154

5255
private static final String DOT_CLASS = ".class";

Diff for: spring-boot-tools/spring-boot-loader/pom.xml

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?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" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<parent>
56
<groupId>org.springframework.boot</groupId>
@@ -26,14 +27,15 @@
2627
<optional>true</optional>
2728
</dependency>
2829
<dependency>
29-
<groupId>org.slf4j</groupId>
30-
<artifactId>jcl-over-slf4j</artifactId>
31-
<scope>test</scope>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-aether</artifactId>
32+
<optional>true</optional>
3233
</dependency>
3334
<dependency>
34-
<groupId>ch.qos.logback</groupId>
35-
<artifactId>logback-classic</artifactId>
36-
<scope>test</scope>
35+
<groupId>commons-logging</groupId>
36+
<artifactId>commons-logging</artifactId>
37+
<version>1.2</version>
38+
<optional>true</optional>
3739
</dependency>
3840
<dependency>
3941
<groupId>org.springframework</groupId>
@@ -78,6 +80,29 @@
7880
</execution>
7981
</executions>
8082
</plugin>
83+
<plugin>
84+
<groupId>org.apache.maven.plugins</groupId>
85+
<artifactId>maven-assembly-plugin</artifactId>
86+
<executions>
87+
<execution>
88+
<id>stub</id>
89+
<phase>prepare-package</phase>
90+
<goals>
91+
<goal>single</goal>
92+
</goals>
93+
<inherited>false</inherited>
94+
<configuration>
95+
<attach>true</attach>
96+
<descriptor>${basedir}/src/assembly/launcher.xml</descriptor>
97+
<archive>
98+
<manifest>
99+
<mainClass>org.springframework.boot.loader.thin.ThinJarLauncher</mainClass>
100+
</manifest>
101+
</archive>
102+
</configuration>
103+
</execution>
104+
</executions>
105+
</plugin>
81106
</plugins>
82107
</build>
83108
</profile>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
3+
<id>exec</id>
4+
<formats>
5+
<format>jar</format>
6+
</formats>
7+
<includeBaseDirectory>false</includeBaseDirectory>
8+
<dependencySets>
9+
<dependencySet>
10+
<includes>
11+
<include>org.springframework.boot:spring-boot-aether:*</include>
12+
<include>org.springframework:spring-core:*</include>
13+
<include>commons-logging:commons-logging:*</include>
14+
</includes>
15+
<unpack>true</unpack>
16+
<useTransitiveFiltering>true</useTransitiveFiltering>
17+
</dependencySet>
18+
</dependencySets>
19+
<fileSets>
20+
<fileSet>
21+
<directory>${basedir}/target/classes</directory>
22+
<outputDirectory>/</outputDirectory>
23+
<includes>
24+
<include>**/*</include>
25+
</includes>
26+
</fileSet>
27+
</fileSets>
28+
</assembly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2012-2015 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+
* http://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 org.springframework.boot.loader.thin;
18+
19+
import java.io.IOException;
20+
import java.util.ArrayList;
21+
import java.util.Collections;
22+
import java.util.List;
23+
24+
import org.apache.maven.model.Model;
25+
import org.apache.maven.model.Parent;
26+
import org.apache.maven.model.building.DefaultModelProcessor;
27+
import org.apache.maven.model.io.DefaultModelReader;
28+
import org.apache.maven.model.locator.DefaultModelLocator;
29+
import org.eclipse.aether.artifact.Artifact;
30+
import org.eclipse.aether.artifact.DefaultArtifact;
31+
import org.eclipse.aether.graph.Dependency;
32+
33+
import org.springframework.core.io.Resource;
34+
35+
/**
36+
* Utility class to help with reading and extracting dependencies from a physical pom.
37+
*
38+
* @author Dave Syer
39+
*
40+
*/
41+
public class PomLoader {
42+
43+
public List<Dependency> getDependencies(Resource pom) {
44+
if (!pom.exists()) {
45+
return Collections.emptyList();
46+
}
47+
Model model = readModel(pom);
48+
return convert(model.getDependencies());
49+
}
50+
51+
public List<Dependency> getDependencyManagement(Resource pom) {
52+
if (!pom.exists()) {
53+
return Collections.emptyList();
54+
}
55+
List<Dependency> list = new ArrayList<Dependency>();
56+
Model model = readModel(pom);
57+
if (model.getParent() != null) {
58+
list.add(new Dependency(getParentArtifact(model), "import"));
59+
}
60+
if (model.getDependencyManagement() != null) {
61+
list.addAll(convert(model.getDependencyManagement().getDependencies()));
62+
}
63+
return list;
64+
}
65+
66+
private Artifact getParentArtifact(Model model) {
67+
Parent parent = model.getParent();
68+
return new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom",
69+
parent.getVersion());
70+
}
71+
72+
private List<Dependency> convert(
73+
List<org.apache.maven.model.Dependency> dependencies) {
74+
List<Dependency> result = new ArrayList<Dependency>();
75+
for (org.apache.maven.model.Dependency dependency : dependencies) {
76+
String scope = dependency.getScope();
77+
if (!"test".equals(scope) && !"provided".equals(scope)) {
78+
result.add(new Dependency(artifact(dependency), dependency.getScope()));
79+
}
80+
}
81+
return result;
82+
}
83+
84+
private Artifact artifact(org.apache.maven.model.Dependency dependency) {
85+
return new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(),
86+
dependency.getClassifier(), dependency.getType(),
87+
dependency.getVersion());
88+
}
89+
90+
private static Model readModel(Resource resource) {
91+
DefaultModelProcessor modelProcessor = new DefaultModelProcessor();
92+
modelProcessor.setModelLocator(new DefaultModelLocator());
93+
modelProcessor.setModelReader(new DefaultModelReader());
94+
95+
try {
96+
return modelProcessor.read(resource.getInputStream(), null);
97+
}
98+
catch (IOException ex) {
99+
throw new IllegalStateException("Failed to build model from effective pom",
100+
ex);
101+
}
102+
}
103+
104+
}

0 commit comments

Comments
 (0)