Fallback to Default Icon if Specified File is Missing

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      While testing the icon feature in the htmlpublisher-plugin, I noticed that if the user specifies a file that does not exist, the plugin does not fall back to the default icon, attempting instead to load a missing file, resulting in a broken image in the UI.

      Steps to reproduce:
      1) In the job configuration, set an icon to a file that does not exist
      2) Run the job
      3) The UI attempts to load a file that is missing, without falling back to the default icon

      Proposed fix
      A simple fix to this issue can be to edit the getIconFileName() method (in HtmlPublisherTarget.java), adding the check for the file existence:

            public String getIconFileName() {
                  String icon;
                  if (StringUtils.isNotBlank(actualHtmlPublisherTarget.icon)) {
                      if (actualHtmlPublisherTarget.icon.startsWith("symbol-")) {
                          icon = actualHtmlPublisherTarget.icon;
                      }
                      else {
                          File iconFile = new File(dir(), actualHtmlPublisherTarget.icon);
      
                          if(iconFile.exists()){
                              icon = project.getUrl() + dir().getName() + "/" + 
             actualHtmlPublisherTarget.icon;
                          }else{
                              icon = "symbol-document-text"; 
                          }
                      }
                  } else {
                      icon = "symbol-document-text";
                  }
                  return dir().exists() ? icon : null;
            }
      

      Would this be a useful improvement? If so, I'd be happy to submit a PR!

            Assignee:
            Unassigned
            Reporter:
            Giovanni
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: