Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Lightweight JIRA integration in IntelliJ IDEA

Topic of this post is a setup of simple JIRA integration in IntelliJ IDEA without Atlassian Plugin. Principals can be applied to any similar applications, like YouTrack. Plugins might provide extensive functionality for ticket management, but I find web application in browser good enough for that purpose and don't want to clutter my IDE with too much functionality. It is nice however to be able to jump to the current task description, or quickly navigate to tasks referenced in commit messages.

Pick a current ticket as a task

JIRA tickets can be shown as tasks. For start, open a task with a shortcut "Shift+Alt+N".

Clicking on settings icon will open task settings where new server can be added. Click plus (+), select JIRA and fill in the details:
Default search options will show only tasks assigned to you.
Take a note there is a commit message tab that you can customize to match your projects standards, it defaults to a common one: {id} {summary}
Now you can open task "Shift+Alt+N", pick one, and you will be presented with the dialog. Here I like to pick "Create Changelist" so all your changes for this task go into this changelist. There is possibility to create branch and change ticket status, but that can be done in respective tools(If you don't switch tickets that often).
When task is selected, you can open it in a browser at any time with shortcut "Alt+Shift+B".

Click on a ticket number in commit message

There is a beautiful feature of Version Control panel that can turn ticket numbers in commit messages and changelist names into links that open JIRA ticket in browser. It can be setup in Settings->Version Control->Issue Navigation. Here you add a new line where Issue ID is regular expression that should recognize ticket number. For example, ticket DATACMNS-975 can be covered with
[A-Z]+\-\d+
Expression can probably be improved, but this one is fine as well. Link should be issue URL with a placeholder for a ticket number. If link example is "https://jira.spring.io/browse/DATACMNS-975", then template would be:
https://jira.spring.io/browse/$0
After saving, look at the history of a project or a file. You should be able to click on a ticket number in commit messages in order to open them in a browser.

Iterator from Supplier

Creating an Iterator can be one step towards creating a stream from some resource. SupplierIterator takes only a Supplier and uses buffer for the next value. Example is inspired by java.io.BufferedReader.lines() method.

public class SupplierIterator<T> implements Iterator<T> {
   private T buffer = null;
   private Supplier<T> supplier;

   public SupplierIterator(Supplier<T> supplier) {
      this.supplier = supplier;
   }

   @Override
   public boolean hasNext() {
      return (buffer != null) ||
         (buffer = supplier.get()) != null;
   }

   @Override
   public T next() {
      if (hasNext()) {
         T next = buffer;
         buffer = null;
         return next;
      } else {
         throw new NoSuchElementException();
      }
   }
}

Get Stream from Iterator

If you have a class implementing Iterable, you can get a Stream over elements just by:
StreamSupport.stream(iterable.spliterator(), false);
 If the class doesn't already have a stream method. But if you only have an iterator and still want to use streams, you can use the fact that Iterable is a functional interface since it has only one non-default method, so if you already have an iterator, you can create Iterable by:
Iterable<String> iterable = () -> iterator;
It returns always the same iterator, so it is more a hack then a solution, but approach can be used by one of those classes that can produce iterator but are not implementing Iterable interface.
Iterable<String> iterable = () -> legacyClass.iterator();
return StreamSupport.stream(iterable.spliterator(), false);