Web resources

Fisheye/Crucible plugins may define downloadable resources.If your plugin requires Fisheye/Crucible to include additional static Javascript or CSS files, you will need to use downloadable web resources to make them available. Web resources are included for download, at the top of the page in the HTML's header.

Web resources can also take advantage of caching (i.e. only download a resource if it has changed) and batching (i.e. serve multiple files in one request). If you would like to include other static files for download, such as images, please see Downloadable Plugin Resources.

Defining a Single Web Resource

Downloadable resources are configured to map a name of some downloadable file to its location within the plugin jar-file.

1
2
<web-resource key="autofavourite-resources" name="Auto-Favourite Resources">
    <resource type="download" name="autofavourite.css" location="autofavourite.css"/>
</web-resource>
  • Resources must be contained within a webresource tag.
  • The key of the webresource is how it will be referenced from within the application
  • Each resource must be of type="download"
  • The name of the resource will be suffixed to the URL
  • The location of the resource is where it appears within the plugin itself

Referring to Web Resources

In your plugin's Velocity template, you need to refer to a WebResourceManager, and call the requireResource() method:

1
2
$webResourceManager.requireResource("com.atlassian.fisheye.plugin.autofavourite:autofavourite-resources")

Because Fisheye/Crucible does not transparently support template engines like Velocity of Freemarker, you will need to register the WebResourceManager in the page context yourself, before passing control to your template engine of choice.

For instance, to use a web-resource in a velocity template, let Fisheye/Crucible inject both the VelocityHelper and the WebResourceManager into your servlet and then register the WebResourceManager in the velocity context before invoking the template engine:

1
2
public class MyServlet extends HttpServlet {

    private final WebResourceManager webResourceManager;
    private VelocityHelper velocityHelper;

    @Autowired
    public MyServlet(WebResourceManager webResourceManager, VelocityHelper velocityHelper) {
        this.webResourceManager = webResourceManager;
        this.velocityHelper = velocityHelper;
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        final Map<String, Object> context = new HashMap<String, Object>();
        context.put("webResourceManager", webResourceManager);

        response.setContentType("text/html");
        velocityHelper.renderVelocityTemplate(
                getClass().getResourceAsStream("/templates/myPageTemplate.vm"),
                context, response.getWriter());
    }
}

You can then use the web-resource in the template /templates/myPageTemplate.vm

1
2
<html>
<head>
    <title>My Plugin</title>
    $webResourceManager.requireResource("com.atlassian.fisheye.plugin.myplugin:my-resources")
</head>

<body>
  ...
</body>
</html>

To be able to use the WebResourceManager, make sure you include com.atlassian.plugins:atlassian-plugins-webresource to your project's dependencies:

pom.xml

1
2
<dependency>
    <groupId>com.atlassian.plugins</groupId>
    <artifactId>atlassian-plugins-webresource</artifactId>
    <version>...</version>
</dependency>

Rate this page: