Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.boot.actuate.sbom;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -29,6 +28,7 @@
import org.springframework.boot.actuate.sbom.SbomProperties.Sbom;
import org.springframework.core.io.Resource;
import org.springframework.util.MimeType;
import org.springframework.util.function.ThrowingFunction;

/**
* {@link EndpointWebExtension @EndpointWebExtension} for the {@link SbomEndpoint}.
Expand Down Expand Up @@ -68,14 +68,9 @@ private MimeType getMediaType(String id, Resource resource) {
if (sbomProperties != null && sbomProperties.getMediaType() != null) {
return sbomProperties.getMediaType();
}
return this.detectedMediaTypeCache.computeIfAbsent(id, (ignored) -> {
try {
return detectSbomType(resource);
}
catch (IOException ex) {
throw new UncheckedIOException("Failed to detect type of resource '%s'".formatted(resource), ex);
}
}).getMediaType();
return this.detectedMediaTypeCache
.computeIfAbsent(id, (ThrowingFunction<String, SbomType>) (ignored) -> detectSbomType(resource))
.getMediaType();
}

private SbomType detectSbomType(Resource resource) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ private void cleanupCaches() {
private AbstractApplicationLauncher getAbstractApplicationLauncher(Application application,
Class<? extends AbstractApplicationLauncher> launcherClass) {
String cacheKey = application.getContainer() + ":" + application.getPackaging() + ":" + launcherClass.getName();
if (this.launcherCache.containsKey(cacheKey)) {
return this.launcherCache.get(cacheKey);
}
AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application,
new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID()));
this.launcherCache.put(cacheKey, launcher);
return launcher;
return this.launcherCache.computeIfAbsent(cacheKey, (ignored) -> ReflectionUtils.newInstance(launcherClass,
application, new File(buildOutput.getRootLocation(), "app-launcher-" + UUID.randomUUID())));
}

private Application getApplication(EmbeddedServletContainerTest annotation, String container) {
Expand Down