Once again I am back with questions and am hoping someone here can help me out.
I’ve been preparing my add-on for the marketplace and have been following this tutorial while doing it: https://developer.atlassian.com/platform/marketplace/ommitting-web-resources-for-unlicensed-server-apps/ but I seem to have once again hit upon a wall I can’t get past.
I’ve been following the tutorial (which I’m implementing in my own add-on) bu no matter what I do the add-on doesn’t work when I try to test it. Can someone point me to what I’m doing wrong?
ConditionEvaluator
public interface ConditionEvaluator
{
public boolean evaluate(ConditionType type);
}
ConditionEvaluatorImpl
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.upm.api.license.PluginLicenseManager;
import com.atlassian.upm.api.license.entity.PluginLicense;
import javax.inject.Inject;
@Scanned
public class ConditionEvaluatorImpl implements ConditionEvaluator
{
@ComponentImport
PluginLicenseManager licenseManager;
@Inject
public ConditionEvaluatorImpl(final PluginLicenseManager licenseManager)
{
this.licenseManager = licenseManager;
}
@Override
public boolean evaluate(ConditionType type)
{
switch (type)
{
case LICENSED:
return isLicenseValid();
default:
return false;
}
}
private boolean isLicenseValid()
{
boolean isLicensed = false;
boolean hasErrors = false;
for (PluginLicense pluginLicense : licenseManager.getLicense())
{
isLicensed = true;
hasErrors = hasErrors || pluginLicense.getError().isDefined();
}
isLicensed = isLicensed && !hasErrors;
return isLicensed;
}
}
ConditionType
public enum ConditionType
{
LICENSED
}
IsPluginLicensedCondition
import com.atlassian.plugin.webresource.condition.SimpleUrlReadingCondition;
public class IsPluginLicensedCondition extends SimpleUrlReadingCondition
{
private ConditionEvaluator conditionEvaluator;
public IsPluginLicensedCondition(final ConditionEvaluator conditionEvaluator)
{
this.conditionEvaluator = conditionEvaluator;
}
@Override
protected boolean isConditionTrue()
{
return conditionEvaluator.evaluate(ConditionType.LICENSED);
}
@Override
protected String queryKey()
{
// This string will be appended to URLs as a GET parameter
// whenever 'isConditionTrue' returns true.
// You should make the string short, but unique to your app.
return "myPluginName";
}
}
atlassian-plugin.xml
<plugin-info>
<version>${project.version}</version>
<param name="atlassian-licensing-enabled">true</param>
<vendor name="${project.organization.name}" url="${project.organization.url}"/>
</plugin-info>
<web-resource key="tigSearchbarExtension-resources" name="tigSearchbarExtension Web Resources">
<condition class="tig.jira.extension.tigSearchbarExtension.service.IsPluginLicensedCondition"/>
<dependency>com.atlassian.auiplugin:ajs</dependency>
<resource type="download" name="tigSearchbarExtension.js" location="/js/tigSearchbarExtension.js"/>
<resource type="download" name="searchBar.css" location="/css/searchBar.css"/>
<resource type="download" name="images/" location="/images"/>
</web-resource>
pom.xml
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
<!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
<!--
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-core</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-runtime</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<!-- Licensing
<dependency>
<groupId>com.atlassian.upm</groupId>
<artifactId>licensing-api</artifactId>
<version>2.21.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.upm</groupId>
<artifactId>upm-api</artifactId>
<version>2.21</version>
<scope>provided</scope>
</dependency>-->
<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-osgi-testrunner</artifactId>
<version>${plugin.testrunner.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2-atlassian-1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.atlassian.plugins</groupId>
<artifactId>atlassian-plugins-webresource-api</artifactId>
<version>3.5.39</version>
</dependency>
<dependency>
<groupId>com.atlassian.upm</groupId>
<artifactId>upm-api</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>com.atlassian.upm</groupId>
<artifactId>licensing-api</artifactId>
<version>2.21.4</version>
</dependency>
<!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
<!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
<!--
<dependency>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-client</artifactId>
<version>${testkit.version}</version>
<scope>test</scope>
</dependency>
-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<productDataPath>${project.basedir}/src/test/resources/generated-test-resources.zip</productDataPath>
<applications>
<application>
<applicationKey>jira-servicedesk</applicationKey>
<version>${jira.servicedesk.application.version}</version>
</application>
</applications>
<!-- Uncomment to install TestKit backdoor in JIRA. -->
<!--
<pluginArtifacts>
<pluginArtifact>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-plugin</artifactId>
<version>${testkit.version}</version>
</pluginArtifact>
</pluginArtifacts>
-->
<enableQuickReload>true</enableQuickReload>
<enableFastdev>false</enableFastdev>
<!-- See here for an explanation of default instructions: -->
<!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>
tig.jira.extension.tigSearchbarExtension.api,
</Export-Package>
<!-- Add package import here -->
<Import-Package>org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
avax.ws.rs*;version="[1,2)",
javax.servlet*;version="2.5",
javax.xml.bind*;version="[2.1,3)",
*;version="0";resolution:=optional, *</Import-Package>
<!-- Ensure plugin is spring powered -->
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jira.version>7.2.2</jira.version>
<amps.version>6.2.11</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<jira.servicedesk.application.version>3.2.2</jira.servicedesk.application.version>
<atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
<!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<!-- TestKit version 6.x for JIRA 6.x -->
<testkit.version>6.3.11</testkit.version>
</properties>