Disable YUI compressor
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<compressResources>false</compressResources>
[..]
</configuration>
</plugin>
Confluence – Get favourites by user
Using the label manager.
List getFavouriteSpaces(String username)
Confluence – Determine the base URL
Using the SettingsManager:
String baseUrl = settingsManager.getGlobalSettings().getBaseUrl();
Confluence – Get the context path
Using the BootstrapManager:
String contextPath = bootstrapManager.getWebAppContextPath();
Confluence – Using Velocity Template for a Macro
final VelocityContext contextMap = new VelocityContext(MacroUtils.defaultVelocityContext());
contextMap.put("key", obj); // references obj as variable named $key in the velocity template
VelocityUtils.getRenderedTemplate("path/to/template.vm", contextMap);
Confluence – Perform a content search with restrictions
final SearchManager searchManager // <- injected
final SearchQuery inSpacesQuery = new InSpaceQuery("DS");
final SearchQuery contentTypeQuery = new ContentTypeQuery(ContentTypeEnum.ATTACHMENT);
final SearchQuery query = BooleanQuery.andQuery(inSpacesQuery,contentTypeQuery);
final SearchSort searchSort = new CreatedSort(Order.DESCENDING);
final SearchFilter contentPermissionFilter = ContentPermissionsSearchFilter.getInstance();
final SearchFilter spacePermissionFilter = SpacePermissionsSearchFilter.getInstance();
final SearchFilter permissionsFilter = new ChainedSearchFilter(contentPermissionFilter, spacePermissionFilter);
final ResultFilter maxResultFilter = new SubsetResultFilter(20);
final ISearch search = new ContentSearch(query, searchSort,permissionsFilter, maxResultFilter);
final SearchResults results = searchManager.search(search);
Reference exported Web Resources like CSS/JS in a Velocity Template
Include this directive in the velocity template:
#requireResource("PLUGINKEY:WEBRESOURCEKEY")
Example declaration of a web resource in the atlassian-plugin.xml
:
<web-resource name="Some Web Resources" i18n-name-key="some-web-resources.name" key="WEBRESOURCEKEY">
<description key="some-web-resources.description">Some Web Resources</description>
<resource name="some.css" type="download" location="somepath/some-min.css"/>
</web-resource>
Webworks/XWorks Action – Rendering a template without the page frame
Applying the parameter decorator=popup or decorator=none is one option.
Another option is to specify the decorator in the velocity template’s header section
<head>
<meta name="decorator" content="atl.popup" />
</head>
Bitbucket – Stash – Enable a Package Logger via REST
curl -u admin -v -X PUT -d "" -H "Content-Type: application/json" http://localhost:7990/stash/rest/api/latest/logs/logger/com.hascode/debug
JIRA – Find existing locations for web-items and web-sections
Their declarations can be found in <source-installation-directory>/jira-project/jira-components/jira-core/src/main/resources/webfragment/system-user-nav-bar-sections.xml
JIRA – Detect current JIRA version
This utility class helps matching versions against the current version
package com.hascode.jira.workflow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.atlassian.jira.util.BuildUtilsInfo;
import com.google.common.primitives.Ints;
public class JiraVersionHelper {
private static final Logger logger = LoggerFactory.getLogger(JiraVersionHelper.class);
private final BuildUtilsInfo buildUtilsInfo;
public JiraVersionHelper(final BuildUtilsInfo buildUtilsInfo) {
this.buildUtilsInfo = buildUtilsInfo;
}
public boolean currentVersionGreaterOrEqualThan(int major, int minor, int micro) {
int[] version = { major, minor, micro };
if (Ints.lexicographicalComparator().compare(buildUtilsInfo.getVersionNumbers(), version) >= 0) {
if (logger.isDebugEnabled()) {
logger.debug("given version {}.{}.{} is greater or equal than the current JIRA version: {}", major,
minor, micro, buildUtilsInfo.getVersion());
}
return true;
}
if (logger.isDebugEnabled()) {
logger.debug("given version {}.{}.{} is smaller than the current JIRA version: {}", major, minor, micro,
buildUtilsInfo.getVersion());
}
return false;
}
}
Confluence – Search for Spaces by Space Label
Label label …
List spaces = labelManager.getSpacesWithLabel(label);
or
List spaces = labelManager.getSpacesWithLabel("labelString", Namespace.GLOBAL);
Confluence – Read User Details
for (String group : userDetailsManager.getProfileGroups()) {
System.err.println(“Group: ” + group + ” has keys:”);
for (String key : userDetailsManager.getProfileKeys(group)) {
System.err.println(“key: ” + key + ” / current user’s value: ” + userDetailsManager.getStringProperty(currentUser, key));
}
}
Group: personal has keys:
key: phone / current user’s value: 1234
key: im / current user’s value: -
key: website / current user’s value: www.hascode.com
Group: business has keys:
key: position / current user’s value: CTO
key: department / current user’s value: Technologies
key: location / current user’s value: Wiesbaden
ActiveObjects Create Entity with NotNull Constraint
The entity:
public interface Book extends Entity {
[..]
@NotNull
String getTitle();
}
Create a new book entity:
ActiveObjects ao; // -> set via dependency injection
Book book = ao.create(Book.class, new DBParam("TITLE", "some title"));