Hello! I have to write stash plugin, that connects to JIRA by rest. What I wrote for test:
package com.*******.stash.plugin.autocloseissue; import java.net.URI; import com.atlassian.event.api.EventListener; import com.atlassian.jira.rest.client.api.JiraRestClient; import com.atlassian.jira.rest.client.api.JiraRestClientFactory; import com.atlassian.jira.rest.client.api.domain.Issue; import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory; import com.atlassian.stash.event.pull.PullRequestMergedEvent; import com.atlassian.stash.pull.PullRequest; import com.atlassian.stash.pull.PullRequestState; import com.atlassian.stash.repository.Repository; public class AutoCloseIssue { @EventListener public void onPullRequestMerged(PullRequestMergedEvent event) throws Exception { final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); final URI jiraServerUri = new URI("http://jira.*******.com/"); final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "*******", "*******"); final Issue issue = restClient.getIssueClient().getIssue("TL-25").claim(); final PullRequest pr = event.getPullRequest(); final Repository repo = pr.getToRef().getRepository(); } }
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2"> <plugin-info> <description>${project.description}</description> <version>${project.version}</version> <vendor name="${project.organization.name}" url="${project.organization.url}" /> <param name="plugin-icon">images/pluginIcon.png</param> <param name="plugin-logo">images/pluginLogo.png</param> </plugin-info> <!-- publish our component --> <component key="AutoCloseIssue" class="com.*******.stash.plugin.autocloseissue.AutoCloseIssue" /> </atlassian-plugin>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.*******.stash.plugin.autocloseissue</groupId> <artifactId>autocloseissue-plugin</artifactId> <version>1.0-SNAPSHOT</version> <organization> <name>*****</name> <url>http://www.******.com/</url> </organization> <name>autocloseissue-plugin</name> <description>This is the Stash plugin for automatic close issue after pull request merged.</description> <packaging>atlassian-plugin</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-parent</artifactId> <version>${stash.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.atlassian.sal</groupId> <artifactId>sal-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-spi</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-page-objects</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-api</artifactId> <version>6.4.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-api</artifactId> <version>2.0.0-m31</version> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>2.0.0-m31</version> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-plugin</artifactId> <version>6.4.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.9.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</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> </dependencies> <build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-stash-plugin</artifactId> <version>${amps.version}</version> <extensions>true</extensions> <configuration> <products> <product> <id>stash</id> <instanceId>stash</instanceId> <version>${stash.version}</version> <dataVersion>${stash.data.version}</dataVersion> </product> </products> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> <properties> <stash.version>3.8.0</stash.version> <stash.data.version>3.8.0</stash.data.version> <amps.version>5.0.13</amps.version> <plugin.testrunner.version>1.2.3</plugin.testrunner.version> </properties> </project>
But when I upload plugin to stash and restart it, tomcat has exception:
Exception in thread "ThreadPoolAsyncTaskExecutor::Thread 20" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'activator' defined in URL [bundle://42.0:0/META-INF/spring/atlassian-plugins-components.xml]: Invocation of init method failed; nested exception is com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.HeaderDelegateProvider: The class com.sun.jersey.core.impl.provider.header.LocaleProvider implementing provider interface com.sun.jersey.spi.HeaderDelegateProvider could not be instantiated: Cannot cast com.sun.jersey.core.impl.provider.header.LocaleProvider to com.sun.jersey.spi.HeaderDelegateProvider at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:473) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355) at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85) at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320) at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: com.sun.jersey.spi.service.ServiceConfigurationError: com.sun.jersey.spi.HeaderDelegateProvider: The class com.sun.jersey.core.impl.provider.header.LocaleProvider implementing provider interface com.sun.jersey.spi.HeaderDelegateProvider could not be instantiated: Cannot cast com.sun.jersey.core.impl.provider.header.LocaleProvider to com.sun.jersey.spi.HeaderDelegateProvider at com.sun.jersey.core.osgi.Activator$OsgiServiceFinder$1.next(Activator.java:80) at com.sun.jersey.core.spi.factory.AbstractRuntimeDelegate.<init>(AbstractRuntimeDelegate.java:76) at com.sun.jersey.server.impl.provider.RuntimeDelegateImpl.<init>(RuntimeDelegateImpl.java:54) at com.sun.jersey.server.osgi.Activator.start(Activator.java:63) at com.atlassian.plugins.rest.module.Activator.afterPropertiesSet(Activator.java:22) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335) ... 19 more Caused by: java.lang.ClassCastException: Cannot cast com.sun.jersey.core.impl.provider.header.LocaleProvider to com.sun.jersey.spi.HeaderDelegateProvider at java.lang.Class.cast(Unknown Source) at com.sun.jersey.core.osgi.Activator$OsgiServiceFinder$1.next(Activator.java:78) ... 25 more
I think, that collision with different versions of rest-library. But how can I fix it?
Community moderators have prevented the ability to post new answers.
I found solution: don't use import
com.atlassian.jira.rest.client.api.* but
import
com.atlassian.jira.rest.client.*:
package com.*******.stash.plugin.autocloseissue; import java.net.URI; import com.atlassian.event.api.EventListener; import com.atlassian.jira.rest.client.JiraRestClient; import com.atlassian.jira.rest.client.JiraRestClientFactory; import com.atlassian.jira.rest.client.domain.Issue; import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory; import com.atlassian.stash.event.pull.PullRequestMergedEvent; import com.atlassian.stash.pull.PullRequest; import com.atlassian.stash.pull.PullRequestState; import com.atlassian.stash.repository.Repository; public class AutoCloseIssue { @EventListener public void onPullRequestMerged(PullRequestMergedEvent event) throws Exception { final JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory(); final URI jiraServerUri = new URI("http://jira.*******.com/"); final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, "*******", "*******"); final Issue issue = restClient.getIssueClient().getIssue("TL-25").claim(); final PullRequest pr = event.getPullRequest(); final Repository repo = pr.getToRef().getRepository(); } }
And in pom.xml don't use jira-rest-java-client-api and jira-rest-java-client-core but jira-rest-java-client:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.******.stash.plugin.autocloseissue</groupId> <artifactId>autocloseissue-plugin</artifactId> <version>1.0-SNAPSHOT</version> <organization> <name>******</name> <url>http://www.******.com/</url> </organization> <name>autocloseissue-plugin</name> <description>This is the Stash plugin for automatic close issue after pull request merged.</description> <packaging>atlassian-plugin</packaging> <dependencyManagement> <dependencies> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-parent</artifactId> <version>${stash.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>com.atlassian.sal</groupId> <artifactId>sal-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-spi</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.stash</groupId> <artifactId>stash-page-objects</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-api</artifactId> <version>6.4.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client</artifactId> <version>2.0.0-m2</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> <exclusion> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-json</artifactId> </exclusion> <exclusion> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </exclusion> <exclusion> <groupId>com.atlassian.sal</groupId> <artifactId>sal-api</artifactId> </exclusion> <exclusion> <groupId>com.atlassian.event</groupId> <artifactId>atlassian-event</artifactId> </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </exclusion> <exclusion> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </exclusion> <exclusion> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> </exclusion> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </exclusion> <exclusion> <groupId>com.sun.jersey</groupId> <artifactId>jersey-core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</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> </dependencies> <build> <plugins> <plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-stash-plugin</artifactId> <version>${amps.version}</version> <extensions>true</extensions> <configuration> <products> <product> <id>stash</id> <instanceId>stash</instanceId> <version>${stash.version}</version> <dataVersion>${stash.data.version}</dataVersion> </product> </products> </configuration> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> <properties> <stash.version>3.8.0</stash.version> <stash.data.version>3.8.0</stash.data.version> <amps.version>5.0.13</amps.version> <plugin.testrunner.version>1.2.3</plugin.testrunner.version> </properties> </project>
Hi Pavel!
Please see Igor Yastrebov's answer here: https://answers.atlassian.com/questions/288618
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, I saw it. So I have <dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-client</artifactId> <version>1.9.1</version> <scope>provided</scope> </dependency> in my pow.xml. It doesn't help for me. =(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you check maven dependencies tree? Maybe some other package brings the jersey-client.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I checked, but didn't see any jersey-client except mine. There is full build log: http://pastebin.com/Cze5H7cE
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see: [INFO] Unpacking /home/pagrom/.m2/repository/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar to /home/pagrom/Win/Users/pgromov/autocloseissue-plugin/target/classes To be sure check your final jar to make sure that it does not contain the jersey client.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.