|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.net.MalformedURLException;
|
22 | 22 | import java.net.URL;
|
23 |
| -import java.nio.charset.Charset; |
24 |
| -import java.nio.charset.UnsupportedCharsetException; |
25 |
| -import java.nio.file.Files; |
26 |
| -import java.nio.file.Path; |
27 | 23 | import java.util.ArrayList;
|
28 | 24 | import java.util.Arrays;
|
29 | 25 | import java.util.Collections;
|
30 | 26 | import java.util.List;
|
31 |
| -import java.util.Locale; |
32 | 27 | import java.util.Map;
|
33 | 28 | import java.util.Set;
|
34 | 29 | import java.util.stream.Collectors;
|
|
46 | 41 | import org.springframework.boot.loader.tools.FileUtils;
|
47 | 42 | import org.springframework.util.Assert;
|
48 | 43 | import org.springframework.util.ObjectUtils;
|
49 |
| -import org.springframework.util.StringUtils; |
50 | 44 |
|
51 | 45 | /**
|
52 | 46 | * Base class to run a Spring Boot application.
|
@@ -351,45 +345,18 @@ private void addActiveProfileArgument(RunArguments arguments) {
|
351 | 345 |
|
352 | 346 | private void addClasspath(List<String> args) throws MojoExecutionException {
|
353 | 347 | try {
|
354 |
| - StringBuilder classpath = new StringBuilder(); |
355 |
| - for (URL ele : getClassPathUrls()) { |
356 |
| - if (!classpath.isEmpty()) { |
357 |
| - classpath.append(File.pathSeparator); |
358 |
| - } |
359 |
| - classpath.append(new File(ele.toURI())); |
360 |
| - } |
| 348 | + String classpath = ClasspathBuilder.build(getClassPathUrls()); |
361 | 349 | if (getLog().isDebugEnabled()) {
|
362 | 350 | getLog().debug("Classpath for forked process: " + classpath);
|
363 | 351 | }
|
364 | 352 | args.add("-cp");
|
365 |
| - if (needsClasspathArgFile()) { |
366 |
| - args.add("@" + ArgFile.create(classpath).path()); |
367 |
| - } |
368 |
| - else { |
369 |
| - args.add(classpath.toString()); |
370 |
| - } |
| 353 | + args.add(classpath); |
371 | 354 | }
|
372 | 355 | catch (Exception ex) {
|
373 | 356 | throw new MojoExecutionException("Could not build classpath", ex);
|
374 | 357 | }
|
375 | 358 | }
|
376 | 359 |
|
377 |
| - private boolean needsClasspathArgFile() { |
378 |
| - // Windows limits the maximum command length, so we use an argfile there |
379 |
| - return runsOnWindows(); |
380 |
| - } |
381 |
| - |
382 |
| - private boolean runsOnWindows() { |
383 |
| - String os = System.getProperty("os.name"); |
384 |
| - if (!StringUtils.hasLength(os)) { |
385 |
| - if (getLog().isWarnEnabled()) { |
386 |
| - getLog().warn("System property os.name is not set"); |
387 |
| - } |
388 |
| - return false; |
389 |
| - } |
390 |
| - return os.toLowerCase(Locale.ROOT).contains("win"); |
391 |
| - } |
392 |
| - |
393 | 360 | protected URL[] getClassPathUrls() throws MojoExecutionException {
|
394 | 361 | try {
|
395 | 362 | List<URL> urls = new ArrayList<>();
|
@@ -468,37 +435,4 @@ static String format(String key, String value) {
|
468 | 435 |
|
469 | 436 | }
|
470 | 437 |
|
471 |
| - record ArgFile(Path path) { |
472 |
| - |
473 |
| - private void write(CharSequence content) throws IOException { |
474 |
| - Files.writeString(this.path, "\"" + escape(content) + "\"", getCharset()); |
475 |
| - } |
476 |
| - |
477 |
| - private Charset getCharset() { |
478 |
| - String nativeEncoding = System.getProperty("native.encoding"); |
479 |
| - if (nativeEncoding == null) { |
480 |
| - return Charset.defaultCharset(); |
481 |
| - } |
482 |
| - try { |
483 |
| - return Charset.forName(nativeEncoding); |
484 |
| - } |
485 |
| - catch (UnsupportedCharsetException ex) { |
486 |
| - return Charset.defaultCharset(); |
487 |
| - } |
488 |
| - } |
489 |
| - |
490 |
| - private String escape(CharSequence content) { |
491 |
| - return content.toString().replace("\\", "\\\\"); |
492 |
| - } |
493 |
| - |
494 |
| - static ArgFile create(CharSequence content) throws IOException { |
495 |
| - Path tempFile = Files.createTempFile("spring-boot-", ".argfile"); |
496 |
| - tempFile.toFile().deleteOnExit(); |
497 |
| - ArgFile argFile = new ArgFile(tempFile); |
498 |
| - argFile.write(content); |
499 |
| - return argFile; |
500 |
| - } |
501 |
| - |
502 |
| - } |
503 |
| - |
504 | 438 | }
|
0 commit comments