Create Scripts with Code Completion in IntelliJ

I just found out there is an easy way to use IntelliJ IDEA to create and start Epos Scripts. This allows you to use full code completion and documentation in the code editor :)

To set things up, install Epos and IntelliJ IDEA and create a new Maven Project. In the Projects pom.xml, add the epos repository and a single dependency to the full Epos Application:


<repositories>
  <repository>
    <id>bioinf-jena</id>
    <url>http://bio.informatik.uni-jena.de/artifactory/repo</url>
    <name>Bioinf Jena</name>
  </repository>
</repositories>
<dependencies>
  <dependency>
    <groupId>de.unijena.bioinf</groupId>
    <artifactId>epos</artifactId>
    <version>0.9</version>
  </dependency>
</dependencies>

Now create a new Groovy Script in src/main/java, say TestScript.groovy and enter the following code:


import epos.model.tree.io.Newick

def tree = Newick.getTreeFromString("((A,B),C);")
tree.getRoot().depthFirstIterator().each { n->
  println "Node : ${n}"
}

Notice that you should already have full code completion now. You can also open the “Maven Projects” tab on the right and click on “Download Sources and Documentation” to get access to the Epos source code and JavaDoc comments (the download might take a while). For example, move the cursor over the depthFirstIterator call and press Ctrl-Q (or CMD-J on a Mac) to get JavaDoc comments. You can also press Ctrl-B (or CMD-B) to jump to the source.

Intellij Javadoc comment

Last but not least, we have to set up an External Tool to start our script right from within idea. You need this if you want to access epos instances from within the script, for example the workspace or the job handler. In the IDEA main menu, select File->Settings and search for External Tools. Create a new External tool and enter the following:

  • An arbitrary Name and Description (i.e. Epos)
  • Programm: The full path to the epos executable
  • Parameters: -s –db MEM –script $FilePath$
  • Working Directory: $FileDir$

This will start the given Epos installation and pass the path to the file currently opened in IntelliJ as script parameter. The files directory (i.e. src/main/java ) is used as working directory.

External Tool Configuration

Now, in the the script, you can use the main menu Tool-> Epos to start the current Script in Epos (note that the name depends on the name you entered before).

4 Comments

  1. EPOS says:

    Good working code to create scripts.Thanks

  2. mike says:

    looking great bruv not long to go now

  3. fantastic post, very informative. I ponder why the opposite experts of this sector do not notice this. You must proceed your writing. I am sure, you have a great readers’ base already!

Leave a Reply