Is there a way to list all add-ons and the spaces they are used on?
Asked by SteenerO:

Is there a way to list all installed add-ons and in what spaces they are used?


Answers:
author: Davin Studer
body: Here is a user macro that I have created for this. Just put it on a page and it should give you a report of all of the macros and user macros that are being used in your instance. This requires at least Confluence 5.5 as the MacroBrowserManager.getMacroSummaries() method was added in 5.5.

```
## Developed by: Davin Studer## Date created: 12/17/2014## @noparams #set($containerManagerClass = $content.class.forName('com.atlassian.spring.container.ContainerManager'))#set($getInstanceMethod = $containerManagerClass.getDeclaredMethod('getInstance',null))#set($containerManager = $getInstanceMethod.invoke(null,null))#set($containerContext = $containerManager.containerContext)#set($macroBrowserManager = $containerContext.getComponent('macroBrowserManager'))#set($allMacros = $macroBrowserManager.getMacroSummaries())########################################################################################### This is used for getting around velocity issues when writing jQuery.                ############################################################################################set( $d = '$' )########################################################################################### Populate the macro information into a string that we will use as a JS object array. ############################################################################################set ($i = 0)#set($macroObjects = "")#foreach($macro in $allMacros)  #if($i != 0)    #set($macroObjects = $macroObjects + ",")  #end  #set($macroObjects = $macroObjects + "{title:'" + $macro.getTitle().getKey().replace("'","\'") + "', name:'" + $macro.getMacroName().replace("'","\'") + "'}")#set ($i = $i + 1)#end&lt;script type="text/javascript"&gt;var queue = {    macros: [$macroObjects],    current: 0,    start: function () {        this.macros.sort(compare);        this.current = 0;        this.next();    },    next: function () {    	if (this.current &gt;= this.macros.length) {            AJS.$('#queryStatus span').removeClass('aui-lozenge-current');            AJS.$('#queryStatus span').addClass('aui-lozenge-success');            AJS.$('#queryStatus span').text('Report Complete');            AJS.tablessortable.setTableSortable(AJS.$('#macroUsageReport table'));            return null;		}		else {			this.current += 1;			lookupMacro(this.macros[this.current - 1]);		}    }};function lookupMacro(macro) {    var html = '';    var searchURL = '';        AJS.$('#queryStatus span').text('Getting counts for macro: ' + macro.title);        searchURL = AJS.params.baseUrl + '/rest/searchv3/1.0/search?where=conf_all&amp;spaceSearch=true&amp;queryString=macroName:' + encodeURIComponent(macro.name);    AJS.${d}.ajax(        {            type: 'GET',            url: searchURL,            dataType: "json",            success: function(data) {                if(data.total &gt; 0) {                    var spaces = '';                    for(var i = 0; i &lt; data.results.length; i++)                    {                        if(spaces.indexOf(data.results[i].searchResultContainer.name) == -1)                        {                            spaces = spaces == '' ? '' : spaces + ', ';                            spaces = spaces + data.results[i].searchResultContainer.name;                        }                    }                    html = '&lt;tr&gt;';                    html += '   &lt;td class="confluenceTd"&gt;' + macro.title + '&lt;/td&gt;';                    html += '   &lt;td class="confluenceTd"&gt;' + macro.name + '&lt;/td&gt;';                    html += '   &lt;td class="confluenceTd"&gt;' + data.total + '&lt;/td&gt;';                    html += '   &lt;td class="confluenceTd"&gt;' + spaces + '&lt;/td&gt;';                    html += '   &lt;td class="confluenceTd"&gt;&lt;a href="' + AJS.params.baseUrl + '/dosearchsite.action?where=conf_all&amp;spaceSearch=true&amp;queryString=macroName:' + encodeURIComponent(macro.name) + '" target="_blank"&gt;macro usage&lt;/a&gt;&lt;/td&gt;';                    html += '&lt;/tr&gt;';                }                AJS.$('#macroUsageReport table tbody').append(html);                                queue.next();            },            error: function (x, y, z) {                AJS.$('#queryStatus span').removeClass('aui-lozenge-current');                AJS.$('#queryStatus span').addClass('aui-lozenge-error');                AJS.$('#queryStatus span').text('Error getting counts for macro:' + macro.title);            }        }    );}function compare(a, b) {    if (a.title &lt; b.title) {        return -1;    }    if (a.title &gt; b.title) {        return 1;    }    return 0;}AJS.toInit(function(){    queue.start();    });&lt;/script&gt;&lt;div id="queryStatus"&gt;    &lt;span class="status-macro aui-lozenge aui-lozenge-current"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div id="macroUsageReport"&gt;    &lt;table class="confluenceTable"&gt;        &lt;thead&gt;            &lt;tr&gt;                &lt;th&gt;Macro Title&lt;/th&gt;                &lt;th&gt;Macro Name&lt;/th&gt;                &lt;th&gt;Times Used&lt;/th&gt;                &lt;th&gt;Spaces Used In&lt;/th&gt;                &lt;th&gt;Pages Used On&lt;/th&gt;            &lt;/tr&gt;        &lt;/thead&gt;        &lt;tbody&gt;        &lt;/tbody&gt;    &lt;/table&gt;&lt;/div&gt;
```


author: DebbieR
body: Hi Davin,

Thank you for sharing. Is that all you have to do as it didn't work for me. All I see is the code on the page? I am on Confluence 5.5.3.

Thanks

comments: author: Davin Studer
body: You have to make a user macro out of it. Go to Confluence Admin -\> User Macros to set it up. Then just put the macro on the page you want once you have created it.


author: DebbieR
body: Thanks so much David. Works perfectly. Sorry I'm a beginner. Just one final question, is it ok to have the macro on a page as it builds the report each time the page is loaded, or am I better off instructing staff to see a list of all add ons, install the macro and then run it? ie: does it do any damage having the macro on the page building the report each time? Thanks again


author: Davin Studer
body: It doesn't hurt to put it on a page and have it run each time.


author: Daniel Wester
body: Yes and no. You can go into the database and do a sql query for the macro content but some add ons will add in event listeners, other servlets etc which you wouldn't be able to do that for. Take a look at <https://answers.atlassian.com/questions/59203> for more details.


Tags: confluence-administration