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.

<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:

$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:

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

<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
<dependency>
    <groupId>com.atlassian.plugins</groupId>
    <artifactId>atlassian-plugins-webresource</artifactId>
    <version>...</version>
</dependency>

Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport