ClassPath Class — spring-boot Architecture
Architecture documentation for the ClassPath class in ClassPath.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/ClassPath.java lines 49–149
final class ClassPath {
private static final Collector<CharSequence, ?, String> JOIN_BY_PATH_SEPARATOR = Collectors
.joining(File.pathSeparator);
private final boolean preferArgFile;
private final String path;
private ClassPath(boolean preferArgFile, String path) {
this.preferArgFile = preferArgFile;
this.path = path;
}
/**
* Return the args to append to a java command line call (including {@code -cp}).
* @param allowArgFile if an arg file can be used
* @return the command line arguments
*/
List<String> args(boolean allowArgFile) {
return (!this.path.isEmpty()) ? List.of("-cp", classPathArg(allowArgFile)) : Collections.emptyList();
}
private String classPathArg(boolean allowArgFile) {
if (this.preferArgFile && allowArgFile) {
try {
return "@" + createArgFile();
}
catch (IOException ex) {
return this.path;
}
}
return this.path;
}
@Override
public String toString() {
return this.path;
}
private Path createArgFile() throws IOException {
Path argFile = Files.createTempFile("spring-boot-", ".argfile");
argFile.toFile().deleteOnExit();
Files.writeString(argFile, "\"" + this.path.replace("\\", "\\\\") + "\"", charset());
return argFile;
}
private Charset charset() {
try {
String nativeEncoding = System.getProperty("native.encoding");
return (nativeEncoding != null) ? Charset.forName(nativeEncoding) : Charset.defaultCharset();
}
catch (UnsupportedCharsetException ex) {
return Charset.defaultCharset();
}
}
/**
* Factory method to create a {@link ClassPath} of the given URLs.
* @param urls the class path URLs
* @return a new {@link ClassPath} instance
*/
static ClassPath of(URL... urls) {
return of(Arrays.asList(urls));
}
/**
* Factory method to create a {@link ClassPath} of the given URLs.
* @param urls the class path URLs
* @return a new {@link ClassPath} instance
*/
static ClassPath of(List<URL> urls) {
return of(System::getProperty, urls);
}
/**
* Factory method to create a {@link ClassPath} of the given URLs.
* @param getSystemProperty {@link UnaryOperator} allowing access to system properties
* @param urls the class path URLs
* @return a new {@link ClassPath} instance
*/
static ClassPath of(UnaryOperator<@Nullable String> getSystemProperty, List<URL> urls) {
boolean preferArgFile = urls.size() > 1 && isWindows(getSystemProperty);
return new ClassPath(preferArgFile, urls.stream().map(ClassPath::toPathString).collect(JOIN_BY_PATH_SEPARATOR));
}
private static boolean isWindows(UnaryOperator<@Nullable String> getSystemProperty) {
String os = getSystemProperty.apply("os.name");
return StringUtils.hasText(os) && os.toLowerCase(Locale.ROOT).contains("win");
}
private static String toPathString(URL url) {
try {
return Paths.get(url.toURI()).toString();
}
catch (URISyntaxException ex) {
throw new IllegalArgumentException(ex);
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free