Skip to content
This repository has been archived by the owner on Oct 26, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Siavash Safi committed Aug 9, 2017
0 parents commit 4fdc5b2
Show file tree
Hide file tree
Showing 14 changed files with 7,220 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
.DS_Store

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Catawiki B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Prism is a `{code}` macro plugin for Atlassian JIRA.

## Features
* Support for many programming languages
* Client side syntax highlighting using [Prism](http://prismjs.com/)

## Build
Install **Atlassian Plugin SDK** and run `atlas-package`.

## Usage
Default language is Ruby:

```
{code}
class Bar < Foo
def initialize(a)
@a = a
end
end
{code}
```

You can specify another language:

```
{code:java}
public class Bar extends Foo {
private int a;
public Bar(int a) {
this.a = a;
}
}
{code}
```

## Issues
Visual editing in Rich Text Editor is not supported. While you don't have to disable Rich Text Editor in JIRA, you cannot use the **visual tab** to do code editing.

## Notes
This plugin uses a slightly modified version of [Prism](http://prismjs.com/) to fix JS compile issues in Atlassian Plugin SDK.

This plugin is released without any support, if you want to add a new feature or fix a bug feel free to submit a PR.

Also check [this JIRA Server issue](https://jira.atlassian.com/browse/JRASERVER-21067) regarding `{code}` macro limitations and why this plugin was developed.
177 changes: 177 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?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.catawiki.jira</groupId>
<artifactId>prism</artifactId>
<version>1.0.0</version>

<organization>
<name>Catawiki B.V.</name>
<url>https://www.catawiki.com/</url>
</organization>

<name>Prism</name>
<description>Code syntax highlighting plugin for Atlassian JIRA.</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<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>

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

<!-- 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>
<!-- 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>
com.catawiki.jira.prism,
</Export-Package>

<!-- Add package import here -->
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;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>
</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>
<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>

</project>
55 changes: 55 additions & 0 deletions src/main/java/com/catawiki/jira/prism/Code.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.catawiki.jira.prism;

import com.atlassian.jira.template.soy.SoyTemplateRendererProvider;
import com.atlassian.renderer.RenderContext;
import com.atlassian.renderer.v2.RenderMode;
import com.atlassian.renderer.v2.macro.BaseMacro;
import com.atlassian.renderer.v2.macro.MacroException;
import com.atlassian.soy.renderer.SoyException;
import com.atlassian.soy.renderer.SoyTemplateRenderer;
import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class Code extends BaseMacro {

private static final String FALLBACK_RENDER_OUTPUT = "{noformat}%s{noformat}";

private final SoyTemplateRenderer soyTemplateRenderer;

public Code(final SoyTemplateRendererProvider soyTemplateRendererProvider) {
super();
this.soyTemplateRenderer = soyTemplateRendererProvider.getRenderer();
}

@Override
public boolean hasBody() {
return true;
}

@Override
public RenderMode getBodyRenderMode() {
return RenderMode.allow(RenderMode.F_NONE);
}

@Override
public String execute(Map<String, Object> parameters, String body, RenderContext renderContext) throws MacroException {

ImmutableMap.Builder<String, Object> templateParams = ImmutableMap.builder();
templateParams.put("content", body);
String language = "ruby";
if (parameters.get("0") != null) {
language = (String) parameters.get("0");
}
templateParams.put("language", language);

try {
return this.soyTemplateRenderer.render(
"com.catawiki.jira.prism:handler",
"Prism.Macros.Code.html",
templateParams.build());
} catch (SoyException e) {
return String.format(FALLBACK_RENDER_OUTPUT, body);
}
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/catawiki/jira/prism/Init.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.catawiki.jira.prism;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import com.atlassian.plugin.PluginController;

public class Init implements InitializingBean, DisposableBean {

private static final String STANDARD_JIRA_CODE_MACRO = "com.atlassian.jira.plugin.system.renderers.wiki.macros:code";
private static final String STANDARD_JIRA_NOFORMAT_MACRO = "com.atlassian.jira.plugin.system.renderers.wiki.macros:noformat";

private final PluginController pluginController;

public Init(PluginController pc){
this.pluginController = pc;
}

/**
* Called when JIRA Syntax Highlighter is being disabled or removed. Enables JIRA standard
* Wiki Renderer Macro Plugin for {code}.
*
* @throws Exception
*/
public void destroy() throws Exception {
pluginController.enablePluginModule(STANDARD_JIRA_CODE_MACRO);
}

/**
* Called when JIRA Syntax Highlighter has been enabled. Disables JIRA standard Wiki Renderer
* Macro Plugin for {code}.
*
* @throws Exception
*/
public void afterPropertiesSet() throws Exception {
pluginController.disablePluginModule(STANDARD_JIRA_CODE_MACRO);
}

}
10 changes: 10 additions & 0 deletions src/main/resources/META-INF/spring/plugin-context.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.atlassian.com/schema/atlassian-scanner
http://www.atlassian.com/schema/atlassian-scanner/atlassian-scanner.xsd">
<atlassian-scanner:scan-indexes/>
</beans>
Loading

0 comments on commit 4fdc5b2

Please sign in to comment.