Skip to content

Commit 661fcfe

Browse files
committed
Merge branch '3.3.x' into 3.4.x
2 parents eeced8c + 082c585 commit 661fcfe

File tree

7 files changed

+307
-351
lines changed

7 files changed

+307
-351
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractAotMojo.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,31 @@ protected final void compileSourceFiles(URL[] classPath, File sourcesDirectory,
145145
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
146146
try (StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null)) {
147147
JavaCompilerPluginConfiguration compilerConfiguration = new JavaCompilerPluginConfiguration(this.project);
148-
List<String> options = new ArrayList<>();
149-
options.add("-cp");
150-
options.add(ClasspathBuilder.forURLs(classPath).build().toString());
151-
options.add("-d");
152-
options.add(outputDirectory.toPath().toAbsolutePath().toString());
148+
List<String> args = new ArrayList<>();
149+
args.addAll(ClassPath.of(classPath).args(false));
150+
args.add("-d");
151+
args.add(outputDirectory.toPath().toAbsolutePath().toString());
153152
String releaseVersion = compilerConfiguration.getReleaseVersion();
154153
if (releaseVersion != null) {
155-
options.add("--release");
156-
options.add(releaseVersion);
154+
args.add("--release");
155+
args.add(releaseVersion);
157156
}
158157
else {
159158
String source = compilerConfiguration.getSourceMajorVersion();
160159
if (source != null) {
161-
options.add("--source");
162-
options.add(source);
160+
args.add("--source");
161+
args.add(source);
163162
}
164163
String target = compilerConfiguration.getTargetMajorVersion();
165164
if (target != null) {
166-
options.add("--target");
167-
options.add(target);
165+
args.add("--target");
166+
args.add(target);
168167
}
169168
}
170-
options.addAll(new RunArguments(this.compilerArguments).getArgs());
169+
args.addAll(new RunArguments(this.compilerArguments).getArgs());
171170
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromPaths(sourceFiles);
172171
Errors errors = new Errors();
173-
CompilationTask task = compiler.getTask(null, fileManager, errors, options, null, compilationUnits);
172+
CompilationTask task = compiler.getTask(null, fileManager, errors, args, null, compilationUnits);
174173
boolean result = task.call();
175174
if (!result || errors.hasReportedErrors()) {
176175
throw new IllegalStateException("Unable to compile generated source" + errors);

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractRunMojo.java

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.apache.maven.toolchain.ToolchainManager;
4040

4141
import org.springframework.boot.loader.tools.FileUtils;
42-
import org.springframework.boot.maven.ClasspathBuilder.Classpath;
4342

4443
/**
4544
* Base class to run a Spring Boot application.
@@ -58,132 +57,151 @@ public abstract class AbstractRunMojo extends AbstractDependencyFilterMojo {
5857

5958
/**
6059
* The Maven project.
60+
*
6161
* @since 1.0.0
6262
*/
6363
@Parameter(defaultValue = "${project}", readonly = true, required = true)
6464
private MavenProject project;
6565

6666
/**
6767
* The current Maven session. This is used for toolchain manager API calls.
68+
*
6869
* @since 2.3.0
6970
*/
7071
@Parameter(defaultValue = "${session}", readonly = true)
7172
private MavenSession session;
7273

7374
/**
7475
* The toolchain manager to use to locate a custom JDK.
76+
*
7577
* @since 2.3.0
7678
*/
7779
@Component
7880
private ToolchainManager toolchainManager;
7981

8082
/**
81-
* Add maven resources to the classpath directly, this allows live in-place editing of
82-
* resources. Duplicate resources are removed from {@code target/classes} to prevent
83-
* them from appearing twice if {@code ClassLoader.getResources()} is called. Please
84-
* consider adding {@code spring-boot-devtools} to your project instead as it provides
85-
* this feature and many more.
83+
* Add maven resources to the classpath directly, this allows live in-place
84+
* editing of resources. Duplicate resources are removed from
85+
* {@code target/classes} to prevent them from appearing twice if
86+
* {@code ClassLoader.getResources()} is called. Please consider adding
87+
* {@code spring-boot-devtools} to your project instead as it provides this
88+
* feature and many more.
89+
*
8690
* @since 1.0.0
8791
*/
8892
@Parameter(property = "spring-boot.run.addResources", defaultValue = "false")
8993
private boolean addResources = false;
9094

9195
/**
9296
* Path to agent jars.
97+
*
9398
* @since 2.2.0
9499
*/
95100
@Parameter(property = "spring-boot.run.agents")
96101
private File[] agents;
97102

98103
/**
99104
* Flag to say that the agent requires -noverify.
105+
*
100106
* @since 1.0.0
101107
*/
102108
@Parameter(property = "spring-boot.run.noverify")
103109
private boolean noverify = false;
104110

105111
/**
106-
* Current working directory to use for the application. If not specified, basedir
107-
* will be used.
112+
* Current working directory to use for the application. If not specified,
113+
* basedir will be used.
114+
*
108115
* @since 1.5.0
109116
*/
110117
@Parameter(property = "spring-boot.run.workingDirectory")
111118
private File workingDirectory;
112119

113120
/**
114-
* JVM arguments that should be associated with the forked process used to run the
115-
* application. On command line, make sure to wrap multiple values between quotes.
121+
* JVM arguments that should be associated with the forked process used to run
122+
* the application. On command line, make sure to wrap multiple values between
123+
* quotes.
124+
*
116125
* @since 1.1.0
117126
*/
118127
@Parameter(property = "spring-boot.run.jvmArguments")
119128
private String jvmArguments;
120129

121130
/**
122131
* List of JVM system properties to pass to the process.
132+
*
123133
* @since 2.1.0
124134
*/
125135
@Parameter
126136
private Map<String, String> systemPropertyVariables;
127137

128138
/**
129-
* List of Environment variables that should be associated with the forked process
130-
* used to run the application.
139+
* List of Environment variables that should be associated with the forked
140+
* process used to run the application.
141+
*
131142
* @since 2.1.0
132143
*/
133144
@Parameter
134145
private Map<String, String> environmentVariables;
135146

136147
/**
137148
* Arguments that should be passed to the application.
149+
*
138150
* @since 1.0.0
139151
*/
140152
@Parameter
141153
private String[] arguments;
142154

143155
/**
144156
* Arguments from the command line that should be passed to the application. Use
145-
* spaces to separate multiple arguments and make sure to wrap multiple values between
146-
* quotes. When specified, takes precedence over {@link #arguments}.
157+
* spaces to separate multiple arguments and make sure to wrap multiple values
158+
* between quotes. When specified, takes precedence over {@link #arguments}.
159+
*
147160
* @since 2.2.3
148161
*/
149162
@Parameter(property = "spring-boot.run.arguments")
150163
private String commandlineArguments;
151164

152165
/**
153166
* The spring profiles to activate. Convenience shortcut of specifying the
154-
* 'spring.profiles.active' argument. On command line use commas to separate multiple
155-
* profiles.
167+
* 'spring.profiles.active' argument. On command line use commas to separate
168+
* multiple profiles.
169+
*
156170
* @since 1.3.0
157171
*/
158172
@Parameter(property = "spring-boot.run.profiles")
159173
private String[] profiles;
160174

161175
/**
162-
* The name of the main class. If not specified the first compiled class found that
163-
* contains a 'main' method will be used.
176+
* The name of the main class. If not specified the first compiled class found
177+
* that contains a 'main' method will be used.
178+
*
164179
* @since 1.0.0
165180
*/
166181
@Parameter(property = "spring-boot.run.main-class")
167182
private String mainClass;
168183

169184
/**
170-
* Additional classpath elements that should be added to the classpath. An element can
171-
* be a directory with classes and resources or a jar file.
185+
* Additional classpath elements that should be added to the classpath. An
186+
* element can be a directory with classes and resources or a jar file.
187+
*
172188
* @since 3.2.0
173189
*/
174190
@Parameter(property = "spring-boot.run.additional-classpath-elements")
175191
private String[] additionalClasspathElements;
176192

177193
/**
178-
* Directory containing the classes and resource files that should be used to run the
179-
* application.
194+
* Directory containing the classes and resource files that should be used to
195+
* run the application.
196+
*
180197
* @since 1.0.0
181198
*/
182199
@Parameter(defaultValue = "${project.build.outputDirectory}", required = true)
183200
private File classesDirectory;
184201

185202
/**
186203
* Skip the execution.
204+
*
187205
* @since 1.3.2
188206
*/
189207
@Parameter(property = "spring-boot.run.skip", defaultValue = "false")
@@ -206,9 +224,10 @@ private String determineMainClass() throws MojoExecutionException {
206224
}
207225

208226
/**
209-
* Returns the directories that contain the application's classes and resources. When
210-
* the application's main class has not been configured, each directory is searched in
211-
* turn for an appropriate main class.
227+
* Returns the directories that contain the application's classes and resources.
228+
* When the application's main class has not been configured, each directory is
229+
* searched in turn for an appropriate main class.
230+
*
212231
* @return the directories that contain the application's classes and resources
213232
* @since 3.1.0
214233
*/
@@ -237,6 +256,7 @@ private void run(String startClassName) throws MojoExecutionException, MojoFailu
237256

238257
/**
239258
* Run the application.
259+
*
240260
* @param processExecutor the {@link JavaProcessExecutor} to use
241261
* @param workingDirectory the working directory of the forked JVM
242262
* @param args the arguments (JVM arguments and application arguments)
@@ -250,6 +270,7 @@ protected abstract void run(JavaProcessExecutor processExecutor, File workingDir
250270

251271
/**
252272
* Resolve the application arguments to use.
273+
*
253274
* @return a {@link RunArguments} defining the application arguments
254275
*/
255276
protected RunArguments resolveApplicationArguments() {
@@ -261,6 +282,7 @@ protected RunArguments resolveApplicationArguments() {
261282

262283
/**
263284
* Resolve the environment variables to use.
285+
*
264286
* @return an {@link EnvVariables} defining the environment variables
265287
*/
266288
protected EnvVariables resolveEnvVariables() {
@@ -281,15 +303,15 @@ private Map<String, String> determineEnvironmentVariables() {
281303

282304
/**
283305
* Resolve the JVM arguments to use.
306+
*
284307
* @return a {@link RunArguments} defining the JVM arguments
285308
*/
286309
protected RunArguments resolveJvmArguments() {
287310
StringBuilder stringBuilder = new StringBuilder();
288311
if (this.systemPropertyVariables != null) {
289-
stringBuilder.append(this.systemPropertyVariables.entrySet()
290-
.stream()
291-
.map((e) -> SystemPropertyFormatter.format(e.getKey(), e.getValue()))
292-
.collect(Collectors.joining(" ")));
312+
stringBuilder.append(this.systemPropertyVariables.entrySet().stream()
313+
.map((e) -> SystemPropertyFormatter.format(e.getKey(), e.getValue()))
314+
.collect(Collectors.joining(" ")));
293315
}
294316
if (this.jvmArguments != null) {
295317
stringBuilder.append(" ").append(this.jvmArguments);
@@ -333,14 +355,12 @@ private void addActiveProfileArgument(RunArguments arguments) {
333355

334356
private void addClasspath(List<String> args) throws MojoExecutionException {
335357
try {
336-
Classpath classpath = ClasspathBuilder.forURLs(getClassPathUrls()).build();
358+
ClassPath classpath = ClassPath.of(getClassPathUrls());
337359
if (getLog().isDebugEnabled()) {
338360
getLog().debug("Classpath for forked process: " + classpath);
339361
}
340-
args.add("-cp");
341-
args.add(classpath.argument());
342-
}
343-
catch (Exception ex) {
362+
args.addAll(classpath.args(true));
363+
} catch (Exception ex) {
344364
throw new MojoExecutionException("Could not build classpath", ex);
345365
}
346366
}
@@ -353,8 +373,7 @@ protected URL[] getClassPathUrls() throws MojoExecutionException {
353373
addProjectClasses(urls);
354374
addDependencies(urls);
355375
return urls.toArray(new URL[0]);
356-
}
357-
catch (IOException ex) {
376+
} catch (IOException ex) {
358377
throw new MojoExecutionException("Unable to build classpath", ex);
359378
}
360379
}

0 commit comments

Comments
 (0)