JENKINS-47509# Initialize mapped URL lazily
@@ -11,20 +11,11 @@ import javax.annotation.Nonnull;
*/
public class BlueOceanUrlObjectImpl extends BlueOceanUrlObject {
- private final String mappedUrl;
+ private volatile String mappedUrl;
+ private final ModelObject modelObject;
public BlueOceanUrlObjectImpl(ModelObject modelObject) {
- String url = null;
- for(BlueOceanUrlMapper mapper: BlueOceanUrlMapper.all()){
- url = mapper.getUrl(modelObject);
- if(url != null){
- break;
- }
- }
- if(url == null){
- url = BlueOceanUrlMapperImpl.getLandingPagePath();
- }
- this.mappedUrl = url;
+ this.modelObject = modelObject;
}
@Override
@@ -34,6 +25,7 @@ public class BlueOceanUrlObjectImpl extends BlueOceanUrlObject {
@Override
public @Nonnull String getUrl() {
+ setUrlIfNeeded();
return mappedUrl;
}
@@ -41,4 +33,31 @@ public class BlueOceanUrlObjectImpl extends BlueOceanUrlObject {
public @Nonnull String getIconUrl() {
return "/plugin/blueocean-rest-impl/images/48x48/blueocean.png";
}
+
+ private void setUrlIfNeeded(){
+ String url = mappedUrl;
+ if(url == null){
+ synchronized (this){
+ url = mappedUrl;
+ if(url == null){
+ url = computeUrl();
+ this.mappedUrl = url;
+ }
+ }
+ }
+ }
+
+ private String computeUrl(){
+ String url = null;
+ for(BlueOceanUrlMapper mapper: BlueOceanUrlMapper.all()){
+ url = mapper.getUrl(modelObject);
+ if(url != null){
+ break;
+ }
+ }
+ if(url == null){
+ url = BlueOceanUrlMapperImpl.getLandingPagePath();
+ }
+ return url;
+ }
}
